OCPP.c 45 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. /*
  364. void ocpp_chk_remoteStart_cmd()
  365. {
  366. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
  367. {}
  368. else if (!isDetectPlugin()) {
  369. // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
  370. byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  371. for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++) {
  372. if (ocpp_sub_get_remote_start_transaction_req(acDirIndex)) {
  373. if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
  374. ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
  375. ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
  376. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  377. //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
  378. //ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
  379. DetectPluginStart(acDirIndex);
  380. return;
  381. }
  382. ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
  383. }
  384. }
  385. byte threeGunIndex = 0;
  386. byte dcIndex = 0;
  387. bool isGunUsingStatus = false;
  388. byte scheduleIndex = 0;
  389. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  390. // 如果有 AC 槍,且 DC 槍也有兩把
  391. if (acDirIndex == 1 && _index == 1) {
  392. threeGunIndex = 1;
  393. }
  394. if (ocpp_sub_get_remote_start_transaction_req(_index + threeGunIndex)) {
  395. dcIndex = _index;
  396. }
  397. if (chargingInfo[_index]->SystemStatus != S_IDLE) {
  398. isGunUsingStatus = true;
  399. }
  400. if (chargingInfo[_index]->schedule.isTriggerStart) {
  401. scheduleIndex = _index;
  402. }
  403. }
  404. // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
  405. if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
  406. if (dcIndex == 0) {
  407. threeGunIndex = 0;
  408. }
  409. ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
  410. return;
  411. }
  412. if (dcIndex == 0) {
  413. threeGunIndex = 0;
  414. }
  415. if (ocpp_sub_get_remote_start_transaction_req(dcIndex + threeGunIndex)) {
  416. if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
  417. chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
  418. chargingInfo[dcIndex]->RemoteStartFlag = YES;
  419. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  420. //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
  421. DetectPluginStart(dcIndex);
  422. }
  423. ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
  424. } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
  425. if (chargingInfo[scheduleIndex]->SystemStatus == S_IDLE ||
  426. chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
  427. chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
  428. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  429. DetectPluginStart(scheduleIndex);
  430. }
  431. chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
  432. }
  433. }
  434. }
  435. */
  436. void ocpp_chk_update_cmd()
  437. {
  438. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  439. if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
  440. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
  441. if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
  442. DEBUG_INFO_MSG("Backend : update start. \n");
  443. sleep(2);
  444. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
  445. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
  446. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  447. KillTask();
  448. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  449. setChargerMode(_index, MODE_UPDATE);
  450. }
  451. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
  452. ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
  453. }
  454. byte updateResult = CheckUpdateProcess();
  455. if (updateResult == PASS) {
  456. DEBUG_INFO_MSG("Backend : update complete. \n");
  457. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  458. } else if (updateResult == MODELNAME_FAIL) {
  459. DEBUG_INFO_MSG("Backend : model name is none match. \n");
  460. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  461. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  462. sleep(5);
  463. KillAllTask();
  464. system("/usr/bin/run_evse_restart.sh");
  465. return;
  466. } else {
  467. DEBUG_INFO_MSG("Backend : update fail. \n");
  468. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  469. }
  470. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  471. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  472. sleep(5);
  473. system("reboot -f");
  474. }
  475. }
  476. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  477. if (ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES) {
  478. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = NO;
  479. if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL) {
  480. DEBUG_INFO_MSG("Backend : update start. \n");
  481. sleep(2);
  482. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "");
  483. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing");
  484. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  485. KillTask();
  486. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  487. setChargerMode(_index, MODE_UPDATE);
  488. }
  489. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
  490. ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
  491. }
  492. byte updateResult = CheckUpdateProcess();
  493. if (updateResult == PASS) {
  494. DEBUG_INFO_MSG("Backend : update complete. \n");
  495. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
  496. } else if (updateResult == MODELNAME_FAIL) {
  497. DEBUG_INFO_MSG("Backend : model name is none match. \n");
  498. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
  499. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  500. sleep(5);
  501. KillAllTask();
  502. system("/usr/bin/run_evse_restart.sh");
  503. return;
  504. } else {
  505. DEBUG_INFO_MSG("Backend : update fail. \n");
  506. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
  507. }
  508. strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
  509. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  510. sleep(5);
  511. system("reboot -f");
  512. }
  513. }
  514. }
  515. }
  516. bool ocpp_chk_invalid_id_cmd(byte gunIndex)
  517. {
  518. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  519. if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE")) {
  520. if (strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
  521. strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
  522. strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
  523. return true;
  524. }
  525. }
  526. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  527. if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE")) {
  528. if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Blocked") == EQUAL ||
  529. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Expired") == EQUAL ||
  530. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Invalid") == EQUAL ||
  531. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
  532. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
  533. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
  534. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
  535. strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Unknown") == EQUAL) {
  536. return true;
  537. }
  538. }
  539. }
  540. return false;
  541. }
  542. bool ocpp_chk_profileConf_cmd(byte _index)
  543. {
  544. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  545. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  546. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  547. return true;
  548. }
  549. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  550. if (ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  551. ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  552. return true;
  553. }
  554. }
  555. return false;
  556. }
  557. void ocpp_lift_profileReq_cmd(byte gunIndex)
  558. {
  559. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  560. if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
  561. if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
  562. ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
  563. }
  564. }
  565. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  566. if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
  567. if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
  568. ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
  569. }
  570. }
  571. }
  572. }
  573. void ocpp_set_startTransation_cmd(byte gunIndex)
  574. {
  575. byte _OcppGunIndex = gunIndex;
  576. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  577. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
  578. _OcppGunIndex = 2;
  579. }
  580. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  581. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  582. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  583. } else {
  584. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
  585. }
  586. PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  587. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
  588. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  589. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  590. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  591. } else {
  592. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
  593. }
  594. PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  595. ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
  596. }
  597. }
  598. void ocpp_set_stopTransation_cmd(byte gunIndex)
  599. {
  600. byte _OcppGunIndex = gunIndex;
  601. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  602. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
  603. _OcppGunIndex = 2;
  604. }
  605. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  606. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  607. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  608. } else {
  609. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
  610. }
  611. PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  612. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
  613. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  614. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  615. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  616. } else {
  617. strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
  618. }
  619. PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
  620. ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
  621. }
  622. }
  623. void ocpp_set_errorCode_cmd(byte gunIndex, char *errString)
  624. {
  625. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  626. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, errString);
  627. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  628. }
  629. }
  630. void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason)
  631. {
  632. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  633. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  634. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, reason);
  635. }
  636. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  637. if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "") == EQUAL) {
  638. strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, reason);
  639. }
  640. }
  641. }
  642. void ocpp_set_authorizeReq_cmd(byte value)
  643. {
  644. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  645. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = value;
  646. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  647. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = value;
  648. }
  649. }
  650. void ocpp_set_authorizeConf_cmd(byte value)
  651. {
  652. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  653. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = value;
  654. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  655. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = value;
  656. }
  657. }
  658. void ocpp_set_errCode_cmd(byte gunIndex)
  659. {
  660. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  661. if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL) {
  662. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "InternalError");
  663. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->ConnectorAlarmCode);
  664. } else if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL) {
  665. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "OtherError");
  666. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->EvConnAlarmCode);
  667. }
  668. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  669. }
  670. }
  671. void ocpp_clear_errorCode_cmd(byte gunIndex)
  672. {
  673. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  674. if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError") != EQUAL) {
  675. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError");
  676. }
  677. if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "") != EQUAL) {
  678. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
  679. }
  680. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  681. }
  682. }
  683. void ocpp_clear_idTag_cmd(byte gun_index)
  684. {
  685. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  686. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  687. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  688. strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "");
  689. }
  690. }
  691. void ocpp_clear_stopReason(byte gun_index)
  692. {
  693. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
  695. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  696. strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
  697. }
  698. }
  699. unsigned short _ocpp_get_connect_timeout()
  700. {
  701. uint16_t result = (TIMEOUT_SPEC_HANDSHAKING / 1000);
  702. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  703. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
  704. result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  705. }
  706. }
  707. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  708. if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "") != 0) {
  709. result = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  710. }
  711. }
  712. return result;
  713. }
  714. bool _ocpp_get_disconnect_policy()
  715. {
  716. bool result = false;
  717. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  718. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE") == EQUAL &&
  719. strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == EQUAL) {
  720. result = true;
  721. }
  722. }
  723. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  724. if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL &&
  725. strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL) {
  726. result = true;
  727. }
  728. }
  729. return result;
  730. }
  731. bool ocpp_get_authorize_conf()
  732. {
  733. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  734. return ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
  735. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  736. return ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
  737. }
  738. return false;
  739. }
  740. bool ocpp_get_startTransation_req(byte gunIndex)
  741. {
  742. bool result = false;
  743. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  744. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  745. result = ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq;
  746. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  747. result = ShmOCPP20Data->CpMsg.bits[gunIndex].TransactionEventReq;
  748. }
  749. return result;
  750. }
  751. void ocpp_chargingProfile_process(byte _index)
  752. {
  753. int _time = 0;
  754. int _startCount = NO_DEFINE;
  755. int _maxCount = 0;
  756. if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
  757. if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
  758. ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES) {
  759. _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  760. _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
  761. _startCount = NO_DEFINE;
  762. for (byte _count = 0; _count < _maxCount; _count++) {
  763. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  764. if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
  765. if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
  766. ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
  767. _startCount = _count;
  768. }
  769. }
  770. }
  771. PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
  772. if (_startCount < _maxCount) {
  773. PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  774. chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
  775. if (chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
  776. chargingInfo[_index]->PresentChargingVoltage > 0) {
  777. chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
  778. } else {
  779. chargingInfo[_index]->ChargingProfileCurrent = 0;
  780. }
  781. } else {
  782. chargingInfo[_index]->ChargingProfilePower = -1;
  783. chargingInfo[_index]->ChargingProfileCurrent = -1;
  784. }
  785. } else {
  786. chargingInfo[_index]->ChargingProfilePower = -1;
  787. chargingInfo[_index]->ChargingProfileCurrent = -1;
  788. }
  789. } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
  790. if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[_index].chargingProfileKind, "Absolute") == EQUAL &&
  791. ShmOCPP20Data->SmartChargingProfile[_index].id == YES) {
  792. _time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].startSchedule);
  793. _maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod);
  794. _startCount = NO_DEFINE;
  795. for (byte _count = 0; _count < _maxCount; _count++) {
  796. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  797. if (_time >= ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod) {
  798. if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
  799. ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR) {
  800. _startCount = _count;
  801. }
  802. }
  803. }
  804. PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
  805. if (_startCount < _maxCount) {
  806. PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit);
  807. chargingInfo[_index]->ChargingProfilePower = ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit * AC_OUTPUT_VOL;
  808. if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0) {
  809. chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
  810. } else {
  811. chargingInfo[_index]->ChargingProfileCurrent = 0;
  812. }
  813. } else {
  814. chargingInfo[_index]->ChargingProfilePower = -1;
  815. chargingInfo[_index]->ChargingProfileCurrent = -1;
  816. }
  817. } else {
  818. chargingInfo[_index]->ChargingProfilePower = -1;
  819. chargingInfo[_index]->ChargingProfileCurrent = -1;
  820. }
  821. } else {
  822. chargingInfo[_index]->ChargingProfilePower = -1;
  823. chargingInfo[_index]->ChargingProfileCurrent = -1;
  824. }
  825. PRINTF_FUNC("Profile : ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
  826. PRINTF_FUNC("Profile : ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
  827. }