RelayBoard.c 77 KB

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