OCPP.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. //------------------------------------------------------------------------------
  8. int opcc_chk_reserve_expired(byte gun_index)
  9. {
  10. int result = NO;
  11. struct tm expiredDate;
  12. struct timeb expiredTime;
  13. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  14. if (sscanf((char *) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
  15. "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
  16. &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
  17. &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
  18. expiredDate.tm_year -= 1900;
  19. expiredDate.tm_mon -= 1;
  20. expiredTime.time = mktime(&expiredDate);
  21. if (!CheckTimeOut(expiredTime)) {
  22. result = YES;
  23. }
  24. }
  25. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  26. if (sscanf((char *) ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,
  27. "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
  28. &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
  29. &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
  30. expiredDate.tm_year -= 1900;
  31. expiredDate.tm_mon -= 1;
  32. expiredTime.time = mktime(&expiredDate);
  33. if (!CheckTimeOut(expiredTime)) {
  34. result = YES;
  35. }
  36. }
  37. }
  38. return result;
  39. }
  40. //===============================================
  41. // OCPP routine
  42. //===============================================
  43. void ocpp_process_start()
  44. {
  45. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  46. system("/root/OcppBackend &");
  47. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  48. system("/root/OcppBackend20 &");
  49. }
  50. }
  51. void ocpp_auto_response_BootNotification()
  52. {
  53. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  54. if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
  55. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
  56. }
  57. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  58. if (ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES) {
  59. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = NO;
  60. }
  61. }
  62. }
  63. bool ocpp_is_resPass_StartTransationConf(byte gun_index)
  64. {
  65. bool result = false;
  66. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  67. result = ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf;
  68. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  69. result = ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf;
  70. }
  71. return result;
  72. }
  73. void ocpp_auto_response_StartTransationConf(byte gun_index)
  74. {
  75. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  76. if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf) {
  77. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
  78. }
  79. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  80. if (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf) {
  81. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = NO;
  82. }
  83. }
  84. }
  85. void ocpp_auto_response_ReserveConf(byte gun_index)
  86. {
  87. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  88. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
  89. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  90. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
  91. }
  92. }
  93. bool ocpp_chk_authrization_cmd()
  94. {
  95. char buf2[16] = "";
  96. memset(buf2, 0, ARRAY_SIZE(buf2));
  97. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  98. sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  99. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  100. sprintf(buf2, "%s", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  101. }
  102. // 因為無法得知實際的長度,所以只能用搜尋的方式
  103. if (strcmp(buf2, "Accepted") == EQUAL) {
  104. return true;
  105. }
  106. return false;
  107. }
  108. bool opcc_sub_get_reset_req()
  109. {
  110. bool result = false;
  111. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  112. result = ShmOCPP16Data->MsMsg.bits.ResetReq;
  113. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  114. result = ShmOCPP20Data->MsMsg.bits.ResetReq;
  115. }
  116. return result;
  117. }
  118. void ocpp_sub_run_reset(bool canReset)
  119. {
  120. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  121. if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
  122. DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
  123. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
  124. ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
  125. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  126. sleep(3);
  127. system("reboot -f");
  128. } else if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
  129. DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
  130. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
  131. ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
  132. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  133. sleep(3);
  134. KillAllTask();
  135. system("/usr/bin/run_evse_restart.sh");
  136. }
  137. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  138. if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL) {
  139. DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
  140. sprintf((char *)ShmOCPP20Data->Reset.Response_status, "Accepted");
  141. ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
  142. ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
  143. sleep(3);
  144. system("reboot -f");
  145. } else if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "OnIdle") == EQUAL) {
  146. DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
  147. sprintf((char *)ShmOCPP20Data->Reset.Response_status, "Accepted");
  148. ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
  149. ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
  150. sleep(3);
  151. KillAllTask();
  152. system("/usr/bin/run_evse_restart.sh");
  153. }
  154. }
  155. }
  156. void ocpp_chk_reset_cmd()
  157. {
  158. if (opcc_sub_get_reset_req()) {
  159. bool canReset = true;
  160. if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
  161. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  162. if (chargingInfo[_index]->SystemStatus != S_IDLE &&
  163. chargingInfo[_index]->SystemStatus != S_RESERVATION &&
  164. chargingInfo[_index]->SystemStatus != S_MAINTAIN) {
  165. canReset = false;
  166. if (chargingInfo[_index]->SystemStatus >= S_REASSIGN &&
  167. chargingInfo[_index]->SystemStatus < S_TERMINATING) {
  168. // Reset 系統先停止充電
  169. ChargingTerminalProcess(_index);
  170. }
  171. }
  172. }
  173. }
  174. if (canReset) {
  175. // Reset -> change status to maintain.
  176. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  177. setChargerMode(_index, MODE_MAINTAIN);
  178. }
  179. ChangeLcmByIndex(_LCM_FIX);
  180. }
  181. ocpp_sub_run_reset(canReset);
  182. }
  183. }
  184. void ocpp_chk_reserved_cmd(byte gunIndex)
  185. {
  186. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  187. if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
  188. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
  189. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
  190. if (opcc_chk_reserve_expired(gunIndex)) {
  191. PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
  192. DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
  193. chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
  194. chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
  195. }
  196. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  197. }
  198. if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
  199. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
  200. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
  201. if (opcc_chk_reserve_expired(gunIndex)) {
  202. PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
  203. DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
  204. chargingInfo[gunIndex]->ReservationId = 0;
  205. chargingInfo[gunIndex]->SystemStatus = S_IDLE;
  206. }
  207. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
  208. }
  209. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  210. if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
  211. ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
  212. ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
  213. if (opcc_chk_reserve_expired(gunIndex)) {
  214. PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
  215. DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
  216. chargingInfo[gunIndex]->ReservationId = ShmOCPP20Data->ReserveNow[gunIndex].id;
  217. chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
  218. }
  219. ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  220. }
  221. if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
  222. ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
  223. ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
  224. if (opcc_chk_reserve_expired(gunIndex)) {
  225. PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
  226. DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
  227. chargingInfo[gunIndex]->ReservationId = 0;
  228. chargingInfo[gunIndex]->SystemStatus = S_IDLE;
  229. }
  230. ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
  231. }
  232. }
  233. }
  234. void ocpp_chk_availability_cmd(byte gunIndex)
  235. {
  236. byte type = 0; // 0 : none, 1 : operative, 2 inoperative
  237. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  238. if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
  239. PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
  240. DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
  241. ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
  242. if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
  243. if (isDb_ready) {
  244. DB_Update_Operactive(localDb, gunIndex, true);
  245. }
  246. type = 1;
  247. } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
  248. if (isDb_ready) {
  249. DB_Update_Operactive(localDb, gunIndex, false);
  250. }
  251. type = 2;
  252. }
  253. }
  254. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  255. if (ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
  256. PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
  257. DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
  258. ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
  259. if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Operative") == EQUAL) {
  260. if (isDb_ready) {
  261. DB_Update_Operactive(localDb, gunIndex, true);
  262. }
  263. type = 1;
  264. } else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Inoperative") == EQUAL) {
  265. if (isDb_ready) {
  266. DB_Update_Operactive(localDb, gunIndex, false);
  267. }
  268. type = 2;
  269. }
  270. }
  271. }
  272. if (type == 1) {
  273. chargingInfo[gunIndex]->IsAvailable = YES;
  274. if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
  275. chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
  276. chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
  277. setChargerMode(gunIndex, MODE_IDLE);
  278. }
  279. } else if (type == 2) {
  280. chargingInfo[gunIndex]->IsAvailable = NO;
  281. if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
  282. chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
  283. chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
  284. setChargerMode(gunIndex, MODE_MAINTAIN);
  285. }
  286. }
  287. }
  288. void ocpp_chk_unlock_cmd(byte gunIndex)
  289. {
  290. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  291. if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
  292. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
  293. if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
  294. chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
  295. // Unlocked - 充電中,需停止充電
  296. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
  297. ChargingTerminalProcess(gunIndex);
  298. }
  299. strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
  300. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
  301. }
  302. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  303. if (ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
  304. ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
  305. if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
  306. chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
  307. // Unlocked - 充電中,需停止充電
  308. strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "UnlockCommand");
  309. ChargingTerminalProcess(gunIndex);
  310. }
  311. strcpy((char *)ShmOCPP20Data->UnlockConnector[gunIndex].Response_status, "Unlocked");
  312. ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
  313. }
  314. }
  315. }
  316. bool ocpp_chk_remoteStop_cmd(byte gunIndex)
  317. {
  318. byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  319. // 有 AC 槍的話
  320. if (acDirIndex > 0 && gunIndex > 0) {
  321. gunIndex += acDirIndex;
  322. }
  323. bool result = false;
  324. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  325. result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
  326. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  327. result = ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq;
  328. }
  329. if (result) {
  330. DEBUG_INFO_MSG("Remote Stop by OCPP (%d) \n", gunIndex);
  331. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  332. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
  333. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
  334. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  335. strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "Remote");
  336. ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq = NO;
  337. }
  338. }
  339. return result;
  340. }
  341. bool ocpp_sub_get_remote_start_transaction_req(byte gun_index)
  342. {
  343. bool result = false;
  344. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  345. result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq;
  346. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  347. result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq;
  348. }
  349. if (result) {
  350. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,
  351. (char *)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag);
  352. }
  353. return result;
  354. }
  355. void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result)
  356. {
  357. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  358. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStartTransactionReq = result;
  359. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  360. ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStartTransactionReq = result;
  361. }
  362. }
  363. void ocpp_chk_remoteStart_cmd()
  364. {
  365. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
  366. {}
  367. else if (!isDetectPlugin()) {
  368. // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
  369. byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  370. for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++) {
  371. if (ocpp_sub_get_remote_start_transaction_req(acDirIndex)) {
  372. if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
  373. ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
  374. ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
  375. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  376. //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
  377. //ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
  378. DetectPluginStart(ac_index);
  379. return;
  380. }
  381. ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
  382. }
  383. }
  384. byte threeGunIndex = 0;
  385. byte dcIndex = 0;
  386. bool isGunUsingStatus = false;
  387. byte scheduleIndex = 0;
  388. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  389. // 如果有 AC 槍,且 DC 槍也有兩把
  390. if (acDirIndex == 1 && _index == 1) {
  391. threeGunIndex = 1;
  392. }
  393. if (ocpp_sub_get_remote_start_transaction_req(_index + threeGunIndex)) {
  394. dcIndex = _index;
  395. }
  396. if (chargingInfo[_index]->SystemStatus != S_IDLE) {
  397. isGunUsingStatus = true;
  398. }
  399. if (chargingInfo[_index]->schedule.isTriggerStart) {
  400. scheduleIndex = _index;
  401. }
  402. }
  403. // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
  404. if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
  405. if (dcIndex == 0) {
  406. threeGunIndex = 0;
  407. }
  408. ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
  409. return;
  410. }
  411. if (dcIndex == 0) {
  412. threeGunIndex = 0;
  413. }
  414. if (ocpp_sub_get_remote_start_transaction_req(dcIndex + threeGunIndex)) {
  415. if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
  416. chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
  417. chargingInfo[dcIndex]->RemoteStartFlag = YES;
  418. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  419. //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
  420. DetectPluginStart(dcIndex);
  421. }
  422. ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
  423. } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
  424. if (chargingInfo[scheduleIndex]->SystemStatus == S_IDLE ||
  425. chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
  426. chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
  427. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  428. DetectPluginStart(scheduleIndex);
  429. }
  430. chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
  431. }
  432. }
  433. }
  434. void ocpp_chk_update_cmd()
  435. {
  436. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  437. if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
  438. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
  439. if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
  440. DEBUG_INFO_MSG("Backend : update start. \n");
  441. sleep(2);
  442. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
  443. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
  444. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  445. KillTask();
  446. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  447. setChargerMode(_index, MODE_UPDATE);
  448. }
  449. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
  450. ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
  451. }
  452. byte updateResult = CheckUpdateProcess();
  453. if (updateResult == PASS) {
  454. DEBUG_INFO_MSG("Backend : update complete. \n");
  455. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  456. } else if (updateResult == MODELNAME_FAIL) {
  457. DEBUG_INFO_MSG("Backend : model name is none match. \n");
  458. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  459. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  460. sleep(5);
  461. KillAllTask();
  462. system("/usr/bin/run_evse_restart.sh");
  463. return;
  464. } else {
  465. DEBUG_INFO_MSG("Backend : update fail. \n");
  466. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  467. }
  468. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  469. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  470. sleep(5);
  471. system("reboot -f");
  472. }
  473. }
  474. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  475. if (ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES) {
  476. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = NO;
  477. if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL) {
  478. DEBUG_INFO_MSG("Backend : update start. \n");
  479. sleep(2);
  480. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "");
  481. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing");
  482. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  483. KillTask();
  484. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  485. setChargerMode(_index, MODE_UPDATE);
  486. }
  487. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
  488. ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
  489. }
  490. byte updateResult = CheckUpdateProcess();
  491. if (updateResult == PASS) {
  492. DEBUG_INFO_MSG("Backend : update complete. \n");
  493. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
  494. } else if (updateResult == MODELNAME_FAIL) {
  495. DEBUG_INFO_MSG("Backend : model name is none match. \n");
  496. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
  497. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  498. sleep(5);
  499. KillAllTask();
  500. system("/usr/bin/run_evse_restart.sh");
  501. return;
  502. } else {
  503. DEBUG_INFO_MSG("Backend : update fail. \n");
  504. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
  505. }
  506. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
  507. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  508. sleep(5);
  509. system("reboot -f");
  510. }
  511. }
  512. }
  513. }
  514. bool ocpp_chk_invalid_id_cmd(byte gunIndex)
  515. {
  516. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  517. if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE")) {
  518. if (strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
  519. strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
  520. strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
  521. return true;
  522. }
  523. }
  524. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  525. if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE")) {
  526. if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Blocked") == EQUAL ||
  527. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Expired") == EQUAL ||
  528. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Invalid") == EQUAL ||
  529. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
  530. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
  531. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
  532. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
  533. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Unknown") == EQUAL) {
  534. return true;
  535. }
  536. }
  537. }
  538. return false;
  539. }
  540. bool ocpp_chk_profileConf_cmd(byte _index)
  541. {
  542. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  543. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  544. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  545. return true;
  546. }
  547. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  548. if (ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  549. ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  550. return true;
  551. }
  552. }
  553. return false;
  554. }
  555. void ocpp_lift_profileReq_cmd(byte gunIndex)
  556. {
  557. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  558. if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
  559. if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
  560. ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
  561. }
  562. }
  563. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  564. if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
  565. if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
  566. ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
  567. }
  568. }
  569. }
  570. }
  571. void ocpp_set_startTransation_cmd(byte gunIndex)
  572. {
  573. byte _OcppGunIndex = gunIndex;
  574. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  575. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
  576. _OcppGunIndex = 2;
  577. }
  578. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  579. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  580. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  581. } else {
  582. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
  583. }
  584. PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  585. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
  586. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  587. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  588. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  589. } else {
  590. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
  591. }
  592. PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  593. ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
  594. }
  595. }
  596. void ocpp_set_stopTransation_cmd(byte gunIndex)
  597. {
  598. byte _OcppGunIndex = gunIndex;
  599. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  600. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
  601. _OcppGunIndex = 2;
  602. }
  603. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  604. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  605. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  606. } else {
  607. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
  608. }
  609. PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  610. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
  611. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  612. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  613. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  614. } else {
  615. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
  616. }
  617. PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  618. ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
  619. }
  620. }
  621. void ocpp_set_errorCode_cmd(byte gunIndex, char *errString)
  622. {
  623. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  624. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, errString);
  625. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  626. }
  627. }
  628. void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason)
  629. {
  630. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  631. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  632. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, reason);
  633. }
  634. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  635. if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "") == EQUAL) {
  636. strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, reason);
  637. }
  638. }
  639. }
  640. void ocpp_set_authorizeReq_cmd(byte value)
  641. {
  642. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  643. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = value;
  644. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  645. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = value;
  646. }
  647. }
  648. void ocpp_set_authorizeConf_cmd(byte value)
  649. {
  650. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  651. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = value;
  652. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  653. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = value;
  654. }
  655. }
  656. void ocpp_set_errCode_cmd(byte gunIndex)
  657. {
  658. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  659. if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL) {
  660. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "InternalError");
  661. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->ConnectorAlarmCode);
  662. } else if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL) {
  663. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "OtherError");
  664. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->EvConnAlarmCode);
  665. }
  666. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  667. }
  668. }
  669. void ocpp_clear_errorCode_cmd(byte gunIndex)
  670. {
  671. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  672. if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError") != EQUAL) {
  673. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError");
  674. }
  675. if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "") != EQUAL) {
  676. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
  677. }
  678. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  679. }
  680. }
  681. void ocpp_clear_idTag_cmd(byte gun_index)
  682. {
  683. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  684. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  685. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  686. strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "");
  687. }
  688. }
  689. void ocpp_clear_stopReason(byte gun_index)
  690. {
  691. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
  693. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  694. strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
  695. }
  696. }
  697. unsigned short _ocpp_get_connect_timeout()
  698. {
  699. uint16_t result = (TIMEOUT_SPEC_HANDSHAKING / 1000);
  700. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  701. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
  702. result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  703. }
  704. }
  705. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  706. if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "") != 0) {
  707. result = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  708. }
  709. }
  710. return result;
  711. }
  712. bool _ocpp_get_disconnect_policy()
  713. {
  714. bool result = false;
  715. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  716. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE") == EQUAL &&
  717. strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == EQUAL) {
  718. result = true;
  719. }
  720. }
  721. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  722. if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL &&
  723. strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL) {
  724. result = true;
  725. }
  726. }
  727. return result;
  728. }
  729. bool ocpp_get_authorize_conf()
  730. {
  731. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  732. return ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
  733. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  734. return ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
  735. }
  736. return false;
  737. }
  738. bool ocpp_get_startTransation_req(byte gunIndex)
  739. {
  740. bool result = false;
  741. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  742. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  743. result = ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq;
  744. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  745. result = ShmOCPP20Data->CpMsg.bits[gunIndex].TransactionEventReq;
  746. }
  747. return result;
  748. }
  749. void ocpp_chargingProfile_process(byte _index)
  750. {
  751. int _time = 0;
  752. int _startCount = NO_DEFINE;
  753. int _maxCount = 0;
  754. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  755. if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
  756. ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES) {
  757. _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  758. _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
  759. _startCount = NO_DEFINE;
  760. for (byte _count = 0; _count < _maxCount; _count++) {
  761. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  762. if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
  763. if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
  764. ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
  765. _startCount = _count;
  766. }
  767. }
  768. }
  769. PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
  770. if (_startCount < _maxCount) {
  771. PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  772. chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
  773. if (chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
  774. chargingInfo[_index]->PresentChargingVoltage > 0) {
  775. chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
  776. } else {
  777. chargingInfo[_index]->ChargingProfileCurrent = 0;
  778. }
  779. } else {
  780. chargingInfo[_index]->ChargingProfilePower = -1;
  781. chargingInfo[_index]->ChargingProfileCurrent = -1;
  782. }
  783. } else {
  784. chargingInfo[_index]->ChargingProfilePower = -1;
  785. chargingInfo[_index]->ChargingProfileCurrent = -1;
  786. }
  787. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  788. if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[_index].chargingProfileKind, "Absolute") == EQUAL &&
  789. ShmOCPP20Data->SmartChargingProfile[_index].id == YES) {
  790. _time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].startSchedule);
  791. _maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod);
  792. _startCount = NO_DEFINE;
  793. for (byte _count = 0; _count < _maxCount; _count++) {
  794. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  795. if (_time >= ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod) {
  796. if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
  797. ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR) {
  798. _startCount = _count;
  799. }
  800. }
  801. }
  802. PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
  803. if (_startCount < _maxCount) {
  804. PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit);
  805. chargingInfo[_index]->ChargingProfilePower = ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit * AC_OUTPUT_VOL;
  806. if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0) {
  807. chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
  808. } else {
  809. chargingInfo[_index]->ChargingProfileCurrent = 0;
  810. }
  811. } else {
  812. chargingInfo[_index]->ChargingProfilePower = -1;
  813. chargingInfo[_index]->ChargingProfileCurrent = -1;
  814. }
  815. } else {
  816. chargingInfo[_index]->ChargingProfilePower = -1;
  817. chargingInfo[_index]->ChargingProfileCurrent = -1;
  818. }
  819. } else {
  820. chargingInfo[_index]->ChargingProfilePower = -1;
  821. chargingInfo[_index]->ChargingProfileCurrent = -1;
  822. }
  823. PRINTF_FUNC("Profile : ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
  824. PRINTF_FUNC("Profile : ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
  825. }