Primary.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include "../Config.h"
  6. #include "../Log/log.h"
  7. #include "../Define/define.h"
  8. #include "../ShareMemory/shmMem.h"
  9. #include "../SelectGun/SelectGun.h"
  10. #include "main.h"
  11. #include "../timeout.h"
  12. struct SysInfoData *pSysInfo = NULL;
  13. struct ChargingInfoData *pDcChargingInfo = NULL;
  14. struct SysConfigData *pSysConfig = NULL;
  15. //------------------------------------------------------------------------------
  16. typedef struct StLedConfig {
  17. //OutputDrvValue[0]
  18. uint8_t LeftButtonLed: 1; //bit 0, H: ON, L:OFF
  19. uint8_t RightButtonLed: 1; //bit 1, H: ON, L:OFF
  20. uint8_t GreenLED: 1; //bit 2, H: ON, L:OFF
  21. uint8_t YellowLED: 1; //bit 3, H: ON, L:OFF
  22. uint8_t RedLED: 1; //bit 4, H: ON, L:OFF
  23. uint8_t SystemLed4: 1; //bit 5, H: ON, L:OFF
  24. uint8_t AcContactor: 1; //bit 6, H: ON, L:OFF
  25. uint8_t Reserved: 1; //bit 7 reserved
  26. } LedConfig;
  27. //------------------------------------------------------------------------------
  28. void ChangeLCM(uint8_t page)
  29. {
  30. pSysInfo->SystemPage = page;
  31. }
  32. // ***********************************
  33. // Enter LCM Page
  34. // ***********************************
  35. void EnterViewPage()
  36. {
  37. ChangeLCM(_LCM_VIEW);
  38. StopSystemTimeoutDet();
  39. }
  40. void EnterAuthorizePage(uint8_t gunIndex)
  41. {
  42. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  43. log_info("Select Gun(%d) in Authorizing",gunIndex);
  44. ClearDetectPluginFlag();
  45. ChangeGunSelectByIndex(gunIndex);
  46. confirmSelGun(gunIndex);
  47. ChangeLCM(_LCM_START_SCAN);
  48. strcpy((char *)pSysConfig->UserId, "");
  49. setChargerMode(gunIndex,MODE_AUTHORIZING);
  50. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  51. }
  52. void EnterLinkErrorPage()
  53. {
  54. StopSystemTimeoutDet();
  55. //StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  56. ChangeLCM(_LCM_LINK_ERROR);
  57. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  58. //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_LinkError);
  59. }
  60. void EnterDetailViewPage(uint8_t gunIndex)
  61. {
  62. log_info("Show Gun(%d) Detail View",gunIndex);
  63. ChangeGunSelectByIndex(gunIndex);
  64. ChangeLCM(_LCM_DETAIL_VIEW);
  65. StopGunInfoTimeoutDet(gunIndex);
  66. StartGunInfoTimeoutDet(gunIndex,Timeout_DetailView);
  67. }
  68. void EnterAuthorizeStopPage()
  69. {
  70. log_info("Select Gun(%d) in Stopping",pSysInfo->CurGunSelected);
  71. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  72. StopSystemTimeoutDet();
  73. strcpy((char *)pSysConfig->UserId, "");
  74. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  75. if (pDcChargingInfo->isRemoteStart) {
  76. pSysInfo->SystemPage = _LCM_STOP_APP;
  77. } else {
  78. pSysInfo->SystemPage = _LCM_STOP_RFID;
  79. }
  80. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  81. }
  82. void EnterSummaryPage()
  83. {
  84. StopSystemTimeoutDet();
  85. log_info("Showing Summary Page");
  86. pSysInfo->SystemPage = _LCM_SUMMARY;
  87. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  88. }
  89. // *****************************
  90. // Enter System status
  91. // *****************************
  92. void ReturnIDLE(uint8_t gunIndex)
  93. {
  94. log_info("Gun(%d) return to IDLE",gunIndex);
  95. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  96. EnterViewPage();
  97. StopSystemTimeoutDet();
  98. StopGunInfoTimeoutDet(gunIndex);
  99. setChargerMode(gunIndex,MODE_IDLE);
  100. destroySelGun(gunIndex);
  101. }
  102. void ReturnAuthorize()
  103. {
  104. StopSystemTimeoutDet();
  105. EnterAuthorizePage(pSysInfo->CurGunSelected);
  106. }
  107. void CheckLeftButton()
  108. {
  109. uint8_t gunIndex = 0;
  110. switch (pSysInfo->SystemPage) {
  111. case _LCM_VIEW:
  112. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  113. if(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
  114. EnterAuthorizePage(LEFT_GUN_NUM);
  115. } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  116. EnterDetailViewPage(LEFT_GUN_NUM);
  117. }
  118. break;
  119. case _LCM_START_SCAN:
  120. case _LCM_START_AUTHORIZE_FAIL:
  121. case _LCM_LINK_ERROR:
  122. ReturnIDLE(pSysInfo->CurGunSelected);
  123. break;
  124. case _LCM_DETAIL_VIEW:
  125. case _LCM_STOP_RFID:
  126. case _LCM_STOP_APP:
  127. case _LCM_STOP_RFID_FAIL:
  128. EnterViewPage();
  129. break;
  130. case _LCM_SUMMARY:
  131. log_info("Return View Page");
  132. ReturnIDLE(pSysInfo->CurGunSelected);
  133. break;
  134. case _LCM_ERROR:
  135. ReturnIDLE(pSysInfo->CurGunSelected);
  136. break;
  137. }
  138. }
  139. void CheckRightButton()
  140. {
  141. uint8_t gunIndex = 0;
  142. switch (pSysInfo->SystemPage) {
  143. case _LCM_VIEW:
  144. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  145. if(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
  146. EnterAuthorizePage(RIGHT_GUN_NUM);
  147. } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  148. EnterDetailViewPage(RIGHT_GUN_NUM);
  149. }
  150. break;
  151. case _LCM_START_AUTHORIZE_FAIL:
  152. ReturnAuthorize();
  153. break;
  154. case _LCM_WAIT_PLUGIN:
  155. EnterLinkErrorPage();
  156. break;
  157. case _LCM_LINK_ERROR:
  158. ReturnAuthorize();
  159. break;
  160. case _LCM_DETAIL_VIEW:
  161. EnterAuthorizeStopPage();
  162. break;
  163. case _LCM_STOP_RFID_FAIL:
  164. EnterAuthorizeStopPage();
  165. break;
  166. case _LCM_WAIT_PLUGOUT:
  167. EnterSummaryPage();
  168. break;
  169. case _LCM_ERROR:
  170. ReturnIDLE(pSysInfo->CurGunSelected);
  171. break;
  172. }
  173. }
  174. void CheckPrimaryWarm(void)
  175. {
  176. uint8_t i = 0;
  177. uint8_t Rtn = 0;
  178. struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  179. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  180. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  181. DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  182. if (pSysWarning->WarningCount > 0) {
  183. Rtn = 0;
  184. for (i = 0; i < pSysWarning->WarningCount; i++) {
  185. if (memcmp(&pSysWarning->WarningCode[i][0], "042251", 6) == 0) {
  186. EmcOccureByString("042251");
  187. ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = YES;
  188. Rtn = 1;
  189. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042252", 6) == 0) {
  190. ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = YES;
  191. EmcOccureByString("042252");
  192. Rtn = 1;
  193. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042327", 6) == 0) {
  194. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP = YES;
  195. EmcOccureByString("042200");
  196. Rtn = 1;
  197. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042328", 6) == 0) {
  198. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP = YES;
  199. EmcOccureByString("042200");
  200. Rtn = 1;
  201. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042200", 6) == 0) {
  202. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = YES;
  203. EmcOccureByString("042200");
  204. Rtn = 1;
  205. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042201", 6) == 0) {
  206. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = YES;
  207. EmcOccureByString("042201");
  208. Rtn = 1;
  209. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042202", 6) == 0) {
  210. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = YES;
  211. EmcOccureByString("042202");
  212. Rtn = 1;
  213. } else if (memcmp(&pSysWarning->WarningCode[i][0], "042267", 6) == 0) {
  214. ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = YES;
  215. EmcOccureByString("042267");
  216. Rtn = 1;
  217. } else if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
  218. EmcOccureByString("012304");
  219. Rtn = 1;
  220. }
  221. }
  222. if (Rtn == 0) {
  223. ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
  224. ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
  225. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP = NO;
  226. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP = NO;
  227. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
  228. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
  229. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
  230. ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
  231. ReleaseEmsOccureByString(0, "042251");
  232. ReleaseEmsOccureByString(0, "042252");
  233. ReleaseEmsOccureByString(0, "042200");
  234. ReleaseEmsOccureByString(0, "042327");
  235. ReleaseEmsOccureByString(0, "042328");
  236. ReleaseEmsOccureByString(0, "042201");
  237. ReleaseEmsOccureByString(0, "042202");
  238. ReleaseEmsOccureByString(0, "042267");
  239. ReleaseEmsOccureByString(0, "012304");
  240. }
  241. } else {
  242. ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
  243. ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
  244. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP = NO;
  245. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP = NO;
  246. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
  247. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
  248. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
  249. ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
  250. ReleaseEmsOccureByString(0, "042251");
  251. ReleaseEmsOccureByString(0, "042252");
  252. ReleaseEmsOccureByString(0, "042200");
  253. ReleaseEmsOccureByString(0, "042327");
  254. ReleaseEmsOccureByString(0, "042328");
  255. ReleaseEmsOccureByString(0, "042201");
  256. ReleaseEmsOccureByString(0, "042202");
  257. ReleaseEmsOccureByString(0, "042267");
  258. ReleaseEmsOccureByString(0, "012304");
  259. }
  260. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  261. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = YES;
  262. EmcOccureByString("012251");
  263. } else {
  264. ReleaseEmsOccureByString(0, "012251");
  265. }
  266. if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
  267. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = YES;
  268. EmcOccureByString("012238");
  269. } else {
  270. ReleaseEmsOccureByString(0, "012238");
  271. }
  272. if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
  273. pAlarmCode->AlarmEvents.bits.SpdTrip = YES;
  274. } else {
  275. pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
  276. }
  277. if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
  278. pAlarmCode->AlarmEvents.bits.DoorOpen = YES;
  279. EmcOccureByString("012252");
  280. } else {
  281. ReleaseEmsOccureByString(0, "012252");
  282. }
  283. }
  284. void ChkPrimaryStatus(void)
  285. {
  286. static bool leftBtnPush = false;
  287. static bool rightBtnPush = false;
  288. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  289. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  290. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  291. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  292. // Check Primary Board status
  293. CheckPrimaryWarm();
  294. if ((pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
  295. && pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
  296. log_info("Offline policy no charge");
  297. return;;
  298. }
  299. // Show Version
  300. if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
  301. ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS )
  302. pSysConfig->ShowInformation = YES;
  303. else
  304. pSysConfig->ShowInformation = NO;
  305. if (pSysConfig->ShowInformation)
  306. return;
  307. // Press Left Button
  308. if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush ) {
  309. leftBtnPush = true;
  310. CheckLeftButton();
  311. log_info("left btn down...............................%x %x %x",
  312. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
  313. } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE && leftBtnPush) {
  314. leftBtnPush = false;
  315. }
  316. // Press Right Button
  317. if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush ) {
  318. rightBtnPush = true;
  319. CheckRightButton();
  320. log_info("right btn down...............................%x %x %x",
  321. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus, pSysInfo->SystemPage);
  322. } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE && rightBtnPush) {
  323. rightBtnPush = false;
  324. }
  325. }