RelayBoard.c 81 KB

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