123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <time.h>
- #include <sys/ioctl.h>
- #include <sys/stat.h>
- #include <sys/timeb.h>
- #include <sys/time.h>
- #include <net/if.h>
- #include <linux/can.h>
- #include <linux/can/raw.h>
- #include <signal.h>
- #include "../Config.h"
- #include "../Log/log.h"
- #include "../Define/define.h"
- #include "../ShareMemory/shmMem.h"
- #include "../SelectGun/SelectGun.h"
- #include "Ev_Comm.h"
- #include "Module_EvComm.h"
- #include "../CSU/main.h"
- //------------------------------------------------------------------------------
- static struct SysConfigData *pSysConfig = NULL;
- static struct SysInfoData *pSysInfo = NULL;
- static struct FaultCodeData *pFaultCode = NULL;
- static struct AlarmCodeData *pAlarmCode = NULL;
- static struct CHAdeMOData *ShmCHAdeMOData = NULL;
- static struct GBTData *ShmGBTData = NULL;
- static struct CcsData *ShmCcsData = NULL;
- static DcCommonInfo *ShmDcCommonData = NULL;
- static SelectGunInfo *ShmSelectGunInfo = NULL;
- uint8_t deratingIndex[2];
- // 限制最大充電電壓,因應不同 type 槍線來限制
- // Chademo : 500V, 125A,
- // GB : 750, 120A
- // CCS : 950V, 120A
- //DS60-120 add
- //static double chademoVol = 5000;
- //static double ccsVol = 9500;
- //static double gbVol = 7500;
- static float maxChargingVol[2] = {0, 0}; // 限制最大充電電壓,如依照模塊則填上 0
- // 限制最大充電電流與能量透過 Web
- static float maxChargingCur[2] = {0, 0}; // 限制最大充電電流,如依照模塊則填上 0
- static float maxChargingPow = 0; // 限制最大充電能量,如依照模塊則填上 0
- static float LogInfo[2][10]; //DS60-120 add
- static int CanFd = -1;
- bool psuOutputReady[2] = {0, 0};
- //------------------------------------------------------------------------------
- extern void CANReceiver(int fd);
- extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
- extern void ClearAbnormalStatus_GB(uint8_t gun_index);
- extern void ClearAbnormalStatus_CCS(uint8_t gun_index);
- //------------------------------------------------------------------------------
- int GetCanFd(void)
- {
- return CanFd;
- }
- void GetClockTime(struct timespec* _now_time, void* null)
- {
- clock_gettime(CLOCK_MONOTONIC, _now_time);
- }
- 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;
- }
- unsigned long GetClockTimeoutValue(struct timespec _start_time)
- {
- struct timespec ts_end;
- unsigned long ret = 0;
- clock_gettime(CLOCK_MONOTONIC, &ts_end);
- ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
- return ret;
- }
- int InitCanBus(void)
- {
- int s0, nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- struct can_filter rxfilter[3];
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
- log_error("Set SO_RCVTIMEO NG");
- }
- nbytes = 40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
- log_error("Set SO_RCVBUF NG");
- }
- nbytes = 40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
- log_error("Set SO_SNDBUF NG");
- }
- rxfilter[0].can_id = 0x01;
- rxfilter[0].can_mask = 0x000000FF;
- rxfilter[1].can_id = 0x02;
- rxfilter[1].can_mask = 0x000000FF;
- rxfilter[2].can_id = 0x01FF;
- rxfilter[2].can_mask = 0x00000FFF;
- if (setsockopt(s0, SOL_CAN_RAW, CAN_RAW_FILTER,
- &rxfilter, sizeof(struct can_filter) * 3) < 0) {
- log_error("RX setsockopt CAN_RAW_FILTER failed");
- }
- strcpy(ifr0.ifr_name, "can0");
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- void SetNatural200AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
- {
- memset(&deratingByConnOtp->deratingTargetRate[0], 200, sizeof(deratingByConnOtp->deratingTargetRate));
- }
- void SetNatural300AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
- {
- deratingByConnOtp->deratingTargetCurrent[0] = 500;
- deratingByConnOtp->deratingTargetCurrent[1] = 300;
- deratingByConnOtp->deratingTargetCurrent[2] = 100;
- deratingByConnOtp->deratingTargetCurrent[3] = 100;
- deratingByConnOtp->deratingTargetCurrent[4] = 100;
- }
- void SetLiquidCoolGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
- {
- deratingByConnOtp->deratingTargetCurrent[0] = 500;
- deratingByConnOtp->deratingTargetCurrent[1] = 400;
- deratingByConnOtp->deratingTargetCurrent[2] = 300;
- deratingByConnOtp->deratingTargetCurrent[3] = 300;
- deratingByConnOtp->deratingTargetCurrent[4] = 300;
- }
- void SetCHAdeMoTypeJOTPValue(uint8_t regulation, struct DERATING_BY_OTP* deratingByConnOtp)
- {
- if (regulation == 'J') {
- memset(&deratingByConnOtp->deratingTargetRate[0], 125, sizeof(deratingByConnOtp->deratingTargetRate));
- }
- else {
- memset(&deratingByConnOtp->deratingTargetRate[0], 120, sizeof(deratingByConnOtp->deratingTargetRate));
- }
- }
- void SetCHAdeMoTypeKOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
- {
- memset(&deratingByConnOtp->deratingTargetRate[0], 200, sizeof(deratingByConnOtp->deratingTargetRate));
- }
- void SetCHAdeMoTypeSJOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
- {
- deratingByConnOtp->deratingTargetRate[0] = 1;
- deratingByConnOtp->deratingTargetRate[1] = 0.8;
- }
- static void SetGunTypeOTPValue(void)
- {
- struct ChargingInfoData* pDcChargingInfo = NULL;
- uint8_t Gun1Type = 0;
- uint8_t Gun2Type = 0;
- int i;
- if (pSysConfig->TotalConnectorCount == 1) {
- pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(0);
- Gun1Type = pSysConfig->ModelName[7];
- Gun2Type = pSysConfig->ModelName[7];
- switch (Gun1Type) {
- //CHAdeMo
- case 'J':
- SetCHAdeMoTypeJOTPValue(pSysConfig->ModelName[3], &pDcChargingInfo->deratingByConnOtp);
- break;
- case 'K':
- SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- case 'S':
- SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- // 風冷200A以下
- case 'U':
- case 'E':
- case 'M':
- case 'N':
- SetNatural200AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- // 風冷300A
- case 'T':
- case 'D':
- SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- // 水冷
- case 'V':
- case 'F':
- case 'P':
- case 'R':
- SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- }
- }
- else if (pSysConfig->TotalConnectorCount == 2) {
- Gun1Type = pSysConfig->ModelName[7];
- Gun2Type = pSysConfig->ModelName[9];
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
- pDcChargingInfo->deratingByConnOtp.isNeedDerating = GUNOTPDERATING;
- switch (i == 0 ? Gun1Type : Gun2Type) {
- //CHAdeMo
- case 'J':
- SetCHAdeMoTypeJOTPValue(pSysConfig->ModelName[3], &pDcChargingInfo->deratingByConnOtp);
- break;
- case 'K':
- SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- case 'S':
- SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- // 風冷200A以下
- case 'U':
- case 'E':
- case 'M':
- case 'N':
- SetNatural200AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- // 風冷300A
- case 'T':
- case 'D':
- SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- // 水冷
- case 'V':
- case 'F':
- case 'P':
- case 'R':
- SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
- break;
- }
- }
- }
- }
- float GetMaxChargingVol(uint8_t index)
- {
- return maxChargingVol[index];
- }
- float GetMaxCharginigCur(uint8_t index)
- {
- return maxChargingCur[index];
- }
- static void SendCommunicationOnly(uint8_t index)
- {
- struct ChargingInfoData *pDcCharginigInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- uint8_t targetID = pDcCharginigInfo->Evboard_id;
- /*
- if (pSysConfig->TotalConnectorCount == 1 &&
- pDcCharginigInfo->Type == _Type_CCS_2 &&
- ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
- targetID += 1;
- }
- */
- SetChargingPermission(index,
- COMMUNICATION,
- pDcCharginigInfo->AvailableChargingPower,
- 0,
- 0,
- targetID);
- }
- static void SendStopOnly(uint8_t index)
- {
- struct ChargingInfoData *pDcCharginigInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- uint8_t targetID = pDcCharginigInfo->Evboard_id;
- /*
- if (pSysConfig->TotalConnectorCount == 1 &&
- pDcCharginigInfo->Type == _Type_CCS_2 &&
- ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
- targetID += 1;
- }
- */
- SetChargingPermission(index,
- STOP,
- pDcCharginigInfo->AvailableChargingPower,
- 0,
- 0,
- targetID);
- }
- static uint8_t GetStopChargingReasonByEvse(uint8_t gunIndex, uint8_t *reason)
- {
- uint8_t result = NO;
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == 0x01) {
- // 012251
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 2;
- *(reason + 2) = 2;
- *(reason + 1) = 5;
- *(reason + 0) = 1;
- result = YES;
- }
- if (pDcChargingInfo->Type == _Type_Chademo) {
- if (pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
- // 011012
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 1;
- *(reason + 2) = 0;
- *(reason + 1) = 1;
- *(reason + 0) = 2;
- result = YES;
- } else if (pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail == YES) {
- // 012289
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 2;
- *(reason + 2) = 2;
- *(reason + 1) = 8;
- *(reason + 0) = 9;
- result = YES;
- } else if (pAlarmCode->AlarmEvents.bits.ChademoGfdTrip == YES) {
- // 012234
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 2;
- *(reason + 2) = 2;
- *(reason + 1) = 3;
- *(reason + 0) = 4;
- result = YES;
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- if (pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
- // 012290
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 2;
- *(reason + 2) = 2;
- *(reason + 1) = 9;
- *(reason + 0) = 0;
- result = YES;
- } else if (pAlarmCode->AlarmEvents.bits.GbGfdTrip == YES) {
- // 012236
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 2;
- *(reason + 2) = 2;
- *(reason + 1) = 3;
- *(reason + 0) = 6;
- result = YES;
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
- // 011014
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 1;
- *(reason + 2) = 0;
- *(reason + 1) = 1;
- *(reason + 0) = 4;
- result = YES;
- } else if (pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail == YES) {
- // 012288
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 2;
- *(reason + 2) = 2;
- *(reason + 1) = 8;
- *(reason + 0) = 8;
- result = YES;
- } else if (pAlarmCode->AlarmEvents.bits.CcsGfdTrip == YES) {
- // 012235
- *(reason + 5) = 0;
- *(reason + 4) = 1;
- *(reason + 3) = 2;
- *(reason + 2) = 2;
- *(reason + 1) = 3;
- *(reason + 0) = 5;
- result = YES;
- }
- }
- return result;
- }
- static void setCurrentOutput(void)
- {
- struct ChargingInfoData *chargingData_1 = NULL;
- struct ChargingInfoData *chargingData_2 = NULL;
- if (pSysConfig->TotalConnectorCount == 1) {
- chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- //chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- if (chargingData_1->FireChargingVoltage <= 500) { //DS60-120 add
- chargingData_1->PresentChargingCurrent = 0;
- }
- } else if (pSysConfig->TotalConnectorCount == 2) {
- chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
- if (chargingData_1->FireChargingVoltage <= 500) { //DS60-120 add
- chargingData_1->PresentChargingCurrent = 0;
- }
- if (chargingData_2->FireChargingVoltage <= 500) {
- chargingData_2->PresentChargingCurrent = 0;
- }
- }
- }
- static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
- {
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol) {
- *vol = maxChargingVol[index];
- }
- if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur) {
- *cur = maxChargingCur[index];
- }
- if (((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
- pDcChargingInfo->SystemStatus <= S_CHARGING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) &&
- pDcChargingInfo->ChargingProfileCurrent >= 0 &&
- pDcChargingInfo->ChargingProfileCurrent <= *cur
- ) {
- *cur = pDcChargingInfo->ChargingProfileCurrent;
- }
- }
- void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
- {
- if (((chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
- chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP) ||
- (chargingData->ChillerTemp >= STAGE1_GUN_DERATING_TEMP &&
- chargingData->ChillerTemp < STAGE2_GUN_DERATING_TEMP)) &&
- chargingData->deratingByConnOtp.deratingIndex < 1)
- {
- chargingData->deratingByConnOtp.deratingIndex = 1;
- }
- else if ((chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP ||
- chargingData->ChillerTemp >= STAGE2_GUN_DERATING_TEMP) &&
- chargingData->ConnectorTemp != UNDEFINED_TEMP &&
- chargingData->ChillerTemp != UNDEFINED_TEMP &&
- chargingData->deratingByConnOtp.deratingIndex < 2)
- {
- chargingData->deratingByConnOtp.deratingIndex = 2;
- }
- if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
- {
- *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
- }
- else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
- {
- if (*cur > chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex])
- *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex];
- }
- }
- static void SetPresentChargingOutputCap(void)
- {
- float pow1 = 0, cur1 = 0;
- float pow2 = 0, cur2 = 0;
- struct ChargingInfoData *chargingData_1 = NULL;
- struct ChargingInfoData *chargingData_2 = NULL;
- struct PrimaryMcuData* ShmPrimaryMcuData = (struct PrimaryMcuData*)GetShmPrimaryMcuData();
- if (pSysConfig->TotalConnectorCount == 1) {
- chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- } else if (pSysConfig->TotalConnectorCount == 2) {
- chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
- }
- /*
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- float vol = 0;
- #endif //!defined DD360Tcci && !defined DD360Audi
- */
- pow1 = chargingData_1->AvailableChargingPower;
- cur1 = chargingData_1->AvailableChargingCurrent;
- /*
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- vol = chargingData_1->MaximumChargingVoltage;
- GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
- //GetMaxPowerMethod(chargingData_1->Index, &pow1);
- #endif //!defined DD360Tcci && !defined DD360Audi
- */
- if (pow1 <= 0) {
- cur1 = 0;
- } else {
- if (chargingData_1->SystemStatus == S_CHARGING &&
- chargingData_1->FireChargingVoltage > 1500) {
- float maxCur = 0;
- maxCur = (pow1 * 1000) / chargingData_1->FireChargingVoltage;
- if (maxCur * 10 <= cur1) {
- //log_info("Gun1 -> MaxCharging Current = %f, Cap Current = %f ", (maxCur * 10), cur1);
- cur1 = maxCur * 10;
- }
- }
- }
- if (chargingData_1->deratingByConnOtp.isNeedDerating) {
- GetOtpPwrOrCurMethod(chargingData_1, &pow1, &cur1);
- if (deratingIndex[0] != chargingData_1->deratingByConnOtp.deratingIndex) {
- log_info("Gun0 Derating Index Set %d", chargingData_1->deratingByConnOtp.deratingIndex);
- deratingIndex[0] = chargingData_1->deratingByConnOtp.deratingIndex;
- }
- }
- pow2 = chargingData_2->AvailableChargingPower;
- cur2 = chargingData_2->AvailableChargingCurrent;
- /*
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- vol = chargingData_2->MaximumChargingVoltage;
- GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
- //GetMaxPowerMethod(chargingData_2->Index, &pow2);
- #endif //!defined DD360Tcci && !defined DD360Audi
- */
- if (pow2 <= 0) {
- cur2 = 0;
- } else {
- if (chargingData_2->SystemStatus == S_CHARGING &&
- chargingData_2->FireChargingVoltage > 1500) {
- float maxCur = 0;
- maxCur = (pow2 * 1000) / chargingData_2->FireChargingVoltage;
- if (maxCur * 10 <= cur2) {
- //log_info("Gun2 -> MaxCharging Current = %f, Cap Current = %f ", (maxCur * 10), cur2);
- cur2 = maxCur * 10;
- }
- }
- }
- if (chargingData_2->deratingByConnOtp.isNeedDerating) {
- GetOtpPwrOrCurMethod(chargingData_2, &pow2, &cur2);
- if (deratingIndex[1] != chargingData_2->deratingByConnOtp.deratingIndex) {
- log_info("Gun1 Derating Index Set %d", chargingData_2->deratingByConnOtp.deratingIndex);
- deratingIndex[1] = chargingData_2->deratingByConnOtp.deratingIndex;
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
- if (cur1 > 1500) {
- log_info("Gun0 chiller alarm set current less than 150A");
- cur1 = 1500;
- }
- if (cur2 > 1500) {
- log_info("Gun1 chiller alarm set current less than 150A");
- cur2 = 1500;
- }
- }
- //DS60-120 add
- if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 ||
- LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
- (LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 5 ||
- LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1 + 5) ||
- (LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <= pow2 - 5 ||
- LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >= pow2 + 5) ||
- (LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <= cur2 - 5 ||
- LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5)
- ) {
- //log_info("----------------------------------------------------- ");
- log_info("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f",
- pow1 / 10, cur1 / 10, pow2 / 10, cur2 / 10);
- //log_info("----------------------------------------------------- ");
- LogInfo[0][EV_LOG_OUTPUT_CAP_POW] = pow1;
- LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;
- LogInfo[1][EV_LOG_OUTPUT_CAP_POW] = pow2;
- LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] = cur2;
- chargingData_1->RealMaxCurrent = cur1;
- chargingData_1->RealMaxPower = pow1;
- if (pSysConfig->TotalConnectorCount == 2) {
- chargingData_2->RealMaxCurrent = cur2;
- chargingData_2->RealMaxPower = pow2;
- }
- }
- if (pSysConfig->TotalConnectorCount == 2) {
- chargingData_2->RealMaxCurrent = cur2;
- chargingData_2->RealMaxPower = pow2;
- }
- SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
- }
- /*
- static uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
- {
- PcPsuOutput *pPcPsuOutput = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[gunIndex];
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- int vol = 0;
- vol = abs(pPcPsuOutput->Voltage - pDcChargingInfo->FireChargingVoltage);
- if (vol <= 10) {
- return YES;
- }
- return NO;
- }
- */
- /**
- * [SetPresentChargingOutputFromPcPsu 充電狀態讀取電源櫃PSU輸出電壓電流,縮小誤差值]
- * @Author Jerry
- * @DateTime 2021-07-05
- */
- /*
- static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
- {
- float vol1 = 0, cur1 = 0;
- float vol2 = 0, cur2 = 0;
- PcPsuOutput *pPcPsuOutput0 = NULL;
- PcPsuOutput *pPcPsuOutput1 = NULL;
- struct ChargingInfoData *chargingData0 = NULL;
- struct ChargingInfoData *chargingData1 = NULL;
- switch (gunCount) {
- case 1:
- pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
- pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
- chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- break;
- case 2:
- pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
- pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[1];
- chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
- break;
- }
- vol1 = pPcPsuOutput0->Voltage == 0 ? chargingData0->FireChargingVoltage : (((float)pPcPsuOutput0->Voltage));
- cur1 = (chargingData0->PresentChargingCurrent * 10);//(((float)pPcPsuOutput0->Current) * 0.1);
- vol2 = pPcPsuOutput1->Voltage == 0 ? chargingData1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
- cur2 = (chargingData1->PresentChargingCurrent * 10);//(((float)pPcPsuOutput1->Current) * 0.1);
- if (
- (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
- (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] <= vol1 - CHK_VOL_RANGE) ||
- (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] >= cur1 + CHK_CUR_RANGE) ||
- (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] <= cur1 - CHK_CUR_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] >= vol2 + CHK_VOL_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] <= vol2 - CHK_VOL_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
- ) {
- log_info("G1->Out Vol=%.1f,Out Cur=%.1f - G2->Out Vol=%.1f,Out Cur=%.1f",
- vol1,
- cur1 / 10,
- vol2,
- cur2 / 10);
- LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
- LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
- LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] = vol2;
- LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] = cur2;
- }
- SetPresentOutputPower(vol1, cur1, vol2, cur2);
- }
- */
- static void SetPresentChargingOutputPower(void)
- {
- float vol1 = 0, cur1 = 0;
- float vol2 = 0, cur2 = 0;
- PcPsuOutput *pPcPsuOutput1 = NULL;
- PcPsuOutput *pPcPsuOutput2 = NULL;
- struct ChargingInfoData *chargingData_1 = NULL;
- struct ChargingInfoData *chargingData_2 = NULL;
- bool isPsuVol1 = false, isPsuVol2 = false, isPsuCur1 = false, isPsuCur2 = false;
- if (pSysConfig->TotalConnectorCount == 1) {
- pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
- pPcPsuOutput2 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
- chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- } else if (pSysConfig->TotalConnectorCount == 2) {
- pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
- pPcPsuOutput2 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[1];
- chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
- }
- psuOutputReady[0] = chargingData_1->SystemStatus != S_CHARGING ? false : psuOutputReady[0];
- psuOutputReady[1] = chargingData_2->SystemStatus != S_CHARGING ? false : psuOutputReady[1];
- isPsuVol1 = chargingData_1->PantographFlag ? true : (pPcPsuOutput1->Voltage != 0 && psuOutputReady[0] == true);
- isPsuVol2 = chargingData_2->PantographFlag ? true : (pPcPsuOutput2->Voltage != 0 && psuOutputReady[1] == true);
- isPsuCur1 = chargingData_1->PantographFlag ? true : false;
- isPsuCur2 = chargingData_2->PantographFlag ? true : false;
- //vol1 = chargingData_1->FireChargingVoltage;
- vol1 = isPsuVol1 == false ? chargingData_1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
- cur1 = isPsuCur1 == false ? (chargingData_1->PresentChargingCurrent * 10) : pPcPsuOutput1->Current;
- //vol2 = chargingData_2->FireChargingVoltage;
- vol2 = isPsuVol2 == false ? chargingData_2->FireChargingVoltage : (((float)pPcPsuOutput2->Voltage));
- cur2 = isPsuCur2 == false ? (chargingData_2->PresentChargingCurrent * 10) : pPcPsuOutput2->Current;
- //DS60-120 add
- if ((LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
- (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] <= vol1 - CHK_VOL_RANGE) ||
- (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] >= cur1 + CHK_CUR_RANGE) ||
- (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] <= cur1 - CHK_CUR_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] >= vol2 + CHK_VOL_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] <= vol2 - CHK_VOL_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) ||
- (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
- ) {
- log_info("G1-> Vol=%.1f, Cur=%.1f - G2-> Vol = %.1f, Cur = %.1f",
- vol1 / 10,
- cur1 / 10,
- vol2 / 10,
- cur2 / 10);
- LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
- LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
- LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] = vol2;
- LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] = cur2;
- }
- //if (_outVol_1 != vol1 ||
- // _outCur_1 != cur1 ||
- // _outVol_2 != vol2 ||
- // _outCur_2 != cur2) {
- /*log_info("G1 -> Output Vol = %f, Output Cur = %f -- G2 -> Output Vol = %f, Output Cur = %f ",
- vol1, cur1, vol2, cur2);
- */
- // _outVol_1 = vol1; _outCur_1 = cur1; _outVol_2 = vol2; _outCur_2 = cur2;
- //}
- SetPresentOutputPower(vol1, cur1, vol2, cur2);
- }
- /*
- static void checkConnectorOVPState(uint8_t gunIndex)
- {
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- // 避免槍溫偵測誤判
- static uint8_t gunTempAllowCount[2] = {0};
- bool isOTP = false;
- switch (pDcChargingInfo->Type) {
- case _Type_Chademo:
- if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP) {
- isOTP = true;
- }
- break;
- case _Type_CCS_2:
- if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP) {
- isOTP = true;
- }
- break;
- case _Type_GB:
- if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP) {
- isOTP = true;
- }
- break;
- }
- if (ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP == YES) {
- isOTP = true;
- }
- if (isOTP) {
- if (gunTempAllowCount[gunIndex] >= 2) {
- pDcChargingInfo->StopChargeFlag = YES;
- } else {
- gunTempAllowCount[gunIndex] += 1;
- }
- } else {
- gunTempAllowCount[gunIndex] = 0;
- }
- }
- */
- static time_t GetRtcInfoForEpoch(void)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- struct tm t;
- time_t result;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- t.tm_year = tmCSU->tm_year;
- t.tm_mon = tmCSU->tm_mon;
- t.tm_mday = tmCSU->tm_mday;
- t.tm_hour = tmCSU->tm_hour;
- t.tm_min = tmCSU->tm_min;
- t.tm_sec = tmCSU->tm_sec;
- t.tm_isdst = -1;
- result = mktime(&t);
- return result;
- }
- static void FormatVoltageAndCurrent(void)
- {
- uint8_t gunIndex = 0;
- ParsingRatedCur parsingRatedCur = {0};
- RateCurInfo *pRatedCurInfo = NULL;
- if (RatedCurrentParsing((char *)pSysConfig->ModelName, &parsingRatedCur) != PASS) {
- log_error("Parsing rated current failed");
- return;
- }
- maxChargingPow = parsingRatedCur.Power;
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[gunIndex];
- maxChargingVol[gunIndex] = pRatedCurInfo->Voltage;
- maxChargingCur[gunIndex] = pRatedCurInfo->Current;
- log_info("Conn %d GunType = %d, MaxVol = %f, MaxCur = %f ",
- gunIndex,
- pRatedCurInfo->GunType,
- maxChargingVol[gunIndex],
- maxChargingCur[gunIndex]);
- }
- }
- static int DiffTimeb(struct timeb ST, struct timeb ET)
- {
- //return milli-second
- unsigned int StartTime, StopTime;
- StartTime = (unsigned int)ST.time;
- StopTime = (unsigned int)ET.time;
- return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
- }
- int main(int argc, char *argv[])
- {
- bool chkChademoPermission[2] = {false};
- int isContinue = 1;
- uint8_t gunIndex = 0;
- uint8_t typeIndex = 0;
- uint8_t priorityLow = 1;
- uint8_t SendErrorCount[2] = {0, 0};
- uint8_t gfgResult = 0;
- uint32_t _timeBuf = 0;
- uint32_t chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {0};
- float maxVol, maxCur;
- struct timespec _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timespec _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- time_t rtc = {0};
- struct ChargingInfoData *pDcChargingInfo = NULL;
- struct timeb waitChargingTime;
- struct timeb nowTime;
- uint8_t Comcont = 0;
- uint8_t evstatus;
- if (CreateAllCsuShareMemory() == FAIL) {
- log_error("create share memory error");
- return FAIL;
- }
- MappingGunChargingInfo("EvComm Task");
- pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
- ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
- ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
- ShmGBTData = (struct GBTData *)GetShmGBTData();
- ShmCcsData = (struct CcsData *)GetShmCcsData();
- ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
- CanFd = InitCanBus();
- FormatVoltageAndCurrent();
- signal(SIGCHLD,SIG_IGN);
-
- CANReceiver(CanFd);
- //SetGunTypeOTPValue();
- rtc = GetRtcInfoForEpoch();
- while (isContinue) {
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- typeIndex = pDcChargingInfo->type_index;
- if (priorityLow == 1) {
- // 優先權較低 - 只要有回應即不會再詢問
- if (pDcChargingInfo->Type == _Type_Chademo &&
- ShmCHAdeMOData->evse[typeIndex].SelfTest_Comp != PASS) {
- SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
- GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
- } else if (pDcChargingInfo->Type == _Type_GB &&
- ShmGBTData->evse[typeIndex].SelfTest_Comp != PASS) {
- SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
- GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 &&
- ShmCcsData->V2GMessage_DIN70121[typeIndex].SelfTest_Comp != PASS) {
- SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
- GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
- }
- }
- /*
- if (pDcChargingInfo->Type == _Type_Chademo) {
- pAlarmCode->AlarmEvents.bits.ChademoboardStestFail =
- (ShmCHAdeMOData->evse[typeIndex].SelfTest_Comp != PASS) ? true : false;
- pAlarmCode->AlarmEvents.bits.ChademoModuleCommFail =
- ( CanFd < 0 ) ? true : false;
- } else if (pDcChargingInfo->Type == _Type_GB) {
- pAlarmCode->AlarmEvents.bits.GbtboardStestFail =
- (ShmGBTData->evse[typeIndex].SelfTest_Comp != PASS) ? true : false;
- pAlarmCode->AlarmEvents.bits.mFail =
- ( CanFd < 0 ) ? true : false;
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- pAlarmCode->AlarmEvents.bits.CCSboardStestFail =
- (ShmCcsData->V2GMessage_DIN70121[typeIndex].SelfTest_Comp != PASS) ? true : false;
- pAlarmCode->AlarmEvents.bits.ChademoModuleCommFail =
- ( CanFd < 0 ) ? true : false;
-
- }*/
- //固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
- //log_info("GetMiscellaneousInfo. index = %d, Eid = %d ",
- // gunIndex,
- // pDcChargingInfo->Evboard_id);
- GetMiscellaneousInfo(gunIndex,
- pDcChargingInfo->RelayK1K2Status,
- pDcChargingInfo->PresentChargedEnergy,
- (pDcChargingInfo->PresentChargingVoltage * 10),
- pDcChargingInfo->Evboard_id);
- //checkConnectorOVPState(gunIndex);
- }
- switch (pDcChargingInfo->SystemStatus) {
- case S_IDLE:
- case S_AUTHORIZING:
- case S_RESERVATION:
- if (pDcChargingInfo->Type == _Type_Chademo) {
- ClearAbnormalStatus_Chademo(gunIndex);
- if (pSysInfo->PageIndex == _PAGE_PLUGIN) {
- if (!chkChademoPermission[gunIndex]) {
- chkChademoPermission[gunIndex] = true;
- GetClockTime(&_chk_chademo_permission_timeout[gunIndex], NULL);
- SendCommunicationOnly(gunIndex);
- } else {
- _timeBuf = GetClockTimeoutValue(_chk_chademo_permission_timeout[gunIndex]);
- if (_timeBuf < 0) {
- GetClockTime(&_chk_chademo_permission_timeout[gunIndex], NULL);
- } else {
- if (_timeBuf / 1000 > 10000) {
- SendCommunicationOnly(gunIndex);
- GetClockTime(&_chk_chademo_permission_timeout[gunIndex], NULL);
- }
- }
- }
- } else if (chkChademoPermission[gunIndex]) {
- chkChademoPermission[gunIndex] = false;
- SendStopOnly(gunIndex);
- }
- if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP == NO) {
- pDcChargingInfo->StopChargeFlag = NO;
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- ClearAbnormalStatus_GB(gunIndex);
- if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP == NO) {
- pDcChargingInfo->StopChargeFlag = NO;
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- ClearAbnormalStatus_CCS(gunIndex);
- if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO) {
- pDcChargingInfo->StopChargeFlag = NO;
- }
- }
- // Set Ev board in communication mode
- // Get EVCCID for authorize when gun plug-in only for CCS
- if ( pDcChargingInfo->ConnectorPlugIn && pSysConfig->isAuthrizeByEVCCID &&
- ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
- if (Comcont == 1 && evstatus < 15) {
- GetEVCCIDReq(gunIndex,pDcChargingInfo->Evboard_id);
- SendCommunicationOnly(gunIndex);
- }
- }
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 && priorityLow == 1) {
- GetOutputReq(gunIndex,pDcChargingInfo->Evboard_id);
- if (evstatus != ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus) {
- evstatus = ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;
- }
- if ( evstatus > 19 && evstatus < 255 )
- GetEVCCIDReq(gunIndex,pDcChargingInfo->Evboard_id);
- }
- if (priorityLow == 1) {
- pDcChargingInfo->PresentChargedEnergy = 0;
- pDcChargingInfo->PresentChargingPower = 0;
- pDcChargingInfo->GroundFaultStatus = GFD_WAIT;
- pDcChargingInfo->RealRatingPower = 0;
- pDcChargingInfo->StopChargeFlag = NO;
- pDcChargingInfo->NormalStopChargeFlag = NO;//DS60-120 add
- pDcChargingInfo->ChargingFee = 0.0;
- pDcChargingInfo->EvBatterySoc = 0;
- pDcChargingInfo->EvBatteryStartSoc = 0; //DS60-120 add
- pDcChargingInfo->EvBatteryMaxVoltage = 0; //DS60-120 add
- pDcChargingInfo->ChargingProfilePower = -1; //DS60-120 add
- pDcChargingInfo->ChargingProfileCurrent = -1; //DS60-120 add
- if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) { //DS60-120 add
- pDcChargingInfo->PresentChargingVoltage = 0;
- pDcChargingInfo->PresentChargingCurrent = 0;
- pDcChargingInfo->EvBatteryMaxVoltage = 0;
- }
- chargingTime[gunIndex] = 0;
- //maxChargingCur[gunIndex] = pSysConfig->MaxChargingCurrent * 10;
- //maxChargingPow = (pSysConfig->MaxChargingPower * 10);
- //DS60-120 add
- SendErrorCount[gunIndex] = 0;
- //maxChargingPow = pSysConfig->MaxChargingPower * 10;
- // ShmPsuData->SystemAvailablePower 已是 * 10
- //maxChargingPow = ShmPsuData->SystemAvailablePower;
- if (pSysConfig->MaxChargingPower * 10 != 0 &&
- pSysConfig->MaxChargingPower * 10 < maxChargingPow) {
- maxChargingPow = pSysConfig->MaxChargingPower * 10;
- }
- LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = 0;
- LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = 0;
- LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] = 0;
- LogInfo[gunIndex][EV_LOG_SOC] = 0;
- SetPresentChargingOutputPower();
- }
- break;
- case S_PREPARNING:
- chkChademoPermission[gunIndex] = false; //DS60-120 add
- // 設定當前輸出
- SetPresentChargingOutputPower();
- pDcChargingInfo->PowerConsumption = 0;
- break;
- case S_PREPARING_FOR_EV:
- // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
- GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
- //log_info("PresentChargingVoltage = %f ", pDcChargingInfo->PresentChargingVoltage);
- //log_info("PresentChargingCurrent = %f ", pDcChargingInfo->PresentChargingCurrent);
- //log_info("AvailableChargingPower = %f ", pDcChargingInfo->AvailableChargingPower);
- //log_info("AvailableChargingCurrent = %f ", pDcChargingInfo->AvailableChargingCurrent);
- //log_info("MaximumChargingVoltage = %f ", pDcChargingInfo->MaximumChargingVoltage);
- // 設定當前輸出
- SetPresentChargingOutputPower();
- if (ShmSelectGunInfo->WaitDoCommPermission[gunIndex] == YES) {
- ShmSelectGunInfo->WaitDoCommPermission[gunIndex] = NO;
- //if (priorityLow == 1) {
- // 樁端輸出能力
- maxVol = pDcChargingInfo->MaximumChargingVoltage;
- maxCur = pDcChargingInfo->AvailableChargingCurrent;
- GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
- //DS60-120 add
- if (LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] != maxVol ||
- LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] != maxCur) {
- LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = maxVol;
- LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = maxCur;
- log_info("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f",
- gunIndex,
- maxVol / 10,
- maxCur / 10,
- pDcChargingInfo->AvailableChargingPower / 10);
- }
- pDcChargingInfo->RealMaxVoltage = maxVol;
- SetChargingPermission(gunIndex,
- START,
- pDcChargingInfo->AvailableChargingPower,
- maxCur,
- maxVol,
- pDcChargingInfo->Evboard_id);
- // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
- GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id);
- }
- GetClockTime(&_chk_ratingPower_timeout[gunIndex], NULL);
- break;
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- // 開始確認車端是否同意開始充電
- GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
- // 設定當前輸出
- SetPresentChargingOutputPower();
- if (priorityLow % 5 == 1) {
- // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
- GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id); //DS60-120 add
- // 樁端輸出能力改變
- SetPresentChargingOutputCap();
- }
- //DS60-120 add
- if (LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] != pDcChargingInfo->EvBatteryMaxVoltage) {
- LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] = pDcChargingInfo->EvBatteryMaxVoltage;
- log_info("index = %d, Ev Maximum Battery Voltage = %f ",
- gunIndex,
- pDcChargingInfo->EvBatteryMaxVoltage);
- }
- if (LogInfo[gunIndex][EV_LOG_SOC] != pDcChargingInfo->EvBatterySoc) {
- LogInfo[gunIndex][EV_LOG_SOC] = pDcChargingInfo->EvBatterySoc;
- log_info("index = %d, SOC = %d ",
- gunIndex,
- pDcChargingInfo->EvBatterySoc);
- }
- // 持續通知 Isolation 測試狀態
- if (priorityLow == 1) {
- // 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
- // if (_chargingData[_index]->FireChargingVoltage >= 3500)
- // pDcChargingInfo->GroundFaultStatus = GFD_PASS;
- //log_info("To EV_%d GFD = %d ", _index,pDcChargingInfo->GroundFaultStatus);
- //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
- {
- //if ((GetClockTimeoutValue(_derating_time) / 1000) > 1000)
- gfgResult = pDcChargingInfo->GroundFaultStatus;
- // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
- if (pDcChargingInfo->Type == _Type_Chademo ||
- pDcChargingInfo->Type == _Type_GB) {
- if (gfgResult == GFD_WARNING) {
- gfgResult = GFD_PASS;
- }
- }
- if (gfgResult == GFD_WARNING || gfgResult == GFD_PASS) {
- if (((GetClockTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 12000 &&
- pDcChargingInfo->RealRatingPower > 0) ||
- (GetClockTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 14000) {
- //log_info("**********EvComm : gunIndex= %d, RealRatingPower = %d ",
- // gunIndex,pDcChargingInfo->RealRatingPower);
- //gfgResult = GFD_PASS;
- //DS60-120 add
- if (LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] != pDcChargingInfo->RealRatingPower) {
- LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] = pDcChargingInfo->RealRatingPower;
- log_info("Conn %d, RealRatingPower = %d ",
- gunIndex,
- pDcChargingInfo->RealRatingPower);
- }
- } else {
- gfgResult = GFD_WAIT;
- }
- }
- SetIsolationStatus(gunIndex, gfgResult, pDcChargingInfo->Evboard_id);
- }
- if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->PrechargeStatus == PRECHARGE_READY
- ) {
- SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
- }
- }
- ftime(&waitChargingTime);
- break;
- case S_CHARGING:
- //if (waitPsuVolwithRealyVol(gunIndex) == NO) {
- // continue;
- //}
- GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id); //DS60-120 add
- // 計算 Power
- pDcChargingInfo->PresentChargingPower =
- ((float)((pDcChargingInfo->PresentChargingVoltage) *
- (pDcChargingInfo->PresentChargingCurrent)) / 1000);
- //DS60-120 remove
- if (chargingTime[gunIndex] == 0 ||
- chargingTime[gunIndex] > pDcChargingInfo->PresentChargedDuration) {
- chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
- } else {
- int passTime = pDcChargingInfo->PresentChargedDuration - chargingTime[gunIndex];
- if (passTime > 0) {
- float changingPow = (pDcChargingInfo->PresentChargingPower) * passTime / 3600;
- if (pSysConfig->BillingData.isBilling) {
- pDcChargingInfo->ChargingFee += changingPow * pSysConfig->BillingData.Cur_fee;
- }
- pDcChargingInfo->PresentChargedEnergy += changingPow;
- pDcChargingInfo->PowerConsumption += changingPow;
- ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption += changingPow;
- chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
- }
- }
- // 開始確認車端是否同意開始充電
- GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
- // 設定當前輸出
- ftime(&nowTime);
- if (!(DiffTimeb(waitChargingTime, nowTime) < 5000 ||
- DiffTimeb(waitChargingTime, nowTime) < 0)) {
- psuOutputReady[gunIndex] = true;
- }
- SetPresentChargingOutputPower();
- // for test end
- if (priorityLow % 5 == 0) {
- // 樁端輸出能力改變
- SetPresentChargingOutputCap();
- }
- if ((pDcChargingInfo->GroundFaultStatus == GFD_FAIL) ||
- (pDcChargingInfo->Type == _Type_CCS_2)) {
- SetIsolationStatus(gunIndex,
- pDcChargingInfo->GroundFaultStatus,
- pDcChargingInfo->Evboard_id);
- }
- /*
- else if (pDcChargingInfo->Type == _Type_CCS_2) {
- SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
- }*/
- // GFD 失敗再通知
- if (priorityLow == 1) {
- if (pDcChargingInfo->Type == _Type_CCS_2 &&
- pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
- SetEvsePrechargeInfo(gunIndex,
- PRECHARGE_CHARELAY_PASS,
- pDcChargingInfo->Evboard_id);
- }
- }
- break;
- case S_ALARM:
- case S_TERMINATING:
- // 設定當前輸出
- setCurrentOutput();
- SetPresentChargingOutputPower();
- // 槍鎖還在,則代表是樁端要求的停止
- if (pDcChargingInfo->GunLocked == START ||
- pDcChargingInfo->Type == _Type_CCS_2) {
- uint8_t normalStop = 0x01;
- uint8_t stopReason[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- if (GetStopChargingReasonByEvse(gunIndex, stopReason)) {
- normalStop = 0x02;
- }
- EvseStopChargingEvent(normalStop,
- stopReason,
- pDcChargingInfo->Evboard_id);
- SendErrorCount[gunIndex] += 1; //DS60-120 add
- }
- if (pDcChargingInfo->Type == _Type_CCS_2) {
- SetIsolationStatus(gunIndex,
- pDcChargingInfo->GroundFaultStatus,
- pDcChargingInfo->Evboard_id);
- }
- GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
- //DS60-120 add
- if (pDcChargingInfo->SystemStatus == S_ALARM) {
- if (priorityLow == 1) {
- // 樁端輸出能力
- maxVol = pDcChargingInfo->MaximumChargingVoltage;
- maxCur = pDcChargingInfo->AvailableChargingCurrent;
- GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
- SetChargingPermission(gunIndex,
- STOP,
- pDcChargingInfo->AvailableChargingPower,
- maxCur,
- maxVol,
- pDcChargingInfo->Evboard_id);
- }
- }
- break;
- case S_COMPLETE:
- // 設定當前輸出
- SetPresentChargingOutputPower();
- if (priorityLow == 1) {
- // 樁端輸出能力
- maxVol = pDcChargingInfo->MaximumChargingVoltage;
- maxCur = pDcChargingInfo->AvailableChargingCurrent;
- GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
- SetChargingPermission(gunIndex,
- STOP,
- pDcChargingInfo->AvailableChargingPower,
- maxCur,
- maxVol,
- pDcChargingInfo->Evboard_id);
- //DS60-120 add
- //if (pDcChargingInfo->EvBatterySoc >= 100) {
- // //滿電,則直接清掉錯誤
- // if (pDcChargingInfo->Type == _Type_Chademo) {
- // ClearAbnormalStatus_Chademo(gunIndex);
- // } else if (pDcChargingInfo->Type == _Type_GB) {
- // ClearAbnormalStatus_GB(gunIndex);
- // } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- // ClearAbnormalStatus_CCS(gunIndex);
- // }
- //}
- }
- break;
- }//switch
- }//for
- Comcont >= 200 ? Comcont = 1: Comcont++;
- priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
- usleep(50000);
- }//while
- return 0;
- }
|