Module_AlarmDetect.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. /*
  2. * Module_AlarmDetect.c
  3. *
  4. * Created on: 2020年01月15日
  5. * Author: Eason Yang
  6. */
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <sys/time.h>
  10. #include <sys/timeb.h>
  11. #include <sys/ipc.h>
  12. #include <sys/shm.h>
  13. #include <sys/mman.h>
  14. #include <unistd.h>
  15. #include <stdarg.h>
  16. #include <stdio.h> /*標準輸入輸出定義*/
  17. #include <stdlib.h> /*標準函數庫定義*/
  18. #include <unistd.h> /*Unix 標準函數定義*/
  19. #include <fcntl.h> /*檔控制定義*/
  20. #include <termios.h> /*PPSIX 終端控制定義*/
  21. #include <errno.h> /*錯誤號定義*/
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <time.h>
  25. #include <ctype.h>
  26. #include "define.h"
  27. #include "main.h"
  28. #define FILTER_SPEC 2
  29. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  30. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  31. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  32. #define Debug
  33. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  34. #define PASS 1
  35. #define FAIL 0
  36. #define ON 1
  37. #define OFF 0
  38. #define SPEC_OV 275
  39. #define SPEC_UV 160
  40. #define SPEC_OC (32*1.1)
  41. #define SPEC_OT 85
  42. #define HYSTERETIC_OUV 10
  43. #define HYSTERETIC_OT 10
  44. #define HYSTERETIC_OC 10
  45. struct{
  46. unsigned short int OV[3];
  47. unsigned short int UV[3];
  48. unsigned short int OC;
  49. unsigned short int OT_AMB;
  50. unsigned short int GMI;
  51. unsigned short int Short;
  52. unsigned short int Leakage;
  53. unsigned short int HandShakingTimeout;
  54. unsigned short int EmrgencyBTN;
  55. unsigned short int Relay_Welding;
  56. unsigned short int Relay_DrivingFault;
  57. unsigned short int CP_LevelFail;
  58. unsigned short int MCU_SelfTestFail;
  59. }Alarm_Counter[2];
  60. void trim(char *s);
  61. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
  62. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  63. struct StatusCodeData *ShmStatusCodeData;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. struct Charger *ShmCharger;
  66. int StoreLogMsg(const char *fmt, ...)
  67. {
  68. char Buf[4096+256];
  69. char buffer[4096];
  70. time_t CurrentTime;
  71. struct tm *tm;
  72. va_list args;
  73. va_start(args, fmt);
  74. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  75. va_end(args);
  76. memset(Buf,0,sizeof(Buf));
  77. CurrentTime = time(NULL);
  78. tm=localtime(&CurrentTime);
  79. if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
  80. {
  81. sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
  82. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  83. buffer,
  84. tm->tm_year+1900,tm->tm_mon+1,
  85. ShmSysConfigAndInfo->SysConfig.ModelName,
  86. ShmSysConfigAndInfo->SysConfig.SerialNumber);
  87. }
  88. else
  89. {
  90. sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  91. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  92. buffer,
  93. tm->tm_year+1900,tm->tm_mon+1);
  94. }
  95. #ifdef SystemLogMessage
  96. system(Buf);
  97. #endif
  98. #ifdef ConsloePrintLog
  99. 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);
  100. #endif
  101. return rc;
  102. }
  103. int DiffTimeb(struct timeb ST, struct timeb ET)
  104. {
  105. //return milli-second
  106. unsigned int StartTime,StopTime;
  107. StartTime=(unsigned int)ST.time;
  108. StopTime=(unsigned int)ET.time;
  109. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  110. }
  111. //==========================================
  112. // Init all share memory
  113. //==========================================
  114. int InitShareMemory()
  115. {
  116. int result = PASS;
  117. int MeterSMId;
  118. //creat ShmSysConfigAndInfo
  119. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  120. {
  121. #ifdef SystemLogMessage
  122. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  123. #endif
  124. result = FAIL;
  125. }
  126. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  127. {
  128. #ifdef SystemLogMessage
  129. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  130. #endif
  131. result = FAIL;
  132. }
  133. else
  134. {}
  135. //creat ShmStatusCodeData
  136. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  137. {
  138. #ifdef SystemLogMessage
  139. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  140. #endif
  141. result = FAIL;
  142. }
  143. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  144. {
  145. #ifdef SystemLogMessage
  146. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  147. #endif
  148. result = FAIL;
  149. }
  150. else
  151. {}
  152. //creat ShmStatusCodeData
  153. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  154. {
  155. DEBUG_ERROR("shmget ShmCharger NG\r\n");
  156. result = FAIL;
  157. }
  158. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  159. {
  160. DEBUG_ERROR("shmat ShmCharger NG\r\n");
  161. result = FAIL;
  162. }
  163. else
  164. {}
  165. //creat ShmOCPP16Data
  166. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  167. {
  168. DEBUG_ERROR("shmget ShmOCPP16Data NG\r\n");
  169. result = FAIL;
  170. }
  171. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  172. {
  173. DEBUG_ERROR("shmat ShmOCPP16Data NG\r\n");
  174. result = FAIL;
  175. }
  176. else
  177. {}
  178. return result;
  179. }
  180. //==========================================
  181. // Common routine
  182. //==========================================
  183. void trim(char *s)
  184. {
  185. int i=0, j, k, l=0;
  186. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  187. i++;
  188. j = strlen(s)-1;
  189. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  190. j--;
  191. if(i==0 && j==strlen(s)-1) { }
  192. else if(i==0) s[j+1] = '\0';
  193. else {
  194. for(k=i; k<=j; k++) s[l++] = s[k];
  195. s[l] = '\0';
  196. }
  197. }
  198. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  199. {
  200. strncpy(dest, src + start, cnt);
  201. dest[cnt] = 0;
  202. }
  203. //==========================================
  204. // Main process
  205. //==========================================
  206. int main(void)
  207. {
  208. if(InitShareMemory() == FAIL)
  209. {
  210. DEBUG_ERROR("InitShareMemory NG\n");
  211. if(ShmStatusCodeData!=NULL)
  212. {
  213. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  214. }
  215. sleep(5);
  216. return FAIL;
  217. }
  218. for(;;)
  219. {
  220. for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
  221. {
  222. //=====================================
  223. // Over voltage detection
  224. //=====================================
  225. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
  226. {
  227. if(Alarm_Counter[gun_index].OV[0] > FILTER_SPEC)
  228. {
  229. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == OFF)
  230. {
  231. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = ON;
  232. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
  233. DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
  234. }
  235. }
  236. else
  237. {
  238. Alarm_Counter[gun_index].OV[0]++;
  239. }
  240. }
  241. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
  242. {
  243. Alarm_Counter[gun_index].OV[0] = 0;
  244. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON)
  245. {
  246. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = OFF;
  247. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
  248. DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
  249. }
  250. }
  251. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  252. {
  253. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
  254. {
  255. if(Alarm_Counter[gun_index].OV[1] > FILTER_SPEC)
  256. {
  257. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == OFF)
  258. {
  259. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = ON;
  260. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
  261. DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
  262. }
  263. }
  264. else
  265. {
  266. Alarm_Counter[gun_index].OV[1]++;
  267. }
  268. }
  269. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
  270. {
  271. Alarm_Counter[gun_index].OV[1] = 0;
  272. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON)
  273. {
  274. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = OFF;
  275. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
  276. DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
  277. }
  278. }
  279. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
  280. {
  281. if(Alarm_Counter[gun_index].OV[2] > FILTER_SPEC)
  282. {
  283. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == OFF)
  284. {
  285. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = ON;
  286. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
  287. DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
  288. }
  289. }
  290. else
  291. {
  292. Alarm_Counter[gun_index].OV[2]++;
  293. }
  294. }
  295. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
  296. {
  297. Alarm_Counter[gun_index].OV[2] = 0;
  298. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON)
  299. {
  300. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = OFF;
  301. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
  302. DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
  303. }
  304. }
  305. }
  306. //=====================================
  307. // Under voltage detection
  308. //=====================================
  309. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
  310. {
  311. if(Alarm_Counter[gun_index].UV[0] > FILTER_SPEC)
  312. {
  313. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == OFF)
  314. {
  315. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = ON;
  316. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
  317. DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
  318. }
  319. }
  320. else
  321. {
  322. Alarm_Counter[gun_index].UV[0]++;
  323. }
  324. }
  325. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
  326. {
  327. Alarm_Counter[gun_index].UV[0] = 0;
  328. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON)
  329. {
  330. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = OFF;
  331. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
  332. DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
  333. }
  334. }
  335. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  336. {
  337. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
  338. {
  339. if(Alarm_Counter[gun_index].UV[1] > FILTER_SPEC)
  340. {
  341. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == OFF)
  342. {
  343. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = ON;
  344. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
  345. DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
  346. }
  347. }
  348. else
  349. {
  350. Alarm_Counter[gun_index].UV[1]++;
  351. }
  352. }
  353. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
  354. {
  355. Alarm_Counter[gun_index].UV[1] = 0;
  356. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON)
  357. {
  358. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = OFF;
  359. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
  360. DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
  361. }
  362. }
  363. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
  364. {
  365. if(Alarm_Counter[gun_index].UV[2] > FILTER_SPEC)
  366. {
  367. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == OFF)
  368. {
  369. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = ON;
  370. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
  371. DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
  372. }
  373. }
  374. else
  375. {
  376. Alarm_Counter[gun_index].UV[2]++;
  377. }
  378. }
  379. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
  380. {
  381. Alarm_Counter[gun_index].UV[2] = 0;
  382. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON)
  383. {
  384. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = OFF;
  385. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
  386. DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
  387. }
  388. }
  389. }
  390. //=====================================
  391. // Over current detection
  392. //=====================================
  393. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
  394. {
  395. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
  396. {
  397. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
  398. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
  399. DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
  400. }
  401. }
  402. else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
  403. {
  404. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
  405. {
  406. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
  407. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
  408. DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
  409. }
  410. }
  411. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  412. {
  413. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
  414. {
  415. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
  416. {
  417. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
  418. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
  419. DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
  420. }
  421. }
  422. else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
  423. {
  424. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
  425. {
  426. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
  427. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
  428. DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
  429. }
  430. }
  431. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
  432. {
  433. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
  434. {
  435. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
  436. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
  437. DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
  438. }
  439. }
  440. else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
  441. {
  442. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
  443. {
  444. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
  445. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
  446. DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
  447. }
  448. }
  449. }
  450. //=====================================
  451. // Over temperature detection
  452. //=====================================
  453. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)
  454. {
  455. if(Alarm_Counter[gun_index].OT_AMB > FILTER_SPEC)
  456. {
  457. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == OFF)
  458. {
  459. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = ON;
  460. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_TEMPERATURE;
  461. DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \r\n");
  462. }
  463. }
  464. else
  465. {
  466. Alarm_Counter[gun_index].OT_AMB++;
  467. }
  468. }
  469. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)))
  470. {
  471. Alarm_Counter[gun_index].OT_AMB = 0;
  472. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == ON)
  473. {
  474. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = OFF;
  475. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_TEMPERATURE;
  476. DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \r\n");
  477. }
  478. }
  479. //=====================================
  480. // Ground fault detection
  481. //=====================================
  482. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL)
  483. {
  484. if(Alarm_Counter[gun_index].GMI > FILTER_SPEC)
  485. {
  486. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == OFF)
  487. {
  488. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = ON;
  489. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
  490. DEBUG_INFO("ALARM_GROUND_FAIL : alarm \r\n");
  491. }
  492. }
  493. else
  494. {
  495. Alarm_Counter[gun_index].GMI++;
  496. }
  497. }
  498. else if (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL))
  499. {
  500. Alarm_Counter[gun_index].GMI = 0;
  501. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == ON)
  502. {
  503. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = OFF;
  504. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
  505. DEBUG_INFO("ALARM_GROUND_FAIL : recover \r\n");
  506. }
  507. }
  508. //=====================================
  509. // CP level fail detection
  510. //=====================================
  511. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR)
  512. {
  513. if(Alarm_Counter[gun_index].CP_LevelFail > FILTER_SPEC)
  514. {
  515. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == OFF)
  516. {
  517. ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = ON;
  518. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_ERROR;
  519. DEBUG_INFO("ALARM_CP_ERROR : alarm \r\n");
  520. }
  521. }
  522. else
  523. {
  524. Alarm_Counter[gun_index].CP_LevelFail++;
  525. }
  526. }
  527. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR))
  528. {
  529. Alarm_Counter[gun_index].CP_LevelFail= 0;
  530. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == ON)
  531. {
  532. ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = OFF;
  533. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_ERROR;
  534. DEBUG_INFO("ALARM_CP_ERROR : recover \r\n");
  535. }
  536. }
  537. //=====================================
  538. // Current AC/DC leak detection
  539. //=====================================
  540. if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC) ||
  541. (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
  542. {
  543. if(Alarm_Counter[gun_index].Leakage > FILTER_SPEC)
  544. {
  545. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF)
  546. {
  547. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
  548. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
  549. {
  550. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
  551. ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = ON;
  552. DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
  553. }
  554. else if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
  555. {
  556. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
  557. ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = ON;
  558. DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
  559. }
  560. }
  561. }
  562. else
  563. {
  564. Alarm_Counter[gun_index].Leakage++;
  565. }
  566. }
  567. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)) ||
  568. (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)))
  569. {
  570. Alarm_Counter[gun_index].Leakage = 0;
  571. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON)
  572. {
  573. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
  574. if(ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage == ON)
  575. {
  576. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
  577. ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = OFF;
  578. DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
  579. }
  580. else if(ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage == ON)
  581. {
  582. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
  583. ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = OFF;
  584. DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
  585. }
  586. }
  587. }
  588. //=====================================
  589. // MCU self test fail detection
  590. //=====================================
  591. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL)
  592. {
  593. if(Alarm_Counter[gun_index].MCU_SelfTestFail > FILTER_SPEC)
  594. {
  595. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == OFF)
  596. {
  597. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = ON;
  598. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
  599. DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \r\n");
  600. }
  601. }
  602. else
  603. {
  604. Alarm_Counter[gun_index].MCU_SelfTestFail++;
  605. }
  606. }
  607. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL))
  608. {
  609. Alarm_Counter[gun_index].MCU_SelfTestFail = 0;
  610. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == ON)
  611. {
  612. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = OFF;
  613. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
  614. DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \r\n");
  615. }
  616. }
  617. //=====================================
  618. // Hand shaking timeout detection
  619. //=====================================
  620. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
  621. {
  622. if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == OFF)
  623. {
  624. ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut = ON;
  625. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_HANDSHAKE_TIMEOUT;
  626. DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \r\n");
  627. }
  628. }
  629. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT))
  630. {
  631. if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == ON)
  632. {
  633. ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut = OFF;
  634. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_HANDSHAKE_TIMEOUT;
  635. DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \r\n");
  636. }
  637. }
  638. //=====================================
  639. // Emergency stop detection
  640. //=====================================
  641. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP)
  642. {
  643. if(Alarm_Counter[gun_index].EmrgencyBTN > FILTER_SPEC)
  644. {
  645. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == OFF)
  646. {
  647. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = ON;
  648. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_EMERGENCY_STOP;
  649. DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \r\n");
  650. }
  651. }
  652. else
  653. {
  654. Alarm_Counter[gun_index].EmrgencyBTN++;
  655. }
  656. }
  657. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP))
  658. {
  659. Alarm_Counter[gun_index].EmrgencyBTN = 0;
  660. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == ON)
  661. {
  662. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = OFF;
  663. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_EMERGENCY_STOP;
  664. DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \r\n");
  665. }
  666. }
  667. //=====================================
  668. // Relay welding detection
  669. //=====================================
  670. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING)
  671. {
  672. if(Alarm_Counter[gun_index].Relay_Welding > FILTER_SPEC)
  673. {
  674. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == OFF)
  675. {
  676. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = ON;
  677. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_WELDING;
  678. DEBUG_INFO("ALARM_RELAY_STATUS : alarm \r\n");
  679. }
  680. }
  681. else
  682. {
  683. Alarm_Counter[gun_index].Relay_Welding++;
  684. }
  685. }
  686. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING))
  687. {
  688. Alarm_Counter[gun_index].Relay_Welding = 0;
  689. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == ON)
  690. {
  691. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = OFF;
  692. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_WELDING;
  693. DEBUG_INFO("ALARM_RELAY_STATUS : recover \r\n");
  694. }
  695. }
  696. //=====================================
  697. // Relay driving fault detection
  698. //=====================================
  699. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT)
  700. {
  701. if(Alarm_Counter[gun_index].Relay_DrivingFault > FILTER_SPEC)
  702. {
  703. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == OFF)
  704. {
  705. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = ON;
  706. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_DRIVE_FAULT;
  707. DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \r\n");
  708. }
  709. }
  710. else
  711. {
  712. Alarm_Counter[gun_index].Relay_DrivingFault++;
  713. }
  714. }
  715. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT))
  716. {
  717. Alarm_Counter[gun_index].Relay_DrivingFault = 0;
  718. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == ON)
  719. {
  720. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = OFF;
  721. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_DRIVE_FAULT;
  722. DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \r\n");
  723. }
  724. }
  725. //=====================================
  726. // Current short detection
  727. //=====================================
  728. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT)
  729. {
  730. if(Alarm_Counter[gun_index].Short > FILTER_SPEC)
  731. {
  732. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == OFF)
  733. {
  734. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = ON;
  735. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_SHORT;
  736. DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \r\n");
  737. }
  738. }
  739. else
  740. {
  741. Alarm_Counter[gun_index].Short++;
  742. }
  743. }
  744. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT))
  745. {
  746. Alarm_Counter[gun_index].Short = 0;
  747. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == ON)
  748. {
  749. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = OFF;
  750. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_SHORT;
  751. DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \r\n");
  752. }
  753. }
  754. //=====================================
  755. // Rotatory switch detection
  756. //=====================================
  757. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
  758. {
  759. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == OFF)
  760. {
  761. ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = ON;
  762. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
  763. DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \r\n");
  764. }
  765. }
  766. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT))
  767. {
  768. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == ON)
  769. {
  770. ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = OFF;
  771. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
  772. DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \r\n");
  773. }
  774. }
  775. //=====================================
  776. // Leakage module detection
  777. //=====================================
  778. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL)
  779. {
  780. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == OFF)
  781. {
  782. ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = ON;
  783. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
  784. DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \r\n");
  785. }
  786. }
  787. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL))
  788. {
  789. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == ON)
  790. {
  791. ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = OFF;
  792. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
  793. DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \r\n");
  794. }
  795. }
  796. //=====================================
  797. // Shutter detection
  798. //=====================================
  799. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT)
  800. {
  801. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == OFF)
  802. {
  803. ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = ON;
  804. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_SHUTTER_FAULT;
  805. DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \r\n");
  806. }
  807. }
  808. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT))
  809. {
  810. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == ON)
  811. {
  812. ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = OFF;
  813. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
  814. DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \r\n");
  815. }
  816. }
  817. //=====================================
  818. // Locker detection
  819. //=====================================
  820. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT)
  821. {
  822. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == OFF)
  823. {
  824. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = ON;
  825. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LOCKER_FAULT;
  826. DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \r\n");
  827. }
  828. }
  829. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT))
  830. {
  831. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == ON)
  832. {
  833. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = OFF;
  834. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
  835. DEBUG_INFO("ALARM_LOCKER_FAULT : recover \r\n");
  836. }
  837. }
  838. //=====================================
  839. // Power drop detection
  840. //=====================================
  841. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP)
  842. {
  843. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == OFF)
  844. {
  845. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = ON;
  846. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
  847. DEBUG_INFO("ALARM_POWER_DROP : alarm \r\n");
  848. }
  849. }
  850. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP))
  851. {
  852. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == ON)
  853. {
  854. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = OFF;
  855. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
  856. DEBUG_INFO("ALARM_POWER_DROP : recover \r\n");
  857. }
  858. }
  859. //=====================================
  860. // OCPP error code message
  861. //=====================================
  862. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)
  863. {
  864. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverVoltage");
  865. }
  866. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)
  867. {
  868. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "UnderVoltage");
  869. }
  870. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)
  871. {
  872. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverCurrentFailure");
  873. }
  874. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
  875. {
  876. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "HighTemperature");
  877. }
  878. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
  879. {
  880. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "GroundFailure");
  881. }
  882. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
  883. {
  884. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  885. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CpError");
  886. }
  887. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
  888. {
  889. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  890. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ACLeakage");
  891. }
  892. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
  893. {
  894. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  895. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "DCLeakage");
  896. }
  897. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
  898. {
  899. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  900. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "McuTestFail");
  901. }
  902. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
  903. {
  904. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  905. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "HandshakeTimeout");
  906. }
  907. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
  908. {
  909. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  910. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "EmergencyStop");
  911. }
  912. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
  913. {
  914. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  915. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayWelding");
  916. }
  917. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
  918. {
  919. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  920. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "LeakageModuleFail");
  921. }
  922. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
  923. {
  924. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  925. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ShutterFault");
  926. }
  927. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
  928. {
  929. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "ConnectorLockFailure");
  930. }
  931. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
  932. {
  933. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  934. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "PowerDrop");
  935. }
  936. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)
  937. {
  938. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  939. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CircuitShort");
  940. }
  941. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
  942. {
  943. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  944. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RotatorySwitchFault");
  945. }
  946. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
  947. {
  948. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  949. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayDriveFault");
  950. }
  951. else
  952. {
  953. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "NoError");
  954. memset(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, 0x00, ARRAY_SIZE(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
  955. }
  956. //=====================================
  957. // Latch alarm recover in state A
  958. //=====================================
  959. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 1))
  960. {
  961. /*
  962. TODO: Recover latch alarm here
  963. */
  964. }
  965. //=====================================
  966. // Latch alarm recover in state B1 and B2
  967. //=====================================
  968. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 2) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 3))
  969. {
  970. /*
  971. TODO: Recover latch alarm here
  972. */
  973. }
  974. //=====================================
  975. // Latch alarm recover in state C
  976. //=====================================
  977. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 4))
  978. {
  979. /*
  980. TODO: Recover latch alarm here
  981. */
  982. }
  983. }
  984. usleep(100000);
  985. }
  986. return FAIL;
  987. }