Module_AlarmDetect.c 39 KB

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