AcPlug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include "../Define/define.h"
  10. #include "../ShareMemory/shmMem.h"
  11. #include "../Config.h"
  12. #include "../Log/log.h"
  13. #include "Module_InternalComm.h"
  14. #include "internalComm.h"
  15. //------------------------------------------------------------------------------
  16. static struct SysConfigData *pSysConfig = NULL;
  17. static struct SysInfoData *pSysInfo = NULL;
  18. static struct AlarmCodeData *pAlarmCode = NULL;
  19. static struct InfoCodeData *pInfoCode = NULL;
  20. static struct FaultCodeData *pFaultCode = NULL;
  21. static struct OCPP16Data *ShmOCPP16Data = NULL;
  22. static int Uart5Fd = 0;
  23. static struct timespec _ac_charging_comp;
  24. static struct timespec _ac_preparing;
  25. static struct timeb _ac_startChargingTime;
  26. static struct timeb _ac_endChargingTime;
  27. static Ac_Status acStatus;
  28. static Ac_Led_Status ledStatus;
  29. static Ac_Alarm_code acAlarmCode;
  30. static Ac_Charging_energy acChargingEnergy;
  31. static Ac_Charging_current acChargingCurrent;
  32. static int _alarm_code[] = {
  33. AC_OVP,
  34. AC_UVP,
  35. AC_OCP,
  36. AC_OTP,
  37. AC_GMI_FAULT,
  38. AC_CP_ERROR,
  39. AC_AC_LEAKAGE,
  40. AC_DC_LEAKAGE,
  41. AC_SYSTEM_SELFTEST_FAULT,
  42. AC_HANDSHAKE_TIMEOUT,
  43. AC_EMC_STOP,
  44. AC_RELAY_WELDING,
  45. AC_GF_MODULE_FAULT,
  46. AC_SHUTTER_FAULT,
  47. AC_LOCKER_FAULT,
  48. AC_POWER_DROP,
  49. AC_CIRCUIT_SHORT,
  50. AC_ROTARY_SWITCH_FAULT,
  51. AC_RELAY_DRIVE_FAULT
  52. };
  53. //------------------------------------------------------------------------------
  54. static void OcppStopTransation(uint8_t gunIndex)
  55. {
  56. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  57. if (strcmp((char *)pAcChargingInfo->StartUserId, "") == EQUAL) {
  58. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag,
  59. (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
  60. } else {
  61. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag,
  62. (char *)pAcChargingInfo->StartUserId);
  63. }
  64. log_info("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
  65. ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
  66. }
  67. static void SetCpDuty(uint8_t _value)
  68. {
  69. Config_Ac_Duty(Uart5Fd, ADDR_AC_PLUG, _value);
  70. }
  71. static uint8_t GetChargingCurrent(void)
  72. {
  73. return Query_Charging_Current(Uart5Fd, ADDR_AC_PLUG, &acChargingCurrent);
  74. }
  75. static uint8_t GetChargingEnergy(void)
  76. {
  77. return Query_Charging_Energy(Uart5Fd, ADDR_AC_PLUG, &acChargingEnergy);
  78. }
  79. static void ChangeStartOrStopDateTime(uint8_t isStart)
  80. {
  81. char cmdBuf[32];
  82. struct timeb csuTime;
  83. struct tm *tmCSU;
  84. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  85. ftime(&csuTime);
  86. tmCSU = localtime(&csuTime.time);
  87. sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d",
  88. tmCSU->tm_year + 1900,
  89. tmCSU->tm_mon + 1,
  90. tmCSU->tm_mday,
  91. tmCSU->tm_hour,
  92. tmCSU->tm_min,
  93. tmCSU->tm_sec);
  94. if (isStart) {
  95. strcpy((char *)pAcChargingInfo->StartDateTime, cmdBuf);
  96. } else {
  97. strcpy((char *)pAcChargingInfo->StopDateTime, cmdBuf);
  98. }
  99. }
  100. static void OcppStartTransation(uint8_t gunIndex)
  101. {
  102. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  103. if (strcmp((char *)pAcChargingInfo->StartUserId, "") == EQUAL) {
  104. strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag,
  105. (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
  106. } else {
  107. strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag,
  108. (char *)pAcChargingInfo->StartUserId);
  109. }
  110. log_info("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
  111. ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
  112. }
  113. static void SetLegacyReq(uint8_t _switch)
  114. {
  115. Config_Legacy_Req(Uart5Fd, ADDR_AC_PLUG, _switch);
  116. }
  117. static void ChangeLedStatus(void)
  118. {
  119. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  120. if (pAcChargingInfo->SystemStatus == S_IDLE) {
  121. ledStatus.ActionMode = 1;
  122. } else if (pAcChargingInfo->SystemStatus == S_PREPARNING) {
  123. ledStatus.ActionMode = 3;
  124. } else if (pAcChargingInfo->SystemStatus == S_CHARGING) {
  125. ledStatus.ActionMode = 4;
  126. }
  127. Config_LED_Status(Uart5Fd, ADDR_AC_PLUG, &ledStatus);
  128. }
  129. static uint8_t isModeChange(void)
  130. {
  131. uint8_t result = NO;
  132. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  133. if (pAcChargingInfo->SystemStatus != pAcChargingInfo->PreviousSystemStatus) {
  134. result = YES;
  135. pAcChargingInfo->PreviousSystemStatus = pAcChargingInfo->SystemStatus;
  136. }
  137. return result;
  138. }
  139. static bool OcppRemoteStop(uint8_t gunIndex)
  140. {
  141. bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
  142. if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
  143. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
  144. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
  145. }
  146. return result;
  147. }
  148. static void CheckAlarmOccur(void)
  149. {
  150. bool isErr = false;
  151. uint8_t count = 0;
  152. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  153. for (count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
  154. if (acAlarmCode.AcAlarmCode & _alarm_code[count]) {
  155. isErr = true;
  156. switch (_alarm_code[count]) {
  157. case AC_OVP: pAlarmCode->AlarmEvents.bits.AcSystemInputOVP = YES; break;
  158. case AC_UVP: pAlarmCode->AlarmEvents.bits.AcSystemInputUVP = YES; break;
  159. case AC_OCP: pAlarmCode->AlarmEvents.bits.SystemAcOutputOCP = YES; break;
  160. case AC_OTP: pAlarmCode->AlarmEvents.bits.SystemAmbientOTP = YES; break;
  161. case AC_GMI_FAULT: pAlarmCode->AlarmEvents.bits.AcGroundfaultFail = YES; break;
  162. case AC_CP_ERROR: pInfoCode->InfoEvents.bits.PilotFault = YES; break;
  163. case AC_AC_LEAKAGE: pAlarmCode->AlarmEvents.bits.RcdTrip = YES; break;
  164. case AC_DC_LEAKAGE: pAlarmCode->AlarmEvents.bits.RcdTrip = YES; break;
  165. case AC_SYSTEM_SELFTEST_FAULT: pAlarmCode->AlarmEvents.bits.McuSelftestFail = YES; break;
  166. case AC_HANDSHAKE_TIMEOUT: break;
  167. //case AC_EMC_STOP: pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = YES; break;
  168. case AC_RELAY_WELDING: pFaultCode->FaultEvents.bits.AcOutputRelayWelding = YES; break;
  169. case AC_GF_MODULE_FAULT: pFaultCode->FaultEvents.bits.RcdSelfTestFail = YES; break;
  170. case AC_SHUTTER_FAULT: break;
  171. case AC_LOCKER_FAULT: pFaultCode->FaultEvents.bits.AcConnectorLockFail = YES; break;
  172. case AC_POWER_DROP: pAlarmCode->AlarmEvents.bits.SystemL1InputDrop = YES; break;
  173. case AC_CIRCUIT_SHORT: pAlarmCode->AlarmEvents.bits.CircuitShort = YES; break;
  174. case AC_ROTARY_SWITCH_FAULT: break;
  175. case AC_RELAY_DRIVE_FAULT: pFaultCode->FaultEvents.bits.AcOutputRelayDrivingFault = YES; break;
  176. }
  177. } else {
  178. switch (_alarm_code[count]) {
  179. case AC_OVP: pAlarmCode->AlarmEvents.bits.AcSystemInputOVP = NO; break;
  180. case AC_UVP: pAlarmCode->AlarmEvents.bits.AcSystemInputUVP = NO; break;
  181. case AC_OCP: pAlarmCode->AlarmEvents.bits.SystemAcOutputOCP = NO; break;
  182. case AC_OTP: pAlarmCode->AlarmEvents.bits.SystemAmbientOTP = NO; break;
  183. case AC_GMI_FAULT: pAlarmCode->AlarmEvents.bits.AcGroundfaultFail = NO; break;
  184. case AC_CP_ERROR: pInfoCode->InfoEvents.bits.PilotFault = NO; break;
  185. case AC_AC_LEAKAGE: pAlarmCode->AlarmEvents.bits.RcdTrip = NO; break;
  186. case AC_DC_LEAKAGE: pAlarmCode->AlarmEvents.bits.RcdTrip = NO; break;
  187. case AC_SYSTEM_SELFTEST_FAULT: pAlarmCode->AlarmEvents.bits.McuSelftestFail = NO; break;
  188. case AC_HANDSHAKE_TIMEOUT: break;
  189. //case AC_EMC_STOP: pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO; break;
  190. case AC_RELAY_WELDING: pFaultCode->FaultEvents.bits.AcOutputRelayWelding = NO; break;
  191. case AC_GF_MODULE_FAULT: pFaultCode->FaultEvents.bits.RcdSelfTestFail = NO; break;
  192. case AC_SHUTTER_FAULT: break;
  193. case AC_LOCKER_FAULT: pFaultCode->FaultEvents.bits.AcConnectorLockFail = NO; break;
  194. case AC_POWER_DROP: pAlarmCode->AlarmEvents.bits.SystemL1InputDrop = NO; break;
  195. case AC_CIRCUIT_SHORT: pAlarmCode->AlarmEvents.bits.CircuitShort = NO; break;
  196. case AC_ROTARY_SWITCH_FAULT: break;
  197. case AC_RELAY_DRIVE_FAULT: pFaultCode->FaultEvents.bits.AcOutputRelayDrivingFault = NO; break;
  198. }
  199. }
  200. }
  201. pAcChargingInfo->IsErrorOccur = isErr;
  202. }
  203. static void GetAcAlarmCode(void)
  204. {
  205. if (Query_AC_Alarm_Code(Uart5Fd, ADDR_AC_PLUG, &acAlarmCode) == PASS) {
  206. CheckAlarmOccur();
  207. }
  208. }
  209. static void GetAcStatus(void)
  210. {
  211. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  212. if (Query_AC_Status(Uart5Fd, ADDR_AC_PLUG, &acStatus) == PASS) {
  213. pSysConfig->AcRatingCurrent = acStatus.MaxCurrent;
  214. if (pSysConfig->AcMaxChargingCurrent == 0) {
  215. pSysConfig->AcMaxChargingCurrent = pSysConfig->AcRatingCurrent;
  216. }
  217. pAcChargingInfo->ConnectorPlugIn = acStatus.CpStatus;
  218. // log_info("CpStatus = %d \n", acStatus.CpStatus);
  219. // printf("CurLimit = %d \n", acStatus.CurLimit);
  220. // printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
  221. // printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
  222. // printf("LockStatus = %d \n", acStatus.LockStatus);
  223. // printf("RelayStatus = %d \n", acStatus.RelayStatus);
  224. // printf("ShutterStatus = %d \n", acStatus.ShutterStatus);
  225. // printf("MeterStatus = %d \n", acStatus.MeterStatus);
  226. // printf("PpStatus = %d \n", acStatus.PpStatus);
  227. // printf("MaxCurrent = %d \n", acStatus.MaxCurrent);
  228. // printf("RotateSwitchStatus = %d \n", acStatus.RelayStatus);
  229. // printf("============================== \n");
  230. //
  231. // pAcChargingInfo->SystemStatus = acStatus.CpStatus;
  232. }
  233. // else
  234. // log_info("GetAcStatus return fail. \n");
  235. }
  236. static void ChangeToCsuMode(void)
  237. {
  238. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  239. pAcChargingInfo->IsModeChagned = Config_CSU_Mode(Uart5Fd, ADDR_AC_PLUG);
  240. // if (pAcChargingInfo->IsModeChagned == PASS)
  241. // {
  242. // Config_Reset_MCU(Uart5Fd, ADDR_AC_PLUG);
  243. // }
  244. }
  245. static void GetAcModelName(void)
  246. {
  247. memset(pSysConfig->AcModelName, 0, sizeof(pSysConfig->AcModelName));
  248. if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, pSysConfig->AcModelName) == PASS) {
  249. log_info("ac model name = %s \n", pSysConfig->AcModelName);
  250. }
  251. }
  252. static void GetFwVersion_AC(void)
  253. {
  254. Ver ver = {0};
  255. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  256. if (Query_FW_Ver(Uart5Fd, ADDR_AC_PLUG, &ver) == PASS) {
  257. pAcChargingInfo->SelfTest_Comp = YES;
  258. strcpy((char *)pAcChargingInfo->version, ver.Version_FW);
  259. }
  260. }
  261. void AcPlugTask(int uartFD)
  262. {
  263. static float _beforeChargingTotalEnergy = 0.0;
  264. if (pSysConfig->AcConnectorCount <= 0) {
  265. return;
  266. }
  267. //share memory mapping
  268. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  269. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  270. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  271. pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
  272. pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  273. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  274. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  275. Uart5Fd = uartFD;
  276. //pAcChargingInfo->SelfTest_Comp = YES;
  277. //pAcChargingInfo->IsModeChagned = PASS;
  278. //---------------------------------------------
  279. if (pAcChargingInfo->SelfTest_Comp == NO) {
  280. pAcChargingInfo->IsModeChagned = NO;
  281. GetFwVersion_AC();
  282. GetAcModelName();
  283. } else if (pAcChargingInfo->SelfTest_Comp == YES) {
  284. if (pAcChargingInfo->IsModeChagned != PASS) {
  285. ChangeToCsuMode();
  286. return;
  287. }
  288. GetAcStatus();
  289. GetAcAlarmCode();
  290. uint8_t _status = S_NONE;
  291. if (pAcChargingInfo->SystemStatus == S_IDLE && pAcChargingInfo->IsErrorOccur) {
  292. _status = S_ALARM;
  293. } else if (acStatus.CpStatus == AC_SYS_A || pAcChargingInfo->IsErrorOccur) {
  294. if (pAcChargingInfo->SystemStatus == S_CHARGING) {
  295. _status = S_TERMINATING;
  296. } else if (pAcChargingInfo->SystemStatus >= S_TERMINATING) {
  297. if (GetClockTimeoutValue(_ac_charging_comp) >= 10000000 && acStatus.CpStatus == AC_SYS_A) {
  298. _status = S_IDLE;
  299. }
  300. } else {
  301. _status = S_IDLE;
  302. }
  303. } else if (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
  304. pAcChargingInfo->SystemStatus < S_CHARGING) {
  305. if (acStatus.CpStatus == AC_SYS_C && acStatus.RelayStatus == YES) {
  306. _status = S_CHARGING;
  307. } else if (GetClockTimeoutValue(_ac_preparing) >= 30000000) {
  308. _status = S_IDLE;
  309. }
  310. } else if ((acStatus.CpStatus == AC_SYS_B || pAcChargingInfo->ConnectorPlugIn == AC_SYS_B) &&
  311. pAcChargingInfo->IsAvailable &&
  312. !pAcChargingInfo->IsErrorOccur &&
  313. (pSysInfo->WaitForPlugit == YES ||
  314. pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE)) {
  315. if (pAcChargingInfo->RemoteStartFlag == YES) {
  316. log_info("** AC Remote \n");
  317. pAcChargingInfo->RemoteStartFlag = NO;
  318. strcpy((char *)pAcChargingInfo->StartUserId, "");
  319. pSysInfo->WaitForPlugit = NO;
  320. _status = S_PREPARNING;
  321. } else if (pSysInfo->OrderCharging == NO_DEFINE) {
  322. log_info("** UserId = %s \n", pSysConfig->UserId);
  323. strcpy((char *)pAcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
  324. log_info("** CardNumber = %s \n", pAcChargingInfo->StartUserId);
  325. strcpy((char *)pSysConfig->UserId, "");
  326. pSysInfo->WaitForPlugit = NO;
  327. _status = S_PREPARNING;
  328. }
  329. } else if (pAcChargingInfo->SystemStatus == S_CHARGING) {
  330. if (OcppRemoteStop(1)) {
  331. _status = S_TERMINATING;
  332. }
  333. }
  334. //printf("_status = %d \n", _status);
  335. if (_status != S_NONE && pAcChargingInfo->SystemStatus != _status) {
  336. pAcChargingInfo->SystemStatus = _status;
  337. }
  338. // 設定限制最大充電電流 >= 6 ~ <= 32
  339. switch (pAcChargingInfo->SystemStatus) {
  340. case S_IDLE:
  341. case S_ALARM: {
  342. if (isModeChange()) {
  343. pAcChargingInfo->PresentChargedEnergy = 0.0;
  344. pAcChargingInfo->PresentChargingVoltage = 0;
  345. pAcChargingInfo->ChargingFee = 0.0;
  346. strcpy((char *)pAcChargingInfo->StartDateTime, "");
  347. strcpy((char *)pAcChargingInfo->StopDateTime, "");
  348. _beforeChargingTotalEnergy = 0.0;
  349. }
  350. ChangeLedStatus();
  351. }
  352. break;
  353. case S_PREPARNING: {
  354. if (isModeChange()) {
  355. pSysInfo->SystemPage = _PAGE_PRECHARGE;
  356. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  357. if (pSysInfo->OrderCharging != NO_DEFINE) {
  358. pSysInfo->OrderCharging = NO_DEFINE;
  359. }
  360. GetClockTime(&_ac_preparing, NULL);
  361. }
  362. if (GetChargingEnergy() == PASS) {
  363. //pAcChargingInfo->PresentChargedEnergy = acChargingEnergy.Energy / 100;
  364. _beforeChargingTotalEnergy = acChargingEnergy.Energy;
  365. }
  366. SetLegacyReq(YES);
  367. ChangeLedStatus();
  368. }
  369. break;
  370. case S_CHARGING: {
  371. if (isModeChange()) {
  372. ftime(&_ac_startChargingTime);
  373. OcppStartTransation(1);
  374. ChangeStartOrStopDateTime(YES);
  375. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  376. }
  377. if (GetChargingEnergy() == PASS) {
  378. if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0) {
  379. pAcChargingInfo->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
  380. if (pSysConfig->BillingData.isBilling) {
  381. pAcChargingInfo->ChargingFee += pAcChargingInfo->PresentChargedEnergy * pSysConfig->BillingData.Cur_fee;
  382. }
  383. }
  384. _beforeChargingTotalEnergy = acChargingEnergy.Energy;
  385. }
  386. if (GetChargingCurrent() == PASS) {
  387. pAcChargingInfo->PresentChargingPower = (((float)(AC_DEFAULT_VOL * acChargingCurrent.OuputCurrentL1) / 10) / 1000);
  388. }
  389. ftime(&_ac_endChargingTime);
  390. pAcChargingInfo->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
  391. pAcChargingInfo->PresentChargingVoltage = AC_DEFAULT_VOL;
  392. pAcChargingInfo->PresentChargingCurrent = ((float)acChargingCurrent.OuputCurrentL1 / 10);
  393. // 用以判斷是否有在輸出
  394. pAcChargingInfo->IsCharging = acStatus.RelayStatus;
  395. SetCpDuty(pSysConfig->AcMaxChargingCurrent);
  396. ChangeLedStatus();
  397. }
  398. break;
  399. case S_TERMINATING: {
  400. if (isModeChange()) {
  401. ChangeStartOrStopDateTime(NO);
  402. GetClockTime(&_ac_charging_comp, NULL);
  403. }
  404. SetLegacyReq(NO);
  405. if (acStatus.RelayStatus == NO) {
  406. pAcChargingInfo->SystemStatus = S_COMPLETE;
  407. }
  408. }
  409. break;
  410. case S_COMPLETE: {
  411. if (isModeChange()) {
  412. GetClockTime(&_ac_charging_comp, NULL);
  413. ftime(&_ac_endChargingTime);
  414. if (strcmp((char *)pAcChargingInfo->StartDateTime, "") != EQUAL) {
  415. // AC 固定為第2把槍
  416. OcppStopTransation(1);
  417. }
  418. ChangeStartOrStopDateTime(NO);
  419. pAcChargingInfo->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
  420. }
  421. }
  422. break;
  423. }
  424. }
  425. }