RelayBoard.c 78 KB

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