#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 "../../define.h" #include "PrimaryComm.h" #include #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0])) #define PASS 1 #define FAIL -1 #define YES 1 #define NO 0 #define EQUAL 0 #define NORMAL 0 #define ABNORMAL 1 #define TILTSENSORDET 2 typedef unsigned char byte; struct SysConfigAndInfo *ShmSysConfigAndInfo; struct StatusCodeData *ShmStatusCodeData; struct PrimaryMcuData *ShmPrimaryMcuData; struct MeterInformation *ShmCsuMeterData; struct DcCommonInformation *ShmDcCommonData; void trim(char *s); int mystrcmp(char *p1,char *p2); void substr(char *dest, const char* src, unsigned int start, unsigned int cnt); void split(char **arr, char *str, const char *del); int Uart1Fd; char *priPortName = "/dev/ttyS1"; Ver ver; Gpio_in gpio_in; Rtc rtc; struct timespec _flash_time; byte flash = NO; struct timespec _tilt_time; byte tilt = NO; byte gun_count; byte _acSwitch; bool _isNeedChkTilt; byte _curDeviceStatus[3] = {0, 0, 0}; byte _reCheckCount[3] = {0, 0, 0}; struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; void PRINTF_FUNC(char *string, ...); int StoreLogMsg(const char *fmt, ...); #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args) int StoreLogMsg(const char *fmt, ...) { char Buf[4096+256]; char buffer[4096]; va_list args; struct timeb SeqEndTime; struct tm *tm; va_start(args, fmt); int rc = vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); memset(Buf,0,sizeof(Buf)); ftime(&SeqEndTime); SeqEndTime.time = time(NULL); tm=localtime(&SeqEndTime.time); if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) { sprintf(Buf,"%02d:%02d:%02d:%03d - %s", tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer); printf("%s \n", Buf); } else { sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s_Log", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer, tm->tm_year+1900,tm->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber); system(Buf); } return rc; } 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; } void PRINTF_FUNC(char *string, ...) { va_list args; char buffer[4096]; va_start(args, string); vsnprintf(buffer, sizeof(buffer), string, args); va_end(args); DEBUG_INFO("%s ", buffer); } //================================= // Common routine //================================= char* getTimeString(void) { char *result=malloc(21); time_t timep; struct tm *p; time(&timep); p=gmtime(&timep); sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec); return result; } void trim(char *s) { int i=0, j, k, l=0; while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n')) i++; j = strlen(s)-1; while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n')) j--; if(i==0 && j==strlen(s)-1) { } else if(i==0) s[j+1] = '\0'; else { for(k=i; k<=j; k++) s[l++] = s[k]; s[l] = '\0'; } } int mystrcmp(char *p1,char *p2) { while(*p1==*p2) { if(*p1=='\0' || *p2=='\0') break; p1++; p2++; } if(*p1=='\0' && *p2=='\0') return(PASS); else return(FAIL); } void substr(char *dest, const char* src, unsigned int start, unsigned int cnt) { strncpy(dest, src + start, cnt); dest[cnt] = 0; } void split(char **arr, char *str, const char *del) { char *s = strtok(str, del); while(s != NULL) { *arr++ = s; s = strtok(NULL, del); } } //========================================== // Init all share memory //========================================== int InitShareMemory() { int result = PASS; int MeterSMId; //creat ShmSysConfigAndInfo if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n"); #endif result = FAIL; } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n"); #endif result = FAIL; } //creat ShmStatusCodeData if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmStatusCodeData NG\n"); #endif result = FAIL; } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmStatusCodeData NG\n"); #endif result = FAIL; } //creat ShmStatusCodeData if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n"); #endif result = FAIL; } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef ShmPrimaryMcuData DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n"); #endif result = FAIL; } if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmCsuMeterKey NG \n"); #endif result = FAIL; } else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmCsuMeterData NG \n"); #endif result = FAIL; } if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmCommonKey NG \n"); #endif result = FAIL; } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmCommonKey NG \n"); #endif result = FAIL; } return result; } //================================================ // Function //================================================ void GetFwAndHwVersion() { if(Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) { //PRINTF_FUNC("s1 = %s \n", ver.Version_FW); strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW); strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW); } if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) { //PRINTF_FUNC("s2 = %s \n", ver.Version_HW); } } void GetInputGpioStatus() { if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS) { if (ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE) { if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector || _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != ShmDcCommonData->psuKeepCommunication) { if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) { if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == NORMAL && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == NORMAL && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU == NORMAL && ShmPrimaryMcuData->InputDet.bits.DoorOpen == NORMAL && (ShmDcCommonData->psuKeepCommunication == YES || gpio_in.AC_Connector == YES)) { ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = YES; _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = YES; } else { ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = _acSwitch = NO; _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = NO; } } else _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++; } else _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = NO; } if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3 && ShmDcCommonData->psuKeepCommunication == YES && gpio_in.AC_Connector == NO) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES; } else { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO; } // ------------------------------------------------------------------- if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) { if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) { _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker; ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker; } else _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++; } else _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0; ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD; ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open; ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0]; ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1]; ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn; //PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1); //PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2); //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus); if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] == 3 && ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) DEBUG_ERROR("AC Mainbreaker occur. \n"); } } void GetMeterConsumption(byte index) { if (Query_Meter_value(Uart1Fd, Addr.IoExtend, &ShmCsuMeterData->_meter[index], &ShmCsuMeterData->isWorking, index) == PASS) { // meter value (Resolution) : 10 if (!ShmCsuMeterData->isWorking) { //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = YES; return; } if (ShmCsuMeterData->_meter[index].isCalculation == YES) { // printf("Meter%d, Comsumption = %.1f, curMeterValue = %.1f \n", // index, // ShmCsuMeterData->_meter[index].newMeterValue, // ShmCsuMeterData->_meter[index].curMeterValue); if (ShmCsuMeterData->_meter[index].curMeterValue == 0) ShmCsuMeterData->_meter[index].curMeterValue = ShmCsuMeterData->_meter[index].newMeterValue; else { // 最大充時,兩個都會累加,但只輸出給一槍使用 ShmCsuMeterData->_meter[index]._chargingValue += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue; if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_NORMAL) { for (byte subIndex = 0; subIndex < gun_count; subIndex++) { if (_chargingData[subIndex]->SystemStatus == SYS_MODE_CHARGING) { ShmCsuMeterData->_meter[subIndex]._curTotalCharging += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue; break; } } } else { ShmCsuMeterData->_meter[index]._curTotalCharging += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue; } ShmCsuMeterData->_meter[index].curMeterValue = ShmCsuMeterData->_meter[index].newMeterValue; } } } } void SetOutputGpio(byte flash, byte tilt) { Gpio_out gpio; // 藍燈 gpio.Button_LED[0] = flash; // 綠燈 gpio.Button_LED[1] = flash; //gpio.Button_LED[1] = 0x00; gpio.System_LED[0] = 0x00; gpio.System_LED[1] = 0x00; gpio.System_LED[2] = tilt; gpio.System_LED[3] = tilt; gpio.AC_Connector = 0x00; gpio.AC_Breaker = 0x00; if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS) { //PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash); } else { //PRINTF_FUNC("SetOutputGpio fail. \n"); } } void SetRtcData() { struct timeb csuTime; struct tm *tmCSU; ftime(&csuTime); tmCSU = localtime(&csuTime.time); // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900, // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min, // tmCSU->tm_sec); rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10; rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10; rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10; rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10; rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10; rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10; rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10; rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10; rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10; rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10; rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10; rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10; rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10; rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10; if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS) { //PRINTF_FUNC("SetRtc sucessfully. \n"); } else { //PRINTF_FUNC("SetRtc fail. \n"); } } void SetModelName() { if (Config_Model_Name(Uart1Fd, Addr.IoExtend, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {} } //================================================ // Main process //================================================ int InitComPort() { int fd; struct termios tios; fd = open(priPortName, O_RDWR); if(fd<=0) { #ifdef SystemLogMessage DEBUG_ERROR("open 407 Communication port NG \n"); #endif return -1; } ioctl (fd, TCGETS, &tios); tios.c_cflag = B115200| CS8 | CLOCAL | CREAD; tios.c_lflag = 0; tios.c_iflag = 0; tios.c_oflag = 0; tios.c_cc[VMIN]=0; tios.c_cc[VTIME]=(unsigned char)1; tios.c_lflag=0; tcflush(fd, TCIFLUSH); ioctl (fd, TCSETS, &tios); return fd; } int GetTimeoutValue(struct timespec *startTime) { struct timespec endTime; clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime); return endTime.tv_sec - startTime->tv_sec; } void GetTimespecFunc(struct timespec *time) { clock_gettime(CLOCK_MONOTONIC_COARSE, time); } //================================================ //================================================ // CANBUS receive task //================================================ //================================================ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData) { for (byte index = 0; index < CHAdeMO_QUANTITY; index++) { if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) { chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index]; return true; } } for (byte index = 0; index < CCS_QUANTITY; index++) { if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) { chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index]; return true; } } for (byte index = 0; index < GB_QUANTITY; index++) { if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) { chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index]; return true; } } return false; } void Initialization() { bool isPass = false; while(!isPass) { isPass = true; for (byte _index = 0; _index < gun_count; _index++) { if (!FindChargingInfoData(_index, &_chargingData[0])) { DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n"); isPass = false; break; } } sleep(1); } } bool CheckCustomer() { bool result = false; char _buf[3] = {0}; memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2); if (strcmp(_buf, "OL") == EQUAL) result = true; return result; } void TiltSensorSwitch(bool _switch) { if (tilt != _switch) tilt = _switch; SetOutputGpio(flash, tilt); } void ChkTiltSensor() { if (ShmPrimaryMcuData->InputDet.bits.AcContactorDetec == YES) { if (_acSwitch == NO) { if (ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE) { PRINTF_FUNC("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_ON ---- \n"); ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_ON; _acSwitch = YES; } } else { switch (ShmDcCommonData->_tiltSensorStep) { case _TILT_SENSOR_STEP_PIN_ON: { TiltSensorSwitch(YES); GetTimespecFunc(&_tilt_time); PRINTF_FUNC("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_WAIT ---- \n"); ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_WAIT; } break; case _TILT_SENSOR_STEP_PIN_WAIT: { int _time = GetTimeoutValue(&_tilt_time); if (_time < 0) GetTimespecFunc(&_tilt_time); else if (_time > 1) { if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == NO) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.TiltSensorStestFail = YES; else ShmStatusCodeData->AlarmCode.AlarmEvents.bits.TiltSensorStestFail = NO; if (_time > TILTSENSORDET) { GetTimespecFunc(&_tilt_time); PRINTF_FUNC("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_OFF ---- \n"); ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_OFF; } } } break; case _TILT_SENSOR_STEP_PIN_OFF: { TiltSensorSwitch(NO); GetTimespecFunc(&_tilt_time); PRINTF_FUNC("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_FINISH ---- \n"); ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_FINISH; } break; case _TILT_SENSOR_STEP_PIN_FINISH : { int _time = GetTimeoutValue(&_tilt_time); if (_time < 0) GetTimespecFunc(&_tilt_time); else if (_time > TILTSENSORDET) { PRINTF_FUNC("---- Tilt Sensor : _TILT_SENSOR_STEP_NONE ---- \n"); ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_NONE; } } break; } } } else { TiltSensorSwitch(NO); ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_NONE; _acSwitch = NO; } } int main(void) { if(InitShareMemory() == FAIL) { #ifdef SystemLogMessage DEBUG_ERROR("InitShareMemory NG\n"); #endif if(ShmStatusCodeData!=NULL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1; } sleep(5); return 0; } Uart1Fd = InitComPort(); if(Uart1Fd < 0) { #ifdef SystemLogMessage DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG"); #endif if (ShmStatusCodeData != NULL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1; } sleep(5); return 0; } SetRtcData(); SetModelName(); GetTimespecFunc(&_flash_time); gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; Initialization(); byte _count = 0; _acSwitch = NO; sleep(1); // 需要判斷這個的客戶碼 : OL _isNeedChkTilt = CheckCustomer(); for(;;) { if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == EQUAL) { if (GetTimeoutValue(&_flash_time) > 1) { if (flash == NO) flash = YES; else flash = NO; SetOutputGpio(flash, tilt); GetTimespecFunc(&_flash_time); } } else { if (GetTimeoutValue(&_flash_time) > 5) { if (flash == NO) flash = YES; SetOutputGpio(flash, tilt); GetTimespecFunc(&_flash_time); } } // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp. // 模組更新 FW 後,需重新做 if(ShmPrimaryMcuData->SelfTest_Comp != PASS) { //PRINTF_FUNC("(407) Get Fw and Hw Ver. \n"); GetFwAndHwVersion(); sleep(1); ShmPrimaryMcuData->SelfTest_Comp = PASS; } else { GetInputGpioStatus(); if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' || ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L') { GetMeterConsumption(_count); _count++; if (_count >= gun_count) _count = 0; } // if (_isNeedChkTilt) // { // ChkTiltSensor(); // } } usleep(100000); } return FAIL; }