Module_AlarmDetect.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571
  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 OCPP20Data *ShmOCPP20Data;
  66. struct Charger *ShmCharger;
  67. unsigned long previousAlarmCode[AC_QUANTITY];
  68. int StoreLogMsg(const char *fmt, ...)
  69. {
  70. char Buf[4096+256];
  71. char buffer[4096];
  72. time_t CurrentTime;
  73. struct tm *tm;
  74. struct timeval tv;
  75. va_list args;
  76. va_start(args, fmt);
  77. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  78. va_end(args);
  79. memset(Buf,0,sizeof(Buf));
  80. CurrentTime = time(NULL);
  81. tm=localtime(&CurrentTime);
  82. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  83. if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
  84. {
  85. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
  86. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  87. buffer,
  88. tm->tm_year+1900,tm->tm_mon+1,
  89. ShmSysConfigAndInfo->SysConfig.ModelName,
  90. ShmSysConfigAndInfo->SysConfig.SerialNumber);
  91. }
  92. else
  93. {
  94. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  95. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  96. buffer,
  97. tm->tm_year+1900,tm->tm_mon+1);
  98. }
  99. #ifdef SystemLogMessage
  100. system(Buf);
  101. #endif
  102. #ifdef ConsloePrintLog
  103. 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);
  104. #endif
  105. return rc;
  106. }
  107. int DiffTimeb(struct timeb ST, struct timeb ET)
  108. {
  109. //return milli-second
  110. unsigned int StartTime,StopTime;
  111. StartTime=(unsigned int)ST.time;
  112. StopTime=(unsigned int)ET.time;
  113. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  114. }
  115. //==========================================
  116. // Init all share memory
  117. //==========================================
  118. int InitShareMemory()
  119. {
  120. int result = PASS;
  121. int MeterSMId;
  122. //creat ShmSysConfigAndInfo
  123. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  124. {
  125. #ifdef SystemLogMessage
  126. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  127. #endif
  128. result = FAIL;
  129. }
  130. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  131. {
  132. #ifdef SystemLogMessage
  133. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  134. #endif
  135. result = FAIL;
  136. }
  137. else
  138. {}
  139. //creat ShmStatusCodeData
  140. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  141. {
  142. #ifdef SystemLogMessage
  143. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  144. #endif
  145. result = FAIL;
  146. }
  147. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  148. {
  149. #ifdef SystemLogMessage
  150. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  151. #endif
  152. result = FAIL;
  153. }
  154. else
  155. {}
  156. //creat ShmStatusCodeData
  157. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  158. {
  159. DEBUG_ERROR("shmget ShmCharger NG\n");
  160. result = FAIL;
  161. }
  162. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  163. {
  164. DEBUG_ERROR("shmat ShmCharger NG\n");
  165. result = FAIL;
  166. }
  167. else
  168. {}
  169. //creat ShmOCPP16Data
  170. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  171. {
  172. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  173. result = FAIL;
  174. }
  175. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  176. {
  177. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  178. result = FAIL;
  179. }
  180. else
  181. {}
  182. //creat ShmOCPP20Data
  183. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  184. {
  185. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  186. result = FAIL;
  187. }
  188. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  189. {
  190. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  191. result = FAIL;
  192. }
  193. else
  194. {}
  195. return result;
  196. }
  197. //==========================================
  198. // Common routine
  199. //==========================================
  200. void trim(char *s)
  201. {
  202. int i=0, j, k, l=0;
  203. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  204. i++;
  205. j = strlen(s)-1;
  206. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  207. j--;
  208. if(i==0 && j==strlen(s)-1) { }
  209. else if(i==0) s[j+1] = '\0';
  210. else {
  211. for(k=i; k<=j; k++) s[l++] = s[k];
  212. s[l] = '\0';
  213. }
  214. }
  215. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  216. {
  217. strncpy(dest, src + start, cnt);
  218. dest[cnt] = 0;
  219. }
  220. void getNowDatetime(uint8_t *data)
  221. {
  222. time_t t = time(NULL);
  223. struct tm tm = *localtime(&t);
  224. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  225. }
  226. //==========================================
  227. // Main process
  228. //==========================================
  229. int main(void)
  230. {
  231. if(InitShareMemory() == FAIL)
  232. {
  233. DEBUG_ERROR("InitShareMemory NG\n");
  234. if(ShmStatusCodeData!=NULL)
  235. {
  236. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  237. }
  238. sleep(5);
  239. return FAIL;
  240. }
  241. for(;;)
  242. {
  243. for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
  244. {
  245. //=====================================
  246. // Over voltage detection
  247. //=====================================
  248. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
  249. {
  250. if(Alarm_Counter[gun_index].OV[0] > FILTER_SPEC)
  251. {
  252. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == OFF)
  253. {
  254. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = ON;
  255. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
  256. DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \n");
  257. }
  258. }
  259. else
  260. {
  261. Alarm_Counter[gun_index].OV[0]++;
  262. }
  263. }
  264. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
  265. {
  266. Alarm_Counter[gun_index].OV[0] = 0;
  267. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON)
  268. {
  269. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = OFF;
  270. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
  271. DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \n");
  272. }
  273. }
  274. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  275. {
  276. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
  277. {
  278. if(Alarm_Counter[gun_index].OV[1] > FILTER_SPEC)
  279. {
  280. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == OFF)
  281. {
  282. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = ON;
  283. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
  284. DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \n");
  285. }
  286. }
  287. else
  288. {
  289. Alarm_Counter[gun_index].OV[1]++;
  290. }
  291. }
  292. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
  293. {
  294. Alarm_Counter[gun_index].OV[1] = 0;
  295. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON)
  296. {
  297. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = OFF;
  298. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
  299. DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \n");
  300. }
  301. }
  302. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)
  303. {
  304. if(Alarm_Counter[gun_index].OV[2] > FILTER_SPEC)
  305. {
  306. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == OFF)
  307. {
  308. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = ON;
  309. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
  310. DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \n");
  311. }
  312. }
  313. else
  314. {
  315. Alarm_Counter[gun_index].OV[2]++;
  316. }
  317. }
  318. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
  319. {
  320. Alarm_Counter[gun_index].OV[2] = 0;
  321. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON)
  322. {
  323. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = OFF;
  324. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
  325. DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \n");
  326. }
  327. }
  328. }
  329. //=====================================
  330. // Under voltage detection
  331. //=====================================
  332. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
  333. {
  334. if(Alarm_Counter[gun_index].UV[0] > FILTER_SPEC)
  335. {
  336. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == OFF)
  337. {
  338. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = ON;
  339. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
  340. DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \n");
  341. }
  342. }
  343. else
  344. {
  345. Alarm_Counter[gun_index].UV[0]++;
  346. }
  347. }
  348. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
  349. {
  350. Alarm_Counter[gun_index].UV[0] = 0;
  351. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON)
  352. {
  353. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = OFF;
  354. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
  355. DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \n");
  356. }
  357. }
  358. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  359. {
  360. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
  361. {
  362. if(Alarm_Counter[gun_index].UV[1] > FILTER_SPEC)
  363. {
  364. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == OFF)
  365. {
  366. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = ON;
  367. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
  368. DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \n");
  369. }
  370. }
  371. else
  372. {
  373. Alarm_Counter[gun_index].UV[1]++;
  374. }
  375. }
  376. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
  377. {
  378. Alarm_Counter[gun_index].UV[1] = 0;
  379. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON)
  380. {
  381. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = OFF;
  382. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
  383. DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \n");
  384. }
  385. }
  386. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)
  387. {
  388. if(Alarm_Counter[gun_index].UV[2] > FILTER_SPEC)
  389. {
  390. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == OFF)
  391. {
  392. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = ON;
  393. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
  394. DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \n");
  395. }
  396. }
  397. else
  398. {
  399. Alarm_Counter[gun_index].UV[2]++;
  400. }
  401. }
  402. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
  403. {
  404. Alarm_Counter[gun_index].UV[2] = 0;
  405. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON)
  406. {
  407. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = OFF;
  408. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
  409. DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \n");
  410. }
  411. }
  412. }
  413. //=====================================
  414. // Over current detection
  415. //=====================================
  416. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
  417. {
  418. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
  419. {
  420. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
  421. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
  422. DEBUG_INFO("ALARM_OVER_CURRENT : alarm \n");
  423. }
  424. }
  425. else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
  426. {
  427. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
  428. {
  429. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
  430. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
  431. DEBUG_INFO("ALARM_OVER_CURRENT : recover \n");
  432. }
  433. }
  434. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  435. {
  436. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
  437. {
  438. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
  439. {
  440. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
  441. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
  442. DEBUG_INFO("ALARM_OVER_CURRENT : alarm \n");
  443. }
  444. }
  445. else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
  446. {
  447. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
  448. {
  449. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
  450. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
  451. DEBUG_INFO("ALARM_OVER_CURRENT : recover \n");
  452. }
  453. }
  454. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)
  455. {
  456. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
  457. {
  458. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
  459. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
  460. DEBUG_INFO("ALARM_OVER_CURRENT : alarm \n");
  461. }
  462. }
  463. else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
  464. {
  465. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
  466. {
  467. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
  468. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
  469. DEBUG_INFO("ALARM_OVER_CURRENT : recover \n");
  470. }
  471. }
  472. }
  473. //=====================================
  474. // Over temperature detection
  475. //=====================================
  476. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)
  477. {
  478. if(Alarm_Counter[gun_index].OT_AMB > FILTER_SPEC)
  479. {
  480. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == OFF)
  481. {
  482. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = ON;
  483. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_TEMPERATURE;
  484. DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \n");
  485. }
  486. }
  487. else
  488. {
  489. Alarm_Counter[gun_index].OT_AMB++;
  490. }
  491. }
  492. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)))
  493. {
  494. Alarm_Counter[gun_index].OT_AMB = 0;
  495. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == ON)
  496. {
  497. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = OFF;
  498. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_TEMPERATURE;
  499. DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \n");
  500. }
  501. }
  502. //=====================================
  503. // Ground fault detection
  504. //=====================================
  505. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL)
  506. {
  507. if(Alarm_Counter[gun_index].GMI > FILTER_SPEC)
  508. {
  509. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == OFF)
  510. {
  511. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = ON;
  512. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
  513. DEBUG_INFO("ALARM_GROUND_FAIL : alarm \n");
  514. }
  515. }
  516. else
  517. {
  518. Alarm_Counter[gun_index].GMI++;
  519. }
  520. }
  521. else if (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL))
  522. {
  523. Alarm_Counter[gun_index].GMI = 0;
  524. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == ON)
  525. {
  526. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = OFF;
  527. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
  528. DEBUG_INFO("ALARM_GROUND_FAIL : recover \n");
  529. }
  530. }
  531. //=====================================
  532. // CP level fail detection
  533. //=====================================
  534. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR)
  535. {
  536. if(Alarm_Counter[gun_index].CP_LevelFail > FILTER_SPEC)
  537. {
  538. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == OFF)
  539. {
  540. ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = ON;
  541. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_ERROR;
  542. DEBUG_INFO("ALARM_CP_ERROR : alarm \n");
  543. }
  544. }
  545. else
  546. {
  547. Alarm_Counter[gun_index].CP_LevelFail++;
  548. }
  549. }
  550. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR))
  551. {
  552. Alarm_Counter[gun_index].CP_LevelFail= 0;
  553. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == ON)
  554. {
  555. ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = OFF;
  556. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_ERROR;
  557. DEBUG_INFO("ALARM_CP_ERROR : recover \n");
  558. }
  559. }
  560. //=====================================
  561. // Current AC/DC leak detection
  562. //=====================================
  563. if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC) ||
  564. (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
  565. {
  566. if(Alarm_Counter[gun_index].Leakage > FILTER_SPEC)
  567. {
  568. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF)
  569. {
  570. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
  571. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
  572. {
  573. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
  574. ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = ON;
  575. DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \n");
  576. }
  577. else if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
  578. {
  579. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
  580. ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = ON;
  581. DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \n");
  582. }
  583. }
  584. }
  585. else
  586. {
  587. Alarm_Counter[gun_index].Leakage++;
  588. }
  589. }
  590. else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)) ||
  591. (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)))
  592. {
  593. Alarm_Counter[gun_index].Leakage = 0;
  594. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON)
  595. {
  596. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
  597. if(ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage == ON)
  598. {
  599. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
  600. ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = OFF;
  601. DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \n");
  602. }
  603. else if(ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage == ON)
  604. {
  605. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
  606. ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = OFF;
  607. DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \n");
  608. }
  609. }
  610. }
  611. //=====================================
  612. // MCU self test fail detection
  613. //=====================================
  614. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL)
  615. {
  616. if(Alarm_Counter[gun_index].MCU_SelfTestFail > FILTER_SPEC)
  617. {
  618. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == OFF)
  619. {
  620. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = ON;
  621. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
  622. DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \n");
  623. }
  624. }
  625. else
  626. {
  627. Alarm_Counter[gun_index].MCU_SelfTestFail++;
  628. }
  629. }
  630. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL))
  631. {
  632. Alarm_Counter[gun_index].MCU_SelfTestFail = 0;
  633. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == ON)
  634. {
  635. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = OFF;
  636. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
  637. DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \n");
  638. }
  639. }
  640. //=====================================
  641. // Hand shaking timeout detection
  642. //=====================================
  643. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
  644. {
  645. if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == OFF)
  646. {
  647. ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut = ON;
  648. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_HANDSHAKE_TIMEOUT;
  649. DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \n");
  650. }
  651. }
  652. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT))
  653. {
  654. if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == ON)
  655. {
  656. ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut = OFF;
  657. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_HANDSHAKE_TIMEOUT;
  658. DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \n");
  659. }
  660. }
  661. //=====================================
  662. // Emergency stop detection
  663. //=====================================
  664. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP)
  665. {
  666. if(Alarm_Counter[gun_index].EmrgencyBTN > FILTER_SPEC)
  667. {
  668. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == OFF)
  669. {
  670. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = ON;
  671. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_EMERGENCY_STOP;
  672. DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \n");
  673. }
  674. }
  675. else
  676. {
  677. Alarm_Counter[gun_index].EmrgencyBTN++;
  678. }
  679. }
  680. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP))
  681. {
  682. Alarm_Counter[gun_index].EmrgencyBTN = 0;
  683. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == ON)
  684. {
  685. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = OFF;
  686. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_EMERGENCY_STOP;
  687. DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \n");
  688. }
  689. }
  690. //=====================================
  691. // Relay welding detection
  692. //=====================================
  693. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING)
  694. {
  695. if(Alarm_Counter[gun_index].Relay_Welding > FILTER_SPEC)
  696. {
  697. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == OFF)
  698. {
  699. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = ON;
  700. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_WELDING;
  701. DEBUG_INFO("ALARM_RELAY_STATUS : alarm \n");
  702. }
  703. }
  704. else
  705. {
  706. Alarm_Counter[gun_index].Relay_Welding++;
  707. }
  708. }
  709. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING))
  710. {
  711. Alarm_Counter[gun_index].Relay_Welding = 0;
  712. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == ON)
  713. {
  714. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = OFF;
  715. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_WELDING;
  716. DEBUG_INFO("ALARM_RELAY_STATUS : recover \n");
  717. }
  718. }
  719. //=====================================
  720. // Relay driving fault detection
  721. //=====================================
  722. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT)
  723. {
  724. if(Alarm_Counter[gun_index].Relay_DrivingFault > FILTER_SPEC)
  725. {
  726. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == OFF)
  727. {
  728. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = ON;
  729. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_DRIVE_FAULT;
  730. DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \n");
  731. }
  732. }
  733. else
  734. {
  735. Alarm_Counter[gun_index].Relay_DrivingFault++;
  736. }
  737. }
  738. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT))
  739. {
  740. Alarm_Counter[gun_index].Relay_DrivingFault = 0;
  741. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == ON)
  742. {
  743. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = OFF;
  744. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_DRIVE_FAULT;
  745. DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \n");
  746. }
  747. }
  748. //=====================================
  749. // Current short detection
  750. //=====================================
  751. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT)
  752. {
  753. if(Alarm_Counter[gun_index].Short > FILTER_SPEC)
  754. {
  755. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == OFF)
  756. {
  757. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = ON;
  758. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_SHORT;
  759. DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \n");
  760. }
  761. }
  762. else
  763. {
  764. Alarm_Counter[gun_index].Short++;
  765. }
  766. }
  767. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT))
  768. {
  769. Alarm_Counter[gun_index].Short = 0;
  770. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == ON)
  771. {
  772. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = OFF;
  773. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_SHORT;
  774. DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \n");
  775. }
  776. }
  777. //=====================================
  778. // Rotatory switch detection
  779. //=====================================
  780. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
  781. {
  782. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == OFF)
  783. {
  784. ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = ON;
  785. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
  786. DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \n");
  787. }
  788. }
  789. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT))
  790. {
  791. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == ON)
  792. {
  793. ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = OFF;
  794. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
  795. DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \n");
  796. }
  797. }
  798. //=====================================
  799. // Leakage module detection
  800. //=====================================
  801. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL)
  802. {
  803. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == OFF)
  804. {
  805. ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = ON;
  806. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
  807. DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \n");
  808. }
  809. }
  810. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL))
  811. {
  812. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == ON)
  813. {
  814. ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = OFF;
  815. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
  816. DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \n");
  817. }
  818. }
  819. //=====================================
  820. // Shutter detection
  821. //=====================================
  822. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT)
  823. {
  824. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == OFF)
  825. {
  826. ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = ON;
  827. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_SHUTTER_FAULT;
  828. DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \n");
  829. }
  830. }
  831. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT))
  832. {
  833. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == ON)
  834. {
  835. ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = OFF;
  836. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
  837. DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \n");
  838. }
  839. }
  840. //=====================================
  841. // Locker detection
  842. //=====================================
  843. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT)
  844. {
  845. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == OFF)
  846. {
  847. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = ON;
  848. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LOCKER_FAULT;
  849. DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \n");
  850. }
  851. }
  852. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT))
  853. {
  854. if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == ON)
  855. {
  856. ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = OFF;
  857. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
  858. DEBUG_INFO("ALARM_LOCKER_FAULT : recover \n");
  859. }
  860. }
  861. //=====================================
  862. // Power drop detection
  863. //=====================================
  864. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP)
  865. {
  866. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == OFF)
  867. {
  868. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = ON;
  869. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
  870. DEBUG_INFO("ALARM_POWER_DROP : alarm \n");
  871. }
  872. }
  873. else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP))
  874. {
  875. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == ON)
  876. {
  877. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = OFF;
  878. ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
  879. DEBUG_INFO("ALARM_POWER_DROP : recover \n");
  880. }
  881. }
  882. //=====================================
  883. // OCPP error code message
  884. //=====================================
  885. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  886. {
  887. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)
  888. {
  889. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverVoltage");
  890. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012200");
  891. }
  892. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)
  893. {
  894. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "UnderVoltage");
  895. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012203");
  896. }
  897. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)
  898. {
  899. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverCurrentFailure");
  900. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012216");
  901. }
  902. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
  903. {
  904. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "HighTemperature");
  905. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012223");
  906. }
  907. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
  908. {
  909. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "GroundFailure");
  910. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012256");
  911. }
  912. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
  913. {
  914. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  915. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "023703");
  916. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "CpError");
  917. }
  918. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
  919. {
  920. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  921. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012233");
  922. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "ACLeakage");
  923. }
  924. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
  925. {
  926. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  927. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012233");
  928. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "DCLeakage");
  929. }
  930. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
  931. {
  932. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  933. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012257");
  934. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "McuTestFail");
  935. }
  936. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
  937. {
  938. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  939. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "HandshakeTimeout");
  940. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "HandshakeTimeout");
  941. }
  942. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
  943. {
  944. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  945. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012251");
  946. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "EmergencyStop");
  947. }
  948. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
  949. {
  950. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  951. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011009");
  952. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "RelayWelding");
  953. }
  954. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
  955. {
  956. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  957. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011004");
  958. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "LeakageModuleFail");
  959. }
  960. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
  961. {
  962. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  963. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011034");
  964. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "ShutterFault");
  965. }
  966. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
  967. {
  968. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "ConnectorLockFailure");
  969. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011027");
  970. }
  971. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
  972. {
  973. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  974. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012212");
  975. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "PowerDrop");
  976. }
  977. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)
  978. {
  979. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  980. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012262");
  981. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "CircuitShort");
  982. }
  983. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
  984. {
  985. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  986. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011036");
  987. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "RotatorySwitchFault");
  988. }
  989. else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
  990. {
  991. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
  992. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011010");
  993. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "RelayDriveFault");
  994. }
  995. else
  996. {
  997. sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "NoError");
  998. memset(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, 0x00, ARRAY_SIZE(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
  999. }
  1000. }
  1001. else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  1002. {
  1003. uint8_t idxEvent = 0;
  1004. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_OVER_VOLTAGE))
  1005. {
  1006. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1007. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1008. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1009. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)?"true":"false"));
  1010. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)?OFF:ON);
  1011. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1012. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012200");
  1013. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L1 input OVP");
  1014. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
  1015. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1016. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1017. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1018. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)
  1019. previousAlarmCode[gun_index] |= ALARM_OVER_VOLTAGE;
  1020. else
  1021. previousAlarmCode[gun_index] &= ~ALARM_OVER_VOLTAGE;
  1022. }
  1023. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_UNDER_VOLTAGE))
  1024. {
  1025. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1026. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1027. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1028. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)?"true":"false"));
  1029. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)?OFF:ON);
  1030. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1031. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012203");
  1032. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L1 input UVP");
  1033. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
  1034. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1035. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1036. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1037. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)
  1038. previousAlarmCode[gun_index] |= ALARM_UNDER_VOLTAGE;
  1039. else
  1040. previousAlarmCode[gun_index] &= ~ALARM_UNDER_VOLTAGE;
  1041. }
  1042. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT) != (previousAlarmCode[gun_index] & ALARM_OVER_CURRENT))
  1043. {
  1044. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1045. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1046. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1047. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)?"true":"false"));
  1048. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)?OFF:ON);
  1049. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1050. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012216");
  1051. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System AC output OCP L1");
  1052. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
  1053. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1054. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1055. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1056. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)
  1057. previousAlarmCode[gun_index] |= ALARM_OVER_CURRENT;
  1058. else
  1059. previousAlarmCode[gun_index] &= ~ALARM_OVER_CURRENT;
  1060. }
  1061. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE) != (previousAlarmCode[gun_index] & ALARM_OVER_TEMPERATURE))
  1062. {
  1063. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1064. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1065. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1066. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)?"true":"false"));
  1067. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)?OFF:ON);
  1068. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1069. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012223");
  1070. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System ambient/inlet OTP");
  1071. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Temperature");
  1072. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1073. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1074. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1075. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
  1076. previousAlarmCode[gun_index] |= ALARM_OVER_TEMPERATURE;
  1077. else
  1078. previousAlarmCode[gun_index] &= ~ALARM_OVER_TEMPERATURE;
  1079. }
  1080. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL) != (previousAlarmCode[gun_index] & ALARM_GROUND_FAIL))
  1081. {
  1082. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1083. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1084. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1085. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)?"true":"false"));
  1086. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)?OFF:ON);
  1087. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1088. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012256");
  1089. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC Ground Fault");
  1090. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Ground(PE)");
  1091. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1092. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1093. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1094. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
  1095. previousAlarmCode[gun_index] |= ALARM_GROUND_FAIL;
  1096. else
  1097. previousAlarmCode[gun_index] &= ~ALARM_GROUND_FAIL;
  1098. }
  1099. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR) != (previousAlarmCode[gun_index] & ALARM_CP_ERROR))
  1100. {
  1101. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1102. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1103. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1104. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)?"true":"false"));
  1105. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)?OFF:ON);
  1106. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1107. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "023703");
  1108. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "pilot fault");
  1109. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Control pilot");
  1110. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1111. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1112. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1113. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
  1114. previousAlarmCode[gun_index] |= ALARM_CP_ERROR;
  1115. else
  1116. previousAlarmCode[gun_index] &= ~ALARM_CP_ERROR;
  1117. }
  1118. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC) != (previousAlarmCode[gun_index] & ALARM_CURRENT_LEAK_AC))
  1119. {
  1120. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1121. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1122. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1123. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)?"true":"false"));
  1124. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)?OFF:ON);
  1125. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1126. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012233");
  1127. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "RCD/CCID trip");
  1128. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "CCID");
  1129. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1130. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1131. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1132. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
  1133. previousAlarmCode[gun_index] |= ALARM_CURRENT_LEAK_AC;
  1134. else
  1135. previousAlarmCode[gun_index] &= ~ALARM_CURRENT_LEAK_AC;
  1136. }
  1137. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC) != (previousAlarmCode[gun_index] & ALARM_CURRENT_LEAK_DC))
  1138. {
  1139. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1140. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1141. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1142. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)?"true":"false"));
  1143. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)?OFF:ON);
  1144. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1145. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012233");
  1146. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "RCD/CCID trip");
  1147. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "CCID");
  1148. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1149. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1150. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1151. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
  1152. previousAlarmCode[gun_index] |= ALARM_CURRENT_LEAK_DC;
  1153. else
  1154. previousAlarmCode[gun_index] &= ~ALARM_CURRENT_LEAK_DC;
  1155. }
  1156. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL) != (previousAlarmCode[gun_index] & ALARM_MCU_TESTFAIL))
  1157. {
  1158. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1159. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1160. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1161. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)?"true":"false"));
  1162. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)?OFF:ON);
  1163. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1164. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012257");
  1165. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "MCU self-test Fault");
  1166. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "MCU");
  1167. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1168. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1169. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1170. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
  1171. previousAlarmCode[gun_index] |= ALARM_MCU_TESTFAIL;
  1172. else
  1173. previousAlarmCode[gun_index] &= ~ALARM_MCU_TESTFAIL;
  1174. }
  1175. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT) != (previousAlarmCode[gun_index] & ALARM_HANDSHAKE_TIMEOUT))
  1176. {
  1177. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1178. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1179. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1180. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)?"true":"false"));
  1181. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)?OFF:ON);
  1182. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1183. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "HandshakeTimeout");
  1184. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "HandshakeTimeout");
  1185. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Operation");
  1186. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1187. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1188. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1189. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
  1190. previousAlarmCode[gun_index] |= ALARM_HANDSHAKE_TIMEOUT;
  1191. else
  1192. previousAlarmCode[gun_index] &= ~ALARM_HANDSHAKE_TIMEOUT;
  1193. }
  1194. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP) != (previousAlarmCode[gun_index] & ALARM_EMERGENCY_STOP))
  1195. {
  1196. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1197. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1198. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1199. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)?"true":"false"));
  1200. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)?OFF:ON);
  1201. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1202. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012251");
  1203. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Emergency stop");
  1204. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Button");
  1205. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1206. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1207. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1208. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
  1209. previousAlarmCode[gun_index] |= ALARM_EMERGENCY_STOP;
  1210. else
  1211. previousAlarmCode[gun_index] &= ~ALARM_EMERGENCY_STOP;
  1212. }
  1213. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING) != (previousAlarmCode[gun_index] & ALARM_RELAY_WELDING))
  1214. {
  1215. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1216. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1217. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1218. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)?"true":"false"));
  1219. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)?OFF:ON);
  1220. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1221. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011009");
  1222. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC output relay welding");
  1223. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Relay");
  1224. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1225. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1226. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1227. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
  1228. previousAlarmCode[gun_index] |= ALARM_RELAY_WELDING;
  1229. else
  1230. previousAlarmCode[gun_index] &= ~ALARM_RELAY_WELDING;
  1231. }
  1232. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL) != (previousAlarmCode[gun_index] & ALARM_LEAK_MODULE_FAIL))
  1233. {
  1234. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1235. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1236. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1237. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)?"true":"false"));
  1238. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)?OFF:ON);
  1239. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1240. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011004");
  1241. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "RCD/CCID self-test fail");
  1242. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "CCID");
  1243. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1244. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1245. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1246. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
  1247. previousAlarmCode[gun_index] |= ALARM_LEAK_MODULE_FAIL;
  1248. else
  1249. previousAlarmCode[gun_index] &= ~ALARM_LEAK_MODULE_FAIL;
  1250. }
  1251. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT) != (previousAlarmCode[gun_index] & ALARM_SHUTTER_FAULT))
  1252. {
  1253. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1254. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1255. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1256. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)?"true":"false"));
  1257. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)?OFF:ON);
  1258. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1259. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011034");
  1260. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Shutter fault");
  1261. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Shutter");
  1262. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1263. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1264. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1265. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
  1266. previousAlarmCode[gun_index] |= ALARM_SHUTTER_FAULT;
  1267. else
  1268. previousAlarmCode[gun_index] &= ~ALARM_SHUTTER_FAULT;
  1269. }
  1270. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT) != (previousAlarmCode[gun_index] & ALARM_LOCKER_FAULT))
  1271. {
  1272. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1273. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1274. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1275. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)?"true":"false"));
  1276. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)?OFF:ON);
  1277. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1278. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011027");
  1279. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC connector lock fail");
  1280. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Locker");
  1281. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1282. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1283. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1284. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
  1285. previousAlarmCode[gun_index] |= ALARM_LOCKER_FAULT;
  1286. else
  1287. previousAlarmCode[gun_index] &= ~ALARM_LOCKER_FAULT;
  1288. }
  1289. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP) != (previousAlarmCode[gun_index] & ALARM_POWER_DROP))
  1290. {
  1291. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1292. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1293. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1294. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)?"true":"false"));
  1295. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)?OFF:ON);
  1296. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1297. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012212");
  1298. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L1 input drop");
  1299. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
  1300. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1301. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1302. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1303. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
  1304. previousAlarmCode[gun_index] |= ALARM_POWER_DROP;
  1305. else
  1306. previousAlarmCode[gun_index] &= ~ALARM_POWER_DROP;
  1307. }
  1308. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT) != (previousAlarmCode[gun_index] & ALARM_CURRENT_SHORT))
  1309. {
  1310. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1311. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1312. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1313. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)?"true":"false"));
  1314. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)?OFF:ON);
  1315. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1316. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012262");
  1317. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Circuit Short L1");
  1318. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
  1319. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1320. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1321. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1322. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)
  1323. previousAlarmCode[gun_index] |= ALARM_CURRENT_SHORT;
  1324. else
  1325. previousAlarmCode[gun_index] &= ~ALARM_CURRENT_SHORT;
  1326. }
  1327. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT) != (previousAlarmCode[gun_index] & ALARM_ROTATORY_SWITCH_FAULT))
  1328. {
  1329. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1330. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1331. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1332. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)?"true":"false"));
  1333. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)?OFF:ON);
  1334. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1335. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011036");
  1336. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Rotary switch fault");
  1337. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Rotary switch");
  1338. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1339. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1340. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1341. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
  1342. previousAlarmCode[gun_index] |= ALARM_ROTATORY_SWITCH_FAULT;
  1343. else
  1344. previousAlarmCode[gun_index] &= ~ALARM_ROTATORY_SWITCH_FAULT;
  1345. }
  1346. if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT) != (previousAlarmCode[gun_index] & ALARM_RELAY_DRIVE_FAULT))
  1347. {
  1348. getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
  1349. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
  1350. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
  1351. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)?"true":"false"));
  1352. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)?OFF:ON);
  1353. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
  1354. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011010");
  1355. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC output relay driving fault");
  1356. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Relay");
  1357. ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
  1358. sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
  1359. idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
  1360. if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
  1361. previousAlarmCode[gun_index] |= ALARM_RELAY_DRIVE_FAULT;
  1362. else
  1363. previousAlarmCode[gun_index] &= ~ALARM_RELAY_DRIVE_FAULT;
  1364. }
  1365. if(idxEvent > 0)
  1366. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = ON;
  1367. }
  1368. //=====================================
  1369. // Latch alarm recover in state A
  1370. //=====================================
  1371. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 1))
  1372. {
  1373. /*
  1374. TODO: Recover latch alarm here
  1375. */
  1376. }
  1377. //=====================================
  1378. // Latch alarm recover in state B1 and B2
  1379. //=====================================
  1380. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 2) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 3))
  1381. {
  1382. /*
  1383. TODO: Recover latch alarm here
  1384. */
  1385. }
  1386. //=====================================
  1387. // Latch alarm recover in state C
  1388. //=====================================
  1389. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 4))
  1390. {
  1391. /*
  1392. TODO: Recover latch alarm here
  1393. */
  1394. }
  1395. }
  1396. usleep(100000);
  1397. }
  1398. return FAIL;
  1399. }