123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <string.h>
- #include <stdint.h>
- #include "../Config.h"
- #include "../Log/log.h"
- #include "../Define/define.h"
- #include "../ShareMemory/shmMem.h"
- #include "../SelectGun/SelectGun.h"
- #include "main.h"
- #include "../timeout.h"
- struct SysInfoData *pSysInfo = NULL;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- struct SysConfigData *pSysConfig = NULL;
- //------------------------------------------------------------------------------
- typedef struct StLedConfig {
- //OutputDrvValue[0]
- uint8_t LeftButtonLed: 1; //bit 0, H: ON, L:OFF
- uint8_t RightButtonLed: 1; //bit 1, H: ON, L:OFF
- uint8_t GreenLED: 1; //bit 2, H: ON, L:OFF
- uint8_t YellowLED: 1; //bit 3, H: ON, L:OFF
- uint8_t RedLED: 1; //bit 4, H: ON, L:OFF
- uint8_t SystemLed4: 1; //bit 5, H: ON, L:OFF
- uint8_t AcContactor: 1; //bit 6, H: ON, L:OFF
- uint8_t Reserved: 1; //bit 7 reserved
- } LedConfig;
- //------------------------------------------------------------------------------
- void ChangeLCM(uint8_t page)
- {
- pSysInfo->SystemPage = page;
- }
- // ***********************************
- // Enter LCM Page
- // ***********************************
- void EnterViewPage()
- {
- ChangeLCM(_LCM_VIEW);
- StopSystemTimeoutDet();
- }
- void EnterAuthorizePage(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- log_info("Select Gun(%d) in Authorizing",gunIndex);
- ClearDetectPluginFlag();
- ChangeGunSelectByIndex(gunIndex);
- confirmSelGun(gunIndex);
- ChangeLCM(_LCM_START_SCAN);
- strcpy((char *)pSysConfig->UserId, "");
- setChargerMode(gunIndex,MODE_AUTHORIZING);
- StartSystemTimeoutDet(Timeout_ReturnViewPage);
- }
- void EnterLinkErrorPage()
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- //ClearDetectPluginFlag();
- StopSystemTimeoutDet();
- //StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
- ChangeLCM(_LCM_LINK_ERROR);
- StartSystemTimeoutDet(Timeout_ReturnViewPage);
- //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_LinkError);
- }
- void EnterDetailViewPage(uint8_t gunIndex)
- {
- log_info("Show Gun(%d) Detail View",gunIndex);
- ChangeGunSelectByIndex(gunIndex);
- ChangeLCM(_LCM_DETAIL_VIEW);
- StopGunInfoTimeoutDet(gunIndex);
- StartGunInfoTimeoutDet(gunIndex,Timeout_DetailView);
- }
- void EnterAuthorizeStopPage()
- {
- log_info("Select Gun(%d) in Stopping",pSysInfo->CurGunSelected);
- StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
- StopSystemTimeoutDet();
- strcpy((char *)pSysConfig->UserId, "");
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- if (pDcChargingInfo->isRemoteStart) {
- pSysInfo->SystemPage = _LCM_STOP_APP;
- } else {
- pSysInfo->SystemPage = _LCM_STOP_RFID;
- }
- StartSystemTimeoutDet(Timeout_ReturnViewPage);
- }
- void StopChargingBtn(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
- pDcChargingInfo->SystemStatus = S_TERMINATING;
- log_info("Press Button to Stop Charging");
- }
- void EnterSummaryPage()
- {
- StopSystemTimeoutDet();
- log_info("Showing Summary Page");
- pSysInfo->SystemPage = _LCM_SUMMARY;
- StartSystemTimeoutDet(Timeout_ReturnViewPage);
- }
- // *****************************
- // Enter System status
- // *****************************
- void ReturnIDLE(uint8_t gunIndex)
- {
- log_info("Gun(%d) return to IDLE",gunIndex);
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- EnterViewPage();
- StopSystemTimeoutDet();
- StopGunInfoTimeoutDet(gunIndex);
- setChargerMode(gunIndex,MODE_IDLE);
- //destroySelGun(gunIndex);
- }
- void ReturnAuthorize()
- {
- StopSystemTimeoutDet();
- EnterAuthorizePage(pSysInfo->CurGunSelected);
- }
- void showConfirmStopPage(uint8_t gunIndex)
- {
- StopSystemTimeoutDet();
- ChangeGunSelectByIndex(gunIndex);
- log_info("Enter Confirm stop Page");
- pSysInfo->SystemPage = _LCM_CONFIRM_STOP;
- StartSystemTimeoutDet(Timeout_ReturnViewPage);
- }
- void CheckLeftButton()
- {
- uint8_t gunIndex = 0;
- switch (pSysInfo->SystemPage) {
- case _LCM_VIEW:
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
- pSysInfo->CurGunSelected = LEFT_GUN_NUM;
- if(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
- EnterAuthorizePage(LEFT_GUN_NUM);
- pSysInfo->SystemPage = _LCM_START_SCAN;
- } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
- //EnterDetailViewPage(LEFT_GUN_NUM);
- showConfirmStopPage(LEFT_GUN_NUM);
- }
- break;
- case _LCM_START_SCAN:
- case _LCM_START_AUTHORIZE_FAIL:
- case _LCM_LINK_ERROR:
- if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
- ReturnIDLE(pSysInfo->CurGunSelected);
- }
- break;
- case _LCM_DETAIL_VIEW:
- case _LCM_STOP_RFID:
- case _LCM_STOP_APP:
- case _LCM_STOP_RFID_FAIL:
- EnterViewPage();
- break;
- case _LCM_SUMMARY:
- if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM)
- break;
- log_info("Return View Page");
- ReturnIDLE(pSysInfo->CurGunSelected);
- break;
- case _LCM_ERROR:
- //EnterSummaryPage();
- if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM)
- break;
- pSysInfo->SystemPage = _LCM_WAIT_PLUGOUT;
- //ReturnIDLE(pSysInfo->CurGunSelected);
- break;
- case _LCM_CONFIRM_STOP:
- if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
- StopChargingBtn(LEFT_GUN_NUM);
- } else {
- EnterViewPage();
- }
- break;
- case _LCM_WAIT_PLUGIN:
- if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
- ReturnIDLE(LEFT_GUN_NUM);
- break;
- case _LCM_WAIT_PLUGOUT:
- EnterSummaryPage();
- break;
- }
- }
- void CheckRightButton()
- {
- uint8_t gunIndex = 0;
- switch (pSysInfo->SystemPage) {
- case _LCM_VIEW:
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
- pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
- if(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
- EnterAuthorizePage(RIGHT_GUN_NUM);
- pSysInfo->SystemPage = _LCM_START_SCAN;
- } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
- //EnterDetailViewPage(RIGHT_GUN_NUM);
- showConfirmStopPage(RIGHT_GUN_NUM);
- }
- break;
- case _LCM_START_SCAN:
- if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM)
- ReturnIDLE(pSysInfo->CurGunSelected);
- break;
- case _LCM_START_AUTHORIZE_FAIL:
- if (pSysInfo->SystemPage == _LCM_START_AUTHORIZE_FAIL && pSysInfo->CurGunSelected == LEFT_GUN_NUM)
- break;
- ReturnAuthorize();
- break;
- case _LCM_WAIT_PLUGIN:
- if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM)
- ReturnIDLE(RIGHT_GUN_NUM);
- break;
- case _LCM_LINK_ERROR:
- if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
- break;
- ReturnAuthorize();
- break;
- case _LCM_DETAIL_VIEW:
- EnterAuthorizeStopPage();
- break;
- case _LCM_STOP_RFID_FAIL:
- EnterAuthorizeStopPage();
- break;
- case _LCM_WAIT_PLUGOUT:
- EnterSummaryPage();
- break;
- case _LCM_ERROR:
- if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
- break;
- pSysInfo->SystemPage = _LCM_WAIT_PLUGOUT;
- //EnterSummaryPage();
- break;
- case _LCM_CONFIRM_STOP:
- if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM) {
- StopChargingBtn(RIGHT_GUN_NUM);
- } else {
- EnterViewPage();
- }
- break;
- case _LCM_SUMMARY:
- if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
- break;
- log_info("Return View Page");
- ReturnIDLE(pSysInfo->CurGunSelected);
- break;
- }
-
- }
- void CheckPrimaryWarm(void)
- {
- uint8_t i = 0;
- uint8_t Rtn = 0;
- struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
- struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
- if (pSysWarning->WarningCount > 0) {
- Rtn = 0;
- for (i = 0; i < pSysWarning->WarningCount; i++) {
- if (memcmp(&pSysWarning->WarningCode[i][0], "042251", 6) == 0) {
- EmcOccureByString("042251");
- ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = YES;
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "042252", 6) == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = YES;
- EmcOccureByString("042252");
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "042327", 6) == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP = YES;
- EmcOccureByString("042327");
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "042328", 6) == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP = YES;
- EmcOccureByString("042328");
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "042200", 6) == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = YES;
- EmcOccureByString("042200");
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "042201", 6) == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = YES;
- EmcOccureByString("042201");
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "042202", 6) == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = YES;
- EmcOccureByString("042202");
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "042267", 6) == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = YES;
- EmcOccureByString("042267");
- Rtn = 1;
- } else if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
- EmcOccureByString("012304");
- Rtn = 1;
- }
- }
- if (Rtn == 0) {
- ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
- ReleaseEmsOccureByString(0, "042251");
- ReleaseEmsOccureByString(0, "042252");
- ReleaseEmsOccureByString(0, "042200");
- ReleaseEmsOccureByString(0, "042327");
- ReleaseEmsOccureByString(0, "042328");
- ReleaseEmsOccureByString(0, "042201");
- ReleaseEmsOccureByString(0, "042202");
- ReleaseEmsOccureByString(0, "042267");
- ReleaseEmsOccureByString(0, "012304");
- }
- } else {
- ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
- ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
- ReleaseEmsOccureByString(0, "042251");
- ReleaseEmsOccureByString(0, "042252");
- ReleaseEmsOccureByString(0, "042200");
- ReleaseEmsOccureByString(0, "042327");
- ReleaseEmsOccureByString(0, "042328");
- ReleaseEmsOccureByString(0, "042201");
- ReleaseEmsOccureByString(0, "042202");
- ReleaseEmsOccureByString(0, "042267");
- ReleaseEmsOccureByString(0, "012304");
- }
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
- pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = YES;
- EmcOccureByString("012251");
- } else {
- ReleaseEmsOccureByString(0, "012251");
- }
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
- pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = YES;
- EmcOccureByString("012238");
- } else {
- ReleaseEmsOccureByString(0, "012238");
- }
- if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
- pAlarmCode->AlarmEvents.bits.SpdTrip = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
- pAlarmCode->AlarmEvents.bits.DoorOpen = YES;
- EmcOccureByString("012252");
- } else {
- ReleaseEmsOccureByString(0, "012252");
- }
- }
- void ChkPrimaryStatus(void)
- {
- static bool leftBtnPush = false;
- static bool rightBtnPush = false;
- pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- // Check Primary Board status
- CheckPrimaryWarm();
- if ((pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
- && pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
- log_info("Offline policy no charge");
- return;;
- }
- // Show Version
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
- ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS )
- pSysConfig->ShowInformation = YES;
- else
- pSysConfig->ShowInformation = NO;
- if (pSysConfig->ShowInformation)
- return;
- // Press Left Button
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush ) {
- leftBtnPush = true;
- CheckLeftButton();
- log_info("left btn down...............................%d %d %d",
- pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
- } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE && leftBtnPush) {
- leftBtnPush = false;
- }
- // Press Right Button
- if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush ) {
- rightBtnPush = true;
- CheckRightButton();
- log_info("right btn down...............................%d %d %d",
- pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus, pSysInfo->SystemPage);
- } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE && rightBtnPush) {
- rightBtnPush = false;
- }
- }
|