RelayBoard.c 78 KB

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