Module_AlarmDetect.c 34 KB

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