RelayBoard.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include "../ShareMemory/shmMem.h"
  10. #include "../Config.h"
  11. #include "../Log/log.h"
  12. #include "Module_InternalComm.h"
  13. #include "internalComm.h"
  14. //------------------------------------------------------------------------------
  15. static struct SysConfigData *pSysConfig = NULL;
  16. static struct SysInfoData *pSysInfo = NULL;
  17. static struct AlarmCodeData *pAlarmCode = NULL;
  18. static struct RelayModuleData *ShmRelayModuleData = NULL;
  19. static struct PsuData *ShmPsuData = NULL;
  20. static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
  21. static DcCommonInfo *ShmDcCommonData = NULL;
  22. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  23. static struct LedModuleData *ShmLedModuleData = NULL;
  24. static struct FanModuleData *ShmFanModuleData = NULL;
  25. static struct GBTData* ShmGBTData = NULL;
  26. static Relay outputRelay = {0};
  27. static Relay regRelay = {0};
  28. static int Uart5Fd = 0;
  29. static struct timeval gFanBoardRunTimer;
  30. static uint16_t _setFanSpeed = 0;
  31. static uint16_t fanSpeedSmoothValue = 1000;
  32. static Led_Color cur_led_color = {COLOR_MIN_LV};
  33. static Led_Color led_color;
  34. static struct timeval _led_priority_time;
  35. int ReservationLed;
  36. time_t ReservationFlashTimer;
  37. //static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  38. //static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  39. //static bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  40. //static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  41. static bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
  42. static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
  43. static void SetLedColor(void);
  44. static struct timeval _close_ac_contactor;
  45. //------------------------------------------------------------------------------
  46. static void RunForceStopProcess(void)
  47. {
  48. static bool isCriticalStop = NO;
  49. static struct timeval _psuCriticalStop;
  50. uint32_t _timebuf;
  51. if (isCriticalStop == NO) {
  52. isCriticalStop = YES;
  53. gettimeofday(&_psuCriticalStop, NULL);
  54. } else {
  55. _timebuf = GetTimeoutValue(_psuCriticalStop);
  56. if (_timebuf < 0) {
  57. gettimeofday(&_psuCriticalStop, NULL);
  58. } else {
  59. if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000)) {
  60. isCriticalStop = NO;
  61. pAlarmCode->AlarmEvents.bits.PsuFailureAlarm = NORMAL;
  62. }
  63. }
  64. }
  65. }
  66. static void StopCheckRelayInfo(uint8_t _chkIndex)
  67. {
  68. if (ShmDcCommonData->CheckRelayStatus[_chkIndex] != STOP) {
  69. ShmDcCommonData->CheckRelayStatus[_chkIndex] = STOP;
  70. }
  71. }
  72. static void StartCheckRelayInfo(uint8_t _chkIndex, uint8_t toState)
  73. {
  74. // SMR1 *2 + SMR2 * 2 + Parallel * 2
  75. static struct timeval lastCheckRelayStateTimer[6] = {0};
  76. //uint8_t *pCheckRelayState = (uint8_t *)ShmDcCommonData->CheckRelayStatus[_chkIndex];
  77. if (ShmDcCommonData->CheckRelayStatus[_chkIndex] == STOP) {
  78. gettimeofday(&lastCheckRelayStateTimer[_chkIndex], NULL);
  79. ShmDcCommonData->CheckRelayStatus[_chkIndex] = START;
  80. } else {
  81. if ((GetTimeoutValue(lastCheckRelayStateTimer[_chkIndex]) / 1000000) >= 1) {
  82. //log_info("relay welding or driving fault = %d ", _chkIndex);
  83. if (toState == 1) {
  84. ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
  85. } else {
  86. ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
  87. }
  88. gettimeofday(&lastCheckRelayStateTimer[_chkIndex], NULL);
  89. }
  90. }
  91. }
  92. static uint8_t getCommTargetID(uint8_t index)
  93. {
  94. uint8_t targetID = 0;
  95. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  96. if (pSysConfig->TotalConnectorCount == 1) {
  97. if (strncmp((char *)&pSysConfig->ModelName[7], "0", 1) != 0) {
  98. targetID = 0x01;
  99. } else if (strncmp((char *)&pSysConfig->ModelName[9], "0", 1) != 0) {
  100. targetID = 0x02;
  101. }
  102. } else {
  103. targetID = pDcChargingInfo->Evboard_id;
  104. }
  105. return targetID;
  106. }
  107. /*static void MatchRelayStatus(void)
  108. {
  109. // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
  110. //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  111. //pSysInfo->AcContactorStatus =
  112. // regRelay.relay_event.bits.AC_Contactor =
  113. // outputRelay.relay_event.bits.AC_Contactor;
  114. regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  115. regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  116. regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  117. regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  118. regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  119. regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  120. regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  121. }
  122. */
  123. static bool IsNoneMatchRelayStatus(void)
  124. {
  125. bool result = false;
  126. if (
  127. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  128. (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
  129. (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
  130. #endif //!defined DD360 && !defined DD360Audi
  131. (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
  132. (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
  133. (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
  134. (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N)
  135. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  136. ||
  137. (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) ||
  138. (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N)
  139. #endif //!defined DD360 && !defined DD360Audi
  140. ) {
  141. result = true;
  142. }
  143. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  144. if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
  145. log_info("AC Contact Relay none match. ");
  146. }
  147. if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
  148. log_info("CCS Precharge Relay none match. ");
  149. }
  150. #endif //
  151. if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
  152. //log_info("SMR1:D+ Relay none match. ");
  153. StartCheckRelayInfo(RELAY_SMR1_P_STATUS, outputRelay.relay_event.bits.Gun1_P);
  154. } else {
  155. StopCheckRelayInfo(RELAY_SMR1_P_STATUS);
  156. }
  157. if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
  158. //log_info("SMR1:D- Relay none match. ");
  159. StartCheckRelayInfo(RELAY_SMR1_N_STATUS, outputRelay.relay_event.bits.Gun1_N);
  160. } else {
  161. StopCheckRelayInfo(RELAY_SMR1_N_STATUS);
  162. }
  163. if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
  164. //log_info("SMR2:D+ Relay none match. ");
  165. StartCheckRelayInfo(RELAY_SMR2_P_STATUS, outputRelay.relay_event.bits.Gun2_P);
  166. } else {
  167. StopCheckRelayInfo(RELAY_SMR2_P_STATUS);
  168. }
  169. if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
  170. //log_info("SMR2:D- Relay none match. ");
  171. StartCheckRelayInfo(RELAY_SMR2_N_STATUS, outputRelay.relay_event.bits.Gun2_N);
  172. } else {
  173. StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
  174. }
  175. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  176. if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
  177. //log_info("Parallel:D+ Relay none match. ");
  178. StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
  179. } else {
  180. StopCheckRelayInfo(RELAY_PARA_P_STATUS);
  181. }
  182. if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
  183. //log_info("Parallel:D- Relay none match. ");
  184. StartCheckRelayInfo(RELAY_PARA_N_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_N);
  185. } else {
  186. StopCheckRelayInfo(RELAY_PARA_N_STATUS);
  187. }
  188. #endif //
  189. return result;
  190. }
  191. static void SetParalleRelayStatus(void)
  192. {
  193. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  194. return;
  195. #endif //!defined DD360 || !defined DD360Audi || !defined DD360ComBox
  196. struct ChargingInfoData *pDcChargingInfo0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  197. struct ChargingInfoData *pDcChargingInfo1 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
  198. // 之後雙槍單模機種,橋接都會上
  199. if (pSysConfig->TotalConnectorCount >= 2) {
  200. if (pDcChargingInfo0->SystemStatus == S_BOOTING || pDcChargingInfo1->SystemStatus == S_BOOTING ||
  201. (pDcChargingInfo0->SystemStatus == S_IDLE && pDcChargingInfo1->SystemStatus == S_IDLE)) {
  202. // 初始化~ 不搭橋接
  203. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  204. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  205. } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
  206. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  207. }
  208. } else {
  209. if (pDcChargingInfo0->IsReadyToCharging == YES ||
  210. pDcChargingInfo1->IsReadyToCharging == YES) {
  211. // ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
  212. if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
  213. if (pSysInfo->ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A) {
  214. // 最大充 - 搭上橋接
  215. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
  216. outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
  217. } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
  218. outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
  219. }
  220. } else {
  221. // 平均充 - 不搭
  222. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  223. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  224. } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
  225. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  226. }
  227. }
  228. } else if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
  229. if (pSysInfo->ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M) {
  230. // 平均充 - 不搭
  231. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  232. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  233. } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
  234. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  235. }
  236. } else {
  237. // 最大充 - 搭上橋接
  238. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
  239. outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
  240. } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
  241. outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. }
  248. }
  249. static void GetGfdAdc(void)
  250. {
  251. int gunIndex = 0;
  252. uint8_t targetID = 0;
  253. struct ChargingInfoData *pDcChargingInfo = NULL;
  254. Gfd gfd_adc = {0};
  255. // define : 每 0.2 ~ 1 秒一次
  256. // occur : <= 75k 歐姆 @ 150 - 750 Vdc
  257. // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
  258. if (Query_Gfd_Adc(Uart5Fd, ADDR_RELAY, &gfd_adc) == PASS) {
  259. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  260. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  261. if (pDcChargingInfo->Type == 0x09 &&
  262. !pSysConfig->AlwaysGfdFlag
  263. ) {
  264. if ((pDcChargingInfo->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE) {
  265. pDcChargingInfo->GroundFaultStatus = GFD_PASS;
  266. }
  267. continue;
  268. }
  269. targetID = getCommTargetID(gunIndex);
  270. if (targetID == 0x01) {
  271. //if (gfd_adc.result_conn1 == GFD_WARNING) {
  272. // gfd_adc.result_conn1 = GFD_PASS;
  273. //}
  274. pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn1;
  275. //log_info("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d ",
  276. // pDcChargingInfo->GroundFaultStatus,
  277. // gfd_adc.rb_step_1,
  278. // gfd_adc.Resister_conn1,
  279. // gfd_adc.voltage_conn1);
  280. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  281. log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d ",
  282. gunIndex,
  283. gfd_adc.rb_step_1,
  284. gfd_adc.Resister_conn1,
  285. gfd_adc.voltage_conn1);
  286. } else if (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
  287. pDcChargingInfo->GroundFaultStatus == GFD_WARNING
  288. ) {
  289. if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  290. log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d ",
  291. gunIndex,
  292. pDcChargingInfo->GroundFaultStatus,
  293. gfd_adc.Resister_conn1,
  294. gfd_adc.voltage_conn1);
  295. }
  296. }
  297. } else if (targetID == 0x02) {
  298. //if (gfd_adc.result_conn2 == GFD_WARNING) {
  299. // gfd_adc.result_conn2 = GFD_PASS;
  300. //}
  301. pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn2;
  302. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  303. log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d ",
  304. gunIndex,
  305. gfd_adc.rb_step_2,
  306. gfd_adc.Resister_conn2,
  307. gfd_adc.voltage_conn2);
  308. } else if (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
  309. pDcChargingInfo->GroundFaultStatus == GFD_WARNING
  310. ) {
  311. if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  312. log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d ",
  313. gunIndex,
  314. pDcChargingInfo->GroundFaultStatus,
  315. gfd_adc.Resister_conn1,
  316. gfd_adc.voltage_conn1);
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. void CheckOutputPowerOverCarReq(uint8_t index)
  324. {
  325. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  326. ShmGBTData = (struct GBTData*)GetShmGBTData();
  327. float fireV = pDcChargingInfo->FireChargingVoltage;
  328. float carV = pDcChargingInfo->EvBatteryMaxVoltage * 10;
  329. /*
  330. log_info("PresentChargingVoltage:%f, FireChargingVoltage:%f ", pDcChargingInfo->PresentChargingVoltage * 10, pDcChargingInfo->FireChargingVoltage);
  331. log_info("fireV:%f, carV:%f, _isOvpChkTimeFlag:%d", fireV, carV, _isOvpChkTimeFlag[index]);
  332. log_info("EvBatterytargetVoltage:%f", pDcChargingInfo->EvBatterytargetVoltage);
  333. if (pDcChargingInfo->Type == _Type_GB) {
  334. log_info("GB EV Board Status:%d", ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
  335. }
  336. */
  337. if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
  338. (pDcChargingInfo->Type == _Type_Chademo ||
  339. pDcChargingInfo->Type == _Type_CCS_2 ||
  340. pDcChargingInfo->Type == _Type_GB)) {
  341. if (fireV >= (carV + (carV * 0.02))) {
  342. if (!_isOvpChkTimeFlag[index]) {
  343. if ((pDcChargingInfo->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
  344. gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
  345. _isOvpChkTimeFlag[index] = YES;
  346. }
  347. } else {
  348. log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f ",
  349. pDcChargingInfo->FireChargingVoltage,
  350. (pDcChargingInfo->EvBatterytargetVoltage * 10));
  351. log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f ",
  352. pDcChargingInfo->FireChargingVoltage,
  353. (pDcChargingInfo->EvBatterytargetVoltage * 10));
  354. if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
  355. if (pDcChargingInfo->Type == _Type_Chademo) {
  356. //pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
  357. ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
  358. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  359. //pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
  360. ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
  361. } else if (pDcChargingInfo->Type == _Type_GB) {
  362. //pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
  363. ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = YES;
  364. }
  365. //pDcChargingInfo->StopChargeFlag = YES;
  366. }
  367. }
  368. } else {
  369. if (_isOvpChkTimeFlag[index] == YES) {
  370. _isOvpChkTimeFlag[index] = NO;
  371. }
  372. }
  373. }
  374. }
  375. void ResetDetAlarmStatus(uint8_t gun)
  376. {
  377. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  378. if (pDcChargingInfo->Type == _Type_Chademo) {
  379. if (pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  380. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  381. }
  382. } else if (pDcChargingInfo->Type == _Type_GB) {
  383. if (pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP == YES) {
  384. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  385. }
  386. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  387. if (pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  388. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  389. }
  390. }
  391. }
  392. void CheckAcInputOvpStatus(uint8_t index)
  393. {
  394. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  395. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
  396. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
  397. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  398. // if ((pDcChargingInfo->SystemStatus >= S_PREPARNING && pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  399. // (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
  400. // {
  401. // if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC)
  402. // {
  403. // if (_psuInputVolR > VIN_MAX_VOLTAGE_IEC ||
  404. // _psuInputVolS > VIN_MAX_VOLTAGE_IEC ||
  405. // _psuInputVolT > VIN_MAX_VOLTAGE_IEC)
  406. // {
  407. // log_info("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f ",
  408. // _psuInputVolR, _psuInputVolS, _psuInputVolT);
  409. // pDcChargingInfo->StopChargeFlag = YES;
  410. // }
  411. //
  412. // }
  413. // else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL)
  414. // {
  415. // if (_psuInputVolR > VIN_MAX_VOLTAGE_UL ||
  416. // _psuInputVolS > VIN_MAX_VOLTAGE_UL ||
  417. // _psuInputVolT > VIN_MAX_VOLTAGE_UL)
  418. // {
  419. // log_info("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f ",
  420. // _psuInputVolR, _psuInputVolS, _psuInputVolT);
  421. // pDcChargingInfo->StopChargeFlag = YES;
  422. // }
  423. // }
  424. // }
  425. // else
  426. //log_info("CheckAcInputOvpStatus");
  427. pDcChargingInfo->StopChargeFlag = YES;
  428. }
  429. }
  430. //void CheckOutputVolNoneMatchFire(uint8_t index)
  431. //{
  432. // struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  433. //
  434. // if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
  435. // (pDcChargingInfo->Type == _Type_Chademo ||
  436. // pDcChargingInfo->Type == _Type_CCS_2 ||
  437. // pDcChargingInfo->Type == _Type_GB)) {
  438. // if (((pDcChargingInfo->PresentChargingVoltage * 10) < pDcChargingInfo->FireChargingVoltage - 300) ||
  439. // ((pDcChargingInfo->PresentChargingVoltage * 10) > pDcChargingInfo->FireChargingVoltage + 300)) {
  440. // if (!_isOutputNoneMatch[index]) {
  441. // _isOutputNoneMatch[index] = YES;
  442. // gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
  443. // } else {
  444. // if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
  445. // /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f ",
  446. // index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
  447. // log_error("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f ",
  448. // index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
  449. // pDcChargingInfo->StopChargeFlag = YES;*/
  450. // }
  451. // }
  452. // } else {
  453. // _isOutputNoneMatch[index] = NO;
  454. // }
  455. // }
  456. //}
  457. void CheckPhaseLossStatus(uint8_t index)
  458. {
  459. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  460. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES ||
  461. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES ||
  462. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  463. //log_info("CheckPhaseLossStatus");
  464. pDcChargingInfo->StopChargeFlag = YES;
  465. }
  466. }
  467. void SetK1K2RelayStatus(uint8_t index)
  468. {
  469. uint8_t targetID = 0;
  470. PreChargingState *pRegPreChargingState = NULL;
  471. PreChargingState *pOutputPreChargingState = NULL;
  472. GunPNState *pRegGunPNState = NULL;
  473. GunPNState *pOutputGunPNState = NULL;
  474. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  475. if (ShmPsuData->Work_Step >= _TEST_MODE &&
  476. ShmPsuData->Work_Step <= _TEST_MODE) {
  477. if (regRelay.relay_event.bits.Gun1_N == NO) {
  478. outputRelay.relay_event.bits.Gun1_N = YES;
  479. } else if (regRelay.relay_event.bits.Gun1_P == NO) {
  480. outputRelay.relay_event.bits.Gun1_P = YES;
  481. }
  482. return;
  483. }
  484. targetID = getCommTargetID(index);
  485. pRegPreChargingState = (PreChargingState *)&regRelay.relay_event.relay_status[0];
  486. pOutputPreChargingState = (PreChargingState *)&outputRelay.relay_event.relay_status[0];
  487. if (targetID == 0x01) {
  488. pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[1];
  489. pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[1];
  490. } else if (targetID == 0x02) {
  491. pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[2];
  492. pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[2];
  493. }
  494. switch (pDcChargingInfo->SystemStatus) {
  495. case S_BOOTING:
  496. case S_IDLE:
  497. case S_AUTHORIZING:
  498. case S_REASSIGN_CHECK:
  499. case S_REASSIGN:
  500. case S_PREPARNING:
  501. case S_PREPARING_FOR_EV:
  502. if (pRegGunPNState->GunP == YES) {
  503. pOutputGunPNState->GunP = NO;
  504. } else if (pRegGunPNState->GunN == YES) {
  505. pOutputGunPNState->GunN = NO;
  506. }
  507. if (targetID == 0x02 && pDcChargingInfo->Type == _Type_CCS_2) {
  508. if (pRegPreChargingState->CcsPrecharge == YES) {
  509. pOutputPreChargingState->CcsPrecharge = NO;
  510. }
  511. }
  512. break;
  513. case S_PREPARING_FOR_EVSE:
  514. case S_CHARGING:
  515. //if (pDcChargingInfo->RelayWeldingCheck != YES) {
  516. // break;
  517. //}
  518. if (pRegGunPNState->GunN == NO) {
  519. if (pDcChargingInfo->GroundFaultStatus != GFD_FAIL) {
  520. pOutputGunPNState->GunN = YES;
  521. } else {
  522. pOutputGunPNState->GunN = NO;
  523. }
  524. } else {
  525. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  526. pOutputGunPNState->GunN = NO;
  527. }
  528. }
  529. if (pRegGunPNState->GunP == NO) {
  530. if (pDcChargingInfo->GroundFaultStatus != GFD_FAIL) {
  531. pOutputGunPNState->GunP = YES;
  532. } else {
  533. pOutputGunPNState->GunP = NO;
  534. }
  535. } else {
  536. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  537. pOutputGunPNState->GunP = NO;
  538. }
  539. }
  540. break;
  541. case S_TERMINATING:
  542. case S_COMPLETE:
  543. case S_ALARM:
  544. if ((pDcChargingInfo->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
  545. pOutputGunPNState->GunP = NO;
  546. pOutputGunPNState->GunN = NO;
  547. }
  548. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  549. pOutputGunPNState->GunP = NO;
  550. pOutputGunPNState->GunN = NO;
  551. }
  552. break;
  553. case S_CCS_PRECHARGE_ST0:
  554. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  555. break;
  556. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  557. //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
  558. // if (pRegPreChargingState->CcsPrecharge == NO) {
  559. // pOutputPreChargingState->CcsPrecharge = YES;
  560. // } else if (pRegPreChargingState->CcsPrecharge == YES) {
  561. // pRegGunPNState->GunP = NO;
  562. // }
  563. //}
  564. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  565. pOutputGunPNState->GunP = NO;
  566. pOutputGunPNState->GunN = NO;
  567. }
  568. break;
  569. case S_CCS_PRECHARGE_ST1:
  570. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  571. break;
  572. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  573. //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
  574. // if (pRegGunPNState->GunP == NO) {
  575. // pOutputGunPNState->GunP = YES;
  576. // } else if (pRegGunPNState->GunP == YES) {
  577. // pOutputPreChargingState->CcsPrecharge = NO;
  578. // }
  579. //}
  580. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  581. pOutputGunPNState->GunP = NO;
  582. pOutputGunPNState->GunN = NO;
  583. }
  584. break;
  585. }
  586. }
  587. // 確認 K1 K2 relay 的狀態
  588. void CheckK1K2RelayOutput(uint8_t index)
  589. {
  590. uint8_t targetID = 0;
  591. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  592. targetID = getCommTargetID(index);
  593. switch (targetID) {
  594. case 0x01:
  595. if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES) {
  596. pDcChargingInfo->RelayK1K2Status = YES;
  597. } else {
  598. pDcChargingInfo->RelayK1K2Status = NO;
  599. }
  600. if (pDcChargingInfo->Type == _Type_CCS_2) {
  601. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  602. if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
  603. pDcChargingInfo->RelayKPK2Status = YES;
  604. } else {
  605. pDcChargingInfo->RelayKPK2Status = NO;
  606. }
  607. #else
  608. if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) {
  609. pDcChargingInfo->RelayKPK2Status = YES;
  610. } else {
  611. pDcChargingInfo->RelayKPK2Status = NO;
  612. }
  613. #endif //!defined DD360 && !defined DD360Audi
  614. }
  615. break;
  616. case 0x02:
  617. if (regRelay.relay_event.bits.Gun2_N == YES &&
  618. regRelay.relay_event.bits.Gun2_P == YES) {
  619. pDcChargingInfo->RelayK1K2Status = YES;
  620. } else {
  621. pDcChargingInfo->RelayK1K2Status = NO;
  622. }
  623. if (pDcChargingInfo->Type == _Type_CCS_2) {
  624. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  625. if (regRelay.relay_event.bits.Gun2_N == YES &&
  626. regRelay.relay_event.bits.CCS_Precharge == YES) {
  627. pDcChargingInfo->RelayKPK2Status = YES;
  628. } else {
  629. pDcChargingInfo->RelayKPK2Status = NO;
  630. }
  631. #else
  632. if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) {
  633. pDcChargingInfo->RelayKPK2Status = YES;
  634. } else {
  635. pDcChargingInfo->RelayKPK2Status = NO;
  636. }
  637. #endif //!defined DD360 && !defined DD360Audi
  638. }
  639. break;
  640. }
  641. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  642. //DS60-120 add
  643. if (pSysInfo->BridgeRelayStatus == YES) {
  644. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
  645. regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
  646. pSysInfo->BridgeRelayStatus = NO;
  647. }
  648. } else if (pSysInfo->BridgeRelayStatus == NO) {
  649. if (regRelay.relay_event.bits.Gun1_Parallel_N == YES &&
  650. regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  651. pSysInfo->BridgeRelayStatus = YES;
  652. }
  653. }
  654. #else
  655. pSysInfo->BridgeRelayStatus = YES;
  656. #endif //!defined DD360 && !defined DD360Audi
  657. }
  658. void SetGfdConfig(uint8_t index, uint8_t resister)
  659. {
  660. Gfd_config gfd_config = {
  661. .index = index,
  662. .state = resister,
  663. };
  664. //log_info("************************GFD Vol = %d, GFD Res = %d ", gfd_config.reqVol, gfd_config.resister);
  665. if (Config_Gfd_Value(Uart5Fd, ADDR_RELAY, &gfd_config) == PASS) {
  666. // log_info("Set reqVol = %f, resister = %d ",
  667. // gfd_config.reqVol,
  668. // gfd_config.resister);
  669. }
  670. }
  671. void CableCheckDetected(uint8_t index)
  672. {
  673. uint8_t targetID = 0;
  674. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  675. // Cable Check
  676. // 當火線上的電壓 = 車端要求的電壓電流
  677. // _chargingData[targetGun]->EvBatterytargetVoltage
  678. // 才可以開始偵測 1s
  679. // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
  680. // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
  681. // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
  682. if (pSysConfig->TotalConnectorCount == 1) {
  683. if (strncmp((char *)&pSysConfig->ModelName[7], "0", 1) != 0) {
  684. targetID = 0;
  685. } else if (strncmp((char *)&pSysConfig->ModelName[9], "0", 1) != 0) {
  686. targetID = 1;
  687. }
  688. } else {
  689. targetID = index;
  690. }
  691. if ((pDcChargingInfo->Type >= _Type_Chademo &&
  692. pDcChargingInfo->Type <= _Type_GB) ||
  693. (pDcChargingInfo->Type == 0x09 &&
  694. pSysConfig->AlwaysGfdFlag)
  695. ) {
  696. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  697. pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  698. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  699. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  700. ) {
  701. //if ((pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) &&
  702. // (pDcChargingInfo->RelayWeldingCheck == YES)
  703. // ) {
  704. if (pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) {
  705. SetGfdConfig(targetID, GFD_CABLECHK);
  706. } else if ((pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0) &&
  707. (pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  708. ) {
  709. SetGfdConfig(targetID, GFD_PRECHARGE);
  710. } else if ((pDcChargingInfo->SystemStatus >= S_CHARGING) &&
  711. (pDcChargingInfo->SystemStatus < S_TERMINATING)
  712. ) {
  713. if ((pDcChargingInfo->Type == _Type_GB) ||
  714. (pDcChargingInfo->Type == _Type_Chademo)
  715. ) {
  716. SetGfdConfig(targetID, GFD_IDLE);
  717. } else {
  718. SetGfdConfig(targetID, GFD_CHARGING);
  719. }
  720. }
  721. }
  722. else if(pDcChargingInfo->SystemStatus == S_TERMINATING || pDcChargingInfo->SystemStatus == S_ALARM)
  723. {
  724. if (pDcChargingInfo->Type == _Type_CCS_2)
  725. {
  726. SetGfdConfig(targetID, GFD_CHARGING);
  727. }
  728. } else {
  729. SetGfdConfig(targetID, GFD_IDLE);
  730. }
  731. }
  732. }
  733. // 讀取 Relay 狀態
  734. void GetRelayOutputStatus(void)
  735. {
  736. if (Query_Relay_Output(Uart5Fd, ADDR_RELAY, &regRelay) == PASS) {
  737. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  738. regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  739. #endif //!defined DD360 && !defined DD360Audi
  740. }
  741. }
  742. // AC 三相輸入電壓
  743. void GetPresentInputVol(void)
  744. {
  745. static uint8_t _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
  746. static uint8_t _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
  747. PresentInputVoltage inputVoltage = {0};
  748. if (Query_Present_InputVoltage(Uart5Fd, ADDR_RELAY, &inputVoltage) == PASS) {
  749. // resolution : 0.1
  750. pSysInfo->InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
  751. pSysInfo->InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
  752. pSysInfo->InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
  753. //********************************************************************************************************//
  754. // Vin (UVP)
  755. if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
  756. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
  757. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
  758. log_info("In Uvp L1N_L12 = %f ", inputVoltage.L1N_L12);
  759. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
  760. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
  761. } else {
  762. _threePhaseUvp[0] += 1;
  763. }
  764. }
  765. } else {
  766. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC) {
  767. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
  768. _threePhaseUvp[0] = 0;
  769. }
  770. }
  771. if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
  772. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
  773. log_info("In Uvp L2N_L23 = %f ", inputVoltage.L2N_L23);
  774. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
  775. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
  776. } else {
  777. _threePhaseUvp[1] += 1;
  778. }
  779. }
  780. } else {
  781. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC) {
  782. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
  783. _threePhaseUvp[1] = 0;
  784. }
  785. }
  786. if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
  787. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
  788. log_info("In Uvp L3N_L31 = %f ", inputVoltage.L3N_L31);
  789. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
  790. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
  791. } else {
  792. _threePhaseUvp[2] += 1;
  793. }
  794. }
  795. } else {
  796. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC) {
  797. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
  798. _threePhaseUvp[2] = 0;
  799. }
  800. }
  801. } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
  802. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
  803. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
  804. log_info("In Uvp L1N_L12 = %f ", inputVoltage.L1N_L12);
  805. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
  806. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
  807. } else {
  808. _threePhaseUvp[0] += 1;
  809. }
  810. }
  811. } else {
  812. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL) {
  813. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
  814. _threePhaseUvp[0] = 0;
  815. }
  816. }
  817. if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
  818. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
  819. log_info("In Uvp L2N_L23 = %f ", inputVoltage.L2N_L23);
  820. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
  821. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
  822. } else {
  823. _threePhaseUvp[1] += 1;
  824. }
  825. }
  826. } else {
  827. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL) {
  828. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
  829. _threePhaseUvp[1] = 0;
  830. }
  831. }
  832. if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
  833. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
  834. log_info("In Uvp L3N_L31 = %f ", inputVoltage.L3N_L31);
  835. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
  836. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
  837. } else {
  838. _threePhaseUvp[2] += 1;
  839. }
  840. }
  841. } else {
  842. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL) {
  843. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
  844. _threePhaseUvp[2] = 0;
  845. }
  846. }
  847. }
  848. //********************************************************************************************************//
  849. // Vin (OVP)
  850. if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
  851. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
  852. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
  853. log_info("In Ovp L1N_L12 = %f ", inputVoltage.L1N_L12);
  854. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
  855. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
  856. } else {
  857. _threePhaseOvp[0] += 1;
  858. }
  859. }
  860. } else {
  861. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC) {
  862. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
  863. _threePhaseOvp[0] = 0;
  864. }
  865. }
  866. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  867. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
  868. log_info("In Ovp L2N_L23 = %f ", inputVoltage.L2N_L23);
  869. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
  870. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
  871. } else {
  872. _threePhaseOvp[1] += 1;
  873. }
  874. }
  875. } else {
  876. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC) {
  877. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
  878. _threePhaseOvp[1] = 0;
  879. }
  880. }
  881. if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == NO) {
  882. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
  883. log_info("In Ovp L3N_L31 = %f ", inputVoltage.L3N_L31);
  884. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
  885. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
  886. } else {
  887. _threePhaseOvp[2] += 1;
  888. }
  889. }
  890. } else {
  891. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC) {
  892. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
  893. _threePhaseOvp[2] = 0;
  894. }
  895. }
  896. } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
  897. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
  898. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
  899. log_info("In Ovp L1N_L12 = %f ", inputVoltage.L1N_L12);
  900. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
  901. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
  902. } else {
  903. _threePhaseOvp[0] += 0;
  904. }
  905. }
  906. } else {
  907. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL) {
  908. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
  909. _threePhaseOvp[0] = 0;
  910. }
  911. }
  912. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  913. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
  914. log_info("In Ovp L2N_L23 = %f ", inputVoltage.L2N_L23);
  915. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
  916. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
  917. } else {
  918. _threePhaseOvp[1] += 0;
  919. }
  920. }
  921. } else {
  922. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL) {
  923. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
  924. _threePhaseOvp[1] = 0;
  925. }
  926. }
  927. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  928. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
  929. log_info("In Ovp L3N_L31 = %f ", inputVoltage.L3N_L31);
  930. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
  931. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
  932. } else {
  933. _threePhaseOvp[2] += 1;
  934. }
  935. }
  936. } else {
  937. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL) {
  938. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
  939. _threePhaseOvp[2] = 0;
  940. }
  941. }
  942. }
  943. }
  944. }
  945. // 左右槍的 Relay 前後的輸出電壓
  946. void GetPersentOutputVol(void)
  947. {
  948. uint8_t index = 0;
  949. uint8_t targetID = 0;
  950. struct ChargingInfoData *pDcChargingInfo = NULL;
  951. PresentOutputVoltage outputVoltage = {0};
  952. if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
  953. return;
  954. }
  955. //log_info("Conn1 fuse 1 = %f ", outputVoltage.behindFuse_Voltage_C1);
  956. //log_info("Conn1 relay 1 = %f ", outputVoltage.behindRelay_Voltage_C1);
  957. //log_info("Conn2 fuse 2 = %f ", outputVoltage.behindFuse_Voltage_C2);
  958. //log_info("Conn2 relay 2 = %f ", outputVoltage.behindRelay_Voltage_C2);
  959. //log_info("outputVoltage.behindFuse_Voltage_C1 = %f ", outputVoltage.behindFuse_Voltage_C1);
  960. //log_info("outputVoltage.behindFuse_Voltage_C2 = %f ", outputVoltage.behindFuse_Voltage_C2);
  961. ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  962. ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  963. ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  964. ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  965. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  966. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  967. targetID = getCommTargetID(index);
  968. switch (targetID) {
  969. case 0x01:
  970. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  971. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  972. pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun1FuseOutputVolt) / 10;
  973. pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
  974. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  975. break;
  976. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  977. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  978. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
  979. break;
  980. case 0x02:
  981. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  982. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  983. pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun2FuseOutputVolt) / 10;
  984. pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
  985. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  986. break;
  987. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  988. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  989. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
  990. break;
  991. }
  992. //log_info("%d persent vol = %f, cur = %f",
  993. // index,
  994. // pDcChargingInfo->PresentChargingVoltage,
  995. // pDcChargingInfo->PresentChargingCurrent);
  996. //unsigned short Ovp = 0;
  997. //unsigned short Ocp = 0;
  998. //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] // 最大輸出電壓與電池電壓最大值
  999. //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ] // 最大輸出電流與需求電流最小值
  1000. //if (pDcChargingInfo->Type == _Type_Chademo) {
  1001. // //Ovp = MaxValue(pDcChargingInfo->MaximumChargingVoltage, pDcChargingInfo->EvBatteryMaxVoltage);
  1002. // //Ocp = MaxValue(pDcChargingInfo->PresentChargingCurrent, ShmCHAdeMOData->ev[pDcChargingInfo->type_index].ChargingCurrentRequest);
  1003. //} else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1004. //}
  1005. }
  1006. }
  1007. void SetRtcData_Relay(void)
  1008. {
  1009. struct timeb csuTime;
  1010. struct tm *tmCSU;
  1011. Rtc rtc = {0};
  1012. ftime(&csuTime);
  1013. tmCSU = localtime(&csuTime.time);
  1014. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
  1015. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  1016. // tmCSU->tm_sec);
  1017. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  1018. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  1019. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  1020. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  1021. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  1022. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  1023. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  1024. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  1025. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  1026. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  1027. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  1028. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  1029. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  1030. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  1031. if (Config_Rtc_Data(Uart5Fd, ADDR_RELAY, &rtc) == PASS) {
  1032. //log_info("SetRtc (RB) sucessfully. ");
  1033. }
  1034. }
  1035. void SetModelName_Relay(void)
  1036. {
  1037. if (Config_Model_Name(Uart5Fd, ADDR_RELAY, pSysConfig->ModelName) == PASS) {
  1038. //log_info("Set Model name (RB) PASS = %s ", pSysConfig->ModelName);
  1039. }
  1040. }
  1041. void GetFwAndHwVersion_Relay(void)
  1042. {
  1043. Ver ver = {0};
  1044. if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  1045. // RelayModuleData
  1046. strcpy((char *)ShmRelayModuleData->version, ver.Version_FW);
  1047. // SystemInfo
  1048. strcpy((char *)pSysInfo->RelayModuleFwRev, ver.Version_FW);
  1049. //log_info("GetFwAndHwVersion_Relay s1 = %s ", ver.Version_FW);
  1050. }
  1051. if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  1052. // SystemInfo
  1053. strcpy((char *)pSysInfo->RelayModuleHwRev, ver.Version_FW);
  1054. //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
  1055. }
  1056. }
  1057. static void outputRelayInit(int fd)
  1058. {
  1059. memset((uint8_t *)&outputRelay, 0, sizeof(Relay));
  1060. if (Config_Relay_Output(fd, ADDR_RELAY, &outputRelay) != PASS) {
  1061. log_info("Config_Relay_Output fail ");
  1062. }
  1063. }
  1064. static bool IsRelayProcessNeedPause(void)
  1065. {
  1066. bool _pause = false;
  1067. static bool isPause = false;
  1068. struct ChargingInfoData *pDcChargingInfo = NULL;
  1069. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1070. {
  1071. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1072. if(pDcChargingInfo->SystemStatus == S_UPDATE)
  1073. {
  1074. SetLedColor();
  1075. _pause = true;
  1076. }
  1077. }
  1078. if(isPause != _pause)
  1079. {
  1080. log_info("Relay Process Now Is %s ", _pause == true ? "Paused" : "Continued");
  1081. }
  1082. isPause = _pause;
  1083. return _pause;
  1084. }
  1085. static void SetFanModuleSpeed(void)
  1086. {
  1087. {
  1088. FanSpeed _fanSpeed = {0};
  1089. _setFanSpeed += fanSpeedSmoothValue;
  1090. if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed) {
  1091. _setFanSpeed = ShmFanModuleData->SetFan1Speed;
  1092. }
  1093. _fanSpeed.speed[0] = _setFanSpeed;
  1094. _fanSpeed.speed[1] = _setFanSpeed;
  1095. _fanSpeed.speed[2] = _setFanSpeed;
  1096. _fanSpeed.speed[3] = _setFanSpeed;
  1097. if (Config_Fan_Speed(Uart5Fd, ADDR_FAN, &_fanSpeed) == PASS) {
  1098. //log_info("successfully Fan");
  1099. }
  1100. }
  1101. }
  1102. // 風扇速度
  1103. static void GetFanSpeed(void)
  1104. {
  1105. FanSpeed fanSpeed = {0};
  1106. //log_info("Get fan board speed ");
  1107. if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
  1108. ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
  1109. ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
  1110. ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
  1111. ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
  1112. // log_info("SystemFanRotaSpeed_1 = %d ", fanSpeed.speed[0]);
  1113. // log_info("SystemFanRotaSpeed_2 = %d ", fanSpeed.speed[1]);
  1114. // log_info("SystemFanRotaSpeed_3 = %d ", fanSpeed.speed[2]);
  1115. // log_info("SystemFanRotaSpeed_4 = %d ", fanSpeed.speed[3]);
  1116. // Config_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed[0]);
  1117. //SysInfoData (SystemFanRotaSpeed)
  1118. }
  1119. }
  1120. static void GetFanSpeedByFunction(void)
  1121. {
  1122. if (ShmDcCommonData->debugflag== YES) {
  1123. ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
  1124. return;
  1125. }
  1126. int gunIndex;
  1127. struct ChargingInfoData* pDcChargingInfo = NULL;
  1128. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  1129. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  1130. if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1131. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1132. ShmDcCommonData->FanOnTime = time((time_t*)NULL);
  1133. if (ShmFanModuleData->SetFan1Speed == 0) {
  1134. ShmFanModuleData->SetFan1Speed = 7000;
  1135. log_info("Set Fan speed 7000");
  1136. }
  1137. }
  1138. }
  1139. if ((time((time_t*)NULL) - ShmDcCommonData->FanOnTime) >= 600 &&
  1140. ShmFanModuleData->SetFan1Speed == 7000) {
  1141. ShmFanModuleData->SetFan1Speed = 0;
  1142. log_info("Close fan");
  1143. }
  1144. /*
  1145. // 風控修改 :
  1146. // ******************************************************* //
  1147. //
  1148. // 當前PSU輸出總 KW PSU Temp
  1149. // 30 x -------------------- x ---------- + 14 x (PSU Temp - 45)
  1150. // 當前樁最大功率 KW 45
  1151. //
  1152. // ******************************************************* //
  1153. // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
  1154. uint32_t _maxPower = ShmPsuData->SystemAvailablePower;
  1155. // 當前PSU輸出總 KW & PSU Temp :
  1156. uint8_t temp = 0;
  1157. uint8_t index = 0;
  1158. uint8_t count = 0;
  1159. uint8_t gunIndex = 0;
  1160. uint8_t _temp_diff = 0;
  1161. float power = 0;
  1162. double _pw_rate = 0;
  1163. double _temp_rate = 0;
  1164. struct ChargingInfoData *pDcChargingInfo = NULL;
  1165. for (index = 0; index < ShmPsuData->GroupCount; index++) {
  1166. for (count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
  1167. if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
  1168. temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  1169. }
  1170. }
  1171. }
  1172. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  1173. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1174. power += (pDcChargingInfo->PresentChargingPower * 10);
  1175. }
  1176. if (_maxPower > 0) {
  1177. _pw_rate = power / (double)_maxPower;
  1178. }
  1179. if (temp > 0) {
  1180. _temp_rate = (double)temp / 50;
  1181. }
  1182. if (temp > 45) {
  1183. _temp_diff = temp - 70;
  1184. }
  1185. ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _temp_diff)) / 100) * MAX_FAN_SPEED;
  1186. if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED) {
  1187. ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
  1188. }
  1189. if (ShmFanModuleData->TestFanSpeed < 0) {
  1190. ShmFanModuleData->TestFanSpeed = 0;
  1191. }
  1192. */
  1193. //
  1194. // printf("power = %f \n", power);
  1195. // printf("_maxPower = %d \n", _maxPower);
  1196. // printf("temp = %d \n", temp);
  1197. //
  1198. // printf("_pw_rate = %f \n", _pw_rate);
  1199. // printf("_temp_rate = %f \n", _temp_rate);
  1200. // printf("_temp_diff = %d \n", _temp_diff);
  1201. // printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
  1202. // printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
  1203. }
  1204. static void SetRtcData_Fan(void)
  1205. {
  1206. struct timeb csuTime;
  1207. struct tm *tmCSU;
  1208. Rtc rtc = {0};
  1209. ftime(&csuTime);
  1210. tmCSU = localtime(&csuTime.time);
  1211. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
  1212. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  1213. // tmCSU->tm_sec);
  1214. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  1215. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  1216. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  1217. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  1218. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  1219. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  1220. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  1221. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  1222. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  1223. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  1224. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  1225. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  1226. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  1227. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  1228. if (Config_Rtc_Data(Uart5Fd, ADDR_FAN, &rtc) == PASS) {
  1229. //log_info("SetRtc (FB) sucessfully. ");
  1230. }
  1231. }
  1232. static void SetModelName_Fan(void)
  1233. {
  1234. if (Config_Model_Name(Uart5Fd, ADDR_FAN, pSysConfig->ModelName) == PASS) {
  1235. log_info("Set Model name PASS = %s ", pSysConfig->ModelName);
  1236. }
  1237. }
  1238. static void GetFwAndHwVersion_Fan(void)
  1239. {
  1240. Ver ver = {0};
  1241. if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
  1242. // FanModuleData
  1243. strcpy((char *)ShmFanModuleData->version, ver.Version_FW);
  1244. // SystemInfo
  1245. strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
  1246. //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
  1247. }
  1248. if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
  1249. // SystemInfo
  1250. strcpy((char *)pSysInfo->FanModuleHwRev, ver.Version_FW);
  1251. //log_info("GetFwAndHwVersion_Fan s2 = %s ", ver.Version_HW);
  1252. }
  1253. }
  1254. static void fanBoardSelfTest(void)
  1255. {
  1256. if (ShmFanModuleData->SelfTest_Comp == YES) {
  1257. return;
  1258. }
  1259. GetFwAndHwVersion_Fan();
  1260. SetModelName_Fan();
  1261. SetRtcData_Fan();
  1262. sleep(1);
  1263. gettimeofday(&gFanBoardRunTimer, NULL);
  1264. }
  1265. static void fanBoardPorcess(void)
  1266. {
  1267. if (ShmFanModuleData->SelfTest_Comp == NO) {
  1268. return;
  1269. }
  1270. if (ShmFanModuleData->SelfTest_Comp == YES ||
  1271. strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
  1272. pSysInfo->FanModuleFwRev[0] != '\0') {
  1273. ShmFanModuleData->SelfTest_Comp = YES;
  1274. if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
  1275. //GetPsuTempForFanSpeed();
  1276. GetFanSpeedByFunction();
  1277. GetFanSpeed();
  1278. pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
  1279. gettimeofday(&gFanBoardRunTimer, NULL);
  1280. /*
  1281. ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
  1282. ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
  1283. ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
  1284. ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
  1285. */
  1286. //log_info("set fan = %d ", ShmFanModuleData->SetFan1Speed);
  1287. SetFanModuleSpeed();
  1288. }
  1289. }
  1290. }
  1291. static void GetFwAndHwVersion_Led(void)
  1292. {
  1293. Ver ver = {0};
  1294. if (Query_FW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS) {
  1295. // LedModuleData
  1296. strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
  1297. // SystemInfo
  1298. strcpy((char *) pSysInfo->LedModuleFwRev, ver.Version_FW);
  1299. log_info("GetFwAndHwVersion_Led s1 = %s ", ver.Version_FW);
  1300. ShmLedModuleData->SelfTest_Comp = YES;
  1301. } else {
  1302. //log_info("GetFwAndHwVersion_Led fail ");
  1303. }
  1304. // if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
  1305. // {
  1306. // // SystemInfo
  1307. // strcpy((char *) pSysInfo->RelayModuleHwRev, ver.Version_FW);
  1308. // //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
  1309. // }
  1310. }
  1311. static bool IsNoneMatchLedColor(void)
  1312. {
  1313. bool result = false;
  1314. if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
  1315. cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
  1316. cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
  1317. cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
  1318. cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
  1319. cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue) {
  1320. result = true;
  1321. }
  1322. return result;
  1323. }
  1324. //static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
  1325. static void SetLedColor(void)
  1326. {
  1327. static uint8_t _checkLedChanged = 3;
  1328. struct ChargingInfoData *chargingData_1 = NULL;
  1329. struct ChargingInfoData *chargingData_2 = NULL;
  1330. uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
  1331. if (pSysConfig->TotalConnectorCount == 1) {
  1332. chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1333. chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1334. } else if (pSysConfig->TotalConnectorCount == 2) {
  1335. chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1336. chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
  1337. }
  1338. if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
  1339. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
  1340. } else if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
  1341. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
  1342. }
  1343. //printf("chargingData_1->SystemStatus=%d\n",chargingData_1->SystemStatus);
  1344. //printf("chargingData_2->SystemStatus=%d\n",chargingData_2->SystemStatus);
  1345. //printf("pSysWarning->Level=%d\n",pSysWarning->Level);
  1346. if (pSysWarning->Level == 2) {
  1347. led_color.Connect_1_Green = COLOR_MIN_LV;
  1348. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1349. led_color.Connect_1_Red = _colorBuf;
  1350. led_color.Connect_2_Green = COLOR_MIN_LV;
  1351. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1352. led_color.Connect_2_Red = _colorBuf;
  1353. } else {
  1354. if (pSysInfo->IsAlternatvieConf) {
  1355. if ((chargingData_1->SystemStatus == S_BOOTING ||
  1356. chargingData_1->SystemStatus == S_IDLE ) &&
  1357. (chargingData_2->SystemStatus == S_BOOTING ||
  1358. chargingData_2->SystemStatus == S_IDLE)) {
  1359. #if defined DD360Audi
  1360. led_color.Connect_1_Green = _colorBuf;
  1361. led_color.Connect_1_Blue = _colorBuf;
  1362. led_color.Connect_1_Red = _colorBuf;
  1363. led_color.Connect_2_Green = _colorBuf;
  1364. led_color.Connect_2_Blue = _colorBuf;
  1365. led_color.Connect_2_Red = _colorBuf;
  1366. #else
  1367. led_color.Connect_1_Green = _colorBuf;
  1368. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1369. led_color.Connect_1_Red = COLOR_MIN_LV;
  1370. led_color.Connect_2_Green = _colorBuf;
  1371. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1372. led_color.Connect_2_Red = COLOR_MIN_LV;
  1373. #endif
  1374. } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
  1375. chargingData_1->SystemStatus <= S_COMPLETE) ||
  1376. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1377. chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1378. (chargingData_2->SystemStatus >= S_AUTHORIZING &&
  1379. chargingData_2->SystemStatus <= S_COMPLETE) ||
  1380. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1381. chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1382. led_color.Connect_1_Green = COLOR_MIN_LV;
  1383. led_color.Connect_1_Blue = _colorBuf;
  1384. led_color.Connect_1_Red = COLOR_MIN_LV;
  1385. led_color.Connect_2_Green = COLOR_MIN_LV;
  1386. led_color.Connect_2_Blue = _colorBuf;
  1387. led_color.Connect_2_Red = COLOR_MIN_LV;
  1388. } else if ( chargingData_1->SystemStatus == S_UPDATE ) {
  1389. led_color.Connect_1_Green = COLOR_MIN_LV;
  1390. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1391. led_color.Connect_1_Red = _colorBuf;
  1392. } else if (chargingData_1->SystemStatus == S_RESERVATION ||
  1393. chargingData_2->SystemStatus == S_RESERVATION) {
  1394. if (ReservationLed) {
  1395. led_color.Connect_1_Green = COLOR_MIN_LV;
  1396. led_color.Connect_2_Green = COLOR_MIN_LV;
  1397. } else {
  1398. led_color.Connect_1_Green = _colorBuf;
  1399. led_color.Connect_2_Green = _colorBuf;
  1400. }
  1401. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1402. led_color.Connect_1_Red = COLOR_MIN_LV;
  1403. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1404. led_color.Connect_2_Red = COLOR_MIN_LV;
  1405. }
  1406. } else {
  1407. //實際操作
  1408. if (chargingData_1->SystemStatus == S_BOOTING ||
  1409. chargingData_1->SystemStatus == S_IDLE ||
  1410. chargingData_1->SystemStatus == S_MAINTAIN) {
  1411. if (chargingData_1->IsAvailable == NO) { //For Audi
  1412. led_color.Connect_1_Green = COLOR_MIN_LV;
  1413. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1414. led_color.Connect_1_Red = _colorBuf;
  1415. } else {
  1416. #if defined DD360Audi
  1417. led_color.Connect_1_Green = _colorBuf;
  1418. led_color.Connect_1_Blue = _colorBuf;
  1419. led_color.Connect_1_Red = _colorBuf;
  1420. #else
  1421. led_color.Connect_1_Green = _colorBuf;
  1422. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1423. led_color.Connect_1_Red = COLOR_MIN_LV;
  1424. #endif
  1425. }
  1426. } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
  1427. chargingData_1->SystemStatus <= S_COMPLETE) ||
  1428. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1429. chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1430. led_color.Connect_1_Green = COLOR_MIN_LV;
  1431. led_color.Connect_1_Blue = _colorBuf;
  1432. led_color.Connect_1_Red = COLOR_MIN_LV;
  1433. }else if ( chargingData_1->SystemStatus == S_UPDATE ) {
  1434. led_color.Connect_1_Green = COLOR_MIN_LV;
  1435. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1436. led_color.Connect_1_Red = _colorBuf;
  1437. } else if (chargingData_1->SystemStatus == S_RESERVATION) {
  1438. if (ReservationLed) {
  1439. led_color.Connect_1_Green = COLOR_MIN_LV;
  1440. } else {
  1441. led_color.Connect_1_Green = _colorBuf;
  1442. }
  1443. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1444. led_color.Connect_1_Red = COLOR_MIN_LV;
  1445. }
  1446. // --------------------------------------------------------------------------
  1447. if (chargingData_2->SystemStatus == S_BOOTING ||
  1448. chargingData_2->SystemStatus == S_IDLE ||
  1449. chargingData_2->SystemStatus == S_MAINTAIN) {
  1450. if (chargingData_2->IsAvailable == NO) {
  1451. led_color.Connect_2_Green = COLOR_MIN_LV;
  1452. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1453. led_color.Connect_2_Red = _colorBuf;
  1454. } else {
  1455. #if defined DD360Audi
  1456. led_color.Connect_2_Green = _colorBuf;
  1457. led_color.Connect_2_Blue = _colorBuf;
  1458. led_color.Connect_2_Red = _colorBuf;
  1459. #else
  1460. led_color.Connect_2_Green = _colorBuf;
  1461. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1462. led_color.Connect_2_Red = COLOR_MIN_LV;
  1463. #endif
  1464. }
  1465. } else if ((chargingData_2->SystemStatus >= S_AUTHORIZING &&
  1466. chargingData_2->SystemStatus <= S_COMPLETE) ||
  1467. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1468. chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1469. led_color.Connect_2_Green = COLOR_MIN_LV;
  1470. led_color.Connect_2_Blue = _colorBuf;
  1471. led_color.Connect_2_Red = COLOR_MIN_LV;
  1472. }else if ( chargingData_2->SystemStatus == S_UPDATE ) {
  1473. led_color.Connect_2_Green = COLOR_MIN_LV;
  1474. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1475. led_color.Connect_2_Red = _colorBuf;
  1476. } else if (chargingData_2->SystemStatus == S_RESERVATION) {
  1477. if (ReservationLed) {
  1478. led_color.Connect_2_Green = COLOR_MIN_LV;
  1479. } else {
  1480. led_color.Connect_2_Green = _colorBuf;
  1481. }
  1482. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1483. led_color.Connect_2_Red = COLOR_MIN_LV;
  1484. }
  1485. }
  1486. }
  1487. if (_checkLedChanged > 0) {
  1488. if (Config_Led_Color(Uart5Fd, ADDR_LED, &led_color) == PASS) {
  1489. _checkLedChanged--;
  1490. cur_led_color.Connect_1_Red = led_color.Connect_1_Red;
  1491. cur_led_color.Connect_1_Green = led_color.Connect_1_Green;
  1492. cur_led_color.Connect_1_Blue = led_color.Connect_1_Blue;
  1493. cur_led_color.Connect_2_Red = led_color.Connect_2_Red;
  1494. cur_led_color.Connect_2_Green = led_color.Connect_2_Green;
  1495. cur_led_color.Connect_2_Blue = led_color.Connect_2_Blue;
  1496. }
  1497. } else if (IsNoneMatchLedColor()) {
  1498. _checkLedChanged = 3;
  1499. }
  1500. }
  1501. static void LEDBoardSelfTest(void)
  1502. {
  1503. // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
  1504. if (ShmLedModuleData->SelfTest_Comp == YES) {
  1505. return;
  1506. }
  1507. #if defined DD360 ||defined DD360Audi
  1508. GetFwAndHwVersion_Led();
  1509. sleep(1);
  1510. gettimeofday(&_led_priority_time, NULL);
  1511. return;
  1512. #endif //defined DD360 || defined DD360Audi
  1513. // 自檢階段
  1514. if (pSysInfo->SelfTestSeq <= _STEST_PSU_CAP) {
  1515. GetFwAndHwVersion_Led();
  1516. sleep(1);
  1517. gettimeofday(&_led_priority_time, NULL);
  1518. } else {
  1519. // 自檢階段沒有問到版號
  1520. if (pAlarmCode->AlarmEvents.bits.LedboardStestFail == NO) {
  1521. pAlarmCode->AlarmEvents.bits.LedboardStestFail = YES;
  1522. }
  1523. }
  1524. }
  1525. static void LEDBoardProcess(void)
  1526. {
  1527. //struct ChargingInfoData *pDcChargingInfo0 = NULL;
  1528. //struct ChargingInfoData *pDcChargingInfo1 = NULL;
  1529. if (ShmLedModuleData->SelfTest_Comp == NO) {
  1530. return;
  1531. }
  1532. if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
  1533. if (time((time_t*)NULL) - ReservationFlashTimer >= 3) {
  1534. ReservationFlashTimer = time((time_t*)NULL);
  1535. if (ReservationLed)
  1536. ReservationLed = 0;
  1537. else
  1538. ReservationLed = 1;
  1539. }
  1540. SetLedColor();
  1541. gettimeofday(&_led_priority_time, NULL);
  1542. }
  1543. }
  1544. void RelayBoardTask(int uartFD)
  1545. {
  1546. bool isRelayBypass = false;
  1547. pid_t pid = fork();
  1548. if (pid == 0) {
  1549. bool isCharging = false;
  1550. bool isStopChargingCount = false;
  1551. uint8_t i = 0;
  1552. int isContinue = 1;
  1553. struct ChargingInfoData *pDcChargingInfo = NULL;
  1554. //share memory mapping
  1555. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1556. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1557. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1558. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  1559. ShmPsuData = (struct PsuData *)GetShmPsuData();
  1560. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1561. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1562. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1563. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  1564. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  1565. Uart5Fd = uartFD;
  1566. for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1567. {
  1568. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1569. if(pDcChargingInfo->PantographFlag == YES)
  1570. {
  1571. isRelayBypass = true;
  1572. }
  1573. }
  1574. //relay init
  1575. if(isRelayBypass == false)
  1576. {
  1577. outputRelayInit(uartFD);
  1578. }
  1579. while (isContinue) {
  1580. if(IsRelayProcessNeedPause() == true)
  1581. {
  1582. sleep(1);
  1583. continue;
  1584. }
  1585. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  1586. if (ShmRelayModuleData->SelfTest_Comp == NO && isRelayBypass == false) {
  1587. GetFwAndHwVersion_Relay();
  1588. SetModelName_Relay(); //DS60-120 add
  1589. SetRtcData_Relay();
  1590. sleep(1);
  1591. }
  1592. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  1593. fanBoardSelfTest();
  1594. #endif //NO_FAN_BOARD
  1595. #if !defined DD360ComBox
  1596. LEDBoardSelfTest();
  1597. #endif //defined DD360ComBox
  1598. if (ShmRelayModuleData->SelfTest_Comp == YES && isRelayBypass == false)
  1599. {
  1600. // ==============優先權最高 10 ms ==============
  1601. // 輸出電壓
  1602. GetPersentOutputVol();
  1603. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1604. // 三相輸入電壓
  1605. GetPresentInputVol();
  1606. #endif //!defined DD360 && !defined DD360Audi
  1607. // 讀取當前 AC relay 狀態
  1608. regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1609. GetRelayOutputStatus();
  1610. // Cable check (Get)
  1611. GetGfdAdc();
  1612. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1613. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1614. // Cable check (Set)
  1615. CableCheckDetected(i);
  1616. // check k1 k2 relay 狀態
  1617. CheckK1K2RelayOutput(i);
  1618. // 依據當前各槍的狀態選擇 搭上/放開 Relay
  1619. SetK1K2RelayStatus(i);
  1620. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1621. if (pSysConfig->PhaseLossPolicy == YES) {
  1622. CheckPhaseLossStatus(i);
  1623. }
  1624. CheckAcInputOvpStatus(i);
  1625. #endif //!defined DD360 && !defined DD360Audi
  1626. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  1627. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  1628. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  1629. //pDcChargingInfo->RelayWeldingCheck = NO;
  1630. //_isRelayWelding[i] = NO;
  1631. _isOvpChkTimeFlag[i] = NO;
  1632. //ResetDetAlarmStatus(i); //DS60-120 add
  1633. }
  1634. if (pDcChargingInfo->SystemStatus == S_BOOTING ||
  1635. (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  1636. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  1637. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1638. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1639. pSysInfo->WaitForPlugit == YES ||
  1640. (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
  1641. pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)
  1642. ) {
  1643. pDcChargingInfo->IsReadyToCharging = YES;
  1644. isCharging = true;
  1645. // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
  1646. //if (pDcChargingInfo->Type == _Type_GB) {
  1647. // if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  1648. // pDcChargingInfo->RelayWeldingCheck == NO) {
  1649. // CheckRelayWeldingStatus(i);
  1650. // }
  1651. //} else {
  1652. //pDcChargingInfo->RelayWeldingCheck = YES;
  1653. //}
  1654. if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  1655. CheckOutputPowerOverCarReq(i);
  1656. //CheckOutputVolNoneMatchFire(i);
  1657. }
  1658. /*else {
  1659. _isOutputNoneMatch[i] = NO;
  1660. }*/
  1661. } else {
  1662. pDcChargingInfo->IsReadyToCharging = NO;
  1663. }
  1664. }
  1665. // 橋接 relay
  1666. SetParalleRelayStatus();
  1667. // 搭上 AC Contactor
  1668. //if (isCharging) {
  1669. // outputRelay.relay_event.bits.AC_Contactor = YES;
  1670. //} else {
  1671. // outputRelay.relay_event.bits.AC_Contactor = NO;
  1672. //}
  1673. if (isCharging ||
  1674. (ShmPsuData->Work_Step >= _TEST_MODE &&
  1675. ShmPsuData->Work_Step <= _TEST_MODE)) {
  1676. isStopChargingCount = false;
  1677. outputRelay.relay_event.bits.AC_Contactor = YES;
  1678. } else {
  1679. if (!isStopChargingCount) {
  1680. gettimeofday(&_close_ac_contactor, NULL);
  1681. isStopChargingCount = true;
  1682. } else {
  1683. if ((outputRelay.relay_event.bits.AC_Contactor == YES &&
  1684. GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
  1685. outputRelay.relay_event.bits.AC_Contactor = NO;
  1686. }
  1687. }
  1688. }
  1689. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  1690. outputRelay.relay_event.bits.AC_Contactor = NO;
  1691. }
  1692. if (pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == ABNORMAL) {
  1693. RunForceStopProcess();
  1694. outputRelay.relay_event.bits.AC_Contactor = NO;
  1695. }
  1696. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  1697. outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
  1698. }
  1699. // 搭上/鬆開 Relay
  1700. if (IsNoneMatchRelayStatus()) {
  1701. if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
  1702. //regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1703. //regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  1704. //regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  1705. //regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  1706. //regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  1707. //regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  1708. //regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  1709. //regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  1710. //MatchRelayStatus();
  1711. //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 ",
  1712. // regRelay.relay_event.bits.AC_Contactor,
  1713. // regRelay.relay_event.bits.Gun1_P,
  1714. // regRelay.relay_event.bits.Gun1_N,
  1715. // regRelay.relay_event.bits.Gun2_P,
  1716. // regRelay.relay_event.bits.Gun2_N,
  1717. // regRelay.relay_event.bits.CCS_Precharge,
  1718. // regRelay.relay_event.bits.Gun1_Parallel_P,
  1719. // regRelay.relay_event.bits.Gun1_Parallel_N);
  1720. }
  1721. }
  1722. }
  1723. else if(isRelayBypass == true)
  1724. {
  1725. for(i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1726. {
  1727. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1728. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  1729. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  1730. pDcChargingInfo->SystemStatus == S_MAINTAIN)
  1731. {
  1732. _isOvpChkTimeFlag[i] = NO;
  1733. }
  1734. if (pDcChargingInfo->SystemStatus == S_CHARGING)
  1735. {
  1736. CheckOutputPowerOverCarReq(i);
  1737. }
  1738. }
  1739. }
  1740. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  1741. fanBoardPorcess();
  1742. #endif //NO_FAN_BOARD
  1743. #if !defined DD360ComBox
  1744. LEDBoardProcess();
  1745. #endif //defined DD360ComBox
  1746. usleep(10000);
  1747. }
  1748. }
  1749. }