123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170 |
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include "../ShareMemory/shmMem.h"
- #include "../Config.h"
- #include "Module_InternalComm.h"
- #include "internalComm.h"
- static struct SysConfigData *pSysConfig = NULL;
- static struct SysInfoData *pSysInfo = NULL;
- static struct AlarmCodeData *pAlarmCode = NULL;
- static struct RelayModuleData *ShmRelayModuleData = NULL;
- static struct PsuData *ShmPsuData = NULL;
- static Relay outputRelay = {0};
- static Relay regRelay = {0};
- static int Uart5Fd = 0;
- static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static struct timeval _close_ac_contactor;
- uint32_t GetTimeoutValue(struct timeval _sour_time)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
- }
- uint8_t getCommTargetID(uint8_t index)
- {
- uint8_t targetID = 0;
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (pSysConfig->TotalConnectorCount == 1) {
- if (strncmp((char *)&pSysConfig->ModelName[7], "0", 1) != 0) {
- targetID = 0x01;
- } else if (strncmp((char *)&pSysConfig->ModelName[9], "0", 1) != 0) {
- targetID = 0x02;
- }
- } else {
- targetID = pDcChargingInfo->Evboard_id;
- }
- return targetID;
- }
- bool IsNoneMatchRelayStatus(void)
- {
- bool result = false;
- if (
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
- (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
- #endif
- (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
- (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
- (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
- (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N)
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- ||
- (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) ||
- (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N)
- #endif
- ) {
-
- result = true;
- }
- return result;
- }
- void SetParalleRelayStatus(void)
- {
- #if defined DD360 || defined DD360Audi || defined DD360ComBox
- return;
- #endif
- struct ChargingInfoData *pDcChargingInfo0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- struct ChargingInfoData *pDcChargingInfo1 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
-
- if (pSysConfig->TotalConnectorCount >= 2) {
- if (pDcChargingInfo0->SystemStatus == S_BOOTING || pDcChargingInfo1->SystemStatus == S_BOOTING ||
- (pDcChargingInfo0->SystemStatus == S_IDLE && pDcChargingInfo1->SystemStatus == S_IDLE)) {
-
- if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
- outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
- } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
- outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
- }
- } else {
- if (pDcChargingInfo0->IsReadyToCharging == YES ||
- pDcChargingInfo1->IsReadyToCharging == YES) {
-
- if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
- if (pSysInfo->ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A) {
-
- if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
- outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
- } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
- outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
- }
- } else {
-
- if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
- outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
- } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
- outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
- }
- }
- } else if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
- if (pSysInfo->ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M) {
-
- if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
- outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
- } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
- outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
- }
- } else {
-
- if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
- outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
- } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
- outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
- }
- }
- }
- }
- }
- }
- }
- void GetGfdAdc(void)
- {
- int gunIndex = 0;
- uint8_t targetID = 0;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- Gfd gfd_adc = {0};
-
-
-
- if (Query_Gfd_Adc(Uart5Fd, ADDR_RELAY, &gfd_adc) == PASS) {
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pDcChargingInfo->Type == 0x09 &&
- !pSysConfig->AlwaysGfdFlag
- ) {
- if ((pDcChargingInfo->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE) {
- pDcChargingInfo->GroundFaultStatus = GFD_PASS;
- }
- continue;
- }
- targetID = getCommTargetID(gunIndex);
- if (targetID == 0x01) {
- if (gfd_adc.result_conn1 == GFD_WARNING) {
- gfd_adc.result_conn1 = GFD_PASS;
- }
- pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn1;
-
-
-
-
-
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
- gunIndex,
- gfd_adc.rb_step_1,
- gfd_adc.Resister_conn1,
- gfd_adc.voltage_conn1);
- } else if (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
- pDcChargingInfo->GroundFaultStatus == GFD_WARNING
- ) {
- if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
- log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
- gunIndex,
- pDcChargingInfo->GroundFaultStatus,
- gfd_adc.Resister_conn1,
- gfd_adc.voltage_conn1);
- }
- }
- } else if (targetID == 0x02) {
- if (gfd_adc.result_conn2 == GFD_WARNING) {
- gfd_adc.result_conn2 = GFD_PASS;
- }
- pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn2;
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
- gunIndex,
- gfd_adc.rb_step_2,
- gfd_adc.Resister_conn2,
- gfd_adc.voltage_conn2);
- } else if (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
- pDcChargingInfo->GroundFaultStatus == GFD_WARNING
- ) {
- if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
- log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
- gunIndex,
- pDcChargingInfo->GroundFaultStatus,
- gfd_adc.Resister_conn1,
- gfd_adc.voltage_conn1);
- }
- }
- }
- }
- }
- }
- void CheckOutputPowerOverCarReq(uint8_t index)
- {
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- float fireV = pDcChargingInfo->FireChargingVoltage;
- float carV = pDcChargingInfo->EvBatteryMaxVoltage * 10;
- if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
- (pDcChargingInfo->Type == _Type_Chademo ||
- pDcChargingInfo->Type == _Type_CCS_2 ||
- pDcChargingInfo->Type == _Type_GB)) {
- if (fireV >= (carV + (carV * 0.02))) {
- if (!_isOvpChkTimeFlag[index]) {
- if ((pDcChargingInfo->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
- gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
- _isOvpChkTimeFlag[index] = YES;
- }
- } else {
- log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
- pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
- log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
- pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
- if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
- if (pDcChargingInfo->Type == _Type_Chademo) {
- pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
- } else if (pDcChargingInfo->Type == _Type_GB) {
- pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
- }
- pDcChargingInfo->StopChargeFlag = YES;
- }
- }
- } else {
- if (_isOvpChkTimeFlag[index] == YES) {
- _isOvpChkTimeFlag[index] = NO;
- }
- }
- }
- }
- void ResetDetAlarmStatus(uint8_t gun)
- {
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
- if (pDcChargingInfo->Type == _Type_Chademo) {
- if (pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP == YES) {
- pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- if (pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP == YES) {
- pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
- pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
- }
- }
- }
- void CheckAcInputOvpStatus(uint8_t index)
- {
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
-
- pDcChargingInfo->StopChargeFlag = YES;
- }
- }
- void CheckPhaseLossStatus(uint8_t index)
- {
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
-
- pDcChargingInfo->StopChargeFlag = YES;
- }
- }
- void SetK1K2RelayStatus(uint8_t index)
- {
- uint8_t targetID = 0;
- PreChargingState *pRegPreChargingState = NULL;
- PreChargingState *pOutputPreChargingState = NULL;
- GunPNState *pRegGunPNState = NULL;
- GunPNState *pOutputGunPNState = NULL;
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
- if (regRelay.relay_event.bits.Gun1_N == NO) {
- outputRelay.relay_event.bits.Gun1_N = YES;
- } else if (regRelay.relay_event.bits.Gun1_P == NO) {
- outputRelay.relay_event.bits.Gun1_P = YES;
- }
- return;
- }
- targetID = getCommTargetID(index);
- pRegPreChargingState = (PreChargingState *)®Relay.relay_event.relay_status[0];
- pOutputPreChargingState = (PreChargingState *)&outputRelay.relay_event.relay_status[0];
- if (targetID == 0x01) {
- pRegGunPNState = (GunPNState *)®Relay.relay_event.relay_status[1];
- pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[1];
- } else if (targetID == 0x02) {
- pRegGunPNState = (GunPNState *)®Relay.relay_event.relay_status[2];
- pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[2];
- }
- switch (pDcChargingInfo->SystemStatus) {
- case S_BOOTING:
- case S_IDLE:
- case S_AUTHORIZING:
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- if (pRegGunPNState->GunP == YES) {
- pOutputGunPNState->GunP = NO;
- } else if (pRegGunPNState->GunN == YES) {
- pOutputGunPNState->GunN = NO;
- }
- if (targetID == 0x02 && pDcChargingInfo->Type == _Type_CCS_2) {
- if (pRegPreChargingState->CcsPrecharge == YES) {
- pOutputPreChargingState->CcsPrecharge = NO;
- }
- }
- break;
- case S_PREPARING_FOR_EVSE:
- case S_CHARGING:
-
-
-
- if (pRegGunPNState->GunN == NO) {
- pOutputGunPNState->GunN = YES;
- } else if (pRegGunPNState->GunP == NO) {
- pOutputGunPNState->GunP = YES;
- }
- break;
- case S_TERMINATING:
- case S_COMPLETE:
- case S_ALARM:
- if ((pDcChargingInfo->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
- if (pRegGunPNState->GunP == YES) {
- pOutputGunPNState->GunP = NO;
- } else if (pRegGunPNState->GunN == YES) {
- pOutputGunPNState->GunN = NO;
- }
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- #if defined DD360 || defined DD360Audi || defined DD360ComBox
- break;
- #endif
- if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
- if (pRegPreChargingState->CcsPrecharge == NO) {
- pOutputPreChargingState->CcsPrecharge = YES;
- } else if (pRegPreChargingState->CcsPrecharge == YES) {
- pRegGunPNState->GunP = NO;
- }
- }
- break;
- case S_CCS_PRECHARGE_ST1:
- #if defined DD360 || defined DD360Audi || defined DD360ComBox
- break;
- #endif
- if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
- if (pRegGunPNState->GunP == NO) {
- pOutputGunPNState->GunP = YES;
- } else if (pRegGunPNState->GunP == YES) {
- pOutputPreChargingState->CcsPrecharge = NO;
- }
- }
- break;
- }
- }
- void CheckK1K2RelayOutput(uint8_t index)
- {
- uint8_t targetID = 0;
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- targetID = getCommTargetID(index);
- switch (targetID) {
- case 0x01:
- if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES) {
- pDcChargingInfo->RelayK1K2Status = YES;
- } else {
- pDcChargingInfo->RelayK1K2Status = NO;
- }
- if (pDcChargingInfo->Type == _Type_CCS_2) {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
- pDcChargingInfo->RelayKPK2Status = YES;
- } else {
- pDcChargingInfo->RelayKPK2Status = NO;
- }
- #else
- if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) {
- pDcChargingInfo->RelayKPK2Status = YES;
- } else {
- pDcChargingInfo->RelayKPK2Status = NO;
- }
- #endif
- }
- break;
- case 0x02:
- if (regRelay.relay_event.bits.Gun2_N == YES &&
- regRelay.relay_event.bits.Gun2_P == YES) {
- pDcChargingInfo->RelayK1K2Status = YES;
- } else {
- pDcChargingInfo->RelayK1K2Status = NO;
- }
- if (pDcChargingInfo->Type == _Type_CCS_2) {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- if (regRelay.relay_event.bits.Gun2_N == YES &&
- regRelay.relay_event.bits.CCS_Precharge == YES) {
- pDcChargingInfo->RelayKPK2Status = YES;
- } else {
- pDcChargingInfo->RelayKPK2Status = NO;
- }
- #else
- if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) {
- pDcChargingInfo->RelayKPK2Status = YES;
- } else {
- pDcChargingInfo->RelayKPK2Status = NO;
- }
- #endif
- }
- break;
- }
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-
- if (pSysInfo->BridgeRelayStatus == YES) {
- if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
- regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
- pSysInfo->BridgeRelayStatus = NO;
- }
- } else if (pSysInfo->BridgeRelayStatus == NO) {
- if (regRelay.relay_event.bits.Gun1_Parallel_N == YES &&
- regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
- pSysInfo->BridgeRelayStatus = YES;
- }
- }
- #else
- pSysInfo->BridgeRelayStatus = YES;
- #endif
- }
- void SetGfdConfig(uint8_t index, uint8_t resister)
- {
- Gfd_config gfd_config = {
- .index = index,
- .state = resister,
- };
-
- if (Config_Gfd_Value(Uart5Fd, ADDR_RELAY, &gfd_config) == PASS) {
- }
- }
- void CableCheckDetected(uint8_t index)
- {
- uint8_t targetID = 0;
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
-
-
-
-
-
-
-
- if (pSysConfig->TotalConnectorCount == 1) {
- if (strncmp((char *)&pSysConfig->ModelName[7], "0", 1) != 0) {
- targetID = 0;
- } else if (strncmp((char *)&pSysConfig->ModelName[9], "0", 1) != 0) {
- targetID = 1;
- }
- } else {
- targetID = index;
- }
- if ((pDcChargingInfo->Type >= _Type_Chademo &&
- pDcChargingInfo->Type <= _Type_GB) ||
- (pDcChargingInfo->Type == 0x09 &&
- pSysConfig->AlwaysGfdFlag)
- ) {
- if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
- pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
- ) {
- if ((pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) &&
- (pDcChargingInfo->RelayWeldingCheck == YES)
- ) {
- SetGfdConfig(targetID, GFD_CABLECHK);
- } else if ((pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0) &&
- (pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
- ) {
- SetGfdConfig(targetID, GFD_PRECHARGE);
- } else if ((pDcChargingInfo->SystemStatus >= S_CHARGING) &&
- (pDcChargingInfo->SystemStatus <= S_TERMINATING)
- ) {
- if ((pDcChargingInfo->Type == _Type_GB) ||
- (pDcChargingInfo->Type == _Type_Chademo)
- ) {
- SetGfdConfig(targetID, GFD_IDLE);
- } else {
- SetGfdConfig(targetID, GFD_CHARGING);
- }
- }
- } else if (pDcChargingInfo->SystemStatus == S_COMPLETE ||
- pDcChargingInfo->SystemStatus == S_PREPARNING ||
- pDcChargingInfo->SystemStatus == S_IDLE) {
- SetGfdConfig(targetID, GFD_IDLE);
- }
- }
- }
- void GetRelayOutputStatus(void)
- {
- if (Query_Relay_Output(Uart5Fd, ADDR_RELAY, ®Relay) == PASS) {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
- #endif
- }
- }
- void GetPresentInputVol(void)
- {
- static uint8_t _threePhaseOvp[3] = {0, 0, 0};
- static uint8_t _threePhaseUvp[3] = {0, 0, 0};
- PresentInputVoltage inputVoltage = {0};
- if (Query_Present_InputVoltage(Uart5Fd, ADDR_RELAY, &inputVoltage) == PASS) {
-
- pSysInfo->InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
- pSysInfo->InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
- pSysInfo->InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
-
-
- if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
- if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
- log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
- if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
- } else {
- _threePhaseUvp[0] += 1;
- }
- }
- } else {
- if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
- _threePhaseUvp[0] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
- if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
- log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
- if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
- } else {
- _threePhaseUvp[1] += 1;
- }
- }
- } else {
- if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
- _threePhaseUvp[1] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
- if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
- log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
- if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
- } else {
- _threePhaseUvp[2] += 1;
- }
- }
- } else {
- if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
- _threePhaseUvp[2] = 0;
- }
- }
- } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
- if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
- log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
- if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
- } else {
- _threePhaseUvp[0] += 1;
- }
- }
- } else {
- if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
- _threePhaseUvp[0] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
- if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
- log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
- if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
- } else {
- _threePhaseUvp[1] += 1;
- }
- }
- } else {
- if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
- _threePhaseUvp[1] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
- if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
- log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
- if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
- } else {
- _threePhaseUvp[2] += 1;
- }
- }
- } else {
- if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
- _threePhaseUvp[2] = 0;
- }
- }
- }
-
-
- if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
- if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
- log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
- if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
- } else {
- _threePhaseOvp[0] += 1;
- }
- }
- } else {
- if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
- _threePhaseOvp[0] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
- if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
- log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
- if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
- } else {
- _threePhaseOvp[1] += 1;
- }
- }
- } else {
- if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
- _threePhaseOvp[1] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == NO) {
- if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
- log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
- if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
- } else {
- _threePhaseOvp[2] += 1;
- }
- }
- } else {
- if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
- _threePhaseOvp[2] = 0;
- }
- }
- } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
- if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
- log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
- if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
- } else {
- _threePhaseOvp[0] += 0;
- }
- }
- } else {
- if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL) {
- pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
- _threePhaseOvp[0] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
- if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
- log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
- if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
- } else {
- _threePhaseOvp[1] += 0;
- }
- }
- } else {
- if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL) {
- pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
- _threePhaseOvp[1] = 0;
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
- if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
- log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
- if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
- } else {
- _threePhaseOvp[2] += 1;
- }
- }
- } else {
- if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL) {
- pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
- _threePhaseOvp[2] = 0;
- }
- }
- }
- }
- }
- void GetPersentOutputVol(void)
- {
- uint8_t index = 0;
- uint8_t targetID = 0;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- PresentOutputVoltage outputVoltage = {0};
- if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
- return;
- }
-
-
-
-
-
-
- ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
- ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
- ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
- ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
- for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- targetID = getCommTargetID(index);
- switch (targetID) {
- case 0x01:
- #if defined DD360 || defined DD360Audi || defined DD360ComBox
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
- pDcChargingInfo->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
- pDcChargingInfo->PresentChargingVoltage = pDcChargingInfo->FireChargingVoltage / 10;
- pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
- break;
- #endif
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
- pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
- break;
- case 0x02:
- #if defined DD360 || defined DD360Audi || defined DD360ComBox
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
- pDcChargingInfo->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
- pDcChargingInfo->PresentChargingVoltage = pDcChargingInfo->FireChargingVoltage / 10;
- pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
- break;
- #endif
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
- pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
- break;
- }
-
-
-
-
-
-
-
-
-
- }
- }
- void SetRtcData_Relay(void)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- Rtc rtc = {0};
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
-
-
-
- rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
- rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
- rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
- rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
- rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
- rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
- rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
- rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
- rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
- rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
- rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
- rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
- rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
- rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
- if (Config_Rtc_Data(Uart5Fd, ADDR_RELAY, &rtc) == PASS) {
-
- }
- }
- void SetModelName_Relay(void)
- {
- if (Config_Model_Name(Uart5Fd, ADDR_RELAY, pSysConfig->ModelName) == PASS) {
-
- }
- }
- void GetFwAndHwVersion_Relay(void)
- {
- Ver ver = {0};
- if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
-
- strcpy((char *)ShmRelayModuleData->version, ver.Version_FW);
-
- strcpy((char *)pSysInfo->RelayModuleFwRev, ver.Version_FW);
-
- }
- if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
-
- strcpy((char *)pSysInfo->RelayModuleHwRev, ver.Version_FW);
-
- }
- }
- void outputRelayInit(int fd)
- {
- memset((uint8_t *)&outputRelay, 0, sizeof(Relay));
- if (Config_Relay_Output(fd, ADDR_RELAY, &outputRelay) != PASS) {
- log_info("Config_Relay_Output fail \n");
- }
- }
- void RelayBoardTaask(int uartFD)
- {
- pid_t pid = fork();
- if (pid == 0) {
- bool isCharging = false;
- bool isStopChargingCount = false;
- uint8_t i = 0;
- int fd = GetInternalFd();
- int isContinue = 1;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- if (CreateAllCsuShareMemory() == FAIL) {
- log_error("Relay Board create share memory failed\r\n");
- }
- MappingGunChargingInfo("Relay Board Task");
-
- pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
- ShmPsuData = (struct PsuData *)GetShmPsuData();
- Uart5Fd = uartFD;
-
- outputRelayInit(uartFD);
- while (isContinue) {
-
- if (ShmRelayModuleData->SelfTest_Comp == NO) {
- GetFwAndHwVersion_Relay();
- SetModelName_Relay();
- SetRtcData_Relay();
- sleep(1);
- } else {
-
-
- GetPersentOutputVol();
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-
- GetPresentInputVol();
-
- regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
- GetRelayOutputStatus();
- #endif
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
-
- CableCheckDetected(i);
-
- CheckK1K2RelayOutput(i);
-
- SetK1K2RelayStatus(i);
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- if (pSysConfig->PhaseLossPolicy == YES) {
- CheckPhaseLossStatus(i);
- }
- CheckAcInputOvpStatus(i);
- #endif
- if (pDcChargingInfo->SystemStatus == S_IDLE) {
- pDcChargingInfo->RelayWeldingCheck = NO;
- _isRelayWelding[i] = NO;
- _isOvpChkTimeFlag[i] = NO;
- ResetDetAlarmStatus(i);
- }
- if (pDcChargingInfo->SystemStatus == S_BOOTING ||
- (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
- pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
- pSysInfo->WaitForPlugit == YES ||
- (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
- pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)) {
- pDcChargingInfo->IsReadyToCharging = YES;
- isCharging = true;
-
-
-
-
-
-
-
- pDcChargingInfo->RelayWeldingCheck = YES;
-
- if (pDcChargingInfo->SystemStatus == S_CHARGING) {
- CheckOutputPowerOverCarReq(i);
-
- } else {
- _isOutputNoneMatch[i] = NO;
- }
- } else {
- pDcChargingInfo->IsReadyToCharging = NO;
- }
- }
-
- GetGfdAdc();
-
- SetParalleRelayStatus();
-
-
-
-
-
-
- if (isCharging ||
- (ShmPsuData->Work_Step >= _TEST_MODE &&
- ShmPsuData->Work_Step <= _TEST_MODE)) {
- isStopChargingCount = false;
- outputRelay.relay_event.bits.AC_Contactor = YES;
- } else {
- if (!isStopChargingCount) {
- gettimeofday(&_close_ac_contactor, NULL);
- isStopChargingCount = true;
- } else {
- if ((outputRelay.relay_event.bits.AC_Contactor == YES &&
- GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
- outputRelay.relay_event.bits.AC_Contactor = NO;
- }
- }
- }
- if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
- outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
- }
-
- if (IsNoneMatchRelayStatus()) {
- if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
-
- regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
- regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
- regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
- regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
- regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
- regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
- regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
-
-
-
-
-
-
-
-
-
- }
- }
- }
- }
- usleep(100000);
- }
- }
|