Primary.c 16 KB

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