/* * Main.c * * Created on: 2019年8月6日 * Author: 7564 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ #include #include #include #include #include #include #include #include "./ShareMemory/shmMem.h" #include "./Define/define.h" #include "./SelectGun/SelectGun.h" #include "Config.h" #include "./ModuleEvComm/Module_EvComm.h" #include "./CSU/main.h" #include "common.h" //------------------------------------------------------------------------------ #define CMD_KEY_WAIT (1) #define CMD_KEY_DONT_WAIT (0) #define DEFAULT_AC_INDEX (2) #define AUTORUN_STEP1_TIME_START (140) // Minutes #define AUTORUN_STEP1_TIME_END (150) #define AUTORUN_STEP2_TIME_START (210) #define AUTORUN_STEP2_TIME_END (410) #define AUTORUN_END_TIME (480) #define AUTORUN_CYCLE_COUNT (30) #define TTY_PATH "/dev/tty" #define STTY_US "stty raw -echo -F " #define STTY_DEF "stty -raw echo -F " #define OPTION_CNT 4 #define STR_OPTION '-' #define OPTION_REFLASH 0x00000001 #define OPTION_LOOP 0x00000002 #define OPTION_OUTPUT_FILE 0x00000004 #define OPTION_TIME 0x00000008 //------------------------------------------------------------------------------ uint8_t _curAutoRunCount = 0; uint8_t _usingAutoRun = 0; struct timeval _autoTime; static struct SysConfigData *pSysConfig = NULL; static struct SysInfoData *pSysInfo = NULL; static struct WARNING_CODE_INFO *pSysWarning = NULL; static struct AlarmCodeData *pAlarmCode = NULL; static struct PrimaryMcuData *ShmPrimaryMcuData = NULL; static struct CHAdeMOData *ShmCHAdeMOData = NULL; static struct CcsData *ShmCcsData = NULL; static struct GBTData *ShmGBTData = NULL; static struct FanModuleData *ShmFanModuleData = NULL; static struct RelayModuleData *ShmRelayModuleData = NULL; static struct LedModuleData *ShmLedModuleData = NULL; static struct OCPP16Data *ShmOCPP16Data = NULL; static SelectGunInfo *ShmSelectGunInfo = NULL; static DcCommonInfo *ShmDcCommonData = NULL; static struct ChargingInfoData *pDcChargingInfo = NULL; static struct ChargingInfoData *pAcChargingInfo = NULL; static char newString[8][16] = {0}; //------------------------------------------------------------------------------ static int DiffTimeb(struct timeb ST, struct timeb ET) { //return milli-second unsigned int StartTime, StopTime; StartTime = (unsigned int)ST.time; StopTime = (unsigned int)ET.time; return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm; } static void get_char(char *word) { fd_set rfds; struct timeval tv; FD_ZERO(&rfds); FD_SET(0, &rfds); tv.tv_sec = 0; tv.tv_usec = 10; //wait input timout time //if input if (select(1, &rfds, NULL, NULL, &tv) > 0) { fgets(word, 128, stdin); } } static uint8_t helpCmd(void) { if (strcmp(newString[0], "?") == 0 || strcmp(newString[0], "help") == 0 || strcmp(newString[0], "h") == 0) { return YES; } return NO; } static uint8_t exitCmd(void) { if (strcmp(newString[0], "c") == EQUAL || strcmp(newString[0], "C") == EQUAL || strncmp(&newString[0][0], "exit", 4) == EQUAL ) { return YES; } return NO; } static uint8_t readCmdKey(uint8_t state) { char word[128] = {0}; int i = 0, j = 0, ctr = 0; memset(word, 0, sizeof(word)); if (state == CMD_KEY_WAIT) { fgets(word, sizeof(word), stdin); } else if (state == CMD_KEY_DONT_WAIT) { get_char(word); if (strlen(word) == 0) { //usleep(50000); return NO; } } memset(newString, 0, sizeof(newString)); strcpy(newString[1], "-1"); strcpy(newString[2], "-1"); for (i = 0; i <= (strlen(word)); i++) { if (word[i] == ' ' || word[i] == '\0' || word[i] == '\r' || word[i] == '\n' || word[i] == 10) { newString[ctr][j] = '\0'; ctr++; j = 0; } else { newString[ctr][j] = word[i]; j++; } } return YES; } unsigned long GetTimeoutValue(struct timeval _sour_time) { struct timeval _end_time; gettimeofday(&_end_time, NULL); return (_end_time.tv_sec - _sour_time.tv_sec); } // return command length int ParsingCmd(char *inputString, char *outputString) { bool valid = false, done = false; int len = 0, start = 0; for(int i = 0; i < strlen(inputString); i++) { if(!valid) { if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n') { valid = true; start = i; } } else { if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= 128) { done = true; break; } } len = (valid && !done) ? len + 1 : len; } if(valid) { memcpy(outputString, &inputString[start], len); outputString[len] = '\0'; } return len; } void ConsoleReflash(int groupCnt, int lineCnt) { for(int i = 0; i < groupCnt; i++) { for(int i = 0; i < lineCnt; i++) { printf("\033[1A"); printf("\033[K"); } } printf("\r"); } int GetCommandSring(char *outputCmdString) { int len = 0, cnt = 0; int cmdLen = 0, totalLen = 0; char word[128]; memset(word, 0x00, sizeof(word)); get_char(word); len = strlen(word); if(len == 0) { return -1; } int start = 0; while(start < len - 1) { if(word[start] != ' ' && word[start] != '\0') { cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]); char newCmd[128]; memset(newCmd, 0x00, 128); memcpy(newCmd, &outputCmdString[totalLen], cmdLen); cnt = cmdLen > 0 ? cnt + 1 : cnt; totalLen += cmdLen + 1; start += cmdLen; } else { start++; } } return cnt; } bool IsLoopStopCmd(void) { bool stop = false; int cnt = 0; char cmd[256]; char totalCmd[256]; memset(cmd, 0x00, 256); memset(totalCmd, 0x00, 256); cnt = GetCommandSring(totalCmd); if(cnt > 0) { strcpy(&cmd[0], totalCmd); if(strcmp(&cmd[0], "c") == 0) { stop = true; } } return stop; } char* GetStartMethodName(int method) { if (method == _CHARGING_START_RFID) { return "RFID"; } else if (method == _CHARGING_START_AUTOSTART) { return "AuthoStartCharging"; } else if (method == _CHARGING_START_REMOTESTART) { return "RemoteStart"; } else if (method == _CHARGING_START_EVCCID){ return "EVCCID"; } else { return "None"; } } void GunEnableInfo(uint8_t index) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index); char _time[30]; sprintf(_time,"%02d:%02d:%02d",(pDcChargingInfo->PresentChargedDuration/3600),(pDcChargingInfo->PresentChargedDuration%3600)/60,pDcChargingInfo->PresentChargedDuration%60); printf("\n"); printf("%s Gun Status = %s \t%s\n\tStartMethod:%s\tDuration:[%s] Temp:[%d:%d]\n",index ? "Right":"Left",GetStatusName(pDcChargingInfo->SystemStatus),pDcChargingInfo->ConnectorPlugIn ? "PlugIn" : "Unplug",GetStartMethodName(pDcChargingInfo->StartMethod),_time,ShmDcCommonData->ConnectorTemp[index][0],ShmDcCommonData->ConnectorTemp[index][1]); printf("\tEV Status:%d\tSoc:%d\n\tTargetVoltage:\t%05.2f V\t\tTargetCurrent:\t%05.2f A\n",ShmDcCommonData->pGunInfo[index].EVStatus,pDcChargingInfo->EvBatterySoc,pDcChargingInfo->EvBatterytargetVoltage,pDcChargingInfo->EvBatterytargetCurrent); printf("\tPresentVoltage:\t%05.2f V\t\tPresentCurrent:\t%05.2f A\n\tPresentPower:\t%05.2f kW\t\tPresentEngergy:\t%05.2f kWh\n", pDcChargingInfo->PresentChargingVoltage,pDcChargingInfo->PresentChargingCurrent,pDcChargingInfo->PresentChargingPower,pDcChargingInfo->PresentChargedEnergy); } void RunStatusProc() { bool keepRun = true; int time = 0; int dispenserLine = 0; struct timespec _Loop_time; printf("\r\n"); printf("Dispenser Info\r\n"); do { time = GetClockTimeoutValue(_Loop_time) / 1000; if(time >= 1000) { ConsoleReflash(1, 2); ConsoleReflash(pSysConfig->TotalConnectorCount, 7); dispenserLine = dispenserLine > 0 ? (dispenserLine + 1) : dispenserLine; ConsoleReflash(1, dispenserLine); dispenserLine = 0; printf("Dispenser Total Connector: %d chiller Temp[%03d:%03d:%03d:%03d]\r\n",pSysConfig->TotalConnectorCount, ShmDcCommonData->SystemTemp[0],ShmDcCommonData->SystemTemp[1], ShmDcCommonData->SystemTemp[2],ShmDcCommonData->SystemTemp[3]); for(int i = 0; i < pSysConfig->TotalConnectorCount; i++) { GunEnableInfo(i); } GetClockTime(&_Loop_time); } if(keepRun) { if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) { continue; } if (strcmp(newString[0], "c") == 0) { printf("Stop show status\n"); keepRun = FALSE; } } }while(keepRun); printf("\r\n"); } void RunCardProc(char *v1, char *v2) { if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) { if (pSysInfo->WaitForPlugit) { pSysInfo->WaitForPlugit = 0x00; printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit); } else { pSysInfo->WaitForPlugit = 0x01; printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit); } } else { strcpy((char *)pSysConfig->UserId, ""); memcpy((char *)pSysConfig->UserId, v1, strlen(v1)); pSysConfig->UserId[strlen(v1)] = '\0'; printf("StartUserId = %s \n", pSysConfig->UserId); } } void RunGunPlugitProc(char *v1, char *v2) { if (strcmp(v1, "ac") == 0) { //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) { // printf("FindChargingInfoData (AC) false \n"); //} pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0); if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) { // get printf("ConnectorPlugIn = %d \n", pAcChargingInfo->ConnectorPlugIn); } else { // set pAcChargingInfo->ConnectorPlugIn = atoi(v2); } return; } int _index = atoi(v1); //if (!FindChargingInfoData(_index, &_chargingData[0])) { // printf("FindChargingInfoData error\n"); // return; //} pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index); if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) { // get printf("index = %x, plug it = %x\n", _index, pDcChargingInfo->ConnectorPlugIn); } else { // set pDcChargingInfo->ConnectorPlugIn = atoi(v2); } } void GetGunLockStatusProc(char *v1, char *v2) { int _index = atoi(v1); //if (!FindChargingInfoData(_index, &_chargingData[0])) { // printf("FindChargingInfoData error\n"); // return; //} pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index); if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) { pDcChargingInfo->GunLocked = atoi(v2); } printf("Gun Locked Status = %d \n", pDcChargingInfo->GunLocked); } void SetSystemIDProc() { char *systemId = "Alston_Test"; memcpy(&pSysConfig->SystemId, systemId, strlen(systemId)); } void RunSelfProc() { printf("self test status = %x\n", pSysInfo->SelfTestSeq); } void GetFwVerProc(void) { printf("ModelName = %s\r\n", pSysConfig->ModelName); printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev); printf("DC Main Debug Version = %s \n", ShmDcCommonData->DebugVersion); printf("407 FW Version = %s\n", ShmPrimaryMcuData->version); printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev); printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev); printf("Relay Board Version = %s \n", pSysInfo->RelayModuleFwRev); printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev); printf("LED Version = %s \n", pSysInfo->LedModuleFwRev); if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) { printf("LCM HW Version = %s \n", ShmDcCommonData->pLcmInfo.verHW); printf("LCM OS Version = %s \n", ShmDcCommonData->pLcmInfo.verFW_OS); printf("LCM APK Version = %s \n", ShmDcCommonData->pLcmInfo.verFW_APK); printf("LCM UI Version = %s \n", ShmDcCommonData->pLcmInfo.verFW_UI); } else { printf("LCM FW Version = V.%03d \n", ShmDcCommonData->LcmFwVersion); } printf("Dispenser Network Information checked: IP = %s Netmask = %s, Gateway = %s \n", pSysConfig->Eth0Interface.EthIpAddress, pSysConfig->Eth0Interface.EthSubmaskAddress, pSysConfig->Eth0Interface.EthGatewayAddress); } void CreateOneError(char *v1) { int value = atoi(v1); pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = value; pSysConfig->BillingData.isBilling = value; } void GetAuthorizeFlag(char *v1) { if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) { printf("AuthorizeFlag = %d \n", pSysInfo->AuthorizeFlag); } else { pSysInfo->AuthorizeFlag = atoi(v1); } } void GetRelayStatus(char *v1) { uint8_t _GunIndex = 0; _GunIndex = atoi((char *)newString[1]); pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex); if (_GunIndex >= pSysConfig->TotalConnectorCount) _GunIndex = 0; printf("Gun%d RelayK1K2Status = %d \n", _GunIndex,pDcChargingInfo->RelayK1K2Status); //printf("Gun%d RelayKPK2Status = %d \n", _GunIndex,pDcChargingInfo->RelayKPK2Status); } void SetRelayStatus() { uint8_t _GunIndex = 0; int isContinue = 1; uint32_t sleepTime = 500000; uint8_t status = 0; char *usageMsg = "Usage:\n" " set , ex: set 0 1\n" " exit | c | C\n" " help | ? | h\n" "\r\n"; ShmDcCommonData->pTest.relayflag = YES; printf ("%s\n", usageMsg); while (isContinue) { if (readCmdKey(CMD_KEY_WAIT) == NO) { sleep(sleepTime); continue; } if (helpCmd() == YES) { printf ("%s\n", usageMsg); continue; } else if (exitCmd() == YES) { ShmDcCommonData->pTest.relayflag = NO; ShmDcCommonData->pGunInfo[0].RelayTest = NO; ShmDcCommonData->pGunInfo[1].RelayTest = NO; sleep(1); return; } else if (strcmp(newString[0], "get") == 0) { GetRelayStatus((char*)newString[1]); } if ((strcmp(newString[0], "set") != 0) && (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) ) { printf("argc 1 is error parameter\r\n"); continue; } if (strcmp(newString[0], "set") == 0) { if (atoi(newString[2]) > 1 || atoi(newString[2]) == -1 ) { printf("set value overflow\r\n"); continue; } } else { if (atoi(newString[2]) < 0 ) { printf("set value underflow\r\n"); continue; } } _GunIndex = atoi((char *)newString[1]); pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex); if (_GunIndex >= pSysConfig->TotalConnectorCount) { printf("gun index over total connector\r\n"); continue; } if (strcmp(newString[0], "set") == 0) {//修改relay狀態 status = atoi((char *)newString[2]); status ? (ShmDcCommonData->pGunInfo[_GunIndex].RelayTest = YES) : (ShmDcCommonData->pGunInfo[_GunIndex].RelayTest = NO); printf("gun%d relay set %s\n",_GunIndex,ShmDcCommonData->pGunInfo[_GunIndex].RelayTest ? "ON" : "OFF"); } usleep(sleepTime); }//while } void FwUpdateFlagProc() { pSysInfo->FirmwareUpdate = 0x01; } void SetCableChkStatus(char *v1, char *v2) { int _index = atoi(v1); //if (!FindChargingInfoData(_index, &_chargingData[0])) { // printf ("FindChargingInfoData error\n"); // return; //} pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index); pDcChargingInfo->GroundFaultStatus = atoi(v2); } void SetChargingInfoCCID(char *v1, char *v2) { int _index = atoi(v1); //if (!FindChargingInfoData(_index, &_chargingData[0])) { // printf ("FindChargingInfoData error\n"); // return; //} pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index); memcpy(pDcChargingInfo->EVCCID, v2, 8); pDcChargingInfo->EVCCID[8] = '\0'; } void SetPowerValue(char *v1, char *v2) { int _index = atoi(v1); float _Current = atof(v2); //if (!FindChargingInfoData(_index, &_chargingData[0])) { // printf ("FindChargingInfoData error\n"); // return; //} pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index); // 盲沖的時候才允許使用~ if (pDcChargingInfo->Type != 9) { return; } pDcChargingInfo->EvBatterytargetCurrent = _Current; } void GetSystemInfo() { printf ("ModelName = %s \n", pSysConfig->ModelName); printf ("SerialNumber = %s \n", pSysConfig->SerialNumber); printf ("InternetConn = %d \n", pSysInfo->InternetConn); printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n", pSysConfig->MaxChargingPower, pSysConfig->MaxChargingCurrent); pSysConfig->ShowInformation = YES; } void ChangeGunstate(char *v1,char *v2) { int _index = atoi((char*)v1); int status = atoi((char*)v2); pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index); pDcChargingInfo->SystemStatus = status; printf("Change Gun%d status into %s",_index,GetStatusName(status)); } void GetGunSelectedNum(char *v1) { if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) { if (AC_QUANTITY > 0 && pSysInfo->CurGunSelectedByAc != NO_DEFINE) { printf("connector select changed = AC \n"); } else { printf("connector selected = %d \n", pSysInfo->CurGunSelected); } } else { int _index = atoi(v1); if (_index <= 1) { pSysInfo->CurGunSelected = _index; pSysInfo->CurGunSelectedByAc = NO_DEFINE; printf("connector select changed = %d \n", _index); } else if (AC_QUANTITY > 0) { pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX; printf("connector select changed = AC \n"); } } } void SetFanSpeed(char *v1) { int speed = atoi(v1); if(speed > 0 ) { ShmDcCommonData->pTest.fanflag = YES; ShmFanModuleData->TestFanSpeed = speed; printf("Set Fan speed: %d \n",ShmFanModuleData->TestFanSpeed); } else { ShmFanModuleData->TestFanSpeed = 0; ShmDcCommonData->pTest.fanflag = NO; printf("Close Fan set\n"); } } void GetFanSpeed() { printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed); printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed); printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed); printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed); } void SetDebugMode(char *v1) { int mode = atoi(v1); ShmDcCommonData->debugflag = mode; pSysConfig->ShowInformation = mode; printf("Set Debug Mode:%d\n" , ShmDcCommonData->debugflag); } void SetGFDMode(char *v1) { int mode = atoi(v1); pSysConfig->AlwaysGfdFlag = mode; } void GetAcInputVol() { printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n", pSysInfo->InputVoltageR, pSysInfo->InputVoltageS, pSysInfo->InputVoltageT); } void GetConnectorCapInfo(char *v1) { int _GunIndex = atoi(v1); //if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) { // printf ("FindChargingInfoData error\n"); // return; //} pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex); printf ("Charger Max Current = %d, Max Power = %d \n", pSysConfig->MaxChargingCurrent * 10, pSysConfig->MaxChargingPower * 10); printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n", _GunIndex, pDcChargingInfo->RealMaxPower, pDcChargingInfo->RealMaxVoltage, pDcChargingInfo->RealMaxCurrent); } static void setConfirmSelGun(uint8_t selGun) { if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) { ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM; //printf("confirmSelGun left\r\n"); } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) { ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM; //printf("confirmSelGun right\r\n"); } } static float ReadAdcVolt(uint8_t AdcChannel) { //AIN0=CCS GUN Temp 1 //AIN1=CCS GUN Temp 2 //AIN2=CCS_Proximity/2 //AIN3=pilot voltage int fd = -1; uint8_t str[64] = { 0 }; uint8_t AdcValue[8] = { '\0' }; if (AdcChannel > 7) { return -1; } sprintf((char*)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel); fd = open((char*)str, O_RDONLY); read(fd, AdcValue, 4); close(fd); return (1.8 * atoi((char*)&AdcValue[0])) / 4095; //return (1.8 * atoi((char *)&AdcValue)) / 4095; } static void getChillerTemperature(struct ChargingInfoData* chargingData) { uint8_t i = 0; float adcVoltage = 0.0; ChillerTemp pChillerTemp; uint8_t maxTemp; for (i = 0; i < 4; i++) { adcVoltage = 0.0; adcVoltage = ReadAdcVolt(i); ShmDcCommonData->TempVolt[i] = adcVoltage; if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40 pChillerTemp.Temp[i] = ((adcVoltage - 0.908) * 500) + 60; //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500); } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) { pChillerTemp.Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60; //log_info("2 adcVoltage = %f", (adcVoltage - 0.9) * 500); } else { pChillerTemp.Temp[i] = UNDEFINED_TEMP; } } maxTemp = pChillerTemp.Temp[0]; memcpy((char*)ShmDcCommonData->SystemTemp, (char*)pChillerTemp.Temp, sizeof(ChillerTemp)); for (i = 1; i < 4; i++) { if (pChillerTemp.Temp[i] > pChillerTemp.Temp[i - 1] && pChillerTemp.Temp[i] != UNDEFINED_TEMP) { maxTemp = pChillerTemp.Temp[i]; } } chargingData->ChillerTemp = maxTemp; } void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur) { for(int i = 0 ; i < 4 ; i++) { if (ShmDcCommonData->SystemTemp[i] >= STAGE1_GUN_DERATING_TEMP && ShmDcCommonData->SystemTemp[i] < STAGE2_GUN_DERATING_TEMP && chargingData->deratingByConnOtp.deratingIndex < 1) { chargingData->deratingByConnOtp.deratingIndex = 1; } else if (ShmDcCommonData->SystemTemp[i] >= STAGE2_GUN_DERATING_TEMP && ShmDcCommonData->SystemTemp[i] != UNDEFINED_TEMP && chargingData->deratingByConnOtp.deratingIndex < 2) { chargingData->deratingByConnOtp.deratingIndex = 2; } } if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0) { *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex]; } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0) { if (*cur > (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10)) { *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10; } } } void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3) { int _GunIndex; uint8_t gunIndex = 0; uint8_t stopChg = 0; uint8_t curGun = 0; int isContinue = 1; float _Voltage; float _Current; float deratingPower; float deratingCurrent; int derating_index = 0; uint8_t PreviousSystemStatus[2] = {0xff}; int idx; char *usageMsg = "Usage:\n" " strchg ex: strchg 0 150 2\n" " chg ex: chg 500 100\n" " c ex: c 0\n" " help | ? | h\n" "\r\n"; if (strcmp(v1, "auto") == EQUAL) { _usingAutoRun = 0x01; _GunIndex = 0; _Voltage = 500; _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage; } else { _usingAutoRun = 0x00; _GunIndex = atoi(v1); _Voltage = atof(v2); _Current = atof(v3); } pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex); printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n", pSysConfig->MaxChargingPower, _Voltage, _Current); if (_Voltage > 1000 || _Voltage < 50) { printf ("Input Voltage over range\n"); return; } //kill ev task ShmDcCommonData->debugflag = YES; ShmDcCommonData->pTest.chillerflag = NO; system("killall Module_EvComm"); pSysInfo->CurGunSelected = _GunIndex; while (isContinue) { memset(&ShmDcCommonData->pTest,0,sizeof(ShmDcCommonData->pTest)); curGun = pSysInfo->CurGunSelected; pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun); if (!pDcChargingInfo->IsAvailable) { printf("Gun%d Not Available\n",curGun); break; } //fix gun 1 switch (pDcChargingInfo->SystemStatus) { case S_IDLE: if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) { PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus; ShmDcCommonData->LcmPage = _PAGE_SELECT_PAY; sleep(3); //if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) { setConfirmSelGun(curGun); //} strcpy((char *)pSysConfig->UserId, "AutoStartCharging"); pDcChargingInfo->ConnectorPlugIn = 1; printf ("[UnconditionalCharge - S_IDLE]\n"); pDcChargingInfo->Type = 9; pDcChargingInfo->StartMethod = _CHARGING_START_AUTOSTART; sleep(1); } if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) { pSysInfo->StartToChargingFlag = 0x01; pDcChargingInfo->SystemStatus = S_PREPARNING; strcpy((char *)pSysConfig->UserId, ""); } break; case S_PREPARNING: if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) { PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus; printf ("[UnconditionalCharge - S_PREPARNIN]\n"); ShmFanModuleData->TestFanSpeed = 7000; //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完) printf ("wait find module\n"); } //main 會在此階段判斷以下資料跳到下一個 state //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完) //sleep(10); //清除 main timeout 機制 pDcChargingInfo->TimeoutFlag = 0; pSysInfo->SystemTimeoutFlag = 0; pSysInfo->SystemPage = _LCM_NONE; //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step pDcChargingInfo->Type = 9; break; case S_PREPARING_FOR_EV: if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) { PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus; printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n"); printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10); } //清除 main timeout 機制 pDcChargingInfo->TimeoutFlag = 0; //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step pDcChargingInfo->Type = 9; //充電電壓電流 pDcChargingInfo->EvBatterySoc = 50; pDcChargingInfo->EvBatterytargetVoltage = 500; pDcChargingInfo->EvBatterytargetCurrent = 2; pDcChargingInfo->AvailableChargingCurrent = 1000; //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 ) //確定模組己升壓完成 //if(pDcChargingInfo->PresentChargingVoltage <= (3000+500) && // pDcChargingInfo->PresentChargingVoltage >= (3000-500) ) { printf ("Precharge Done = %f \n", pDcChargingInfo->PresentChargingVoltage); //EV done pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE; } break; case S_PREPARING_FOR_EVSE: if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) { PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus; printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n"); strcpy((char *)pSysConfig->UserId, ""); } //printf ("tar vol = %d \n", _Voltage); //printf ("tar cur = %d \n", _Current); //清除 main timeout 機制 pDcChargingInfo->TimeoutFlag = 0; //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step pDcChargingInfo->Type = 9; //充電電壓電流 pDcChargingInfo->EvBatterySoc = 50; pDcChargingInfo->EvBatterytargetVoltage = 500; pDcChargingInfo->EvBatterytargetCurrent = 2; pDcChargingInfo->AvailableChargingCurrent = 1000; //printf ("tar vol_ = %d \n", pDcChargingInfo->EvBatterytargetVoltage); // printf ("tar cur_ = %d \n", pDcChargingInfo->EvBatterytargetCurrent); //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 ) //確定模組己升壓完成 if (pDcChargingInfo->GroundFaultStatus == GFD_PASS || pDcChargingInfo->GroundFaultStatus == GFD_WARNING) { printf ("First Ground Fault State (%d)\n", pDcChargingInfo->GroundFaultStatus); printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage); sleep(5); //EV done pDcChargingInfo->SystemStatus = S_CHARGING; } else if (pDcChargingInfo->GroundFaultStatus > GFD_FAIL) { printf ("First Ground Fault check Fail (%d)\n", pDcChargingInfo->GroundFaultStatus); pDcChargingInfo->SystemStatus = S_TERMINATING; } break; case S_CHARGING: if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) { PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus; if (_usingAutoRun == 0x00) { //充電電壓電流 pDcChargingInfo->EvBatterytargetVoltage = _Voltage; pDcChargingInfo->EvBatterytargetCurrent = _Current; pDcChargingInfo->EvBatteryMaxVoltage = _Voltage * 10; } else { _curAutoRunCount = 0; gettimeofday(&_autoTime, NULL); } pDcChargingInfo->EvBatterySoc = 50; pDcChargingInfo->AvailableChargingCurrent = 1000; printf ("[UnconditionalCharge - S_CHARGING]\n"); } if (_usingAutoRun == 0x01) { if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) || ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60) ) { pDcChargingInfo->EvBatterytargetVoltage = _Voltage; pDcChargingInfo->EvBatterytargetCurrent = _Current; } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) { _curAutoRunCount++; if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) { pDcChargingInfo->SystemStatus = S_TERMINATING; } else { gettimeofday(&_autoTime, NULL); } } else { pDcChargingInfo->EvBatterytargetVoltage = 0; pDcChargingInfo->EvBatterytargetCurrent = 0; } } // printf("out : vol = %f, cur = %f \n", // pDcChargingInfo->EvBatterytargetVoltage, // pDcChargingInfo->EvBatterytargetCurrent); //ev task do this for (idx = 0; idx < pSysConfig->TotalConnectorCount; idx++) { struct ChargingInfoData* pInfo = (struct ChargingInfoData*)GetDcChargingInfoData(idx); if (!ShmDcCommonData->TestTemperature) getChillerTemperature(pInfo); // 低溫保護 if ((strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "V", 1) == 0) || (strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "F", 1) == 0)) { if ((ShmDcCommonData->SystemTemp[idx * 2] <= 70 || ShmDcCommonData->SystemTemp[idx * 2 + 1] <= 70)) { if (pInfo->EvBatterytargetCurrent > 250) { pInfo->EvBatterytargetCurrent = 250; printf("Chiller%d temperature(%d %d) too low limit target Current under 250A\n", idx, ShmDcCommonData->SystemTemp[idx * 2], ShmDcCommonData->SystemTemp[idx * 2 + 1]); } } else if ((ShmDcCommonData->SystemTemp[idx * 2] >= 80 || ShmDcCommonData->SystemTemp[idx * 2 + 1] >= 80) && pInfo->EvBatterytargetCurrent != _Current) { pInfo->EvBatterytargetCurrent = _Current; printf("Chiller%d temperature(%d %d) recovery target Current set %.2fA\n", idx, ShmDcCommonData->SystemTemp[idx * 2], ShmDcCommonData->SystemTemp[idx * 2 + 1], pInfo->EvBatterytargetCurrent); } if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) { if (pInfo->EvBatterytargetCurrent > 250) { pInfo->EvBatterytargetCurrent = 250; printf("Chiller alarm limit target Current under 250A\n"); } } } // 高溫保護 if (pInfo->deratingByConnOtp.isNeedDerating) { deratingCurrent = pInfo->EvBatterytargetCurrent; deratingPower = pInfo->AvailableChargingPower; GetOtpPwrOrCurMethod(pInfo, &deratingPower, &deratingCurrent); if (derating_index != pDcChargingInfo->deratingByConnOtp.deratingIndex) { printf("Change Derating Index:%d\n", pInfo->deratingByConnOtp.deratingIndex); derating_index = pInfo->deratingByConnOtp.deratingIndex; } if (pInfo->EvBatterytargetCurrent != deratingCurrent || pInfo->AvailableChargingPower != deratingPower) { pInfo->EvBatterytargetCurrent = deratingCurrent; pInfo->AvailableChargingPower = deratingPower; printf("Derating Current:%.3f Power:%.3f\n", pInfo->EvBatterytargetCurrent, pInfo->AvailableChargingPower); } } } // for // 水冷槍低溫保護 if ((strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "V", 1) == 0) || (strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "F", 1) == 0)) { } pDcChargingInfo->PresentChargingPower = ((float)((pDcChargingInfo->PresentChargingVoltage) * (pDcChargingInfo->PresentChargingCurrent)) / 1000); if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) { printf ("Charging Ground Fault check Fail (%d)\n", pDcChargingInfo->GroundFaultStatus); pDcChargingInfo->SystemStatus = S_TERMINATING; } break; case S_TERMINATING: if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) { PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus; printf ("[UnconditionalCharge - S_TERMINATING]\n"); //無阻塞偵測 keybaord 結束 system(STTY_DEF TTY_PATH); } sleep(1); pDcChargingInfo->ConnectorPlugIn = 0; pDcChargingInfo->SystemStatus = S_COMPLETE; break; case S_COMPLETE: if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) { PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus; printf ("[UnconditionalCharge - S_COMPLETE]\n"); } PreviousSystemStatus[curGun] = 0xFF; stopChg = 0; for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) { if (PreviousSystemStatus[gunIndex] == 0xFF) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun); pDcChargingInfo->IsAvailable ? (pDcChargingInfo->SystemStatus = S_IDLE) : (pDcChargingInfo->SystemStatus = S_MAINTAIN); } else { pSysInfo->CurGunSelected = gunIndex; } pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex); if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_MAINTAIN) { stopChg++; } } pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun); pDcChargingInfo->PresentChargingPower = 0; if (stopChg == pSysConfig->TotalConnectorCount) { system("/root/Module_EvComm &"); ShmFanModuleData->TestFanSpeed = 0; ShmDcCommonData->debugflag = NO; sleep(3); for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex); pDcChargingInfo->IsAvailable ? (pDcChargingInfo->SystemStatus = S_IDLE) : (pDcChargingInfo->SystemStatus = S_MAINTAIN); } return; } break; } if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) { continue; } if (strcmp(newString[0], "strchg") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 || strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ) { printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n"); continue; } if (atoi(newString[1]) == pSysInfo->CurGunSelected) { continue; } _GunIndex = atoi((char *)newString[1]); _Voltage = atof((char *)newString[2]); _Current = atof((char *)newString[3]); printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n", pSysConfig->MaxChargingPower, _Voltage, _Current); if (_Voltage > 1000 || _Voltage < 50) { _Voltage = 200; printf ("Input Voltage over range\n"); continue; } pSysInfo->CurGunSelected = _GunIndex; strcpy((char *)pSysConfig->UserId, ""); } else if (strcmp(newString[0], "chg") == 0) { if (strcmp(newString[1], "-1") == 0) { continue; } if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) { continue; } if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0) { continue; } _GunIndex = atoi((char *)newString[1]); float _vol = atof(newString[2]); float _cur = atof(newString[3]); if (_cur <= 0 || _cur <= 0) { continue; } pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex); printf("reset vol = %f, cur = %f \n", _vol, _cur); pDcChargingInfo->EvBatterytargetVoltage = _vol; pDcChargingInfo->EvBatterytargetCurrent = _cur; } else if (strcmp(newString[0], "c") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) { printf("argc 1 is error parameter\r\n"); continue; } if (atoi((char *)newString[1]) != -1) { pSysInfo->CurGunSelected = atoi((char *)newString[1]); } printf("stop \n\r"); pSysInfo->StartToChargingFlag = 0x00; pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected); pDcChargingInfo->SystemStatus = S_TERMINATING; } else if (helpCmd() == YES) { printf("%s\n", usageMsg); } usleep(100000); } } int printTimeMsg(const char *fmt, ...) { char Buf[4096 + 256] = {0}; char buffer[4096] = {0}; int rc = -1; va_list args; struct timeb SeqEndTime; struct tm *tm; va_start(args, fmt); rc = vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); ftime(&SeqEndTime); SeqEndTime.time = time(NULL); tm = localtime(&SeqEndTime.time); sprintf(Buf, "%02d:%02d:%02d:%03d - %s", tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer); printf("%s", Buf); return rc; } static void resdGunAndChillerTemp(void) { int isContinue = 1; uint8_t i = 0; uint32_t sleepTime = 500000; uint32_t loopTime = 1000; struct timeb showTime; struct timeb nowTime; char *usageMsg = "Usage:\n" " t : loop time, ex: t 1\n" " exit | c | C: exit test\n" " h | help | ?: show usage message\n" "\r\n"; ftime(&showTime); while (isContinue) { ftime(&nowTime); if (DiffTimeb(showTime, nowTime) > loopTime || DiffTimeb(showTime, nowTime) < 0) { for (i = 0; i < pSysConfig->TotalConnectorCount; i++) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i); printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d(%.3f), %3d(%.3f), %3d(%.3f), %3d(%.3f)\r\n", i, pDcChargingInfo->ConnectorTemp, pDcChargingInfo->ChillerTemp, ShmDcCommonData->ConnectorTemp[i][0], ShmDcCommonData->ConnectorTemp[i][1], ShmDcCommonData->SystemTemp[0], ShmDcCommonData->TempVolt[0], ShmDcCommonData->SystemTemp[1], ShmDcCommonData->TempVolt[1], ShmDcCommonData->SystemTemp[2], ShmDcCommonData->TempVolt[2], ShmDcCommonData->SystemTemp[3], ShmDcCommonData->TempVolt[3]); }//for ftime(&showTime); } if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) { usleep(sleepTime); continue; } if (strcmp(newString[0], "t") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 || atoi((char *)newString[1]) > 255 ) { printf("argc 1 is error parameter\r\n"); continue; } loopTime = ((atoi((char *)newString[1])) * 1000); printf("loopTime = %d\r\n", loopTime); ftime(&showTime); continue; } else if (exitCmd() == YES) { return; } else if (helpCmd() == YES) { printf ("%s\n", usageMsg); } usleep(sleepTime); }//while } static void writeOTPTemp(void) { int isContinue = 1; uint32_t sleepTime = 500000; char *usageMsg = "Usage:\n" " OTP , ex: OTP 140 150\n" " exit | c | C\n" " help | ? | h\n" "\r\n"; while (isContinue) { if (readCmdKey(CMD_KEY_WAIT) == NO) { sleep(sleepTime); continue; } if (helpCmd() == YES) { printf ("%s\n", usageMsg); continue; } else if (exitCmd() == YES) { sleep(1); return; } if (strcmp(newString[0], "OTP") != 0) { printf("argc 1 is error parameter\r\n"); continue; } if (atoi(newString[1]) > 255 || atoi(newString[1]) == -1) { printf("Recovey temperature value overflow\r\n"); continue; } if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) { printf("Recovey temperature value overflow\r\n"); continue; } pSysInfo->OTPTempR = atoi(newString[1]); pSysInfo->OTPTemp = atoi(newString[2]); printf("OTP Recovery Temp set:%d\n",pSysInfo->OTPTempR); printf("OTP Temp set:%d\n",pSysInfo->OTPTemp); usleep(sleepTime); }//while } void writeChillerStatus(char *v1) { ShmDcCommonData->chillerCtrl = atoi(newString[1]); if (ShmDcCommonData->chillerCtrl) { ShmDcCommonData->pTest.chillerflag = YES; printf("Chiller set on\n"); } else { ShmDcCommonData->pTest.chillerflag = NO; printf("Chiller set off\n"); } } void showNetworkPage(char* v1) { ShmDcCommonData->showNetPackage = atoi(newString[1]); if (ShmDcCommonData->showNetPackage) printf("Show Network Package on\n"); else printf("Show Network Package off\n"); } void showCANBUSPage(char* v1) { ShmDcCommonData->showCanPackage = atoi(newString[1]); if (ShmDcCommonData->showCanPackage) printf("Show CAN Bus Package on\n"); else printf("Show CAN Bus Package off\n"); } void setSystemTime(char* date,char* time) { char _setTime[30]; char cmdBuf[50]; sprintf(_setTime, "%s %s", date, time); printf("Set Timer:%s", _setTime); sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime); system((char*)cmdBuf); system("hwclock -w -u"); system("hwclock -s"); } static uint8_t getMaxConnectTemp(uint8_t headTemp1, uint8_t headTemp2) { uint8_t maxTemp = 0; if (headTemp1 > TEMP_BOUNDARY && headTemp2 > TEMP_BOUNDARY) { return UNDEFINED_TEMP; } if (headTemp1 <= TEMP_BOUNDARY) { maxTemp = headTemp1; } if (headTemp2 <= TEMP_BOUNDARY) { if (headTemp2 > maxTemp) { maxTemp = headTemp2; } } return maxTemp; } static void writeGunAndChillerTemp(void) { uint8_t _GunIndex = 0; int isContinue = 1; uint32_t sleepTime = 500000; char *usageMsg = "Usage:\n" " conn , ex: conn 0 150\n" " chiller , ex: chiller 0 150\n" " tempR\n" " exit | c | C\n" " help | ? | h\n" "\r\n"; ShmDcCommonData->TestTemperature = YES; while (isContinue) { if (readCmdKey(CMD_KEY_WAIT) == NO) { sleep(sleepTime); continue; } if (helpCmd() == YES) { printf ("%s\n", usageMsg); continue; } else if (exitCmd() == YES) { ShmDcCommonData->TestTemperature = NO; sleep(1); return; } else if (strcmp(newString[0], "tempR") == 0) { resdGunAndChillerTemp(); } if ((strcmp(newString[0], "chiller") != 0) && (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) ) { printf("argc 1 is error parameter\r\n"); continue; } if (strcmp(newString[0], "chiller") == 0) { if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1 || atoi(newString[3]) > 255 || atoi(newString[3]) == -1 || atoi(newString[4]) > 255 || atoi(newString[4]) == -1 || atoi(newString[5]) > 255 || atoi(newString[5]) == -1) { printf("temperature value overflow\r\n"); continue; } } else { if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) { printf("temperature value overflow\r\n"); continue; } } _GunIndex = atoi((char *)newString[1]); pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex); if (_GunIndex >= pSysConfig->TotalConnectorCount) { printf("gun index over total connector\r\n"); continue; } if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值 if (ShmDcCommonData->pGunInfo[_GunIndex].withChiller) { ShmDcCommonData->SystemTemp[0] = atoi(newString[2]); ShmDcCommonData->SystemTemp[1] = atoi(newString[3]); ShmDcCommonData->SystemTemp[2] = atoi(newString[4]); ShmDcCommonData->SystemTemp[3] = atoi(newString[5]); for(int i = 0 ; i < pSysConfig->TotalConnectorCount ; i++) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i); if (!ShmDcCommonData->pGunInfo[i].withChiller) continue; if (i == LEFT_GUN_NUM) { pDcChargingInfo->ChillerTemp = getMaxConnectTemp(ShmDcCommonData->SystemTemp[0],ShmDcCommonData->SystemTemp[1]); } else { pDcChargingInfo->ChillerTemp = getMaxConnectTemp(ShmDcCommonData->SystemTemp[2],ShmDcCommonData->SystemTemp[3]); } printf("set %d chiller temperature = %d\r\n", i, pDcChargingInfo->ChillerTemp); } //memset((char*)ShmDcCommonData->SystemTemp, atoi(newString[2]), sizeof(ShmDcCommonData->SystemTemp)); } else { printf("This Gun without Chiller\r\n"); } } else if (strcmp(newString[0], "conn") == 0) {//修改槍頭溫度值 pDcChargingInfo->ConnectorTemp = atoi(newString[2]); printf("set %d connector temp = %d\r\n", _GunIndex, pDcChargingInfo->ConnectorTemp); } usleep(sleepTime); }//while } void setledcolor(int on_off) { int isContinue = 1; uint32_t sleepTime = 500000; char* usageMsg = "Usage:\n" " r 0~100\n" " g 0~100\n" " b 0~100\n" " exit | c | C\n" " help | ? | h\n" "\r\n"; printf("%s\n", usageMsg); ShmDcCommonData->pTest.ledflag = TRUE; while (isContinue) { if (readCmdKey(CMD_KEY_WAIT) == NO) { sleep(sleepTime); continue; } if (helpCmd() == YES) { printf("%s\n", usageMsg); continue; } else if (exitCmd() == YES) { ShmDcCommonData->pTest.ledflag = FALSE; return; } if ((strcmp(newString[0], "r") != 0) && (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) ) { printf("argc 1 is error parameter\r\n"); continue; } if ((strcmp(newString[0], "g") != 0) && (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) ) { printf("argc 1 is error parameter\r\n"); continue; } if ((strcmp(newString[0], "b") != 0) && (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) ) { printf("argc 1 is error parameter\r\n"); continue; } if (atoi(newString[1]) < 0 || atoi(newString[1]) > 100) { printf("argc 1 is error parameter range is 0~100\r\n"); continue; } if (strcmp(newString[0], "r") == EQUAL && atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) { pSysConfig->LedInfo.Red[0] = atoi(newString[1]); } else { } if (strcmp(newString[0], "g") == EQUAL && atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) { pSysConfig->LedInfo.Green[0] = atoi(newString[1]); } if (strcmp(newString[0], "b") == EQUAL && atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) { pSysConfig->LedInfo.Blue[0] = atoi(newString[1]); } printf("Color set red[%d] green[%d] blue[%d]\n", pSysConfig->LedInfo.Red[0], pSysConfig->LedInfo.Green[0], pSysConfig->LedInfo.Blue[0]); usleep(sleepTime); }//while ShmDcCommonData->pTest.ledflag = FALSE; } void setlcmtest(char* v1) { ShmDcCommonData->lcmtest = atoi(v1); printf("Set LCM Test mode:%s\n", ShmDcCommonData->lcmtest ? "ON" : "OFF"); if (!ShmDcCommonData->lcmtest) { return; } int isContinue = 1; uint32_t sleepTime = 500000; char *usageMsg = "Usage:\n" "\n ===== main menu ==================================" "\n 1: publish_profile_sample." "\n 2: upgrade_lcm_sdcard." "\n 3: publish_restart_sample." "\n 4: publish_power_saving_sample." "\n 5: publish_back_dimming_sample." "\n 6: publish_timesync." "\n 7: publish_textview_add_sample." "\n 8: publish_imageview_add_sample." "\n 9: publish_videoview_add_sample." "\n 10: publish_view_remove_sample." "\n 11: publish_clear_screen." "\n 12: publish_audio_volume." "\n 13: publish_trigger_report_status." "\n 14: publish_qr_code_image." "\n 15: publish_power_saving_wake" "\n 15: upgrade_lcm_apk" "\n ==================================================" "\n Please input item to test: \n" " exit | c | C\n" " help | ? | h\n" "\r\n"; while (isContinue) { if (readCmdKey(CMD_KEY_WAIT) == NO) { sleep(sleepTime); continue; } if (helpCmd() == YES) { printf ("%s\n", usageMsg); continue; } else if (exitCmd() == YES) { ShmDcCommonData->lcmtest = NO; sleep(1); return; } if ((atoi(newString[0]) <= 0 || atoi(newString[0]) > 16 ) ) { printf("argc 1 is error parameter\r\n"); continue; } ShmDcCommonData->lcmcmd = atoi(newString[0]); printf("LCM Test Mode CMD [%d]\n",atoi(newString[0])); if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) { usleep(sleepTime); continue; } if (exitCmd() == YES) { ShmDcCommonData->lcmtest = NO; return; } else if (helpCmd() == YES) { printf ("%s\n", usageMsg); } usleep(sleepTime); }//while } void ShowPowerConsumption(char* v1) { printf("Dispenser Gun0 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[0].PowerConsumption); printf("Dispenser Gun1 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[1].PowerConsumption); } int main(void) { int isContinue = 1; char *usageMsg = "Usage:\n" " state : get gun state\n" " card : scanning card (x)\n" " gun : get gun plugit state\n" " lock : get gun locked state\n" " sysid : test system ID\n" " self : self test state (x)\n" " ver| v | -v : version of board (407 or relay or other)\n" " update : update firmware\n" " cable : set ground fault state\n" " pow : set power value\n" " model : get system information\n" " relay : get relay information\n" " setrelay : set relay on/off\n" " fan : set fan board speed\n" " strchg : auto test charging\n" " strchg : select gun test charging\n" " tempW : write connector header and Chiller temperature\r\n" " tempR : print connector header and chiller temperature\r\n" " OTP : Write OTP temperature\r\n" " chiller : set chiller on/off\r\n" " netdump : show network package\r\n" " candump : show can package\r\n" " powerconsumption : Show Power Consumption\n" " led : set led color\n" " lcmtest : set LCM enter Test Mode\n" " reset : soft reset\n" "\r\n"; if (CreateAllCsuShareMemory() == FAIL) { printf("create share memory error\r\n"); return FAIL; } MappingGunChargingInfo("ReadCmdline Task"); pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo(); pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData(); ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData(); ShmGBTData = (struct GBTData *)GetShmGBTData(); ShmCcsData = (struct CcsData *)GetShmCcsData(); ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData(); ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData(); ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData(); ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData(); ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data(); ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData(); while (isContinue) { if (readCmdKey(CMD_KEY_WAIT) == NO) { continue; } if (strcmp(newString[0], "state") == 0) { // 槍狀態 RunStatusProc(); } else if (strcmp(newString[0], "card") == 0) { // 刷卡狀態 RunCardProc(newString[1], newString[2]); } else if (strcmp(newString[0], "gun") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) { continue; } // 插槍狀態 RunGunPlugitProc(newString[1], newString[2]); } else if (strcmp(newString[0], "lock") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) { continue; } // 插槍狀態 GetGunLockStatusProc(newString[1], newString[2]); } else if (strcmp(newString[0], "sysid") == 0) { // 測試 sys id SetSystemIDProc(); } else if (strcmp(newString[0], "self") == 0) { // CSU 自我檢測狀態 RunSelfProc(newString[1]); } else if (strcmp(newString[0], "ver") == 0 || strcmp(newString[0], "v") == 0 || strcmp(newString[0], "-v") == 0) { //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) { // continue; //} // 取 FW 版號 GetFwVerProc(); } else if (strcmp(newString[0], "update") == 0) { // 更新 FwUpdateFlagProc(newString[1]); } else if (strcmp(newString[0], "cable") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) { continue; } // cable check pass SetCableChkStatus(newString[1], newString[2]); } else if (strcmp(newString[0], "pow") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) { continue; } // cable check pass SetPowerValue(newString[1], newString[2]); } else if (strcmp(newString[0], "model") == 0) { GetSystemInfo(); } else if (strcmp(newString[0], "select") == 0) { // 取得 / 設定 當前選的槍號 GetGunSelectedNum(newString[1]); } else if (strcmp(newString[0], "change") == 0) { // 模擬按鈕改變選槍 ChangeGunstate(newString[1],newString[2]); } else if (strcmp(newString[0], "fan") == 0) { // 設定風扇速度 SetFanSpeed(newString[1]); } else if (strcmp(newString[0], "speed") == 0) { // 取得風扇速度 GetFanSpeed(); } else if (strcmp(newString[0], "debug") == 0) { // 設定 debug mode SetDebugMode(newString[1]); } else if (strcmp(newString[0], "gfd") == 0) { // 設定盲沖使用 GFD 功能 SetGFDMode(newString[1]); } else if (strcmp(newString[0], "acin") == 0) { // 取得三向輸入電壓 GetAcInputVol(); } else if (strcmp(newString[0], "cap") == 0) { GetConnectorCapInfo(newString[1]); } else if (strcmp(newString[0], "error") == 0) { CreateOneError(newString[1]); } else if (strcmp(newString[0], "auth") == 0) { GetAuthorizeFlag(newString[1]); } else if (strcmp(newString[0], "relay") == 0) { GetRelayStatus(newString[1]); } else if (strcmp(newString[0], "setrelay") == 0) { SetRelayStatus(newString[1],newString[2]); } else if (strcmp(newString[0], "ccid") == 0) { if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 || strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) { printf ("Input ccid fail.\n"); continue; } SetChargingInfoCCID(newString[1], newString[2]); } else if (strcmp(newString[0], "strchg") == 0) { //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數 if (strcmp(newString[1], "auto") == 0) { newString[2][0] = 0; newString[3][0] = 0; } else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 || strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) { printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n"); continue; } // 槍狀態 RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]); } else if (strcmp(newString[0], "tempW") == 0) { //測試槍頭和水冷機溫度 writeGunAndChillerTemp(); } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度 resdGunAndChillerTemp(); } else if (strcmp(newString[0], "OTP") == 0) { //測試槍頭和水冷機溫度 writeOTPTemp(); } else if (strcmp(newString[0], "chiller") == 0) { //測試槍頭和水冷機溫度 writeChillerStatus(newString[1]); } else if (strcmp(newString[0], "netdump") == 0) { //印出網路封包 showNetworkPage(newString[1]); } else if (strcmp(newString[0], "candump") == 0) { //印出網路封包 showCANBUSPage(newString[1]); } else if (strcmp(newString[0], "time") == 0) { //設定系統時間 setSystemTime(newString[1], newString[2]); } else if (strcmp(newString[0], "powerconsumption") == 0) { // Power Consumption ShowPowerConsumption(newString[1]); } else if (strcmp(newString[0], "led") == 0) { // LED setledcolor(atoi(newString[1])); } else if (strcmp(newString[0], "l") == 0) { ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_PRESS; sleep(1); ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_RELEASE; } else if (strcmp(newString[0], "r") == 0) { ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_PRESS; sleep(1); ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_RELEASE; } else if (strcmp(newString[0], "c") == 0) { ShmPrimaryMcuData->InputDet.bits.Key3 = BTN_PRESS; sleep(1); ShmPrimaryMcuData->InputDet.bits.Key3 = BTN_RELEASE; } else if (strcmp(newString[0], "DcMeter") == 0) { } else if (strcmp(newString[0], "lcmtest") == 0) { setlcmtest(newString[1]); //} else if (strcmp(newString[0], "lang") == 0) { // setlanguage(newString[1]); } else if (strcmp(newString[0], "dark") == 0) { ShmDcCommonData->isDark = atoi(newString[1]); printf("Dark Mode is %s\n" , atoi(newString[1]) ? "ON" : "OFF"); } else if (strcmp(newString[0], "lcmpage") == 0) { ShmDcCommonData->LcmPage = atoi(newString[1]); printf("Page set %d\n" , atoi(newString[1])); } else if (strcmp(newString[0], "lcmdemo") == 0) { if (atoi(newString[1]) > 0) { ShmDcCommonData->demo_flag = TRUE; ShmDcCommonData->debugflag = TRUE; system("killall Module_EvComm"); system("killall Module_DoComm"); } else { ShmDcCommonData->demo_flag = FALSE; ShmDcCommonData->debugflag = FALSE; } printf("LCM Demo is %s\n" , atoi(newString[1]) ? "ON" : "OFF"); } else if (strcmp(newString[0], "reset") == 0) { system("run_evse_restart.sh"); } else { printf("%s\n", usageMsg); } sleep(1); }//while return 0; }