RelayBoard.c 84 KB

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