RelayBoard.c 79 KB

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