RelayBoard.c 77 KB

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