Primary.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include "../Config.h"
  6. #include "../Log/log.h"
  7. #include "../Define/define.h"
  8. #include "../ShareMemory/shmMem.h"
  9. #include "../SelectGun/SelectGun.h"
  10. #include "../main.h"
  11. //------------------------------------------------------------------------------
  12. //------------------------------------------------------------------------------
  13. static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
  14. {
  15. uint8_t ret = NO;
  16. LedConfig *pLedConfig = (LedConfig *)ledConfig;
  17. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  18. if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
  19. ret = YES;
  20. if (pLedConfig->RedLED == YES) {
  21. pLedConfig->RedLED = NO;
  22. } else {
  23. pLedConfig->RedLED = YES;
  24. }
  25. }
  26. return ret;
  27. }
  28. void PrimaryLedIndicatorCtrlFork(void)
  29. {
  30. #if !defined DD360ComBox
  31. return;
  32. #endif //!defined DD360ComBox
  33. pid_t pid = fork();
  34. if (pid == 0) {
  35. uint8_t gunIndex = 0;
  36. int isContinue = 1;
  37. LedConfig *pLedConfig = NULL;
  38. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  39. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  40. struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  41. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  42. struct ChargingInfoData *pDcChargingInfoData = NULL;
  43. pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
  44. while (isContinue) {
  45. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  46. pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  47. //printf("led indicator status = %d\r\n", pDcChargingInfoData->SystemStatus);
  48. //printf("level = %d\r\n", pSysWarningInfo->Level);
  49. switch (pDcChargingInfoData->SystemStatus) {
  50. case S_BOOTING:
  51. if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
  52. //Module_DoComm tcp disconnect
  53. if (pLedConfig->RedLED == YES ||
  54. pLedConfig->YellowLED == YES ||
  55. pLedConfig->GreenLED == YES) {
  56. pLedConfig->RedLED = NO;
  57. pLedConfig->YellowLED = NO;
  58. pLedConfig->GreenLED = NO;
  59. } else {
  60. pLedConfig->RedLED = YES;
  61. pLedConfig->YellowLED = YES;
  62. pLedConfig->GreenLED = YES;
  63. }
  64. break;
  65. }
  66. pLedConfig->RedLED = YES;
  67. pLedConfig->YellowLED = YES;
  68. pLedConfig->GreenLED = YES;
  69. break;
  70. case S_IDLE:
  71. //Module_DoComm connected and system idle
  72. pLedConfig->RedLED = NO;
  73. pLedConfig->YellowLED = NO;
  74. pLedConfig->GreenLED = YES;
  75. break;
  76. case S_RESERVATION:
  77. case S_AUTHORIZING:
  78. case S_REASSIGN_CHECK:
  79. case S_REASSIGN:
  80. case S_PREPARNING:
  81. case S_PREPARING_FOR_EV:
  82. case S_PREPARING_FOR_EVSE:
  83. case S_CCS_PRECHARGE_ST0:
  84. case S_CCS_PRECHARGE_ST1:
  85. //precharging status
  86. if (pLedConfig->GreenLED == YES) {
  87. pLedConfig->GreenLED = NO;
  88. } else {
  89. pLedConfig->GreenLED = YES;
  90. }
  91. break;
  92. case S_CHARGING:
  93. pLedConfig->RedLED = NO;
  94. if (pLedConfig->YellowLED == YES) {
  95. pLedConfig->YellowLED = NO;
  96. } else {
  97. pLedConfig->YellowLED = YES;
  98. }
  99. pLedConfig->GreenLED = NO;
  100. break;
  101. case S_ALARM:
  102. pLedConfig->YellowLED = NO;
  103. pLedConfig->GreenLED = NO;
  104. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  105. break;
  106. }
  107. pLedConfig->RedLED = YES;
  108. break;
  109. case S_TERMINATING:
  110. case S_COMPLETE:
  111. if (pSysWarningInfo->Level == 2) {
  112. pLedConfig->YellowLED = NO;
  113. pLedConfig->GreenLED = NO;
  114. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  115. break;
  116. }
  117. pLedConfig->RedLED = YES;
  118. } else {
  119. pLedConfig->RedLED = NO;
  120. pLedConfig->YellowLED = YES;
  121. pLedConfig->GreenLED = NO;
  122. }
  123. break;
  124. case S_MAINTAIN:
  125. case S_FAULT:
  126. pLedConfig->YellowLED = NO;
  127. pLedConfig->GreenLED = NO;
  128. if (pSysWarningInfo->Level == 2) {
  129. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  130. break;
  131. }
  132. pLedConfig->RedLED = YES;
  133. }
  134. break;
  135. case S_BOOKING:
  136. case S_DEBUG:
  137. case S_UPDATE:
  138. case S_NONE:
  139. break;
  140. }//switch
  141. } //for
  142. usleep(500000);
  143. } //while
  144. } //fork
  145. }
  146. //------------------------------------------------------------------------------
  147. // 急停狀況的停止充電處理函式
  148. void EmcOccureByString(char *code)
  149. {
  150. uint8_t level = 2;
  151. uint8_t gunIndex = 0;
  152. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  153. struct ChargingInfoData *pDcChargingInfoData = NULL;
  154. // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
  155. // 其錯誤等級為 2
  156. //#if defined DD360 ||defined DD360Audi || defined DD360ComBox
  157. // //DS60-120 remove
  158. // if (strncmp(code, "012251", 6) == EQUAL ||
  159. // strncmp(code, "012252", 6) == EQUAL ||
  160. // strncmp(code, "012238", 6) == EQUAL ||
  161. // strncmp(code, "042251", 6) == EQUAL ||
  162. // strncmp(code, "042252", 6) == EQUAL ||
  163. // strncmp(code, "012304", 6) == EQUAL ||
  164. // strncmp(code, "042200", 6) == EQUAL ||
  165. // strncmp(code, "042201", 6) == EQUAL ||
  166. // strncmp(code, "042202", 6) == EQUAL ||
  167. // strncmp(code, "042267", 6) == EQUAL)
  168. //#endif //defined DD360 || defined DD360Audi
  169. {
  170. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  171. pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  172. //strncpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, code, 6);
  173. if ((pDcChargingInfoData->SystemStatus > S_IDLE &&
  174. pDcChargingInfoData->SystemStatus < S_TERMINATING) ||
  175. (pDcChargingInfoData->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  176. pDcChargingInfoData->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  177. //ChargingTerminalProcess(gunIndex);
  178. ChargingAlarmProcess(gunIndex);
  179. }
  180. }
  181. //#if defined DD360 ||defined DD360Audi || defined DD360ComBox
  182. StopChargingProcessByString(level);
  183. //InformOcppErrOccur(4);
  184. //#endif //defined DD360 || defined DD360Audi
  185. }
  186. }
  187. void ReleaseEmsOccureByString(uint8_t index, char *code)
  188. {
  189. bool isTrigger = false;
  190. uint8_t level = 2;
  191. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  192. if (strncmp(code, "042251", 6) == 0 ) {
  193. isTrigger = true;
  194. } else if (strncmp(code, "012251", 6) == 0 &&
  195. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
  196. isTrigger = true;
  197. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
  198. } else if (strncmp(code, "012252", 6) == 0 &&
  199. pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
  200. isTrigger = true;
  201. pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
  202. } else if (strncmp(code, "012237", 6) == 0 &&
  203. pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
  204. isTrigger = true;
  205. pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
  206. } else if (strncmp(code, "012238", 6) == 0 &&
  207. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  208. isTrigger = true;
  209. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
  210. }
  211. if (isTrigger) {
  212. ReleaseChargingProcessByString(level);
  213. InformOcppErrOccur(6);
  214. }
  215. }
  216. void ChkPrimaryStatus(void)
  217. {
  218. uint8_t Rtn;
  219. static bool leftBtnPush = false;
  220. static bool rightBtnPush = false;
  221. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  222. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  223. struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  224. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  225. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  226. struct ChargingInfoData *pDcChargingInfoData = NULL;
  227. struct ChargingInfoData *pAcChargingInfoData = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  228. if (pSysWarningInfo->WarningCount > 0) {
  229. Rtn = 0;
  230. for (uint8_t i = 0; i < pSysWarningInfo->WarningCount; i++) {
  231. if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042251", 6) == 0) {
  232. EmcOccureByString("042251");
  233. Rtn = 1;
  234. } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042252", 6) == 0) {
  235. EmcOccureByString("042252");
  236. Rtn = 1;
  237. } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042200", 6) == 0) {
  238. EmcOccureByString("042200");
  239. Rtn = 1;
  240. } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042201", 6) == 0) {
  241. EmcOccureByString("042201");
  242. Rtn = 1;
  243. } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042202", 6) == 0) {
  244. EmcOccureByString("042202");
  245. Rtn = 1;
  246. } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "012304", 6) == 0) {
  247. EmcOccureByString("012304");
  248. Rtn = 1;
  249. }
  250. }
  251. if (Rtn == 0) {
  252. ReleaseEmsOccureByString(0, "042251");
  253. ReleaseEmsOccureByString(0, "042252");
  254. ReleaseEmsOccureByString(0, "042200");
  255. ReleaseEmsOccureByString(0, "042201");
  256. ReleaseEmsOccureByString(0, "042202");
  257. ReleaseEmsOccureByString(0, "012304");
  258. }
  259. } else {
  260. ReleaseEmsOccureByString(0, "042251");
  261. ReleaseEmsOccureByString(0, "042252");
  262. ReleaseEmsOccureByString(0, "042200");
  263. ReleaseEmsOccureByString(0, "042201");
  264. ReleaseEmsOccureByString(0, "042202");
  265. ReleaseEmsOccureByString(0, "012304");
  266. }
  267. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  268. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = YES;
  269. EmcOccureByString("012251");
  270. } else {
  271. ReleaseEmsOccureByString(0, "012251");
  272. }
  273. if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
  274. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = YES;
  275. EmcOccureByString("012238");
  276. } else {
  277. ReleaseEmsOccureByString(0, "012238");
  278. }
  279. if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
  280. pAlarmCode->AlarmEvents.bits.SpdTrip = YES;
  281. } else {
  282. pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
  283. }
  284. if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
  285. pAlarmCode->AlarmEvents.bits.DoorOpen = YES;
  286. EmcOccureByString("012252");
  287. } else {
  288. ReleaseEmsOccureByString(0, "012252");
  289. }
  290. //DS60-120 add
  291. //if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
  292. // ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS) {
  293. // pSysConfig->ShowInformation = YES;
  294. //} else {
  295. // pSysConfig->ShowInformation = NO;
  296. //}
  297. pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  298. if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
  299. !leftBtnPush &&
  300. WaitAuthorPageState()
  301. ) {
  302. if (!leftBtnPush) {
  303. leftBtnPush = true;
  304. log_info("left btn down...............................%x\n", pDcChargingInfoData->SystemStatus);
  305. if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  306. switch (pAcChargingInfoData->SystemStatus) {
  307. case S_IDLE:
  308. if (isDetectPlugin()) {
  309. _DetectPlugInTimeout();
  310. StopSystemTimeoutDet();
  311. }
  312. break;
  313. case S_REASSIGN_CHECK:
  314. case S_REASSIGN:
  315. case S_PREPARNING:
  316. case S_PREPARING_FOR_EV:
  317. case S_PREPARING_FOR_EVSE:
  318. case S_CCS_PRECHARGE_ST0:
  319. case S_CCS_PRECHARGE_ST1:
  320. // 取消充電
  321. AcChargingTerminalProcess();
  322. break;
  323. case S_CHARGING:
  324. if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  325. // 停止充電
  326. AcChargingTerminalProcess();
  327. }
  328. break;
  329. case S_COMPLETE:
  330. break;
  331. }
  332. }
  333. switch (pDcChargingInfoData->SystemStatus) {
  334. case S_IDLE:
  335. if (isDetectPlugin()) {
  336. _DetectPlugInTimeout();
  337. StopSystemTimeoutDet();
  338. #if defined DD360Audi
  339. destroySelGun(pSysInfo->CurGunSelected);
  340. #endif //defined DD360Audi
  341. }
  342. #if defined DD360Audi
  343. else {
  344. if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
  345. //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
  346. destroySelGun(pSysInfo->CurGunSelected);
  347. } else {
  348. confirmSelGun(pSysInfo->CurGunSelected);
  349. log_info("confirm select gun ............................... %d \n",
  350. pSysInfo->CurGunSelected);
  351. }
  352. }
  353. #endif //defined DD360Audi
  354. break;
  355. case S_REASSIGN_CHECK:
  356. case S_REASSIGN:
  357. case S_PREPARNING:
  358. case S_PREPARING_FOR_EV:
  359. case S_PREPARING_FOR_EVSE:
  360. case S_CCS_PRECHARGE_ST0:
  361. case S_CCS_PRECHARGE_ST1:
  362. // 取消充電
  363. if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  364. AcChargingTerminalProcess();
  365. } else {
  366. ChargingTerminalProcess(pSysInfo->CurGunSelected);
  367. }
  368. break;
  369. case S_CHARGING:
  370. if (pSysConfig->StopChargingByButton == YES ||
  371. pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  372. // 停止充電
  373. ChargingTerminalProcess(pSysInfo->CurGunSelected);
  374. }
  375. break;
  376. case S_COMPLETE:
  377. // 回 IDLE
  378. //log_info("right btn down.................S_COMPLETE \n");
  379. //pDcChargingInfoData->SystemStatus = S_IDLE;
  380. break;
  381. }
  382. }
  383. } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
  384. if (leftBtnPush) {
  385. leftBtnPush = false;
  386. //log_info("left btn up............................... \n");
  387. }
  388. }
  389. if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
  390. !rightBtnPush
  391. #if defined DD360Audi
  392. &&
  393. getCurLcmPage() != _LCM_IDLE &&
  394. getCurLcmPage() != _LCM_AUTHORIZING &&
  395. getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
  396. getCurLcmPage() != _LCM_AUTHORIZ_FAIL &&
  397. getCurLcmPage() != _LCM_WAIT_FOR_PLUG
  398. #endif //defined DD360Audi
  399. ) {
  400. if (!rightBtnPush) {
  401. rightBtnPush = true;
  402. //log_info("right btn down............................... %d \n", pSysInfo->CurGunSelected);
  403. if (pSysInfo->CurGunSelected + 1 <
  404. pSysConfig->TotalConnectorCount &&
  405. pSysInfo->IsAlternatvieConf == NO) {
  406. pSysInfo->CurGunSelected++;
  407. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  408. } else if (pSysConfig->AcConnectorCount > 0 &&
  409. pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
  410. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  411. } else if (pSysInfo->IsAlternatvieConf == YES) {
  412. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  413. pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  414. if (pDcChargingInfoData->SystemStatus != S_BOOTING &&
  415. pDcChargingInfoData->SystemStatus != S_IDLE &&
  416. pDcChargingInfoData->SystemStatus != S_RESERVATION) {
  417. pSysInfo->CurGunSelected = _index;
  418. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  419. return;
  420. }
  421. }
  422. pSysInfo->CurGunSelected = 0;
  423. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  424. } else {
  425. pSysInfo->CurGunSelected = 0;
  426. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  427. }
  428. }
  429. log_info("current select gun ............................... %d \n",
  430. pSysInfo->CurGunSelected);
  431. } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
  432. if (rightBtnPush) {
  433. rightBtnPush = false;
  434. //log_info("right btn up............................... \n");
  435. }
  436. }
  437. }