TimeTask.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. void _CcsPrechargeTimeout(uint8_t gunIndex)
  2. {
  3. log_info("*********** _CcsPrechargeTimeout ***********\n");
  4. setChargerMode(gunIndex, MODE_IDLE);
  5. }
  6. void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
  7. {
  8. log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
  9. //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
  10. {
  11. setChargerMode(gunIndex, MODE_IDLE);
  12. _AutoReturnTimeout();
  13. }
  14. }
  15. void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
  16. {
  17. if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
  18. if (!isEvGunLocked_chademo(gunIndex)) {
  19. log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
  20. }
  21. } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
  22. if (!isEvGunLocked_ccs(gunIndex)) {
  23. log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
  24. }
  25. } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
  26. if (!isEvGunLocked_ccs(gunIndex)) {
  27. log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
  28. }
  29. }
  30. ChargingTerminalProcess(gunIndex);
  31. _AutoReturnTimeout();
  32. }
  33. void _PrepareTimeout(uint8_t gunIndex)
  34. {
  35. log_info("*********** _PrepareTimeout ***********\n");
  36. setChargerMode(gunIndex, MODE_IDLE);
  37. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
  38. _AutoReturnTimeout();
  39. }
  40. void ClearAuthorizedFlag()
  41. {
  42. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
  43. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
  44. }
  45. void DisplayChargingInfo()
  46. {
  47. log_info("*********** DisplayChargingInfo *********** \n");
  48. for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  49. if (chargingInfo[i]->SystemStatus != S_IDLE &&
  50. chargingInfo[i]->SystemStatus != S_RESERVATION) {
  51. ChangeGunSelectByIndex(i);
  52. return;
  53. }
  54. }
  55. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  56. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
  57. ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE) {
  58. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  59. }
  60. usleep(50000);
  61. #if defined DD360Audi
  62. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  63. #else
  64. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  65. #endif //defined DD360Audi
  66. }
  67. void _DetectPlugInTimeout()
  68. {
  69. log_info("*********** _DetectPlugInTimeout *********** \n");
  70. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  71. ClearDetectPluginFlag();
  72. //usleep(50000);
  73. sleep(1); //Jerry add
  74. #if defined DD360Audi
  75. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  76. #else
  77. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  78. #endif //defined DD360Audi
  79. }
  80. void _AutoReturnTimeout()
  81. {
  82. log_info("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
  83. if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
  84. ClearDetectPluginFlag();
  85. } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
  86. DetectPluginStart();
  87. }
  88. usleep(50000);
  89. #if defined DD360Audi
  90. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  91. #else
  92. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  93. #endif //defined DD360Audi
  94. }
  95. void StopSystemTimeoutDet()
  96. {
  97. gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
  98. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
  99. }
  100. void _SelfTestTimeout()
  101. {
  102. if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE) {
  103. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  104. setChargerMode(gun_index, MODE_ALARM);
  105. }
  106. }
  107. ShmPsuData->Work_Step = _NO_WORKING;
  108. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
  109. log_info("Self test timeout. \n");
  110. }
  111. void CheckConnectionTimeout(void)
  112. {
  113. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  114. if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
  115. _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
  116. } else {
  117. _connectionTimeout = CONN_PLUG_TIME_OUT;
  118. }
  119. return;
  120. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  121. if (system("pidof -s OcppBackend > /dev/null") != 0) {
  122. _connectionTimeout = CONN_PLUG_TIME_OUT;
  123. } else {
  124. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
  125. _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  126. if (_connectionTimeout <= 0) {
  127. _connectionTimeout = CONN_PLUG_TIME_OUT;
  128. }
  129. } else {
  130. _connectionTimeout = CONN_PLUG_TIME_OUT;
  131. }
  132. }
  133. }
  134. void CreateTimeoutFork(void)
  135. {
  136. pid_t timeoutPid;
  137. timeoutPid = fork();
  138. log_info("CreateTimeoutFork = %d\r\n", timeoutPid);
  139. if (timeoutPid == 0) {
  140. gettimeofday(&_cmdSubPriority_time, NULL);
  141. CheckConnectionTimeout();
  142. while (1) {
  143. if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
  144. CheckConnectionTimeout();
  145. gettimeofday(&_cmdSubPriority_time, NULL);
  146. }
  147. //printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
  148. // 系統
  149. switch (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag) {
  150. case Timeout_SelftestChk:
  151. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
  152. _SelfTestTimeout();
  153. StopSystemTimeoutDet();
  154. destroySelGun(DESTROY_ALL_SEL); //jerry add
  155. }
  156. break;
  157. case Timeout_Authorizing:
  158. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
  159. _AuthorizedTimeout();
  160. StopSystemTimeoutDet();
  161. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  162. if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
  163. gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
  164. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  165. log_error("Author timeout restart DoComm\r\n");
  166. system("killall Module_DoComm");
  167. sleep(1);
  168. system("/root/Module_DoComm &");
  169. }
  170. }
  171. break;
  172. case Timeout_VerifyFail:
  173. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
  174. _AutoReturnTimeout();
  175. StopSystemTimeoutDet();
  176. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  177. if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
  178. gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
  179. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  180. log_error("Author timeout restart DoComm\r\n");
  181. system("killall Module_DoComm");
  182. sleep(1);
  183. system("/root/Module_DoComm &");
  184. }
  185. }
  186. break;
  187. case Timeout_VerifyComp:
  188. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
  189. _AutoReturnTimeout();
  190. StopSystemTimeoutDet();
  191. }
  192. break;
  193. case Timeout_WaitPlug:
  194. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
  195. _DetectPlugInTimeout();
  196. StopSystemTimeoutDet();
  197. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  198. }
  199. break;
  200. case Timeout_ReturnToChargingGunDet:
  201. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
  202. #if defined DD360Audi
  203. if (getCurLcmPage() != _LCM_PRE_CHARGE &&
  204. getCurLcmPage() != _LCM_CHARGING &&
  205. getCurLcmPage() != _LCM_COMPLETE) {
  206. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //jerry add
  207. }
  208. #endif //defined DD360Audi
  209. DisplayChargingInfo();
  210. StopSystemTimeoutDet();
  211. }
  212. break;
  213. case Timeout_AuthorizingForStop:
  214. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
  215. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  216. ClearAuthorizedFlag();
  217. StopSystemTimeoutDet();
  218. }
  219. break;
  220. } //switch
  221. // 各槍
  222. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  223. //printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
  224. switch (chargingInfo[gun_index]->TimeoutFlag) {
  225. case Timeout_Preparing:
  226. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
  227. _PrepareTimeout(gun_index);
  228. StopGunInfoTimeoutDet(gun_index);
  229. destroySelGun(gun_index); //jerry add
  230. }
  231. break;
  232. case Timeout_EvChargingDet:
  233. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
  234. _DetectEvChargingEnableTimeout(gun_index);
  235. StopGunInfoTimeoutDet(gun_index);
  236. destroySelGun(gun_index); //jerry add
  237. }
  238. break;
  239. case Timeout_EvseChargingDet:
  240. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
  241. _DetectEvseChargingEnableTimeout(gun_index);
  242. StopGunInfoTimeoutDet(gun_index);
  243. destroySelGun(gun_index); //jerry add
  244. }
  245. break;
  246. case Timeout_EvseCompleteDet:
  247. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
  248. StopGunInfoTimeoutDet(gun_index);
  249. destroySelGun(gun_index); //jerry add
  250. }
  251. break;
  252. case Timeout_ForCcsPrechargeDet:
  253. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
  254. _CcsPrechargeTimeout(gun_index);
  255. StopGunInfoTimeoutDet(gun_index);
  256. destroySelGun(gun_index); //jerry add
  257. }
  258. break;
  259. case Timeout_SelectGun: //Jerry add
  260. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
  261. StopGunInfoTimeoutDet(gun_index);
  262. destroySelGun(gun_index); //jerry add
  263. }
  264. break;
  265. } //switch
  266. } //for
  267. sleep(1);
  268. }//while
  269. }
  270. }