123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059 |
- /*
- * Module_AlarmDetect.c
- *
- * Created on: 2020年01月15日
- * Author: Eason Yang
- */
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include "define.h"
- #include "main.h"
- #define FILTER_SPEC 2
- #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)
- #define Debug
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define PASS 1
- #define FAIL 0
- #define ON 1
- #define OFF 0
- #define SPEC_OV 275
- #define SPEC_UV 160
- #define SPEC_OC (32*1.1)
- #define SPEC_OT 85
- #define HYSTERETIC_OUV 10
- #define HYSTERETIC_OT 10
- #define HYSTERETIC_OC 10
- struct{
- unsigned short int OV[3];
- unsigned short int UV[3];
- unsigned short int OC;
- unsigned short int OT_AMB;
- unsigned short int GMI;
- unsigned short int Short;
- unsigned short int Leakage;
- unsigned short int HandShakingTimeout;
- unsigned short int EmrgencyBTN;
- unsigned short int Relay_Welding;
- unsigned short int Relay_DrivingFault;
- unsigned short int CP_LevelFail;
- unsigned short int MCU_SelfTestFail;
- }Alarm_Counter[2];
- void trim(char *s);
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct OCPP16Data *ShmOCPP16Data;
- struct Charger *ShmCharger;
- int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- time_t CurrentTime;
- struct tm *tm;
- va_list args;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
- {
- sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1,
- ShmSysConfigAndInfo->SysConfig.ModelName,
- ShmSysConfigAndInfo->SysConfig.SerialNumber);
- }
- else
- {
- sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1);
- }
- #ifdef SystemLogMessage
- system(Buf);
- #endif
- #ifdef ConsloePrintLog
- printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
- #endif
- 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;
- }
- //==========================================
- // 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;
- }
- else
- {}
- //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;
- }
- else
- {}
- //creat ShmStatusCodeData
- if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmCharger NG\r\n");
- result = FAIL;
- }
- else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmCharger NG\r\n");
- result = FAIL;
- }
- else
- {}
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmOCPP16Data NG\r\n");
- result = FAIL;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmOCPP16Data NG\r\n");
- result = FAIL;
- }
- else
- {}
- return result;
- }
- //==========================================
- // Common routine
- //==========================================
- 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';
- }
- }
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- //==========================================
- // Main process
- //==========================================
- int main(void)
- {
- if(InitShareMemory() == FAIL)
- {
- DEBUG_ERROR("InitShareMemory NG\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
- }
- sleep(5);
- return FAIL;
- }
- for(;;)
- {
- for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
- {
- //=====================================
- // Over voltage detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
- {
- if(Alarm_Counter[gun_index].OV[0] > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
- DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].OV[0]++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
- {
- Alarm_Counter[gun_index].OV[0] = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
- DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
- {
- if(Alarm_Counter[gun_index].OV[1] > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
- DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].OV[1]++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
- {
- Alarm_Counter[gun_index].OV[1] = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
- DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
- }
- }
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
- {
- if(Alarm_Counter[gun_index].OV[2] > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
- DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].OV[2]++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
- {
- Alarm_Counter[gun_index].OV[2] = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
- DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
- }
- }
- }
- //=====================================
- // Under voltage detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
- {
- if(Alarm_Counter[gun_index].UV[0] > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
- DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].UV[0]++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
- {
- Alarm_Counter[gun_index].UV[0] = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
- DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
- {
- if(Alarm_Counter[gun_index].UV[1] > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
- DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].UV[1]++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
- {
- Alarm_Counter[gun_index].UV[1] = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
- DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
- }
- }
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
- {
- if(Alarm_Counter[gun_index].UV[2] > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
- DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].UV[2]++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
- {
- Alarm_Counter[gun_index].UV[2] = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
- DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
- }
- }
- }
- //=====================================
- // Over current detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
- DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
- }
- }
- else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
- DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
- DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
- }
- }
- else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
- DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
- }
- }
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
- DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
- }
- }
- else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
- DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
- }
- }
- }
- //=====================================
- // Over temperature detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)
- {
- if(Alarm_Counter[gun_index].OT_AMB > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_TEMPERATURE;
- DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].OT_AMB++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)))
- {
- Alarm_Counter[gun_index].OT_AMB = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_TEMPERATURE;
- DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \r\n");
- }
- }
- //=====================================
- // Ground fault detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL)
- {
- if(Alarm_Counter[gun_index].GMI > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
- DEBUG_INFO("ALARM_GROUND_FAIL : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].GMI++;
- }
- }
- else if (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL))
- {
- Alarm_Counter[gun_index].GMI = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
- DEBUG_INFO("ALARM_GROUND_FAIL : recover \r\n");
- }
- }
- //=====================================
- // CP level fail detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR)
- {
- if(Alarm_Counter[gun_index].CP_LevelFail > FILTER_SPEC)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == OFF)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_ERROR;
- DEBUG_INFO("ALARM_CP_ERROR : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].CP_LevelFail++;
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR))
- {
- Alarm_Counter[gun_index].CP_LevelFail= 0;
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == ON)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_ERROR;
- DEBUG_INFO("ALARM_CP_ERROR : recover \r\n");
- }
- }
- //=====================================
- // Current AC/DC leak detection
- //=====================================
- if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC) ||
- (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
- {
- if(Alarm_Counter[gun_index].Leakage > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
- {
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
- ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = ON;
- DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
- }
- else if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
- {
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
- ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = ON;
- DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
- }
- }
- }
- else
- {
- Alarm_Counter[gun_index].Leakage++;
- }
- }
- else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)) ||
- (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)))
- {
- Alarm_Counter[gun_index].Leakage = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
- if(ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage == ON)
- {
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
- ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = OFF;
- DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
- }
- else if(ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage == ON)
- {
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
- ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = OFF;
- DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
- }
- }
- }
- //=====================================
- // MCU self test fail detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL)
- {
- if(Alarm_Counter[gun_index].MCU_SelfTestFail > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
- DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].MCU_SelfTestFail++;
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL))
- {
- Alarm_Counter[gun_index].MCU_SelfTestFail = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
- DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \r\n");
- }
- }
- //=====================================
- // Hand shaking timeout detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
- {
- if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == OFF)
- {
- ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_HANDSHAKE_TIMEOUT;
- DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \r\n");
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT))
- {
- if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == ON)
- {
- ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_HANDSHAKE_TIMEOUT;
- DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \r\n");
- }
- }
- //=====================================
- // Emergency stop detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP)
- {
- if(Alarm_Counter[gun_index].EmrgencyBTN > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_EMERGENCY_STOP;
- DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].EmrgencyBTN++;
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP))
- {
- Alarm_Counter[gun_index].EmrgencyBTN = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_EMERGENCY_STOP;
- DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \r\n");
- }
- }
- //=====================================
- // Relay welding detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING)
- {
- if(Alarm_Counter[gun_index].Relay_Welding > FILTER_SPEC)
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == OFF)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_WELDING;
- DEBUG_INFO("ALARM_RELAY_STATUS : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].Relay_Welding++;
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING))
- {
- Alarm_Counter[gun_index].Relay_Welding = 0;
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == ON)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_WELDING;
- DEBUG_INFO("ALARM_RELAY_STATUS : recover \r\n");
- }
- }
- //=====================================
- // Relay driving fault detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT)
- {
- if(Alarm_Counter[gun_index].Relay_DrivingFault > FILTER_SPEC)
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == OFF)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_DRIVE_FAULT;
- DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].Relay_DrivingFault++;
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT))
- {
- Alarm_Counter[gun_index].Relay_DrivingFault = 0;
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == ON)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_DRIVE_FAULT;
- DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \r\n");
- }
- }
- //=====================================
- // Current short detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT)
- {
- if(Alarm_Counter[gun_index].Short > FILTER_SPEC)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_SHORT;
- DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \r\n");
- }
- }
- else
- {
- Alarm_Counter[gun_index].Short++;
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT))
- {
- Alarm_Counter[gun_index].Short = 0;
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_SHORT;
- DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \r\n");
- }
- }
- //=====================================
- // Rotatory switch detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == OFF)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
- DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \r\n");
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT))
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == ON)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
- DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \r\n");
- }
- }
- //=====================================
- // Leakage module detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL)
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == OFF)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
- DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \r\n");
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL))
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == ON)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
- DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \r\n");
- }
- }
- //=====================================
- // Shutter detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT)
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == OFF)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_SHUTTER_FAULT;
- DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \r\n");
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT))
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == ON)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
- DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \r\n");
- }
- }
- //=====================================
- // Locker detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT)
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == OFF)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LOCKER_FAULT;
- DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \r\n");
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT))
- {
- if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == ON)
- {
- ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
- DEBUG_INFO("ALARM_LOCKER_FAULT : recover \r\n");
- }
- }
- //=====================================
- // Power drop detection
- //=====================================
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = ON;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
- DEBUG_INFO("ALARM_POWER_DROP : alarm \r\n");
- }
- }
- else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP))
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = OFF;
- ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
- DEBUG_INFO("ALARM_POWER_DROP : recover \r\n");
- }
- }
- //=====================================
- // OCPP error code message
- //=====================================
- if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverVoltage");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "UnderVoltage");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverCurrentFailure");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "HighTemperature");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "GroundFailure");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CpError");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ACLeakage");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "DCLeakage");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "McuTestFail");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "HandshakeTimeout");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "EmergencyStop");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayWelding");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "LeakageModuleFail");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ShutterFault");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "ConnectorLockFailure");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "PowerDrop");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CircuitShort");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RotatorySwitchFault");
- }
- else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayDriveFault");
- }
- else
- {
- sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "NoError");
- memset(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, 0x00, ARRAY_SIZE(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
- }
- //=====================================
- // Latch alarm recover in state A
- //=====================================
- if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 1))
- {
- /*
- TODO: Recover latch alarm here
- */
- }
- //=====================================
- // Latch alarm recover in state B1 and B2
- //=====================================
- if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 2) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 3))
- {
- /*
- TODO: Recover latch alarm here
- */
- }
- //=====================================
- // Latch alarm recover in state C
- //=====================================
- if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 4))
- {
- /*
- TODO: Recover latch alarm here
- */
- }
- }
- usleep(100000);
- }
- return FAIL;
- }
|