123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914 |
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <unistd.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include "../ShareMemory/shmMem.h"
- #include "../Config.h"
- #include "../Log/log.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 struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
- static DcCommonInfo *ShmDcCommonData = NULL;
- static struct WARNING_CODE_INFO *pSysWarning = NULL;
- static struct LedModuleData *ShmLedModuleData = NULL;
- static struct FanModuleData *ShmFanModuleData = NULL;
- static Relay outputRelay = {0};
- static Relay regRelay = {0};
- static int Uart5Fd = 0;
- static struct timespec gFanBoardRunTimer;
- static uint16_t _setFanSpeed = 0;
- static uint16_t fanSpeedSmoothValue = 500;
- static Led_Color cur_led_color = {COLOR_MIN_LV};
- static Led_Color led_color;
- static struct timespec _led_priority_time;
- int ReservationLed;
- time_t ReservationFlashTimer;
- bool _show_GFD_Warming[2] = {TRUE};
- //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]; //DS60-120 add
- static struct timespec _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
- static void SetLedColor(void);
- static struct timespec _close_ac_contactor;
- //------------------------------------------------------------------------------
- static void RunForceStopProcess(void)
- {
- static bool isCriticalStop = NO;
- static struct timespec _psuCriticalStop;
- uint32_t _timebuf;
- if (isCriticalStop == NO) {
- isCriticalStop = YES;
- GetClockTime(&_psuCriticalStop, NULL);
- } else {
- _timebuf = GetClockTimeoutValue(_psuCriticalStop);
- if (_timebuf < 0) {
- GetClockTime(&_psuCriticalStop, NULL);
- } else {
- if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000)) {
- isCriticalStop = NO;
- pAlarmCode->AlarmEvents.bits.PsuFailureAlarm = NORMAL;
- }
- }
- }
- }
- static void StopCheckRelayInfo(uint8_t _chkIndex)
- {
- if (ShmDcCommonData->CheckRelayStatus[_chkIndex] != STOP) {
- ShmDcCommonData->CheckRelayStatus[_chkIndex] = STOP;
- }
- }
- static void StartCheckRelayInfo(uint8_t _chkIndex, uint8_t toState)
- {
- // SMR1 *2 + SMR2 * 2 + Parallel * 2
- static struct timespec lastCheckRelayStateTimer[6] = {0};
- //uint8_t *pCheckRelayState = (uint8_t *)ShmDcCommonData->CheckRelayStatus[_chkIndex];
- if (ShmDcCommonData->CheckRelayStatus[_chkIndex] == STOP) {
- GetClockTime(&lastCheckRelayStateTimer[_chkIndex], NULL);
- ShmDcCommonData->CheckRelayStatus[_chkIndex] = START;
- } else {
- if ((GetClockTimeoutValue(lastCheckRelayStateTimer[_chkIndex]) / 1000000) >= 1) {
- //log_info("relay welding or driving fault = %d ", _chkIndex);
- if (toState == 1) {
- ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
- } else {
- ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
- }
- log_info("relay %d %s fault", _chkIndex,(toState == 1) ? "driving" : "welding");
- GetClockTime(&lastCheckRelayStateTimer[_chkIndex], NULL);
- }
- }
- }
- static 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;
- }
- /*static void MatchRelayStatus(void)
- {
- // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
- //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
- //pSysInfo->AcContactorStatus =
- // regRelay.relay_event.bits.AC_Contactor =
- // outputRelay.relay_event.bits.AC_Contactor;
- 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;
- }
- */
- static bool IsNoneMatchRelayStatus(void)
- {
- bool result = false;
- if (
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- (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 //!defined DD360Tcci && !defined DD360Audi
- (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 DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- ||
- (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 //!defined DD360Tcci && !defined DD360Audi
- ) {
- result = true;
- }
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
- log_info("AC Contact Relay none match. ");
- }
- if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
- log_info("CCS Precharge Relay none match. ");
- }
- #endif //
- if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
- //log_info("SMR1:D+ Relay none match. ");
- StartCheckRelayInfo(RELAY_SMR1_P_STATUS, outputRelay.relay_event.bits.Gun1_P);
- } else {
- StopCheckRelayInfo(RELAY_SMR1_P_STATUS);
- }
- if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
- //log_info("SMR1:D- Relay none match. ");
- StartCheckRelayInfo(RELAY_SMR1_N_STATUS, outputRelay.relay_event.bits.Gun1_N);
- } else {
- StopCheckRelayInfo(RELAY_SMR1_N_STATUS);
- }
- if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
- //log_info("SMR2:D+ Relay none match. ");
- StartCheckRelayInfo(RELAY_SMR2_P_STATUS, outputRelay.relay_event.bits.Gun2_P);
- } else {
- StopCheckRelayInfo(RELAY_SMR2_P_STATUS);
- }
- if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
- //log_info("SMR2:D- Relay none match. ");
- StartCheckRelayInfo(RELAY_SMR2_N_STATUS, outputRelay.relay_event.bits.Gun2_N);
- } else {
- StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
- }
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
- //log_info("Parallel:D+ Relay none match. ");
- StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
- } else {
- StopCheckRelayInfo(RELAY_PARA_P_STATUS);
- }
- if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
- //log_info("Parallel:D- Relay none match. ");
- StartCheckRelayInfo(RELAY_PARA_N_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_N);
- } else {
- StopCheckRelayInfo(RELAY_PARA_N_STATUS);
- }
- #endif //
- return result;
- }
- static void SetParalleRelayStatus(void)
- {
- #if defined DD360Tcci || defined DD360Audi || defined DD360ComBox || defined DD360UCar
- return;
- #endif //!defined DD360Tcci || !defined DD360Audi || !defined DD360ComBox
- 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) {
- // ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
- 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;
- }
- }
- }
- }
- }
- }
- }
- static void GetGfdAdc(void)
- {
- int gunIndex = 0;
- uint8_t targetID = 0;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- Gfd gfd_adc = {0};
- // define : 每 0.2 ~ 1 秒一次
- // occur : <= 75k 歐姆 @ 150 - 750 Vdc
- // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
- 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;
- //log_info("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d ",
- // pDcChargingInfo->GroundFaultStatus,
- // gfd_adc.rb_step_1,
- // gfd_adc.Resister_conn1,
- // gfd_adc.voltage_conn1);
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d ",
- 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 && _show_GFD_Warming[gunIndex]) {
- log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d ",
- gunIndex,
- pDcChargingInfo->GroundFaultStatus,
- gfd_adc.Resister_conn1,
- gfd_adc.voltage_conn1);
- _show_GFD_Warming[gunIndex] = FALSE;
- }
- }
- } 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 ",
- 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 && _show_GFD_Warming[gunIndex]) {
- log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d ",
- gunIndex,
- pDcChargingInfo->GroundFaultStatus,
- gfd_adc.Resister_conn1,
- gfd_adc.voltage_conn1);
- _show_GFD_Warming[gunIndex] = FALSE;
- }
- }
- }
- }
- }
- }
- 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) {
- GetClockTime(&_checkOutputVolProtectTimer[index], NULL);
- _isOvpChkTimeFlag[index] = YES;
- }
- } else {
- log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f ",
- pDcChargingInfo->FireChargingVoltage,
- (pDcChargingInfo->EvBatterytargetVoltage * 10));
- log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f ",
- pDcChargingInfo->FireChargingVoltage,
- (pDcChargingInfo->EvBatterytargetVoltage * 10));
- if ((GetClockTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
- if (pDcChargingInfo->Type == _Type_Chademo) {
- //pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
- ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- //pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
- ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
- } else if (pDcChargingInfo->Type == _Type_GB) {
- //pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
- ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = 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) {
- // if ((pDcChargingInfo->SystemStatus >= S_PREPARNING && pDcChargingInfo->SystemStatus <= S_CHARGING) ||
- // (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
- // {
- // if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC)
- // {
- // if (_psuInputVolR > VIN_MAX_VOLTAGE_IEC ||
- // _psuInputVolS > VIN_MAX_VOLTAGE_IEC ||
- // _psuInputVolT > VIN_MAX_VOLTAGE_IEC)
- // {
- // log_info("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f ",
- // _psuInputVolR, _psuInputVolS, _psuInputVolT);
- // pDcChargingInfo->StopChargeFlag = YES;
- // }
- //
- // }
- // else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL)
- // {
- // if (_psuInputVolR > VIN_MAX_VOLTAGE_UL ||
- // _psuInputVolS > VIN_MAX_VOLTAGE_UL ||
- // _psuInputVolT > VIN_MAX_VOLTAGE_UL)
- // {
- // log_info("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f ",
- // _psuInputVolR, _psuInputVolS, _psuInputVolT);
- // pDcChargingInfo->StopChargeFlag = YES;
- // }
- // }
- // }
- // else
- log_info("CheckAcInputOvpStatus");
- pDcChargingInfo->StopChargeFlag = YES;
- }
- }
- //void CheckOutputVolNoneMatchFire(uint8_t index)
- //{
- // struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- //
- // if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
- // (pDcChargingInfo->Type == _Type_Chademo ||
- // pDcChargingInfo->Type == _Type_CCS_2 ||
- // pDcChargingInfo->Type == _Type_GB)) {
- // if (((pDcChargingInfo->PresentChargingVoltage * 10) < pDcChargingInfo->FireChargingVoltage - 300) ||
- // ((pDcChargingInfo->PresentChargingVoltage * 10) > pDcChargingInfo->FireChargingVoltage + 300)) {
- // if (!_isOutputNoneMatch[index]) {
- // _isOutputNoneMatch[index] = YES;
- // GetClockTime(&_checkOutputNoneMatchTimer[index], NULL);
- // } else {
- // if ((GetClockTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
- // /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f ",
- // index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
- // log_error("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f ",
- // index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
- // pDcChargingInfo->StopChargeFlag = YES;*/
- // }
- // }
- // } else {
- // _isOutputNoneMatch[index] = NO;
- // }
- // }
- //}
- 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) {
- log_info("CheckPhaseLossStatus");
- 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 (pDcChargingInfo->RelayWeldingCheck != YES) {
- // break;
- //}
- if (pRegGunPNState->GunN == NO) {
- if (pDcChargingInfo->GroundFaultStatus != GFD_FAIL) {
- pOutputGunPNState->GunN = YES;
- } else {
- pOutputGunPNState->GunN = NO;
- }
- } else {
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- pOutputGunPNState->GunN = NO;
- }
- }
- if (pRegGunPNState->GunP == NO) {
- if (pDcChargingInfo->GroundFaultStatus != GFD_FAIL) {
- pOutputGunPNState->GunP = YES;
- } else {
- pOutputGunPNState->GunP = NO;
- }
- } else {
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- pOutputGunPNState->GunP = NO;
- }
- }
- break;
- case S_TERMINATING:
- case S_COMPLETE:
- case S_ALARM:
- if ((pDcChargingInfo->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
- pOutputGunPNState->GunP = NO;
- pOutputGunPNState->GunN = NO;
- }
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- pOutputGunPNState->GunP = NO;
- pOutputGunPNState->GunN = NO;
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- #if defined DD360Tcci || defined DD360Audi || defined DD360ComBox || defined DD360UCar
- break;
- #endif //defined DD360Tcci || defined DD360Audi || defined DD360ComBox
- //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
- // if (pRegPreChargingState->CcsPrecharge == NO) {
- // pOutputPreChargingState->CcsPrecharge = YES;
- // } else if (pRegPreChargingState->CcsPrecharge == YES) {
- // pRegGunPNState->GunP = NO;
- // }
- //}
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- pOutputGunPNState->GunP = NO;
- pOutputGunPNState->GunN = NO;
- }
- break;
- case S_CCS_PRECHARGE_ST1:
- #if defined DD360Tcci || defined DD360Audi || defined DD360ComBox || defined DD360UCar
- break;
- #endif //defined DD360Tcci || defined DD360Audi || defined DD360ComBox
- //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
- // if (pRegGunPNState->GunP == NO) {
- // pOutputGunPNState->GunP = YES;
- // } else if (pRegGunPNState->GunP == YES) {
- // pOutputPreChargingState->CcsPrecharge = NO;
- // }
- //}
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- pOutputGunPNState->GunP = NO;
- pOutputGunPNState->GunN = NO;
- }
- break;
- }
- }
- // 確認 K1 K2 relay 的狀態
- 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 DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- 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 //!defined DD360Tcci && !defined DD360Audi
- }
- 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 DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- 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 //!defined DD360Tcci && !defined DD360Audi
- }
- break;
- }
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- //DS60-120 add
- 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 //!defined DD360Tcci && !defined DD360Audi
- }
- void SetGfdConfig(uint8_t index, uint8_t resister)
- {
- Gfd_config gfd_config = {
- .index = index,
- .state = resister,
- };
- //log_info("************************GFD Vol = %d, GFD Res = %d ", gfd_config.reqVol, gfd_config.resister);
- if (Config_Gfd_Value(Uart5Fd, ADDR_RELAY, &gfd_config) == PASS) {
- // log_info("Set reqVol = %f, resister = %d ",
- // gfd_config.reqVol,
- // gfd_config.resister);
- }
- }
- void CableCheckDetected(uint8_t index)
- {
- uint8_t targetID = 0;
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- // Cable Check
- // 當火線上的電壓 = 車端要求的電壓電流
- // _chargingData[targetGun]->EvBatterytargetVoltage
- // 才可以開始偵測 1s
- // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
- // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
- // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
- 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)
- // ) {
- if (pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) {
- 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_TERMINATING || pDcChargingInfo->SystemStatus == S_ALARM)
- {
- if (pDcChargingInfo->Type == _Type_CCS_2)
- {
- SetGfdConfig(targetID, GFD_CHARGING);
- }
- } else {
- SetGfdConfig(targetID, GFD_IDLE);
- }
- }
- }
- // 讀取 Relay 狀態
- void GetRelayOutputStatus(void)
- {
- if (Query_Relay_Output(Uart5Fd, ADDR_RELAY, ®Relay) == PASS) {
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
- #endif //!defined DD360Tcci && !defined DD360Audi
- }
- }
- // AC 三相輸入電壓
- void GetPresentInputVol(void)
- {
- static uint8_t _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
- static uint8_t _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
- PresentInputVoltage inputVoltage = {0};
- if (Query_Present_InputVoltage(Uart5Fd, ADDR_RELAY, &inputVoltage) == PASS) {
- // resolution : 0.1
- pSysInfo->InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
- pSysInfo->InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
- pSysInfo->InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
- //********************************************************************************************************//
- // Vin (UVP)
- 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 ", 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 ", 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 ", 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 ", 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 ", 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 ", 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;
- }
- }
- }
- //********************************************************************************************************//
- // Vin (OVP)
- 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 ", 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 ", 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 ", 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 ", 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 ", 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 ", 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;
- }
- }
- }
- }
- }
- // 左右槍的 Relay 前後的輸出電壓
- 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;
- }
- //log_info("Conn1 fuse 1 = %f ", outputVoltage.behindFuse_Voltage_C1);
- //log_info("Conn1 relay 1 = %f ", outputVoltage.behindRelay_Voltage_C1);
- //log_info("Conn2 fuse 2 = %f ", outputVoltage.behindFuse_Voltage_C2);
- //log_info("Conn2 relay 2 = %f ", outputVoltage.behindRelay_Voltage_C2);
- //log_info("outputVoltage.behindFuse_Voltage_C1 = %f ", outputVoltage.behindFuse_Voltage_C1);
- //log_info("outputVoltage.behindFuse_Voltage_C2 = %f ", outputVoltage.behindFuse_Voltage_C2);
- 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 DD360Tcci || defined DD360Audi || defined DD360ComBox || defined DD360UCar
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
- pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun1FuseOutputVolt) / 10;
- pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
- pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
- break;
- #endif //defined DD360Tcci || defined DD360Audi || defined DD360ComBox
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
- pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
- break;
- case 0x02:
- #if defined DD360Tcci || defined DD360Audi || defined DD360ComBox
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
- pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun2FuseOutputVolt) / 10;
- pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
- pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
- break;
- #endif //defined DD360Tcci || defined DD360Audi || defined DD360ComBox
- pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
- pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
- break;
- }
- //log_info("%d persent vol = %f, cur = %f",
- // index,
- // pDcChargingInfo->PresentChargingVoltage,
- // pDcChargingInfo->PresentChargingCurrent);
- //unsigned short Ovp = 0;
- //unsigned short Ocp = 0;
- //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] // 最大輸出電壓與電池電壓最大值
- //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ] // 最大輸出電流與需求電流最小值
- //if (pDcChargingInfo->Type == _Type_Chademo) {
- // //Ovp = MaxValue(pDcChargingInfo->MaximumChargingVoltage, pDcChargingInfo->EvBatteryMaxVoltage);
- // //Ocp = MaxValue(pDcChargingInfo->PresentChargingCurrent, ShmCHAdeMOData->ev[pDcChargingInfo->type_index].ChargingCurrentRequest);
- //} else if (pDcChargingInfo->Type == _Type_CCS_2) {
- //}
- }
- }
- void SetRtcData_Relay(void)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- Rtc rtc = {0};
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- // tmCSU->tm_sec);
- 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) {
- //log_info("SetRtc (RB) sucessfully. ");
- }
- }
- void SetModelName_Relay(void)
- {
- if (Config_Model_Name(Uart5Fd, ADDR_RELAY, pSysConfig->ModelName) == PASS) {
- //log_info("Set Model name (RB) PASS = %s ", pSysConfig->ModelName);
- }
- }
- void GetFwAndHwVersion_Relay(void)
- {
- Ver ver = {0};
- if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
- // RelayModuleData
- strcpy((char *)ShmRelayModuleData->version, ver.Version_FW);
- // SystemInfo
- strcpy((char *)pSysInfo->RelayModuleFwRev, ver.Version_FW);
- //log_info("GetFwAndHwVersion_Relay s1 = %s ", ver.Version_FW);
- }
- if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
- // SystemInfo
- strcpy((char *)pSysInfo->RelayModuleHwRev, ver.Version_FW);
- //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
- }
- }
- static 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 ");
- }
- }
- static bool IsRelayProcessNeedPause(void)
- {
- bool _pause = false;
- static bool isPause = false;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if(pDcChargingInfo->SystemStatus == S_UPDATE)
- {
- SetLedColor();
- _pause = true;
- }
- }
- if(isPause != _pause)
- {
- log_info("Relay Process Now Is %s ", _pause == true ? "Paused" : "Continued");
- }
- isPause = _pause;
- return _pause;
- }
- static void SetFanModuleSpeed(void)
- {
- {
- FanSpeed _fanSpeed = {0};
- _setFanSpeed += fanSpeedSmoothValue;
- if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed) {
- _setFanSpeed = ShmFanModuleData->SetFan1Speed;
- }
- //printf("_setFanSpeed = %d \n", _setFanSpeed);
- _fanSpeed.speed[0] = _setFanSpeed;
- _fanSpeed.speed[1] = _setFanSpeed;
- _fanSpeed.speed[2] = _setFanSpeed;
- _fanSpeed.speed[3] = _setFanSpeed;
- if (Config_Fan_Speed(Uart5Fd, ADDR_FAN, &_fanSpeed) == PASS) {
- //log_info("successfully Fan");
- }
- }
- }
- // 風扇速度
- static void GetFanSpeed(void)
- {
- FanSpeed fanSpeed = {0};
- //log_info("Get fan board speed ");
- if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
- ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
- ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
- ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
- ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
- // log_info("SystemFanRotaSpeed_1 = %d ", fanSpeed.speed[0]);
- // log_info("SystemFanRotaSpeed_2 = %d ", fanSpeed.speed[1]);
- // log_info("SystemFanRotaSpeed_3 = %d ", fanSpeed.speed[2]);
- // log_info("SystemFanRotaSpeed_4 = %d ", fanSpeed.speed[3]);
- // Config_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed[0]);
- //SysInfoData (SystemFanRotaSpeed)
- }
- }
- static void GetFanSpeedByFunction(void)
- {
- if (ShmDcCommonData->DebugFlag == YES) {
- return;
- }
- int gunIndex;
- struct ChargingInfoData* pDcChargingInfo = NULL;
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
- if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- ShmDcCommonData->FanOnTime = time((time_t*)NULL);
- if (ShmFanModuleData->SetFan1Speed == 0) {
- ShmFanModuleData->SetFan1Speed = 7000;
- log_info("Set Fan speed 7000");
- }
- }
- }
- if ((time((time_t*)NULL) - ShmDcCommonData->FanOnTime) >= 600 &&
- ShmFanModuleData->SetFan1Speed == 7000) {
- ShmFanModuleData->SetFan1Speed = 0;
- log_info("Close fan");
- }
- // 風控修改 :
- // ******************************************************* //
- //
- // 當前PSU輸出總 KW PSU Temp
- // 30 x -------------------- x ---------- + 14 x (PSU Temp - 45)
- // 當前樁最大功率 KW 45
- //
- // ******************************************************* //
- /*
- // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
- uint32_t _maxPower = ShmPsuData->SystemAvailablePower;
- // 當前PSU輸出總 KW & PSU Temp :
- uint8_t temp = 0;
- uint8_t index = 0;
- uint8_t count = 0;
- uint8_t gunIndex = 0;
- uint8_t _temp_diff = 0;
- float power = 0;
- double _pw_rate = 0;
- double _temp_rate = 0;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- for (index = 0; index < ShmPsuData->GroupCount; index++) {
- for (count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
- if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
- temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
- }
- }
- }
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- power += (pDcChargingInfo->PresentChargingPower * 10);
- }
- if (_maxPower > 0) {
- _pw_rate = power / (double)_maxPower;
- }
- if (temp > 0) {
- _temp_rate = (double)temp / 50;
- }
- if (temp > 45) {
- _temp_diff = temp - 70;
- }
- ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _temp_diff)) / 100) * MAX_FAN_SPEED;
- if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED) {
- ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
- }
- if (ShmFanModuleData->TestFanSpeed < 0) {
- ShmFanModuleData->TestFanSpeed = 0;
- }
- */
- //
- // printf("power = %f \n", power);
- // printf("_maxPower = %d \n", _maxPower);
- // printf("temp = %d \n", temp);
- //
- // printf("_pw_rate = %f \n", _pw_rate);
- // printf("_temp_rate = %f \n", _temp_rate);
- // printf("_temp_diff = %d \n", _temp_diff);
- // printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
- // printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
- }
- static void SetRtcData_Fan(void)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- Rtc rtc = {0};
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- // tmCSU->tm_sec);
- 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_FAN, &rtc) == PASS) {
- //log_info("SetRtc (FB) sucessfully. ");
- }
- }
- static void SetModelName_Fan(void)
- {
- if (Config_Model_Name(Uart5Fd, ADDR_FAN, pSysConfig->ModelName) == PASS) {
- log_info("Set Model name PASS = %s ", pSysConfig->ModelName);
- }
- }
- static void GetFwAndHwVersion_Fan(void)
- {
- Ver ver = {0};
- if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
- // FanModuleData
- strcpy((char *)ShmFanModuleData->version, ver.Version_FW);
- // SystemInfo
- strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
- //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
- }
- if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
- // SystemInfo
- strcpy((char *)pSysInfo->FanModuleHwRev, ver.Version_FW);
- //log_info("GetFwAndHwVersion_Fan s2 = %s ", ver.Version_HW);
- }
- }
- static void fanBoardSelfTest(void)
- {
- if (ShmFanModuleData->SelfTest_Comp == YES) {
- return;
- }
- GetFwAndHwVersion_Fan();
- SetModelName_Fan();
- SetRtcData_Fan();
- sleep(1);
- GetClockTime(&gFanBoardRunTimer, NULL);
- }
- static void fanBoardPorcess(void)
- {
- if (ShmFanModuleData->SelfTest_Comp == NO) {
- return;
- }
- if (ShmFanModuleData->SelfTest_Comp == YES ||
- strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
- pSysInfo->FanModuleFwRev[0] != '\0') {
- ShmFanModuleData->SelfTest_Comp = YES;
- if (GetClockTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
- //GetPsuTempForFanSpeed();
- //GetFanSpeedByFunction();
- GetFanSpeed();
- pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
- GetClockTime(&gFanBoardRunTimer, NULL);
- /*
- ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
- ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
- ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
- ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
- */
- //log_info("set fan = %d ", ShmFanModuleData->SetFan1Speed);
- SetFanModuleSpeed();
- }
- }
- }
- static void GetFwAndHwVersion_Led(void)
- {
- Ver ver = {0};
- if (Query_FW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS) {
- // LedModuleData
- strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
- // SystemInfo
- strcpy((char *) pSysInfo->LedModuleFwRev, ver.Version_FW);
- log_info("GetFwAndHwVersion_Led s1 = %s ", ver.Version_FW);
- ShmLedModuleData->SelfTest_Comp = YES;
- } else {
- //log_info("GetFwAndHwVersion_Led fail ");
- }
- // if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
- // {
- // // SystemInfo
- // strcpy((char *) pSysInfo->RelayModuleHwRev, ver.Version_FW);
- // //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
- // }
- }
- static bool IsNoneMatchLedColor(void)
- {
- bool result = false;
- if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
- cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
- cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
- cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
- cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
- cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue) {
- result = true;
- }
- return result;
- }
- //static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
- static void SetLedColor(void)
- {
- static uint8_t _checkLedChanged = 3;
- 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);
- } else if (pSysConfig->TotalConnectorCount == 2) {
- chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
- }
- uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
- if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
- _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
- } else if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
- _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
- } else if (pSysConfig->LedInfo.Intensity == LED_INTENSITY_BRIGHTEST) {
- _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
- }
- //printf("chargingData_1->SystemStatus=%d\n",chargingData_1->SystemStatus);
- //printf("chargingData_2->SystemStatus=%d\n",chargingData_2->SystemStatus);
- //printf("pSysWarning->Level=%d\n",pSysWarning->Level);
- if (pSysWarning->Level == 2) {
- led_color.Connect_1_Green = COLOR_MIN_LV;
- led_color.Connect_1_Blue = COLOR_MIN_LV;
- led_color.Connect_1_Red = _colorBuf;
- led_color.Connect_2_Green = COLOR_MIN_LV;
- led_color.Connect_2_Blue = COLOR_MIN_LV;
- led_color.Connect_2_Red = _colorBuf;
- } else {
- if (pSysInfo->IsAlternatvieConf) {
- } else {
- // 左邊燈條
- if (chargingData_1->SystemStatus == S_BOOTING ||
- chargingData_1->SystemStatus == S_IDLE ) {
- if (chargingData_1->IsAvailable == NO) { //For Audi
- led_color.Connect_1_Green = COLOR_MIN_LV;
- led_color.Connect_1_Blue = COLOR_MIN_LV;
- led_color.Connect_1_Red = _colorBuf;
- } else {
- #if defined DD360Audi
- led_color.Connect_1_Green = _colorBuf;
- led_color.Connect_1_Blue = _colorBuf;
- led_color.Connect_1_Red = _colorBuf;
- #else
- led_color.Connect_1_Green = _colorBuf;
- led_color.Connect_1_Blue = COLOR_MIN_LV;
- led_color.Connect_1_Red = COLOR_MIN_LV;
- #endif
- }
- } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
- chargingData_1->SystemStatus <= S_COMPLETE) ||
- (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- led_color.Connect_1_Green = COLOR_MIN_LV;
- led_color.Connect_1_Blue = _colorBuf;
- led_color.Connect_1_Red = COLOR_MIN_LV;
- } else if ( chargingData_1->SystemStatus == S_UPDATE ||
- chargingData_1->SystemStatus == S_MAINTAIN ) {
- led_color.Connect_1_Green = COLOR_MIN_LV;
- led_color.Connect_1_Blue = COLOR_MIN_LV;
- led_color.Connect_1_Red = _colorBuf;
- } else if (chargingData_1->SystemStatus == S_RESERVATION) {
- if (ReservationLed) {
- led_color.Connect_1_Green = COLOR_MIN_LV;
- } else {
- led_color.Connect_1_Green = _colorBuf;
- }
- led_color.Connect_1_Blue = COLOR_MIN_LV;
- led_color.Connect_1_Red = COLOR_MIN_LV;
- }
- // 右邊燈條
- // --------------------------------------------------------------------------
- if (chargingData_2->SystemStatus == S_BOOTING ||
- chargingData_2->SystemStatus == S_IDLE ) {
- if (chargingData_2->IsAvailable == NO) {
- led_color.Connect_2_Green = COLOR_MIN_LV;
- led_color.Connect_2_Blue = COLOR_MIN_LV;
- led_color.Connect_2_Red = _colorBuf;
- } else {
- #if defined DD360Audi
- led_color.Connect_2_Green = _colorBuf;
- led_color.Connect_2_Blue = _colorBuf;
- led_color.Connect_2_Red = _colorBuf;
- #else
- led_color.Connect_2_Green = _colorBuf;
- led_color.Connect_2_Blue = COLOR_MIN_LV;
- led_color.Connect_2_Red = COLOR_MIN_LV;
- #endif
- }
- } else if ((chargingData_2->SystemStatus >= S_AUTHORIZING &&
- chargingData_2->SystemStatus <= S_COMPLETE) ||
- (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- led_color.Connect_2_Green = COLOR_MIN_LV;
- led_color.Connect_2_Blue = _colorBuf;
- led_color.Connect_2_Red = COLOR_MIN_LV;
- }else if ( chargingData_2->SystemStatus == S_UPDATE ||
- chargingData_2->SystemStatus == S_MAINTAIN) {
- led_color.Connect_2_Green = COLOR_MIN_LV;
- led_color.Connect_2_Blue = COLOR_MIN_LV;
- led_color.Connect_2_Red = _colorBuf;
- } else if (chargingData_2->SystemStatus == S_RESERVATION) {
- if (ReservationLed) {
- led_color.Connect_2_Green = COLOR_MIN_LV;
- } else {
- led_color.Connect_2_Green = _colorBuf;
- }
- led_color.Connect_2_Blue = COLOR_MIN_LV;
- led_color.Connect_2_Red = COLOR_MIN_LV;
- }
- }
- }
- if (_checkLedChanged > 0) {
- if (Config_Led_Color(Uart5Fd, ADDR_LED, &led_color) == PASS) {
- _checkLedChanged--;
- cur_led_color.Connect_1_Red = led_color.Connect_1_Red;
- cur_led_color.Connect_1_Green = led_color.Connect_1_Green;
- cur_led_color.Connect_1_Blue = led_color.Connect_1_Blue;
- cur_led_color.Connect_2_Red = led_color.Connect_2_Red;
- cur_led_color.Connect_2_Green = led_color.Connect_2_Green;
- cur_led_color.Connect_2_Blue = led_color.Connect_2_Blue;
- }
- } else if (IsNoneMatchLedColor()) {
- _checkLedChanged = 3;
- }
- }
- static void LEDBoardSelfTest(void)
- {
- // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
- if (ShmLedModuleData->SelfTest_Comp == YES) {
- return;
- }
- #if defined DD360Tcci ||defined DD360Audi || defined DD360UCar
- GetFwAndHwVersion_Led();
- sleep(1);
- GetClockTime(&_led_priority_time, NULL);
- return;
- #endif //defined DD360Tcci || defined DD360Audi
- // 自檢階段
- if (pSysInfo->SelfTestSeq <= _STEST_PSU_CAP) {
- GetFwAndHwVersion_Led();
- sleep(1);
- GetClockTime(&_led_priority_time, NULL);
- } else {
- // 自檢階段沒有問到版號
- if (pAlarmCode->AlarmEvents.bits.LedboardStestFail == NO) {
- pAlarmCode->AlarmEvents.bits.LedboardStestFail = YES;
- }
- }
- }
- static void LEDBoardProcess(void)
- {
- //struct ChargingInfoData *pDcChargingInfo0 = NULL;
- //struct ChargingInfoData *pDcChargingInfo1 = NULL;
- if (ShmLedModuleData->SelfTest_Comp == NO) {
- return;
- }
- pSysConfig->LedInfo.Intensity = LED_INTENSITY_BRIGHTEST;
- if (GetClockTimeoutValue(_led_priority_time) / 1000 >= 500) {
- if (time((time_t*)NULL) - ReservationFlashTimer >= 3) {
- ReservationFlashTimer = time((time_t*)NULL);
- if (ReservationLed)
- ReservationLed = 0;
- else
- ReservationLed = 1;
- }
- SetLedColor();
- GetClockTime(&_led_priority_time, NULL);
- }
- }
- void RelayBoardTask(int uartFD)
- {
- bool isRelayBypass = false;
- pid_t pid = fork();
- if (pid == 0) {
- bool isCharging = false;
- bool isStopChargingCount = false;
- uint8_t i = 0;
- int isContinue = 1;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- //share memory mapping
- pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
- ShmPsuData = (struct PsuData *)GetShmPsuData();
- ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
- ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
- ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
- ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
- Uart5Fd = uartFD;
- for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if(pDcChargingInfo->PantographFlag == YES)
- {
- isRelayBypass = true;
- }
- }
- //relay init
- if(isRelayBypass == false)
- {
- outputRelayInit(uartFD);
- }
- while (isContinue) {
- if(IsRelayProcessNeedPause() == true)
- {
- sleep(1);
- continue;
- }
- // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
- if (ShmRelayModuleData->SelfTest_Comp == NO && isRelayBypass == false) {
- GetFwAndHwVersion_Relay();
- SetModelName_Relay(); //DS60-120 add
- SetRtcData_Relay();
- sleep(1);
- }
- #if !defined NO_FAN_BOARD && !defined DD360ComBox
- fanBoardSelfTest();
- #endif //NO_FAN_BOARD
- #if !defined DD360ComBox
- LEDBoardSelfTest();
- #endif //defined DD360ComBox
- if (ShmRelayModuleData->SelfTest_Comp == YES && isRelayBypass == false)
- {
- // ==============優先權最高 10 ms ==============
- // 輸出電壓
- GetPersentOutputVol();
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- // 三相輸入電壓
- GetPresentInputVol();
- #endif //!defined DD360Tcci && !defined DD360Audi
- // 讀取當前 AC relay 狀態
- regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
- GetRelayOutputStatus();
- // Cable check (Get)
- GetGfdAdc();
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- // Cable check (Set)
- CableCheckDetected(i);
- // check k1 k2 relay 狀態
- CheckK1K2RelayOutput(i);
- // 依據當前各槍的狀態選擇 搭上/放開 Relay
- SetK1K2RelayStatus(i);
- #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- if (pSysConfig->PhaseLossPolicy == YES) {
- CheckPhaseLossStatus(i);
- }
- CheckAcInputOvpStatus(i);
- #endif //!defined DD360Tcci && !defined DD360Audi
- if (pDcChargingInfo->SystemStatus == S_IDLE ||
- pDcChargingInfo->SystemStatus == S_RESERVATION ||
- pDcChargingInfo->SystemStatus == S_MAINTAIN) {
- //pDcChargingInfo->RelayWeldingCheck = NO;
- //_isRelayWelding[i] = NO;
- _isOvpChkTimeFlag[i] = NO;
- _show_GFD_Warming[i] = TRUE;
- //ResetDetAlarmStatus(i); //DS60-120 add
- }
- 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) ||
- ShmDcCommonData->pGunInfo[i].WaitForPlugit == YES ||
- (pSysInfo->PageIndex >= _PAGE_AUTHORIZE &&
- pSysInfo->PageIndex <= _PAGE_PLUGIN)
- ) {
- pDcChargingInfo->IsReadyToCharging = YES;
- isCharging = true;
- // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
- //if (pDcChargingInfo->Type == _Type_GB) {
- // if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
- // pDcChargingInfo->RelayWeldingCheck == NO) {
- // CheckRelayWeldingStatus(i);
- // }
- //} else {
- //pDcChargingInfo->RelayWeldingCheck = YES;
- //}
- if (pDcChargingInfo->SystemStatus == S_CHARGING) {
- CheckOutputPowerOverCarReq(i);
- //CheckOutputVolNoneMatchFire(i);
- }
- /*else {
- _isOutputNoneMatch[i] = NO;
- }*/
- } else {
- pDcChargingInfo->IsReadyToCharging = NO;
- }
- }
- // 橋接 relay
- SetParalleRelayStatus();
- // 搭上 AC Contactor
- //if (isCharging) {
- // outputRelay.relay_event.bits.AC_Contactor = YES;
- //} else {
- // outputRelay.relay_event.bits.AC_Contactor = NO;
- //}
- if (isCharging ||
- (ShmPsuData->Work_Step >= _TEST_MODE &&
- ShmPsuData->Work_Step <= _TEST_MODE)) {
- isStopChargingCount = false;
- outputRelay.relay_event.bits.AC_Contactor = YES;
- } else {
- if (!isStopChargingCount) {
- GetClockTime(&_close_ac_contactor, NULL);
- isStopChargingCount = true;
- } else {
- if ((outputRelay.relay_event.bits.AC_Contactor == YES &&
- GetClockTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
- outputRelay.relay_event.bits.AC_Contactor = NO;
- }
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
- outputRelay.relay_event.bits.AC_Contactor = NO;
- }
- if (pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == ABNORMAL) {
- RunForceStopProcess();
- 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;
- }
- // 搭上/鬆開 Relay
- if (IsNoneMatchRelayStatus()) {
- if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
- //regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
- //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;
- //MatchRelayStatus();
- //log_info("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x ",
- // regRelay.relay_event.bits.AC_Contactor,
- // regRelay.relay_event.bits.Gun1_P,
- // regRelay.relay_event.bits.Gun1_N,
- // regRelay.relay_event.bits.Gun2_P,
- // regRelay.relay_event.bits.Gun2_N,
- // regRelay.relay_event.bits.CCS_Precharge,
- // regRelay.relay_event.bits.Gun1_Parallel_P,
- // regRelay.relay_event.bits.Gun1_Parallel_N);
- }
- }
- }
- else if(isRelayBypass == true)
- {
- for(i = 0; i < pSysConfig->TotalConnectorCount; i++)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if (pDcChargingInfo->SystemStatus == S_IDLE ||
- pDcChargingInfo->SystemStatus == S_RESERVATION ||
- pDcChargingInfo->SystemStatus == S_MAINTAIN)
- {
- _isOvpChkTimeFlag[i] = NO;
- }
- if (pDcChargingInfo->SystemStatus == S_CHARGING)
- {
- CheckOutputPowerOverCarReq(i);
- }
- }
- }
- #if !defined NO_FAN_BOARD && !defined DD360ComBox
- fanBoardPorcess();
- #endif //NO_FAN_BOARD
- #if !defined DD360ComBox
- LEDBoardProcess();
- #endif //defined DD360ComBox
- usleep(10000);
- }
- }
- }
|