RelayBoard.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include "../ShareMemory/shmMem.h"
  10. #include "../Config.h"
  11. #include "../Log/log.h"
  12. #include "Module_InternalComm.h"
  13. #include "internalComm.h"
  14. //------------------------------------------------------------------------------
  15. static struct SysConfigData *pSysConfig = NULL;
  16. static struct SysInfoData *pSysInfo = NULL;
  17. static struct AlarmCodeData *pAlarmCode = NULL;
  18. static struct RelayModuleData *ShmRelayModuleData = NULL;
  19. static struct PsuData *ShmPsuData = NULL;
  20. static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
  21. static DcCommonInfo *ShmDcCommonData = NULL;
  22. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  23. static struct LedModuleData *ShmLedModuleData = NULL;
  24. static struct FanModuleData *ShmFanModuleData = NULL;
  25. static 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. ShmDcCommonData->RelayDisconnectTime = time((time_t*)NULL);
  729. pAlarmCode->AlarmEvents.bits.RelayBoardCommFail = FALSE;
  730. } else {
  731. if ((time((time_t*)NULL) - ShmDcCommonData->RelayDisconnectTime) > 5) {
  732. ShmDcCommonData->RelayDisconnectTime = time((time_t*)NULL);
  733. pAlarmCode->AlarmEvents.bits.RelayBoardCommFail = TRUE;
  734. log_info("Relay communcation Fail");
  735. }
  736. }
  737. }
  738. // AC 三相輸入電壓
  739. void GetPresentInputVol(void)
  740. {
  741. static uint8_t _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
  742. static uint8_t _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
  743. PresentInputVoltage inputVoltage = {0};
  744. if (Query_Present_InputVoltage(Uart5Fd, ADDR_RELAY, &inputVoltage) == PASS) {
  745. // resolution : 0.1
  746. pSysInfo->InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
  747. pSysInfo->InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
  748. pSysInfo->InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
  749. //********************************************************************************************************//
  750. // Vin (UVP)
  751. if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
  752. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
  753. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
  754. log_info("In Uvp L1N_L12 = %f ", inputVoltage.L1N_L12);
  755. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
  756. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
  757. } else {
  758. _threePhaseUvp[0] += 1;
  759. }
  760. }
  761. } else {
  762. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC) {
  763. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
  764. _threePhaseUvp[0] = 0;
  765. }
  766. }
  767. if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
  768. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
  769. log_info("In Uvp L2N_L23 = %f ", inputVoltage.L2N_L23);
  770. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
  771. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
  772. } else {
  773. _threePhaseUvp[1] += 1;
  774. }
  775. }
  776. } else {
  777. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC) {
  778. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
  779. _threePhaseUvp[1] = 0;
  780. }
  781. }
  782. if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
  783. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
  784. log_info("In Uvp L3N_L31 = %f ", inputVoltage.L3N_L31);
  785. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
  786. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
  787. } else {
  788. _threePhaseUvp[2] += 1;
  789. }
  790. }
  791. } else {
  792. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC) {
  793. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
  794. _threePhaseUvp[2] = 0;
  795. }
  796. }
  797. } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
  798. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
  799. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
  800. log_info("In Uvp L1N_L12 = %f ", inputVoltage.L1N_L12);
  801. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
  802. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
  803. } else {
  804. _threePhaseUvp[0] += 1;
  805. }
  806. }
  807. } else {
  808. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL) {
  809. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
  810. _threePhaseUvp[0] = 0;
  811. }
  812. }
  813. if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
  814. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
  815. log_info("In Uvp L2N_L23 = %f ", inputVoltage.L2N_L23);
  816. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
  817. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
  818. } else {
  819. _threePhaseUvp[1] += 1;
  820. }
  821. }
  822. } else {
  823. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL) {
  824. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
  825. _threePhaseUvp[1] = 0;
  826. }
  827. }
  828. if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
  829. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
  830. log_info("In Uvp L3N_L31 = %f ", inputVoltage.L3N_L31);
  831. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
  832. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
  833. } else {
  834. _threePhaseUvp[2] += 1;
  835. }
  836. }
  837. } else {
  838. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL) {
  839. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
  840. _threePhaseUvp[2] = 0;
  841. }
  842. }
  843. }
  844. //********************************************************************************************************//
  845. // Vin (OVP)
  846. if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
  847. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
  848. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
  849. log_info("In Ovp L1N_L12 = %f ", inputVoltage.L1N_L12);
  850. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
  851. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
  852. } else {
  853. _threePhaseOvp[0] += 1;
  854. }
  855. }
  856. } else {
  857. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC) {
  858. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
  859. _threePhaseOvp[0] = 0;
  860. }
  861. }
  862. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  863. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
  864. log_info("In Ovp L2N_L23 = %f ", inputVoltage.L2N_L23);
  865. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
  866. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
  867. } else {
  868. _threePhaseOvp[1] += 1;
  869. }
  870. }
  871. } else {
  872. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC) {
  873. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
  874. _threePhaseOvp[1] = 0;
  875. }
  876. }
  877. if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == NO) {
  878. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
  879. log_info("In Ovp L3N_L31 = %f ", inputVoltage.L3N_L31);
  880. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
  881. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
  882. } else {
  883. _threePhaseOvp[2] += 1;
  884. }
  885. }
  886. } else {
  887. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC) {
  888. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
  889. _threePhaseOvp[2] = 0;
  890. }
  891. }
  892. } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
  893. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
  894. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
  895. log_info("In Ovp L1N_L12 = %f ", inputVoltage.L1N_L12);
  896. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
  897. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
  898. } else {
  899. _threePhaseOvp[0] += 0;
  900. }
  901. }
  902. } else {
  903. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL) {
  904. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
  905. _threePhaseOvp[0] = 0;
  906. }
  907. }
  908. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  909. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
  910. log_info("In Ovp L2N_L23 = %f ", inputVoltage.L2N_L23);
  911. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
  912. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
  913. } else {
  914. _threePhaseOvp[1] += 0;
  915. }
  916. }
  917. } else {
  918. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL) {
  919. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
  920. _threePhaseOvp[1] = 0;
  921. }
  922. }
  923. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  924. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
  925. log_info("In Ovp L3N_L31 = %f ", inputVoltage.L3N_L31);
  926. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
  927. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
  928. } else {
  929. _threePhaseOvp[2] += 1;
  930. }
  931. }
  932. } else {
  933. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL) {
  934. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
  935. _threePhaseOvp[2] = 0;
  936. }
  937. }
  938. }
  939. }
  940. }
  941. // 左右槍的 Relay 前後的輸出電壓
  942. void GetPersentOutputVol(void)
  943. {
  944. uint8_t index = 0;
  945. uint8_t targetID = 0;
  946. struct ChargingInfoData *pDcChargingInfo = NULL;
  947. PresentOutputVoltage outputVoltage = {0};
  948. if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
  949. return;
  950. }
  951. /*
  952. log_info("Conn1 fuse 1 = %f ", outputVoltage.behindFuse_Voltage_C1);
  953. log_info("Conn1 relay 1 = %f ", outputVoltage.behindRelay_Voltage_C1);
  954. log_info("Conn2 fuse 2 = %f ", outputVoltage.behindFuse_Voltage_C2);
  955. log_info("Conn2 relay 2 = %f ", outputVoltage.behindRelay_Voltage_C2);
  956. */
  957. //log_info("outputVoltage.behindFuse_Voltage_C1 = %f ", outputVoltage.behindFuse_Voltage_C1);
  958. //log_info("outputVoltage.behindFuse_Voltage_C2 = %f ", outputVoltage.behindFuse_Voltage_C2);
  959. ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  960. ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  961. ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  962. ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  963. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  964. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  965. targetID = getCommTargetID(index);
  966. switch (targetID) {
  967. case 0x01:
  968. #if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
  969. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  970. pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun1FuseOutputVolt) / 10;
  971. pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
  972. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  973. break;
  974. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  975. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  976. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
  977. break;
  978. case 0x02:
  979. #if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
  980. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  981. pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun2FuseOutputVolt) / 10;
  982. pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
  983. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  984. break;
  985. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  986. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  987. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
  988. break;
  989. }
  990. /*
  991. log_info("FireChargingVoltage:%.1f PresentChargingCurrent:%.1f PresentChargingVoltage:%.1f FuseChargingVoltage:%.1f",
  992. pDcChargingInfo->FireChargingVoltage,
  993. pDcChargingInfo->PresentChargingCurrent,
  994. pDcChargingInfo->PresentChargingVoltage,
  995. pDcChargingInfo->FuseChargingVoltage );
  996. */
  997. //log_info("%d persent vol = %f, cur = %f",
  998. // index,
  999. // pDcChargingInfo->PresentChargingVoltage,
  1000. // pDcChargingInfo->PresentChargingCurrent);
  1001. //unsigned short Ovp = 0;
  1002. //unsigned short Ocp = 0;
  1003. //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] // 最大輸出電壓與電池電壓最大值
  1004. //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ] // 最大輸出電流與需求電流最小值
  1005. //if (pDcChargingInfo->Type == _Type_Chademo) {
  1006. // //Ovp = MaxValue(pDcChargingInfo->MaximumChargingVoltage, pDcChargingInfo->EvBatteryMaxVoltage);
  1007. // //Ocp = MaxValue(pDcChargingInfo->PresentChargingCurrent, ShmCHAdeMOData->ev[pDcChargingInfo->type_index].ChargingCurrentRequest);
  1008. //} else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1009. //}
  1010. }
  1011. }
  1012. void SetRtcData_Relay(void)
  1013. {
  1014. struct timeb csuTime;
  1015. struct tm *tmCSU;
  1016. Rtc rtc = {0};
  1017. ftime(&csuTime);
  1018. tmCSU = localtime(&csuTime.time);
  1019. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
  1020. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  1021. // tmCSU->tm_sec);
  1022. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  1023. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  1024. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  1025. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  1026. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  1027. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  1028. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  1029. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  1030. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  1031. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  1032. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  1033. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  1034. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  1035. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  1036. if (Config_Rtc_Data(Uart5Fd, ADDR_RELAY, &rtc) == PASS) {
  1037. //log_info("SetRtc (RB) sucessfully. ");
  1038. }
  1039. }
  1040. void SetModelName_Relay(void)
  1041. {
  1042. if (Config_Model_Name(Uart5Fd, ADDR_RELAY, pSysConfig->ModelName) == PASS) {
  1043. //log_info("Set Model name (RB) PASS = %s ", pSysConfig->ModelName);
  1044. }
  1045. }
  1046. void GetFwAndHwVersion_Relay(void)
  1047. {
  1048. Ver ver = {0};
  1049. if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  1050. // RelayModuleData
  1051. strcpy((char *)ShmRelayModuleData->version, ver.Version_FW);
  1052. // SystemInfo
  1053. strcpy((char *)pSysInfo->RelayModuleFwRev, ver.Version_FW);
  1054. //log_info("GetFwAndHwVersion_Relay s1 = %s ", ver.Version_FW);
  1055. }
  1056. if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  1057. // SystemInfo
  1058. strcpy((char *)pSysInfo->RelayModuleHwRev, ver.Version_FW);
  1059. //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
  1060. }
  1061. }
  1062. static void outputRelayInit(int fd)
  1063. {
  1064. memset((uint8_t *)&outputRelay, 0, sizeof(Relay));
  1065. if (Config_Relay_Output(fd, ADDR_RELAY, &outputRelay) != PASS) {
  1066. log_info("Config_Relay_Output fail ");
  1067. }
  1068. }
  1069. static bool IsRelayProcessNeedPause(void)
  1070. {
  1071. bool _pause = false;
  1072. static bool isPause = false;
  1073. struct ChargingInfoData *pDcChargingInfo = NULL;
  1074. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1075. {
  1076. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1077. if(pDcChargingInfo->SystemStatus == S_UPDATE)
  1078. {
  1079. SetLedColor();
  1080. _pause = true;
  1081. }
  1082. }
  1083. if(isPause != _pause)
  1084. {
  1085. log_info("Relay Process Now Is %s ", _pause == true ? "Paused" : "Continued");
  1086. }
  1087. isPause = _pause;
  1088. return _pause;
  1089. }
  1090. static void SetFanModuleSpeed(void)
  1091. {
  1092. {
  1093. FanSpeed _fanSpeed = {0};
  1094. _setFanSpeed += fanSpeedSmoothValue;
  1095. if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed) {
  1096. _setFanSpeed = ShmFanModuleData->SetFan1Speed;
  1097. }
  1098. //log_info("_setFanSpeed = %d \n", _setFanSpeed);
  1099. //log_info("ShmFanModuleData->SetFan1Speed = %d \n", ShmFanModuleData->SetFan1Speed);
  1100. _fanSpeed.speed[0] = _setFanSpeed;
  1101. _fanSpeed.speed[1] = _setFanSpeed;
  1102. _fanSpeed.speed[2] = _setFanSpeed;
  1103. _fanSpeed.speed[3] = _setFanSpeed;
  1104. if (Config_Fan_Speed(Uart5Fd, ADDR_FAN, &_fanSpeed) == PASS) {
  1105. //log_info("successfully Fan");
  1106. }
  1107. }
  1108. }
  1109. // 風扇速度
  1110. static void GetFanSpeed(void)
  1111. {
  1112. FanSpeed fanSpeed = {0};
  1113. //log_info("Get fan board speed ");
  1114. if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
  1115. ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
  1116. ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
  1117. ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
  1118. ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
  1119. // log_info("SystemFanRotaSpeed_1 = %d ", fanSpeed.speed[0]);
  1120. // log_info("SystemFanRotaSpeed_2 = %d ", fanSpeed.speed[1]);
  1121. // log_info("SystemFanRotaSpeed_3 = %d ", fanSpeed.speed[2]);
  1122. // log_info("SystemFanRotaSpeed_4 = %d ", fanSpeed.speed[3]);
  1123. // Config_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed[0]);
  1124. //SysInfoData (SystemFanRotaSpeed)
  1125. } else {
  1126. }
  1127. }
  1128. static void GetFanSpeedByFunction(void)
  1129. {
  1130. if (pSysConfig->SwitchDebugFlag == YES) {
  1131. return;
  1132. }
  1133. // 風控修改 :
  1134. // ******************************************************* //
  1135. //
  1136. // 當前PSU輸出總 KW PSU Temp
  1137. // 30 x -------------------- x ---------- + 14 x (PSU Temp - 45)
  1138. // 當前樁最大功率 KW 45
  1139. //
  1140. // ******************************************************* //
  1141. // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
  1142. uint32_t _maxPower = ShmPsuData->SystemAvailablePower;
  1143. // 當前PSU輸出總 KW & PSU Temp :
  1144. uint8_t temp = 0;
  1145. uint8_t index = 0;
  1146. uint8_t count = 0;
  1147. uint8_t gunIndex = 0;
  1148. uint8_t _temp_diff = 0;
  1149. float power = 0;
  1150. double _pw_rate = 0;
  1151. double _temp_rate = 0;
  1152. struct ChargingInfoData *pDcChargingInfo = NULL;
  1153. for (index = 0; index < ShmPsuData->GroupCount; index++) {
  1154. for (count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
  1155. if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
  1156. temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  1157. }
  1158. }
  1159. }
  1160. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  1161. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1162. power += (pDcChargingInfo->PresentChargingPower * 10);
  1163. }
  1164. if (_maxPower > 0) {
  1165. _pw_rate = power / (double)_maxPower;
  1166. }
  1167. if (temp > 0) {
  1168. _temp_rate = (double)temp / 50;
  1169. }
  1170. if (temp > 45) {
  1171. _temp_diff = temp - 70;
  1172. }
  1173. ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _temp_diff)) / 100) * MAX_FAN_SPEED;
  1174. if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED) {
  1175. ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
  1176. }
  1177. if (ShmFanModuleData->TestFanSpeed < 0) {
  1178. ShmFanModuleData->TestFanSpeed = 0;
  1179. }
  1180. //
  1181. // printf("power = %f \n", power);
  1182. // printf("_maxPower = %d \n", _maxPower);
  1183. // printf("temp = %d \n", temp);
  1184. //
  1185. // printf("_pw_rate = %f \n", _pw_rate);
  1186. // printf("_temp_rate = %f \n", _temp_rate);
  1187. // printf("_temp_diff = %d \n", _temp_diff);
  1188. // printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
  1189. // printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
  1190. }
  1191. static void SetRtcData_Fan(void)
  1192. {
  1193. struct timeb csuTime;
  1194. struct tm *tmCSU;
  1195. Rtc rtc = {0};
  1196. ftime(&csuTime);
  1197. tmCSU = localtime(&csuTime.time);
  1198. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
  1199. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  1200. // tmCSU->tm_sec);
  1201. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  1202. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  1203. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  1204. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  1205. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  1206. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  1207. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  1208. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  1209. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  1210. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  1211. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  1212. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  1213. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  1214. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  1215. if (Config_Rtc_Data(Uart5Fd, ADDR_FAN, &rtc) == PASS) {
  1216. //log_info("SetRtc (FB) sucessfully. ");
  1217. }
  1218. }
  1219. static void SetModelName_Fan(void)
  1220. {
  1221. if (Config_Model_Name(Uart5Fd, ADDR_FAN, pSysConfig->ModelName) == PASS) {
  1222. log_info("Set Model name PASS = %s ", pSysConfig->ModelName);
  1223. }
  1224. }
  1225. static void GetFwAndHwVersion_Fan(void)
  1226. {
  1227. Ver ver = {0};
  1228. if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
  1229. // FanModuleData
  1230. strcpy((char *)ShmFanModuleData->version, ver.Version_FW);
  1231. // SystemInfo
  1232. strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
  1233. //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
  1234. }
  1235. if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
  1236. // SystemInfo
  1237. strcpy((char *)pSysInfo->FanModuleHwRev, ver.Version_FW);
  1238. //log_info("GetFwAndHwVersion_Fan s2 = %s ", ver.Version_HW);
  1239. }
  1240. }
  1241. static void fanBoardSelfTest(void)
  1242. {
  1243. if (ShmFanModuleData->SelfTest_Comp == YES) {
  1244. return;
  1245. }
  1246. pAlarmCode->AlarmEvents.bits.FanboardStestFail = YES;
  1247. GetFwAndHwVersion_Fan();
  1248. SetModelName_Fan();
  1249. SetRtcData_Fan();
  1250. sleep(1);
  1251. gettimeofday(&gFanBoardRunTimer, NULL);
  1252. ShmDcCommonData->FanDisconnectTime = time((time_t*)NULL);
  1253. }
  1254. static void fanBoardPorcess(void)
  1255. {
  1256. if (ShmFanModuleData->SelfTest_Comp == NO) {
  1257. return;
  1258. }
  1259. if (ShmFanModuleData->SelfTest_Comp == YES ||
  1260. strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
  1261. pSysInfo->FanModuleFwRev[0] != '\0') {
  1262. ShmFanModuleData->SelfTest_Comp = YES;
  1263. if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
  1264. //GetPsuTempForFanSpeed();
  1265. //GetFanSpeedByFunction();
  1266. GetFanSpeed();
  1267. pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
  1268. gettimeofday(&gFanBoardRunTimer, NULL);
  1269. /*
  1270. ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
  1271. ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
  1272. ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
  1273. ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
  1274. */
  1275. //log_info("set fan = %d ", ShmFanModuleData->SetFan1Speed);
  1276. SetFanModuleSpeed();
  1277. }
  1278. }
  1279. }
  1280. static void GetFwAndHwVersion_Led(void)
  1281. {
  1282. Ver ver = {0};
  1283. if (Query_FW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS) {
  1284. // LedModuleData
  1285. strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
  1286. // SystemInfo
  1287. strcpy((char *) pSysInfo->LedModuleFwRev, ver.Version_FW);
  1288. log_info("GetFwAndHwVersion_Led s1 = %s ", ver.Version_FW);
  1289. ShmLedModuleData->SelfTest_Comp = YES;
  1290. pAlarmCode->AlarmEvents.bits.LedboardStestFail = NO;
  1291. } else {
  1292. //log_info("GetFwAndHwVersion_Led fail ");
  1293. }
  1294. // if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
  1295. // {
  1296. // // SystemInfo
  1297. // strcpy((char *) pSysInfo->RelayModuleHwRev, ver.Version_FW);
  1298. // //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
  1299. // }
  1300. }
  1301. static bool IsNoneMatchLedColor(void)
  1302. {
  1303. bool result = false;
  1304. if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
  1305. cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
  1306. cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
  1307. cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
  1308. cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
  1309. cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue) {
  1310. result = true;
  1311. }
  1312. return result;
  1313. }
  1314. //static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
  1315. static void SetLedColor(void)
  1316. {
  1317. static uint8_t _checkLedChanged = 3;
  1318. struct ChargingInfoData *chargingData_1 = NULL;
  1319. struct ChargingInfoData *chargingData_2 = NULL;
  1320. if (pSysConfig->TotalConnectorCount == 1) {
  1321. chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1322. chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1323. } else if (pSysConfig->TotalConnectorCount == 2) {
  1324. chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1325. chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
  1326. }
  1327. uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
  1328. if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
  1329. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
  1330. } else if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
  1331. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
  1332. } else if (pSysConfig->LedInfo.Intensity == LED_INTENSITY_BRIGHTEST) {
  1333. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
  1334. }
  1335. //printf("chargingData_1->SystemStatus=%d\n",chargingData_1->SystemStatus);
  1336. //printf("chargingData_2->SystemStatus=%d\n",chargingData_2->SystemStatus);
  1337. //printf("pSysWarning->Level=%d\n",pSysWarning->Level);
  1338. if (pSysWarning->Level == 2) {
  1339. led_color.Connect_1_Green = COLOR_MIN_LV;
  1340. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1341. led_color.Connect_1_Red = _colorBuf;
  1342. led_color.Connect_2_Green = COLOR_MIN_LV;
  1343. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1344. led_color.Connect_2_Red = _colorBuf;
  1345. } else {
  1346. if (pSysInfo->IsAlternatvieConf) {
  1347. if ((chargingData_1->SystemStatus == S_BOOTING ||
  1348. chargingData_1->SystemStatus == S_IDLE ||
  1349. chargingData_1->SystemStatus == S_RESERVATION) &&
  1350. (chargingData_2->SystemStatus == S_BOOTING ||
  1351. chargingData_2->SystemStatus == S_IDLE ||
  1352. chargingData_2->SystemStatus == S_RESERVATION)) {
  1353. #if defined DD360Audi
  1354. led_color.Connect_1_Green = _colorBuf;
  1355. led_color.Connect_1_Blue = _colorBuf;
  1356. led_color.Connect_1_Red = _colorBuf;
  1357. led_color.Connect_2_Green = _colorBuf;
  1358. led_color.Connect_2_Blue = _colorBuf;
  1359. led_color.Connect_2_Red = _colorBuf;
  1360. #else
  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. #endif
  1368. } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
  1369. chargingData_1->SystemStatus <= S_COMPLETE) ||
  1370. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1371. chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1372. (chargingData_2->SystemStatus >= S_AUTHORIZING &&
  1373. chargingData_2->SystemStatus <= S_COMPLETE) ||
  1374. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1375. chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1376. led_color.Connect_1_Green = _colorBuf;
  1377. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1378. led_color.Connect_1_Red = COLOR_MIN_LV;
  1379. led_color.Connect_2_Green = _colorBuf;
  1380. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1381. led_color.Connect_2_Red = COLOR_MIN_LV;
  1382. } else if ( chargingData_1->SystemStatus == S_UPDATE ) {
  1383. led_color.Connect_1_Green = COLOR_MIN_LV;
  1384. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1385. led_color.Connect_1_Red = _colorBuf;
  1386. }
  1387. } else {
  1388. if (chargingData_1->SystemStatus == S_BOOTING ||
  1389. chargingData_1->SystemStatus == S_IDLE ||
  1390. chargingData_1->SystemStatus == S_RESERVATION) {
  1391. if (chargingData_1->IsAvailable == NO) { //For Audi
  1392. led_color.Connect_1_Green = COLOR_MIN_LV;
  1393. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1394. led_color.Connect_1_Red = _colorBuf;
  1395. } else {
  1396. #if defined DD360Audi
  1397. led_color.Connect_1_Green = _colorBuf;
  1398. led_color.Connect_1_Blue = _colorBuf;
  1399. led_color.Connect_1_Red = _colorBuf;
  1400. #else
  1401. led_color.Connect_1_Green = COLOR_MIN_LV;
  1402. led_color.Connect_1_Blue = _colorBuf;
  1403. led_color.Connect_1_Red = COLOR_MIN_LV;
  1404. #endif
  1405. }
  1406. } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
  1407. chargingData_1->SystemStatus <= S_COMPLETE) ||
  1408. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1409. chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1410. led_color.Connect_1_Green = _colorBuf;
  1411. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1412. led_color.Connect_1_Red = COLOR_MIN_LV;
  1413. }else if ( chargingData_1->SystemStatus == S_UPDATE ||
  1414. chargingData_1->SystemStatus == S_MAINTAIN ||
  1415. chargingData_1->SystemStatus == S_ALARM ) {
  1416. led_color.Connect_1_Green = COLOR_MIN_LV;
  1417. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1418. led_color.Connect_1_Red = _colorBuf;
  1419. }
  1420. // --------------------------------------------------------------------------
  1421. if (chargingData_2->SystemStatus == S_BOOTING ||
  1422. chargingData_2->SystemStatus == S_IDLE ||
  1423. chargingData_2->SystemStatus == S_RESERVATION ) {
  1424. if (chargingData_2->IsAvailable == NO) {
  1425. led_color.Connect_2_Green = COLOR_MIN_LV;
  1426. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1427. led_color.Connect_2_Red = _colorBuf;
  1428. } else {
  1429. #if defined DD360Audi
  1430. led_color.Connect_2_Green = _colorBuf;
  1431. led_color.Connect_2_Blue = _colorBuf;
  1432. led_color.Connect_2_Red = _colorBuf;
  1433. #else
  1434. led_color.Connect_2_Green = COLOR_MIN_LV;
  1435. led_color.Connect_2_Blue = _colorBuf;
  1436. led_color.Connect_2_Red = COLOR_MIN_LV;
  1437. #endif
  1438. }
  1439. } else if ((chargingData_2->SystemStatus >= S_AUTHORIZING &&
  1440. chargingData_2->SystemStatus <= S_COMPLETE) ||
  1441. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1442. chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1443. led_color.Connect_2_Green = _colorBuf;
  1444. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1445. led_color.Connect_2_Red = COLOR_MIN_LV;
  1446. }else if ( chargingData_2->SystemStatus == S_UPDATE ||
  1447. chargingData_2->SystemStatus == S_MAINTAIN ||
  1448. chargingData_2->SystemStatus == S_ALARM) {
  1449. led_color.Connect_2_Green = COLOR_MIN_LV;
  1450. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1451. led_color.Connect_2_Red = _colorBuf;
  1452. }
  1453. }
  1454. }
  1455. /*
  1456. if (ShmDcCommonData->DemoCount < 1) {
  1457. led_color.Connect_1_Red = COLOR_MIN_LV;
  1458. led_color.Connect_1_Green = COLOR_MIN_LV;
  1459. led_color.Connect_1_Blue = _colorBuf;
  1460. led_color.Connect_2_Red = COLOR_MIN_LV;
  1461. led_color.Connect_2_Green = COLOR_MIN_LV;
  1462. led_color.Connect_2_Blue = _colorBuf;
  1463. } else if (ShmDcCommonData->DemoCount < 8) {
  1464. led_color.Connect_1_Red = COLOR_MIN_LV;
  1465. led_color.Connect_1_Green = _colorBuf;
  1466. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1467. led_color.Connect_2_Red = COLOR_MIN_LV;
  1468. led_color.Connect_2_Green = COLOR_MIN_LV;
  1469. led_color.Connect_2_Blue = _colorBuf;
  1470. } else if (ShmDcCommonData->DemoCount < 18) {
  1471. led_color.Connect_1_Red = COLOR_MIN_LV;
  1472. led_color.Connect_1_Green = _colorBuf;
  1473. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1474. led_color.Connect_2_Red = COLOR_MIN_LV;
  1475. led_color.Connect_2_Green = _colorBuf;
  1476. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1477. } else {
  1478. led_color.Connect_1_Red = COLOR_MIN_LV;
  1479. led_color.Connect_1_Green = COLOR_MIN_LV;
  1480. led_color.Connect_1_Blue = _colorBuf;
  1481. led_color.Connect_2_Red = COLOR_MIN_LV;
  1482. led_color.Connect_2_Green = _colorBuf;
  1483. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1484. }
  1485. //*/
  1486. if (_checkLedChanged > 0) {
  1487. if (Config_Led_Color(Uart5Fd, ADDR_LED, &led_color) == PASS) {
  1488. _checkLedChanged--;
  1489. cur_led_color.Connect_1_Red = led_color.Connect_1_Red;
  1490. cur_led_color.Connect_1_Green = led_color.Connect_1_Green;
  1491. cur_led_color.Connect_1_Blue = led_color.Connect_1_Blue;
  1492. cur_led_color.Connect_2_Red = led_color.Connect_2_Red;
  1493. cur_led_color.Connect_2_Green = led_color.Connect_2_Green;
  1494. cur_led_color.Connect_2_Blue = led_color.Connect_2_Blue;
  1495. }
  1496. } else if (IsNoneMatchLedColor()) {
  1497. _checkLedChanged = 3;
  1498. }
  1499. }
  1500. static void LEDBoardSelfTest(void)
  1501. {
  1502. // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
  1503. if (ShmLedModuleData->SelfTest_Comp == YES) {
  1504. return;
  1505. }
  1506. pAlarmCode->AlarmEvents.bits.LedboardStestFail = YES;
  1507. #if defined DD360 ||defined DD360Audi || defined DD360UCar
  1508. GetFwAndHwVersion_Led();
  1509. sleep(1);
  1510. gettimeofday(&_led_priority_time, NULL);
  1511. return;
  1512. #endif //defined DD360 || defined DD360Audi
  1513. // 自檢階段
  1514. if (pSysInfo->SelfTestSeq <= _STEST_PSU_CAP) {
  1515. GetFwAndHwVersion_Led();
  1516. sleep(1);
  1517. gettimeofday(&_led_priority_time, NULL);
  1518. } else {
  1519. // 自檢階段沒有問到版號
  1520. if (pAlarmCode->AlarmEvents.bits.LedboardStestFail == NO) {
  1521. pAlarmCode->AlarmEvents.bits.LedboardStestFail = YES;
  1522. }
  1523. }
  1524. ShmDcCommonData->LedDisconnectTime = time((time_t*)NULL);
  1525. }
  1526. static void LEDBoardProcess(void)
  1527. {
  1528. //struct ChargingInfoData *pDcChargingInfo0 = NULL;
  1529. //struct ChargingInfoData *pDcChargingInfo1 = NULL;
  1530. if (ShmLedModuleData->SelfTest_Comp == NO) {
  1531. return;
  1532. }
  1533. pSysConfig->LedInfo.Intensity = LED_INTENSITY_BRIGHTEST;
  1534. if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
  1535. //if (pSysConfig->TotalConnectorCount == 1) {
  1536. // pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
  1537. // SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
  1538. //} else if (pSysConfig->TotalConnectorCount == 2) {
  1539. // pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
  1540. // pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
  1541. // SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
  1542. //}
  1543. SetLedColor();
  1544. gettimeofday(&_led_priority_time, NULL);
  1545. }
  1546. }
  1547. void RelayBoardTask(int uartFD)
  1548. {
  1549. bool isRelayBypass = false;
  1550. pid_t pid = fork();
  1551. if (pid == 0) {
  1552. bool isCharging = false;
  1553. bool isStopChargingCount = false;
  1554. uint8_t i = 0;
  1555. int isContinue = 1;
  1556. struct ChargingInfoData *pDcChargingInfo = NULL;
  1557. //share memory mapping
  1558. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1559. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1560. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1561. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  1562. ShmPsuData = (struct PsuData *)GetShmPsuData();
  1563. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1564. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1565. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1566. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  1567. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  1568. Uart5Fd = uartFD;
  1569. for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1570. {
  1571. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1572. if(pDcChargingInfo->PantographFlag == YES)
  1573. {
  1574. isRelayBypass = true;
  1575. }
  1576. }
  1577. //relay init
  1578. if(isRelayBypass == false)
  1579. {
  1580. outputRelayInit(uartFD);
  1581. }
  1582. while (isContinue) {
  1583. if(IsRelayProcessNeedPause() == true)
  1584. {
  1585. sleep(1);
  1586. continue;
  1587. }
  1588. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  1589. if (ShmRelayModuleData->SelfTest_Comp == NO && isRelayBypass == false) {
  1590. pAlarmCode->AlarmEvents.bits.RelaySelftestFail = TRUE;
  1591. GetFwAndHwVersion_Relay();
  1592. SetModelName_Relay(); //DS60-120 add
  1593. SetRtcData_Relay();
  1594. sleep(1);
  1595. ShmDcCommonData->RelayDisconnectTime = time((time_t*)NULL);
  1596. }
  1597. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  1598. fanBoardSelfTest();
  1599. #endif //NO_FAN_BOARD
  1600. #if !defined DD360ComBox
  1601. LEDBoardSelfTest();
  1602. #endif //defined DD360ComBox
  1603. if (ShmRelayModuleData->SelfTest_Comp == YES && isRelayBypass == false)
  1604. {
  1605. // ==============優先權最高 10 ms ==============
  1606. // 輸出電壓
  1607. GetPersentOutputVol();
  1608. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
  1609. // 三相輸入電壓
  1610. GetPresentInputVol();
  1611. #endif //!defined DD360 && !defined DD360Audi
  1612. // 讀取當前 AC relay 狀態
  1613. regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1614. GetRelayOutputStatus();
  1615. // Cable check (Get)
  1616. GetGfdAdc();
  1617. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1618. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1619. // Cable check (Set)
  1620. CableCheckDetected(i);
  1621. // check k1 k2 relay 狀態
  1622. CheckK1K2RelayOutput(i);
  1623. // 依據當前各槍的狀態選擇 搭上/放開 Relay
  1624. SetK1K2RelayStatus(i);
  1625. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
  1626. if (pSysConfig->PhaseLossPolicy == YES) {
  1627. CheckPhaseLossStatus(i);
  1628. }
  1629. CheckAcInputOvpStatus(i);
  1630. #endif //!defined DD360 && !defined DD360Audi
  1631. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  1632. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  1633. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  1634. //pDcChargingInfo->RelayWeldingCheck = NO;
  1635. //_isRelayWelding[i] = NO;
  1636. _isOvpChkTimeFlag[i] = NO;
  1637. //ResetDetAlarmStatus(i); //DS60-120 add
  1638. }
  1639. if (pDcChargingInfo->SystemStatus == S_BOOTING ||
  1640. (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  1641. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  1642. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1643. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1644. pSysInfo->WaitForPlugit == YES ||
  1645. (pSysInfo->PageIndex >= _LCM_START_AUTHORIZING &&
  1646. pSysInfo->PageIndex <= _LCM_WAIT_PLUGIN)
  1647. ) {
  1648. pDcChargingInfo->IsReadyToCharging = YES;
  1649. isCharging = true;
  1650. // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
  1651. //if (pDcChargingInfo->Type == _Type_GB) {
  1652. // if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  1653. // pDcChargingInfo->RelayWeldingCheck == NO) {
  1654. // CheckRelayWeldingStatus(i);
  1655. // }
  1656. //} else {
  1657. //pDcChargingInfo->RelayWeldingCheck = YES;
  1658. //}
  1659. if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  1660. CheckOutputPowerOverCarReq(i);
  1661. //CheckOutputVolNoneMatchFire(i);
  1662. }
  1663. /*else {
  1664. _isOutputNoneMatch[i] = NO;
  1665. }*/
  1666. } else {
  1667. pDcChargingInfo->IsReadyToCharging = NO;
  1668. }
  1669. }
  1670. // 橋接 relay
  1671. SetParalleRelayStatus();
  1672. // 搭上 AC Contactor
  1673. //if (isCharging) {
  1674. // outputRelay.relay_event.bits.AC_Contactor = YES;
  1675. //} else {
  1676. // outputRelay.relay_event.bits.AC_Contactor = NO;
  1677. //}
  1678. if (isCharging ||
  1679. (ShmPsuData->Work_Step >= _TEST_MODE &&
  1680. ShmPsuData->Work_Step <= _TEST_MODE)) {
  1681. isStopChargingCount = false;
  1682. outputRelay.relay_event.bits.AC_Contactor = YES;
  1683. } else {
  1684. if (!isStopChargingCount) {
  1685. gettimeofday(&_close_ac_contactor, NULL);
  1686. isStopChargingCount = true;
  1687. } else {
  1688. if ((outputRelay.relay_event.bits.AC_Contactor == YES &&
  1689. GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
  1690. outputRelay.relay_event.bits.AC_Contactor = NO;
  1691. }
  1692. }
  1693. }
  1694. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  1695. outputRelay.relay_event.bits.AC_Contactor = NO;
  1696. }
  1697. if (pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == ABNORMAL) {
  1698. RunForceStopProcess();
  1699. outputRelay.relay_event.bits.AC_Contactor = NO;
  1700. }
  1701. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  1702. outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
  1703. }
  1704. // 搭上/鬆開 Relay
  1705. if (IsNoneMatchRelayStatus()) {
  1706. if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
  1707. //regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1708. //regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  1709. //regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  1710. //regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  1711. //regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  1712. //regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  1713. //regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  1714. //regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  1715. //MatchRelayStatus();
  1716. //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 ",
  1717. // regRelay.relay_event.bits.AC_Contactor,
  1718. // regRelay.relay_event.bits.Gun1_P,
  1719. // regRelay.relay_event.bits.Gun1_N,
  1720. // regRelay.relay_event.bits.Gun2_P,
  1721. // regRelay.relay_event.bits.Gun2_N,
  1722. // regRelay.relay_event.bits.CCS_Precharge,
  1723. // regRelay.relay_event.bits.Gun1_Parallel_P,
  1724. // regRelay.relay_event.bits.Gun1_Parallel_N);
  1725. }
  1726. }
  1727. } else if(isRelayBypass == true) {
  1728. for(i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1729. {
  1730. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1731. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  1732. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  1733. pDcChargingInfo->SystemStatus == S_MAINTAIN)
  1734. {
  1735. _isOvpChkTimeFlag[i] = NO;
  1736. }
  1737. if (pDcChargingInfo->SystemStatus == S_CHARGING)
  1738. {
  1739. CheckOutputPowerOverCarReq(i);
  1740. }
  1741. }
  1742. }
  1743. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  1744. fanBoardPorcess();
  1745. #endif //NO_FAN_BOARD
  1746. #if !defined DD360ComBox
  1747. LEDBoardProcess();
  1748. #endif //defined DD360ComBox
  1749. usleep(10000);
  1750. }
  1751. }
  1752. }