RelayBoard.c 76 KB

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