RelayBoard.c 77 KB

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