Primary.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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->YellowLED == YES ||
  22. pLedConfig->GreenLED == YES) {
  23. pLedConfig->RedLED = NO;
  24. pLedConfig->YellowLED = NO;
  25. pLedConfig->GreenLED = NO;
  26. } else {
  27. pLedConfig->RedLED = YES;
  28. pLedConfig->YellowLED = YES;
  29. pLedConfig->GreenLED = YES;
  30. }
  31. }
  32. return ret;
  33. }
  34. void PrimaryLedIndicatorCtrlFork(void)
  35. {
  36. #if !defined DD360ComBox
  37. return;
  38. #endif //!defined DD360ComBox
  39. pid_t pid = fork();
  40. if (pid == 0) {
  41. uint8_t gunIndex = 0;
  42. int isContinue = 1;
  43. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  44. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  45. struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  46. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  47. struct ChargingInfoData *pDcChargingInfo = NULL;
  48. LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
  49. while (isContinue) {
  50. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  51. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  52. if (pSysWarning->Level == 2) {
  53. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  54. continue;
  55. }
  56. pLedConfig->YellowLED = NO;
  57. pLedConfig->GreenLED = NO;
  58. pLedConfig->RedLED = YES;
  59. }
  60. //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
  61. //printf("level = %d\r\n", pSysWarning->Level);
  62. switch (pDcChargingInfo->SystemStatus) {
  63. case S_BOOTING:
  64. if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
  65. //Module_DoComm tcp disconnect
  66. if (pLedConfig->RedLED == YES ||
  67. pLedConfig->YellowLED == YES ||
  68. pLedConfig->GreenLED == YES) {
  69. pLedConfig->RedLED = NO;
  70. pLedConfig->YellowLED = NO;
  71. pLedConfig->GreenLED = NO;
  72. } else {
  73. pLedConfig->RedLED = YES;
  74. pLedConfig->YellowLED = YES;
  75. pLedConfig->GreenLED = YES;
  76. }
  77. break;
  78. }
  79. pLedConfig->RedLED = YES;
  80. pLedConfig->YellowLED = YES;
  81. pLedConfig->GreenLED = YES;
  82. break;
  83. case S_IDLE:
  84. //Module_DoComm connected and system idle
  85. pLedConfig->RedLED = NO;
  86. pLedConfig->YellowLED = NO;
  87. pLedConfig->GreenLED = YES;
  88. break;
  89. case S_RESERVATION:
  90. case S_AUTHORIZING:
  91. case S_REASSIGN_CHECK:
  92. case S_REASSIGN:
  93. case S_PREPARNING:
  94. case S_PREPARING_FOR_EV:
  95. case S_PREPARING_FOR_EVSE:
  96. case S_CCS_PRECHARGE_ST0:
  97. case S_CCS_PRECHARGE_ST1:
  98. //precharging status
  99. if (pLedConfig->GreenLED == YES) {
  100. pLedConfig->GreenLED = NO;
  101. } else {
  102. pLedConfig->GreenLED = YES;
  103. }
  104. break;
  105. case S_CHARGING:
  106. pLedConfig->RedLED = NO;
  107. if (pLedConfig->YellowLED == YES) {
  108. pLedConfig->YellowLED = NO;
  109. } else {
  110. pLedConfig->YellowLED = YES;
  111. }
  112. pLedConfig->GreenLED = NO;
  113. break;
  114. case S_ALARM:
  115. pLedConfig->YellowLED = NO;
  116. pLedConfig->GreenLED = NO;
  117. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  118. break;
  119. }
  120. pLedConfig->RedLED = YES;
  121. break;
  122. case S_TERMINATING:
  123. case S_COMPLETE:
  124. //if (pSysWarning->Level == 2) {
  125. // pLedConfig->YellowLED = NO;
  126. // pLedConfig->GreenLED = NO;
  127. // if (checkCabinetEthConnectState(pLedConfig) == YES) {
  128. // break;
  129. // }
  130. // pLedConfig->RedLED = YES;
  131. //} else {
  132. pLedConfig->RedLED = NO;
  133. pLedConfig->YellowLED = YES;
  134. pLedConfig->GreenLED = NO;
  135. //}
  136. break;
  137. case S_MAINTAIN:
  138. case S_FAULT:
  139. pLedConfig->YellowLED = NO;
  140. pLedConfig->GreenLED = NO;
  141. pLedConfig->RedLED = YES;
  142. //if (pSysWarning->Level == 2) {
  143. // if (checkCabinetEthConnectState(pLedConfig) == YES) {
  144. // break;
  145. // }
  146. // pLedConfig->RedLED = YES;
  147. //}
  148. break;
  149. case S_BOOKING:
  150. case S_DEBUG:
  151. case S_UPDATE:
  152. case S_NONE:
  153. break;
  154. }
  155. }//switch
  156. }//for
  157. usleep(500000);
  158. }//while
  159. }
  160. //------------------------------------------------------------------------------
  161. void ChkPrimaryStatus(void)
  162. {
  163. static bool leftBtnPush = false;
  164. static bool rightBtnPush = false;
  165. uint8_t Rtn;
  166. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  167. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  168. struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  169. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  170. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  171. struct ChargingInfoData *pDcChargingInfo = NULL;
  172. struct ChargingInfoData *pAcChargingInfo = NULL;
  173. if (pSysWarning->WarningCount > 0) {
  174. Rtn = 0;
  175. for (uint8_t i = 0; i < pSysWarning->WarningCount; i++) {
  176. if (memcmp(&pSysWarning->WarningCode[i][0], "042251", 6) == 0) {
  177. EmcOccureByString("042251");
  178. Rtn = 1;
  179. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042252", 6) == 0) {
  180. EmcOccureByString("042252");
  181. Rtn = 1;
  182. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042200", 6) == 0) {
  183. EmcOccureByString("042200");
  184. Rtn = 1;
  185. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042201", 6) == 0) {
  186. EmcOccureByString("042201");
  187. Rtn = 1;
  188. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042202", 6) == 0) {
  189. EmcOccureByString("042202");
  190. Rtn = 1;
  191. } else if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
  192. EmcOccureByString("012304");
  193. Rtn = 1;
  194. }
  195. }
  196. if (Rtn == 0) {
  197. ReleaseEmsOccureByString(0, "042251");
  198. ReleaseEmsOccureByString(0, "042252");
  199. ReleaseEmsOccureByString(0, "042200");
  200. ReleaseEmsOccureByString(0, "042201");
  201. ReleaseEmsOccureByString(0, "042202");
  202. ReleaseEmsOccureByString(0, "012304");
  203. }
  204. } else {
  205. ReleaseEmsOccureByString(0, "042251");
  206. ReleaseEmsOccureByString(0, "042252");
  207. ReleaseEmsOccureByString(0, "042200");
  208. ReleaseEmsOccureByString(0, "042201");
  209. ReleaseEmsOccureByString(0, "042202");
  210. ReleaseEmsOccureByString(0, "012304");
  211. }
  212. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  213. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = YES;
  214. EmcOccureByString("012251");
  215. } else {
  216. ReleaseEmsOccureByString(0, "012251");
  217. }
  218. if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
  219. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = YES;
  220. EmcOccureByString("012238");
  221. } else {
  222. ReleaseEmsOccureByString(0, "012238");
  223. }
  224. if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
  225. pAlarmCode->AlarmEvents.bits.SpdTrip = YES;
  226. } else {
  227. pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
  228. }
  229. if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
  230. pAlarmCode->AlarmEvents.bits.DoorOpen = YES;
  231. EmcOccureByString("012252");
  232. } else {
  233. ReleaseEmsOccureByString(0, "012252");
  234. }
  235. //DS60-120 add
  236. //if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
  237. // ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS) {
  238. // pSysConfig->ShowInformation = YES;
  239. //} else {
  240. // pSysConfig->ShowInformation = NO;
  241. //}
  242. if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
  243. !leftBtnPush
  244. #if defined DD360Audi
  245. &&
  246. pSysInfo->SystemPage != _LCM_AUTHORIZING &&
  247. pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
  248. pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL
  249. #endif //defined DD360Audi
  250. ) {
  251. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  252. if (!leftBtnPush) {
  253. leftBtnPush = true;
  254. log_info("left btn down...............................%x\n",
  255. pDcChargingInfo->SystemStatus);
  256. if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  257. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  258. switch (pAcChargingInfo->SystemStatus) {
  259. case S_IDLE:
  260. if (isDetectPlugin()) {
  261. _DetectPlugInTimeout();
  262. StopSystemTimeoutDet();
  263. }
  264. break;
  265. case S_REASSIGN_CHECK:
  266. case S_REASSIGN:
  267. case S_PREPARNING:
  268. case S_PREPARING_FOR_EV:
  269. case S_PREPARING_FOR_EVSE:
  270. case S_CCS_PRECHARGE_ST0:
  271. case S_CCS_PRECHARGE_ST1:
  272. // 取消充電
  273. AcChargingTerminalProcess();
  274. break;
  275. case S_CHARGING:
  276. if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  277. // 停止充電
  278. AcChargingTerminalProcess();
  279. }
  280. break;
  281. case S_COMPLETE:
  282. break;
  283. }
  284. }
  285. switch (pDcChargingInfo->SystemStatus) {
  286. case S_IDLE:
  287. if (isDetectPlugin()) {
  288. _DetectPlugInTimeout();
  289. StopSystemTimeoutDet();
  290. destroySelGun(pSysInfo->CurGunSelected);
  291. } else {
  292. #if defined DD360Audi
  293. if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
  294. //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
  295. destroySelGun(pSysInfo->CurGunSelected);
  296. } else {
  297. confirmSelGun(pSysInfo->CurGunSelected);
  298. log_info("confirm select gun ............................... %d \n",
  299. pSysInfo->CurGunSelected);
  300. }
  301. #endif //defined DD360Audi
  302. }
  303. break;
  304. case S_REASSIGN_CHECK:
  305. case S_REASSIGN:
  306. case S_PREPARNING:
  307. case S_PREPARING_FOR_EV:
  308. case S_PREPARING_FOR_EVSE:
  309. case S_CCS_PRECHARGE_ST0:
  310. case S_CCS_PRECHARGE_ST1:
  311. // 取消充電
  312. if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  313. AcChargingTerminalProcess();
  314. } else {
  315. ChargingTerminalProcess(pSysInfo->CurGunSelected);
  316. }
  317. break;
  318. case S_CHARGING:
  319. if (pSysConfig->StopChargingByButton == YES ||
  320. pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  321. // 停止充電
  322. ChargingTerminalProcess(pSysInfo->CurGunSelected);
  323. }
  324. break;
  325. case S_COMPLETE:
  326. // 回 IDLE
  327. //log_info("right btn down.................S_COMPLETE \n");
  328. //pDcChargingInfo->SystemStatus = S_IDLE;
  329. break;
  330. }
  331. }
  332. } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
  333. if (leftBtnPush) {
  334. leftBtnPush = false;
  335. //log_info("left btn up............................... \n");
  336. }
  337. }
  338. if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
  339. !rightBtnPush
  340. #if defined DD360Audi
  341. &&
  342. pSysInfo->SystemPage != _LCM_IDLE &&
  343. pSysInfo->SystemPage != _LCM_AUTHORIZING &&
  344. pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
  345. pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL &&
  346. pSysInfo->SystemPage != _LCM_WAIT_FOR_PLUG
  347. #endif //defined DD360Audi
  348. ) {
  349. if (!rightBtnPush) {
  350. rightBtnPush = true;
  351. //log_info("right btn down............................... %d \n", pSysInfo->CurGunSelected);
  352. if (pSysInfo->CurGunSelected + 1 < pSysConfig->TotalConnectorCount &&
  353. pSysInfo->IsAlternatvieConf == NO) {
  354. pSysInfo->CurGunSelected++;
  355. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  356. } else if (pSysConfig->AcConnectorCount > 0 &&
  357. pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
  358. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  359. } else if (pSysInfo->IsAlternatvieConf == YES) {
  360. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  361. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  362. if (pDcChargingInfo->SystemStatus != S_BOOTING &&
  363. pDcChargingInfo->SystemStatus != S_IDLE &&
  364. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  365. pSysInfo->CurGunSelected = _index;
  366. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  367. return;
  368. }
  369. }
  370. pSysInfo->CurGunSelected = 0;
  371. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  372. } else {
  373. pSysInfo->CurGunSelected = 0;
  374. ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
  375. }
  376. }
  377. log_info("current select gun ............................... %d \n",
  378. pSysInfo->CurGunSelected);
  379. } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
  380. if (rightBtnPush) {
  381. rightBtnPush = false;
  382. //log_info("right btn up............................... \n");
  383. }
  384. }
  385. }