RelayBoard.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  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 = 1000;
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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. //log_info("Conn1 fuse 1 = %f ", outputVoltage.behindFuse_Voltage_C1);
  944. //log_info("Conn1 relay 1 = %f ", outputVoltage.behindRelay_Voltage_C1);
  945. //log_info("Conn2 fuse 2 = %f ", outputVoltage.behindFuse_Voltage_C2);
  946. //log_info("Conn2 relay 2 = %f ", outputVoltage.behindRelay_Voltage_C2);
  947. //log_info("outputVoltage.behindFuse_Voltage_C1 = %f ", outputVoltage.behindFuse_Voltage_C1);
  948. //log_info("outputVoltage.behindFuse_Voltage_C2 = %f ", outputVoltage.behindFuse_Voltage_C2);
  949. ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  950. ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  951. ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  952. ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  953. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  954. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  955. targetID = getCommTargetID(index);
  956. switch (targetID) {
  957. case 0x01:
  958. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  959. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  960. pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun1FuseOutputVolt) / 10;
  961. pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
  962. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  963. break;
  964. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  965. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  966. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
  967. break;
  968. case 0x02:
  969. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  970. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  971. pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun2FuseOutputVolt) / 10;
  972. pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
  973. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  974. break;
  975. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  976. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  977. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
  978. break;
  979. }
  980. //log_info("%d persent vol = %f, cur = %f",
  981. // index,
  982. // pDcChargingInfo->PresentChargingVoltage,
  983. // pDcChargingInfo->PresentChargingCurrent);
  984. //unsigned short Ovp = 0;
  985. //unsigned short Ocp = 0;
  986. //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] // 最大輸出電壓與電池電壓最大值
  987. //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ] // 最大輸出電流與需求電流最小值
  988. //if (pDcChargingInfo->Type == _Type_Chademo) {
  989. // //Ovp = MaxValue(pDcChargingInfo->MaximumChargingVoltage, pDcChargingInfo->EvBatteryMaxVoltage);
  990. // //Ocp = MaxValue(pDcChargingInfo->PresentChargingCurrent, ShmCHAdeMOData->ev[pDcChargingInfo->type_index].ChargingCurrentRequest);
  991. //} else if (pDcChargingInfo->Type == _Type_CCS_2) {
  992. //}
  993. }
  994. }
  995. void SetRtcData_Relay(void)
  996. {
  997. struct timeb csuTime;
  998. struct tm *tmCSU;
  999. Rtc rtc = {0};
  1000. ftime(&csuTime);
  1001. tmCSU = localtime(&csuTime.time);
  1002. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
  1003. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  1004. // tmCSU->tm_sec);
  1005. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  1006. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  1007. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  1008. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  1009. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  1010. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  1011. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  1012. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  1013. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  1014. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  1015. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  1016. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  1017. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  1018. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  1019. if (Config_Rtc_Data(Uart5Fd, ADDR_RELAY, &rtc) == PASS) {
  1020. //log_info("SetRtc (RB) sucessfully. ");
  1021. }
  1022. }
  1023. void SetModelName_Relay(void)
  1024. {
  1025. if (Config_Model_Name(Uart5Fd, ADDR_RELAY, pSysConfig->ModelName) == PASS) {
  1026. //log_info("Set Model name (RB) PASS = %s ", pSysConfig->ModelName);
  1027. }
  1028. }
  1029. void GetFwAndHwVersion_Relay(void)
  1030. {
  1031. Ver ver = {0};
  1032. if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  1033. // RelayModuleData
  1034. strcpy((char *)ShmRelayModuleData->version, ver.Version_FW);
  1035. // SystemInfo
  1036. strcpy((char *)pSysInfo->RelayModuleFwRev, ver.Version_FW);
  1037. //log_info("GetFwAndHwVersion_Relay s1 = %s ", ver.Version_FW);
  1038. }
  1039. if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  1040. // SystemInfo
  1041. strcpy((char *)pSysInfo->RelayModuleHwRev, ver.Version_FW);
  1042. //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
  1043. }
  1044. }
  1045. static void outputRelayInit(int fd)
  1046. {
  1047. memset((uint8_t *)&outputRelay, 0, sizeof(Relay));
  1048. if (Config_Relay_Output(fd, ADDR_RELAY, &outputRelay) != PASS) {
  1049. log_info("Config_Relay_Output fail ");
  1050. }
  1051. }
  1052. static bool IsRelayProcessNeedPause(void)
  1053. {
  1054. bool _pause = false;
  1055. static bool isPause = false;
  1056. struct ChargingInfoData *pDcChargingInfo = NULL;
  1057. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1058. {
  1059. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1060. if(pDcChargingInfo->SystemStatus == S_UPDATE)
  1061. {
  1062. SetLedColor();
  1063. _pause = true;
  1064. }
  1065. }
  1066. if(isPause != _pause)
  1067. {
  1068. log_info("Relay Process Now Is %s ", _pause == true ? "Paused" : "Continued");
  1069. }
  1070. isPause = _pause;
  1071. return _pause;
  1072. }
  1073. static void SetFanModuleSpeed(void)
  1074. {
  1075. {
  1076. FanSpeed _fanSpeed = {0};
  1077. _setFanSpeed += fanSpeedSmoothValue;
  1078. if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed) {
  1079. _setFanSpeed = ShmFanModuleData->SetFan1Speed;
  1080. }
  1081. _fanSpeed.speed[0] = _setFanSpeed;
  1082. _fanSpeed.speed[1] = _setFanSpeed;
  1083. _fanSpeed.speed[2] = _setFanSpeed;
  1084. _fanSpeed.speed[3] = _setFanSpeed;
  1085. if (Config_Fan_Speed(Uart5Fd, ADDR_FAN, &_fanSpeed) == PASS) {
  1086. //log_info("successfully Fan");
  1087. }
  1088. }
  1089. }
  1090. // 風扇速度
  1091. static void GetFanSpeed(void)
  1092. {
  1093. FanSpeed fanSpeed = {0};
  1094. //log_info("Get fan board speed ");
  1095. if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
  1096. ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
  1097. ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
  1098. ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
  1099. ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
  1100. // log_info("SystemFanRotaSpeed_1 = %d ", fanSpeed.speed[0]);
  1101. // log_info("SystemFanRotaSpeed_2 = %d ", fanSpeed.speed[1]);
  1102. // log_info("SystemFanRotaSpeed_3 = %d ", fanSpeed.speed[2]);
  1103. // log_info("SystemFanRotaSpeed_4 = %d ", fanSpeed.speed[3]);
  1104. // Config_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed[0]);
  1105. //SysInfoData (SystemFanRotaSpeed)
  1106. }
  1107. }
  1108. static void GetFanSpeedByFunction(void)
  1109. {
  1110. if (ShmDcCommonData->debugflag== YES) {
  1111. return;
  1112. }
  1113. // 風控修改 :
  1114. // ******************************************************* //
  1115. //
  1116. // 當前PSU輸出總 KW PSU Temp
  1117. // 30 x -------------------- x ---------- + 14 x (PSU Temp - 45)
  1118. // 當前樁最大功率 KW 45
  1119. //
  1120. // ******************************************************* //
  1121. // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
  1122. uint32_t _maxPower = ShmPsuData->SystemAvailablePower;
  1123. // 當前PSU輸出總 KW & PSU Temp :
  1124. uint8_t temp = 0;
  1125. uint8_t index = 0;
  1126. uint8_t count = 0;
  1127. uint8_t gunIndex = 0;
  1128. uint8_t _temp_diff = 0;
  1129. float power = 0;
  1130. double _pw_rate = 0;
  1131. double _temp_rate = 0;
  1132. struct ChargingInfoData *pDcChargingInfo = NULL;
  1133. for (index = 0; index < ShmPsuData->GroupCount; index++) {
  1134. for (count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
  1135. if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
  1136. temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  1137. }
  1138. }
  1139. }
  1140. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  1141. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1142. power += (pDcChargingInfo->PresentChargingPower * 10);
  1143. }
  1144. if (_maxPower > 0) {
  1145. _pw_rate = power / (double)_maxPower;
  1146. }
  1147. if (temp > 0) {
  1148. _temp_rate = (double)temp / 50;
  1149. }
  1150. if (temp > 45) {
  1151. _temp_diff = temp - 70;
  1152. }
  1153. ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _temp_diff)) / 100) * MAX_FAN_SPEED;
  1154. if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED) {
  1155. ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
  1156. }
  1157. if (ShmFanModuleData->TestFanSpeed < 0) {
  1158. ShmFanModuleData->TestFanSpeed = 0;
  1159. }
  1160. //
  1161. // printf("power = %f \n", power);
  1162. // printf("_maxPower = %d \n", _maxPower);
  1163. // printf("temp = %d \n", temp);
  1164. //
  1165. // printf("_pw_rate = %f \n", _pw_rate);
  1166. // printf("_temp_rate = %f \n", _temp_rate);
  1167. // printf("_temp_diff = %d \n", _temp_diff);
  1168. // printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
  1169. // printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
  1170. }
  1171. static void SetRtcData_Fan(void)
  1172. {
  1173. struct timeb csuTime;
  1174. struct tm *tmCSU;
  1175. Rtc rtc = {0};
  1176. ftime(&csuTime);
  1177. tmCSU = localtime(&csuTime.time);
  1178. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ", tmCSU->tm_year + 1900,
  1179. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  1180. // tmCSU->tm_sec);
  1181. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  1182. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  1183. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  1184. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  1185. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  1186. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  1187. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  1188. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  1189. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  1190. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  1191. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  1192. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  1193. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  1194. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  1195. if (Config_Rtc_Data(Uart5Fd, ADDR_FAN, &rtc) == PASS) {
  1196. //log_info("SetRtc (FB) sucessfully. ");
  1197. }
  1198. }
  1199. static void SetModelName_Fan(void)
  1200. {
  1201. if (Config_Model_Name(Uart5Fd, ADDR_FAN, pSysConfig->ModelName) == PASS) {
  1202. log_info("Set Model name PASS = %s ", pSysConfig->ModelName);
  1203. }
  1204. }
  1205. static void GetFwAndHwVersion_Fan(void)
  1206. {
  1207. Ver ver = {0};
  1208. if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
  1209. // FanModuleData
  1210. strcpy((char *)ShmFanModuleData->version, ver.Version_FW);
  1211. // SystemInfo
  1212. strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
  1213. //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
  1214. }
  1215. if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
  1216. // SystemInfo
  1217. strcpy((char *)pSysInfo->FanModuleHwRev, ver.Version_FW);
  1218. //log_info("GetFwAndHwVersion_Fan s2 = %s ", ver.Version_HW);
  1219. }
  1220. }
  1221. static void fanBoardSelfTest(void)
  1222. {
  1223. if (ShmFanModuleData->SelfTest_Comp == YES) {
  1224. return;
  1225. }
  1226. GetFwAndHwVersion_Fan();
  1227. SetModelName_Fan();
  1228. SetRtcData_Fan();
  1229. sleep(1);
  1230. gettimeofday(&gFanBoardRunTimer, NULL);
  1231. }
  1232. static void fanBoardPorcess(void)
  1233. {
  1234. if (ShmFanModuleData->SelfTest_Comp == NO) {
  1235. return;
  1236. }
  1237. if (ShmFanModuleData->SelfTest_Comp == YES ||
  1238. strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
  1239. pSysInfo->FanModuleFwRev[0] != '\0') {
  1240. ShmFanModuleData->SelfTest_Comp = YES;
  1241. if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
  1242. //GetPsuTempForFanSpeed();
  1243. GetFanSpeedByFunction();
  1244. GetFanSpeed();
  1245. pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
  1246. gettimeofday(&gFanBoardRunTimer, NULL);
  1247. ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
  1248. ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
  1249. ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
  1250. ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
  1251. //log_info("set fan = %d ", ShmFanModuleData->SetFan1Speed);
  1252. SetFanModuleSpeed();
  1253. }
  1254. }
  1255. }
  1256. static void GetFwAndHwVersion_Led(void)
  1257. {
  1258. Ver ver = {0};
  1259. if (Query_FW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS) {
  1260. // LedModuleData
  1261. strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
  1262. // SystemInfo
  1263. strcpy((char *) pSysInfo->LedModuleFwRev, ver.Version_FW);
  1264. log_info("GetFwAndHwVersion_Led s1 = %s ", ver.Version_FW);
  1265. ShmLedModuleData->SelfTest_Comp = YES;
  1266. } else {
  1267. //log_info("GetFwAndHwVersion_Led fail ");
  1268. }
  1269. // if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
  1270. // {
  1271. // // SystemInfo
  1272. // strcpy((char *) pSysInfo->RelayModuleHwRev, ver.Version_FW);
  1273. // //log_info("GetFwAndHwVersion_Relay s2 = %s ", ver.Version_HW);
  1274. // }
  1275. }
  1276. static bool IsNoneMatchLedColor(void)
  1277. {
  1278. bool result = false;
  1279. if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
  1280. cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
  1281. cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
  1282. cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
  1283. cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
  1284. cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue) {
  1285. result = true;
  1286. }
  1287. return result;
  1288. }
  1289. //static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
  1290. static void SetLedColor(void)
  1291. {
  1292. static uint8_t _checkLedChanged = 3;
  1293. struct ChargingInfoData *chargingData_1 = NULL;
  1294. struct ChargingInfoData *chargingData_2 = NULL;
  1295. uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
  1296. if (pSysConfig->TotalConnectorCount == 1) {
  1297. chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1298. chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1299. } else if (pSysConfig->TotalConnectorCount == 2) {
  1300. chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  1301. chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
  1302. }
  1303. if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
  1304. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
  1305. } else if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
  1306. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
  1307. }
  1308. //printf("chargingData_1->SystemStatus=%d\n",chargingData_1->SystemStatus);
  1309. //printf("chargingData_2->SystemStatus=%d\n",chargingData_2->SystemStatus);
  1310. //printf("pSysWarning->Level=%d\n",pSysWarning->Level);
  1311. if (pSysWarning->Level == 2) {
  1312. led_color.Connect_1_Green = COLOR_MIN_LV;
  1313. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1314. led_color.Connect_1_Red = _colorBuf;
  1315. led_color.Connect_2_Green = COLOR_MIN_LV;
  1316. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1317. led_color.Connect_2_Red = _colorBuf;
  1318. } else {
  1319. if (pSysInfo->IsAlternatvieConf) {
  1320. if ((chargingData_1->SystemStatus == S_BOOTING ||
  1321. chargingData_1->SystemStatus == S_IDLE ||
  1322. chargingData_1->SystemStatus == S_RESERVATION) &&
  1323. (chargingData_2->SystemStatus == S_BOOTING ||
  1324. chargingData_2->SystemStatus == S_IDLE ||
  1325. chargingData_2->SystemStatus == S_RESERVATION)) {
  1326. #if defined DD360Audi
  1327. led_color.Connect_1_Green = _colorBuf;
  1328. led_color.Connect_1_Blue = _colorBuf;
  1329. led_color.Connect_1_Red = _colorBuf;
  1330. led_color.Connect_2_Green = _colorBuf;
  1331. led_color.Connect_2_Blue = _colorBuf;
  1332. led_color.Connect_2_Red = _colorBuf;
  1333. #else
  1334. led_color.Connect_1_Green = _colorBuf;
  1335. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1336. led_color.Connect_1_Red = COLOR_MIN_LV;
  1337. led_color.Connect_2_Green = _colorBuf;
  1338. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1339. led_color.Connect_2_Red = COLOR_MIN_LV;
  1340. #endif
  1341. } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
  1342. chargingData_1->SystemStatus <= S_COMPLETE) ||
  1343. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1344. chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1345. (chargingData_2->SystemStatus >= S_AUTHORIZING &&
  1346. chargingData_2->SystemStatus <= S_COMPLETE) ||
  1347. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1348. chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1349. led_color.Connect_1_Green = COLOR_MIN_LV;
  1350. led_color.Connect_1_Blue = _colorBuf;
  1351. led_color.Connect_1_Red = COLOR_MIN_LV;
  1352. led_color.Connect_2_Green = COLOR_MIN_LV;
  1353. led_color.Connect_2_Blue = _colorBuf;
  1354. led_color.Connect_2_Red = COLOR_MIN_LV;
  1355. } else if ( chargingData_1->SystemStatus == S_UPDATE ) {
  1356. led_color.Connect_1_Green = COLOR_MIN_LV;
  1357. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1358. led_color.Connect_1_Red = _colorBuf;
  1359. }
  1360. } else {
  1361. if (chargingData_1->SystemStatus == S_BOOTING ||
  1362. chargingData_1->SystemStatus == S_IDLE ||
  1363. chargingData_1->SystemStatus == S_RESERVATION ||
  1364. chargingData_1->SystemStatus == S_MAINTAIN) {
  1365. if (chargingData_1->IsAvailable == NO) { //For Audi
  1366. led_color.Connect_1_Green = COLOR_MIN_LV;
  1367. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1368. led_color.Connect_1_Red = _colorBuf;
  1369. } else {
  1370. #if defined DD360Audi
  1371. led_color.Connect_1_Green = _colorBuf;
  1372. led_color.Connect_1_Blue = _colorBuf;
  1373. led_color.Connect_1_Red = _colorBuf;
  1374. #else
  1375. led_color.Connect_1_Green = _colorBuf;
  1376. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1377. led_color.Connect_1_Red = COLOR_MIN_LV;
  1378. #endif
  1379. }
  1380. } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
  1381. chargingData_1->SystemStatus <= S_COMPLETE) ||
  1382. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1383. chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1384. led_color.Connect_1_Green = COLOR_MIN_LV;
  1385. led_color.Connect_1_Blue = _colorBuf;
  1386. led_color.Connect_1_Red = COLOR_MIN_LV;
  1387. }else if ( chargingData_1->SystemStatus == S_UPDATE ) {
  1388. led_color.Connect_1_Green = COLOR_MIN_LV;
  1389. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1390. led_color.Connect_1_Red = _colorBuf;
  1391. }
  1392. // --------------------------------------------------------------------------
  1393. if (chargingData_2->SystemStatus == S_BOOTING ||
  1394. chargingData_2->SystemStatus == S_IDLE ||
  1395. chargingData_2->SystemStatus == S_RESERVATION ||
  1396. chargingData_2->SystemStatus == S_MAINTAIN) {
  1397. if (chargingData_2->IsAvailable == NO) {
  1398. led_color.Connect_2_Green = COLOR_MIN_LV;
  1399. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1400. led_color.Connect_2_Red = _colorBuf;
  1401. } else {
  1402. #if defined DD360Audi
  1403. led_color.Connect_2_Green = _colorBuf;
  1404. led_color.Connect_2_Blue = _colorBuf;
  1405. led_color.Connect_2_Red = _colorBuf;
  1406. #else
  1407. led_color.Connect_2_Green = _colorBuf;
  1408. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1409. led_color.Connect_2_Red = COLOR_MIN_LV;
  1410. #endif
  1411. }
  1412. } else if ((chargingData_2->SystemStatus >= S_AUTHORIZING &&
  1413. chargingData_2->SystemStatus <= S_COMPLETE) ||
  1414. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1415. chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1416. led_color.Connect_2_Green = COLOR_MIN_LV;
  1417. led_color.Connect_2_Blue = _colorBuf;
  1418. led_color.Connect_2_Red = COLOR_MIN_LV;
  1419. }else if ( chargingData_2->SystemStatus == S_UPDATE ) {
  1420. led_color.Connect_2_Green = COLOR_MIN_LV;
  1421. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1422. led_color.Connect_2_Red = _colorBuf;
  1423. }
  1424. }
  1425. }
  1426. if (_checkLedChanged > 0) {
  1427. if (Config_Led_Color(Uart5Fd, ADDR_LED, &led_color) == PASS) {
  1428. _checkLedChanged--;
  1429. cur_led_color.Connect_1_Red = led_color.Connect_1_Red;
  1430. cur_led_color.Connect_1_Green = led_color.Connect_1_Green;
  1431. cur_led_color.Connect_1_Blue = led_color.Connect_1_Blue;
  1432. cur_led_color.Connect_2_Red = led_color.Connect_2_Red;
  1433. cur_led_color.Connect_2_Green = led_color.Connect_2_Green;
  1434. cur_led_color.Connect_2_Blue = led_color.Connect_2_Blue;
  1435. }
  1436. } else if (IsNoneMatchLedColor()) {
  1437. _checkLedChanged = 3;
  1438. }
  1439. }
  1440. static void LEDBoardSelfTest(void)
  1441. {
  1442. // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
  1443. if (ShmLedModuleData->SelfTest_Comp == YES) {
  1444. return;
  1445. }
  1446. #if defined DD360 ||defined DD360Audi
  1447. GetFwAndHwVersion_Led();
  1448. sleep(1);
  1449. gettimeofday(&_led_priority_time, NULL);
  1450. return;
  1451. #endif //defined DD360 || defined DD360Audi
  1452. // 自檢階段
  1453. if (pSysInfo->SelfTestSeq <= _STEST_PSU_CAP) {
  1454. GetFwAndHwVersion_Led();
  1455. sleep(1);
  1456. gettimeofday(&_led_priority_time, NULL);
  1457. } else {
  1458. // 自檢階段沒有問到版號
  1459. if (pAlarmCode->AlarmEvents.bits.LedboardStestFail == NO) {
  1460. pAlarmCode->AlarmEvents.bits.LedboardStestFail = YES;
  1461. }
  1462. }
  1463. }
  1464. static void LEDBoardProcess(void)
  1465. {
  1466. //struct ChargingInfoData *pDcChargingInfo0 = NULL;
  1467. //struct ChargingInfoData *pDcChargingInfo1 = NULL;
  1468. if (ShmLedModuleData->SelfTest_Comp == NO) {
  1469. return;
  1470. }
  1471. if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
  1472. //if (pSysConfig->TotalConnectorCount == 1) {
  1473. // pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
  1474. // SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
  1475. //} else if (pSysConfig->TotalConnectorCount == 2) {
  1476. // pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
  1477. // pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
  1478. // SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
  1479. //}
  1480. SetLedColor();
  1481. gettimeofday(&_led_priority_time, NULL);
  1482. }
  1483. }
  1484. void RelayBoardTask(int uartFD)
  1485. {
  1486. bool isRelayBypass = false;
  1487. pid_t pid = fork();
  1488. if (pid == 0) {
  1489. bool isCharging = false;
  1490. bool isStopChargingCount = false;
  1491. uint8_t i = 0;
  1492. int isContinue = 1;
  1493. struct ChargingInfoData *pDcChargingInfo = NULL;
  1494. //share memory mapping
  1495. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1496. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1497. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1498. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  1499. ShmPsuData = (struct PsuData *)GetShmPsuData();
  1500. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1501. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1502. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1503. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  1504. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  1505. Uart5Fd = uartFD;
  1506. for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1507. {
  1508. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1509. if(pDcChargingInfo->PantographFlag == YES)
  1510. {
  1511. isRelayBypass = true;
  1512. }
  1513. }
  1514. //relay init
  1515. if(isRelayBypass == false)
  1516. {
  1517. outputRelayInit(uartFD);
  1518. }
  1519. while (isContinue) {
  1520. if(IsRelayProcessNeedPause() == true)
  1521. {
  1522. sleep(1);
  1523. continue;
  1524. }
  1525. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  1526. if (ShmRelayModuleData->SelfTest_Comp == NO && isRelayBypass == false) {
  1527. GetFwAndHwVersion_Relay();
  1528. SetModelName_Relay(); //DS60-120 add
  1529. SetRtcData_Relay();
  1530. sleep(1);
  1531. }
  1532. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  1533. fanBoardSelfTest();
  1534. #endif //NO_FAN_BOARD
  1535. #if !defined DD360ComBox
  1536. LEDBoardSelfTest();
  1537. #endif //defined DD360ComBox
  1538. if (ShmRelayModuleData->SelfTest_Comp == YES && isRelayBypass == false)
  1539. {
  1540. // ==============優先權最高 10 ms ==============
  1541. // 輸出電壓
  1542. GetPersentOutputVol();
  1543. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1544. // 三相輸入電壓
  1545. GetPresentInputVol();
  1546. #endif //!defined DD360 && !defined DD360Audi
  1547. // 讀取當前 AC relay 狀態
  1548. regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1549. GetRelayOutputStatus();
  1550. // Cable check (Get)
  1551. GetGfdAdc();
  1552. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1553. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1554. // Cable check (Set)
  1555. CableCheckDetected(i);
  1556. // check k1 k2 relay 狀態
  1557. CheckK1K2RelayOutput(i);
  1558. // 依據當前各槍的狀態選擇 搭上/放開 Relay
  1559. SetK1K2RelayStatus(i);
  1560. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1561. if (pSysConfig->PhaseLossPolicy == YES) {
  1562. CheckPhaseLossStatus(i);
  1563. }
  1564. CheckAcInputOvpStatus(i);
  1565. #endif //!defined DD360 && !defined DD360Audi
  1566. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  1567. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  1568. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  1569. //pDcChargingInfo->RelayWeldingCheck = NO;
  1570. //_isRelayWelding[i] = NO;
  1571. _isOvpChkTimeFlag[i] = NO;
  1572. //ResetDetAlarmStatus(i); //DS60-120 add
  1573. }
  1574. if (pDcChargingInfo->SystemStatus == S_BOOTING ||
  1575. (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  1576. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  1577. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1578. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1579. pSysInfo->WaitForPlugit == YES ||
  1580. (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
  1581. pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)
  1582. ) {
  1583. pDcChargingInfo->IsReadyToCharging = YES;
  1584. isCharging = true;
  1585. // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
  1586. //if (pDcChargingInfo->Type == _Type_GB) {
  1587. // if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  1588. // pDcChargingInfo->RelayWeldingCheck == NO) {
  1589. // CheckRelayWeldingStatus(i);
  1590. // }
  1591. //} else {
  1592. //pDcChargingInfo->RelayWeldingCheck = YES;
  1593. //}
  1594. if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  1595. CheckOutputPowerOverCarReq(i);
  1596. //CheckOutputVolNoneMatchFire(i);
  1597. }
  1598. /*else {
  1599. _isOutputNoneMatch[i] = NO;
  1600. }*/
  1601. } else {
  1602. pDcChargingInfo->IsReadyToCharging = NO;
  1603. }
  1604. }
  1605. // 橋接 relay
  1606. SetParalleRelayStatus();
  1607. // 搭上 AC Contactor
  1608. //if (isCharging) {
  1609. // outputRelay.relay_event.bits.AC_Contactor = YES;
  1610. //} else {
  1611. // outputRelay.relay_event.bits.AC_Contactor = NO;
  1612. //}
  1613. if (isCharging ||
  1614. (ShmPsuData->Work_Step >= _TEST_MODE &&
  1615. ShmPsuData->Work_Step <= _TEST_MODE)) {
  1616. isStopChargingCount = false;
  1617. outputRelay.relay_event.bits.AC_Contactor = YES;
  1618. } else {
  1619. if (!isStopChargingCount) {
  1620. gettimeofday(&_close_ac_contactor, NULL);
  1621. isStopChargingCount = true;
  1622. } else {
  1623. if ((outputRelay.relay_event.bits.AC_Contactor == YES &&
  1624. GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
  1625. outputRelay.relay_event.bits.AC_Contactor = NO;
  1626. }
  1627. }
  1628. }
  1629. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  1630. outputRelay.relay_event.bits.AC_Contactor = NO;
  1631. }
  1632. if (pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == ABNORMAL) {
  1633. RunForceStopProcess();
  1634. outputRelay.relay_event.bits.AC_Contactor = NO;
  1635. }
  1636. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  1637. outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
  1638. }
  1639. // 搭上/鬆開 Relay
  1640. if (IsNoneMatchRelayStatus()) {
  1641. if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
  1642. //regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1643. //regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  1644. //regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  1645. //regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  1646. //regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  1647. //regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  1648. //regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  1649. //regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  1650. //MatchRelayStatus();
  1651. //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 ",
  1652. // regRelay.relay_event.bits.AC_Contactor,
  1653. // regRelay.relay_event.bits.Gun1_P,
  1654. // regRelay.relay_event.bits.Gun1_N,
  1655. // regRelay.relay_event.bits.Gun2_P,
  1656. // regRelay.relay_event.bits.Gun2_N,
  1657. // regRelay.relay_event.bits.CCS_Precharge,
  1658. // regRelay.relay_event.bits.Gun1_Parallel_P,
  1659. // regRelay.relay_event.bits.Gun1_Parallel_N);
  1660. }
  1661. }
  1662. }
  1663. else if(isRelayBypass == true)
  1664. {
  1665. for(i = 0; i < pSysConfig->TotalConnectorCount; i++)
  1666. {
  1667. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1668. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  1669. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  1670. pDcChargingInfo->SystemStatus == S_MAINTAIN)
  1671. {
  1672. _isOvpChkTimeFlag[i] = NO;
  1673. }
  1674. if (pDcChargingInfo->SystemStatus == S_CHARGING)
  1675. {
  1676. CheckOutputPowerOverCarReq(i);
  1677. }
  1678. }
  1679. }
  1680. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  1681. fanBoardPorcess();
  1682. #endif //NO_FAN_BOARD
  1683. #if !defined DD360ComBox
  1684. LEDBoardProcess();
  1685. #endif //defined DD360ComBox
  1686. usleep(10000);
  1687. }
  1688. }
  1689. }