RelayBoard.c 79 KB

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