123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- #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"
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
- {
- uint8_t ret = NO;
- LedConfig *pLedConfig = (LedConfig *)ledConfig;
- struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
- ret = YES;
- if (pLedConfig->RedLED == YES) {
- pLedConfig->RedLED = NO;
- } else {
- pLedConfig->RedLED = YES;
- }
- }
- return ret;
- }
- void PrimaryLedIndicatorCtrlFork(void)
- {
- #if !defined DD360ComBox
- return;
- #endif //!defined DD360ComBox
- pid_t pid = fork();
- if (pid == 0) {
- uint8_t gunIndex = 0;
- int isContinue = 1;
- LedConfig *pLedConfig = NULL;
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
- struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- struct ChargingInfoData *pDcChargingInfoData = NULL;
- pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
- while (isContinue) {
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- //printf("led indicator status = %d\r\n", pDcChargingInfoData->SystemStatus);
- //printf("level = %d\r\n", pSysWarningInfo->Level);
- switch (pDcChargingInfoData->SystemStatus) {
- case S_BOOTING:
- if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
- //Module_DoComm tcp disconnect
- if (pLedConfig->RedLED == YES ||
- pLedConfig->YellowLED == YES ||
- pLedConfig->GreenLED == YES) {
- pLedConfig->RedLED = NO;
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = NO;
- } else {
- pLedConfig->RedLED = YES;
- pLedConfig->YellowLED = YES;
- pLedConfig->GreenLED = YES;
- }
- break;
- }
- pLedConfig->RedLED = YES;
- pLedConfig->YellowLED = YES;
- pLedConfig->GreenLED = YES;
- break;
- case S_IDLE:
- //Module_DoComm connected and system idle
- pLedConfig->RedLED = NO;
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = YES;
- break;
- case S_RESERVATION:
- case S_AUTHORIZING:
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- //precharging status
- if (pLedConfig->GreenLED == YES) {
- pLedConfig->GreenLED = NO;
- } else {
- pLedConfig->GreenLED = YES;
- }
- break;
- case S_CHARGING:
- pLedConfig->RedLED = NO;
- if (pLedConfig->YellowLED == YES) {
- pLedConfig->YellowLED = NO;
- } else {
- pLedConfig->YellowLED = YES;
- }
- pLedConfig->GreenLED = NO;
- break;
- case S_ALARM:
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = NO;
- if (checkCabinetEthConnectState(pLedConfig) == YES) {
- break;
- }
- pLedConfig->RedLED = YES;
- break;
- case S_TERMINATING:
- case S_COMPLETE:
- if (pSysWarningInfo->Level == 2) {
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = NO;
- if (checkCabinetEthConnectState(pLedConfig) == YES) {
- break;
- }
- pLedConfig->RedLED = YES;
- } else {
- pLedConfig->RedLED = NO;
- pLedConfig->YellowLED = YES;
- pLedConfig->GreenLED = NO;
- }
- break;
- case S_MAINTAIN:
- case S_FAULT:
- pLedConfig->YellowLED = NO;
- pLedConfig->GreenLED = NO;
- if (pSysWarningInfo->Level == 2) {
- if (checkCabinetEthConnectState(pLedConfig) == YES) {
- break;
- }
- pLedConfig->RedLED = YES;
- }
- break;
- case S_BOOKING:
- case S_DEBUG:
- case S_UPDATE:
- case S_NONE:
- break;
- }//switch
- } //for
- usleep(500000);
- } //while
- } //fork
- }
- //------------------------------------------------------------------------------
- // 急停狀況的停止充電處理函式
- void EmcOccureByString(char *code)
- {
- uint8_t level = 2;
- uint8_t gunIndex = 0;
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct ChargingInfoData *pDcChargingInfoData = NULL;
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
- // 其錯誤等級為 2
- //#if defined DD360 ||defined DD360Audi || defined DD360ComBox
- // //DS60-120 remove
- // if (strncmp(code, "012251", 6) == EQUAL ||
- // strncmp(code, "012252", 6) == EQUAL ||
- // strncmp(code, "012238", 6) == EQUAL ||
- // strncmp(code, "042251", 6) == EQUAL ||
- // strncmp(code, "042252", 6) == EQUAL ||
- // strncmp(code, "012304", 6) == EQUAL ||
- // strncmp(code, "042200", 6) == EQUAL ||
- // strncmp(code, "042201", 6) == EQUAL ||
- // strncmp(code, "042202", 6) == EQUAL ||
- // strncmp(code, "042267", 6) == EQUAL)
- //#endif //defined DD360 || defined DD360Audi
- {
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- //strncpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, code, 6);
- if ((pDcChargingInfoData->SystemStatus > S_IDLE &&
- pDcChargingInfoData->SystemStatus < S_TERMINATING) ||
- (pDcChargingInfoData->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfoData->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- //ChargingTerminalProcess(gunIndex);
- ChargingAlarmProcess(gunIndex);
- }
- }
- //#if defined DD360 ||defined DD360Audi || defined DD360ComBox
- StopChargingProcessByString(level);
- //InformOcppErrOccur(4);
- //#endif //defined DD360 || defined DD360Audi
- }
- }
- void ReleaseEmsOccureByString(uint8_t index, char *code)
- {
- bool isTrigger = false;
- uint8_t level = 2;
- struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- if (strncmp(code, "042251", 6) == 0 ) {
- isTrigger = true;
- } else if (strncmp(code, "012251", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
- } else if (strncmp(code, "012252", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
- } else if (strncmp(code, "012237", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
- } else if (strncmp(code, "012238", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- if (isTrigger) {
- ReleaseChargingProcessByString(level);
- InformOcppErrOccur(6);
- }
- }
- void ChkPrimaryStatus(void)
- {
- uint8_t Rtn;
- static bool leftBtnPush = false;
- static bool rightBtnPush = false;
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
- struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- struct ChargingInfoData *pDcChargingInfoData = NULL;
- struct ChargingInfoData *pAcChargingInfoData = (struct ChargingInfoData *)GetAcChargingInfoData(0);
- if (pSysWarningInfo->WarningCount > 0) {
- Rtn = 0;
- for (uint8_t i = 0; i < pSysWarningInfo->WarningCount; i++) {
- if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042251", 6) == 0) {
- EmcOccureByString("042251");
- Rtn = 1;
- } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042252", 6) == 0) {
- EmcOccureByString("042252");
- Rtn = 1;
- } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042200", 6) == 0) {
- EmcOccureByString("042200");
- Rtn = 1;
- } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042201", 6) == 0) {
- EmcOccureByString("042201");
- Rtn = 1;
- } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042202", 6) == 0) {
- EmcOccureByString("042202");
- Rtn = 1;
- } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "012304", 6) == 0) {
- EmcOccureByString("012304");
- Rtn = 1;
- }
- }
- if (Rtn == 0) {
- ReleaseEmsOccureByString(0, "042251");
- ReleaseEmsOccureByString(0, "042252");
- ReleaseEmsOccureByString(0, "042200");
- ReleaseEmsOccureByString(0, "042201");
- ReleaseEmsOccureByString(0, "042202");
- ReleaseEmsOccureByString(0, "012304");
- }
- } else {
- ReleaseEmsOccureByString(0, "042251");
- ReleaseEmsOccureByString(0, "042252");
- ReleaseEmsOccureByString(0, "042200");
- ReleaseEmsOccureByString(0, "042201");
- ReleaseEmsOccureByString(0, "042202");
- 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");
- }
- //DS60-120 add
- //if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
- // ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS) {
- // pSysConfig->ShowInformation = YES;
- //} else {
- // pSysConfig->ShowInformation = NO;
- //}
- pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
- !leftBtnPush &&
- WaitAuthorPageState()
- ) {
- if (!leftBtnPush) {
- leftBtnPush = true;
- log_info("left btn down...............................%x\n", pDcChargingInfoData->SystemStatus);
- if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
- switch (pAcChargingInfoData->SystemStatus) {
- case S_IDLE:
- if (isDetectPlugin()) {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- // 取消充電
- AcChargingTerminalProcess();
- break;
- case S_CHARGING:
- if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
- // 停止充電
- AcChargingTerminalProcess();
- }
- break;
- case S_COMPLETE:
- break;
- }
- }
- switch (pDcChargingInfoData->SystemStatus) {
- case S_IDLE:
- if (isDetectPlugin()) {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- #if defined DD360Audi
- destroySelGun(pSysInfo->CurGunSelected);
- #endif //defined DD360Audi
- }
- #if defined DD360Audi
- else {
- if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
- //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
- destroySelGun(pSysInfo->CurGunSelected);
- } else {
- confirmSelGun(pSysInfo->CurGunSelected);
- log_info("confirm select gun ............................... %d \n",
- pSysInfo->CurGunSelected);
- }
- }
- #endif //defined DD360Audi
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- // 取消充電
- if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
- AcChargingTerminalProcess();
- } else {
- ChargingTerminalProcess(pSysInfo->CurGunSelected);
- }
- break;
- case S_CHARGING:
- if (pSysConfig->StopChargingByButton == YES ||
- pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
- // 停止充電
- ChargingTerminalProcess(pSysInfo->CurGunSelected);
- }
- break;
- case S_COMPLETE:
- // 回 IDLE
- //log_info("right btn down.................S_COMPLETE \n");
- //pDcChargingInfoData->SystemStatus = S_IDLE;
- break;
- }
- }
- } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
- if (leftBtnPush) {
- leftBtnPush = false;
- //log_info("left btn up............................... \n");
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
- !rightBtnPush
- #if defined DD360Audi
- &&
- getCurLcmPage() != _LCM_IDLE &&
- getCurLcmPage() != _LCM_AUTHORIZING &&
- getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
- getCurLcmPage() != _LCM_AUTHORIZ_FAIL &&
- getCurLcmPage() != _LCM_WAIT_FOR_PLUG
- #endif //defined DD360Audi
- ) {
- if (!rightBtnPush) {
- rightBtnPush = true;
- //log_info("right btn down............................... %d \n", pSysInfo->CurGunSelected);
- if (pSysInfo->CurGunSelected + 1 <
- pSysConfig->TotalConnectorCount &&
- pSysInfo->IsAlternatvieConf == NO) {
- pSysInfo->CurGunSelected++;
- ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
- } else if (pSysConfig->AcConnectorCount > 0 &&
- pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
- pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
- } else if (pSysInfo->IsAlternatvieConf == YES) {
- for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
- pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- if (pDcChargingInfoData->SystemStatus != S_BOOTING &&
- pDcChargingInfoData->SystemStatus != S_IDLE &&
- pDcChargingInfoData->SystemStatus != S_RESERVATION) {
- pSysInfo->CurGunSelected = _index;
- ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
- return;
- }
- }
- pSysInfo->CurGunSelected = 0;
- ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
- } else {
- pSysInfo->CurGunSelected = 0;
- ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
- }
- }
- log_info("current select gun ............................... %d \n",
- pSysInfo->CurGunSelected);
- } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
- if (rightBtnPush) {
- rightBtnPush = false;
- //log_info("right btn up............................... \n");
- }
- }
- }
|