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