Module_InternalComm.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/wireless.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. #include <unistd.h>
  16. #include <stdarg.h>
  17. #include <stdio.h> /*標準輸入輸出定義*/
  18. #include <stdlib.h> /*標準函數庫定義*/
  19. #include <unistd.h> /*Unix 標準函數定義*/
  20. #include <fcntl.h> /*檔控制定義*/
  21. #include <termios.h> /*PPSIX 終端控制定義*/
  22. #include <errno.h> /*錯誤號定義*/
  23. #include <errno.h>
  24. #include <string.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include <math.h>
  29. #include "../../define.h"
  30. #include "Config.h"
  31. #include "internalComm.h"
  32. #include <stdbool.h>
  33. #define Debug
  34. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  35. #define PASS 1
  36. #define FAIL -1
  37. #define YES 1
  38. #define NO 0
  39. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  40. struct StatusCodeData *ShmStatusCodeData;
  41. struct FanModuleData *ShmFanModuleData;
  42. struct RelayModuleData *ShmRelayModuleData;
  43. struct CHAdeMOData *ShmCHAdeMOData;
  44. struct CcsData *ShmCcsData;
  45. #define VIN_MAX_VOLTAGE 250 // 大於該值 : OVP
  46. #define VIN_MIN_VOLTAGE 170 // 小於該值 : UVP
  47. #define VIN_DROP_VOLTAGE 150 // 小於該值 : ac drop
  48. #define VOUT_MAX_VOLTAGE 750
  49. #define VOUT_MIN_VOLTAGE 150
  50. #define IOUT_MAX_CURRENT 50
  51. #define MAX_FAN_SPEED 6000
  52. #define MIN_FAN_SPEED 300
  53. #define GFD_VALUE 500
  54. // 最小切換 Relay 電壓
  55. #define SELF_TO_CHANGE_RELAY_STATUS 600
  56. // 透過電壓確認 Relay 是否搭上的依據電壓
  57. #define CHECK_RELAY_STATUS 300
  58. #define CHECK_RELAY_STATUS_GAP 100
  59. // 安全在停止充電程序中斷開 Relay 的電流
  60. #define SEFETY_SWITCH_RELAY_CUR 20
  61. // 確認 Relay Welding 電壓
  62. #define RELAY_WELDING_DET 300
  63. byte gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  64. // 槍資訊
  65. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  66. byte gfdChkFailCount[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  67. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
  68. int Uart5Fd;
  69. char *relayRs485PortName = "/dev/ttyS5";
  70. unsigned short fanSpeedSmoothValue = 100;
  71. struct timeval _priority_time;
  72. Ver ver;
  73. PresentInputVoltage inputVoltage;
  74. PresentOutputVoltage outputVoltage;
  75. FanSpeed fanSpeed;
  76. Temperature temperature;
  77. AuxPower auxPower;
  78. Gfd gfd_adc;
  79. Gfd_config gfd_config;
  80. //Gpio_in gpio_in;
  81. //Gpio_out gpio_out;
  82. Relay outputRelay;
  83. Relay regRelay;
  84. bool isStopChargingCount = false;
  85. bool isSystemBooting = false;
  86. struct timeval _close_ac_contactor;
  87. int DiffTimeb(struct timeb ST, struct timeb ET)
  88. {
  89. //return milli-second
  90. unsigned int StartTime,StopTime;
  91. StartTime=(unsigned int)ST.time;
  92. StopTime=(unsigned int)ET.time;
  93. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  94. }
  95. unsigned short MaxValue(unsigned short value1, unsigned short value2)
  96. {
  97. return value1 >= value2 ? value1 : value2;
  98. }
  99. //==========================================
  100. // Communication Function
  101. //==========================================
  102. // *******************Fan*******************
  103. void GetFwAndHwVersion_Fan()
  104. {
  105. if(Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
  106. {
  107. // FanModuleData
  108. strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
  109. // SystemInfo
  110. strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ver.Version_FW);
  111. printf("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
  112. }
  113. if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
  114. {
  115. // SystemInfo
  116. strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
  117. printf("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
  118. }
  119. }
  120. void GetFanSpeed()
  121. {
  122. printf("Get fan board speed \n");
  123. if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS)
  124. {
  125. ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
  126. ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
  127. ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
  128. ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
  129. printf("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
  130. printf("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
  131. printf("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
  132. printf("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
  133. // Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
  134. //SysInfoData (SystemFanRotaSpeed)
  135. }
  136. }
  137. // 5V 12V 24V 48V
  138. void GetAuxPower()
  139. {
  140. if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS)
  141. {
  142. ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
  143. ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
  144. //ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
  145. //ShmSysConfigAndInfo->SysInfo.AuxPower5V = auxPower.voltage[6];
  146. // aux power voltage
  147. //printf("aux1 = %x, \n", auxPower.voltage[0]);
  148. //printf("aux2 = %x, \n", auxPower.voltage[1]);
  149. }
  150. }
  151. void SetFanModuleSpeed()
  152. {
  153. // 調整風扇速度要漸進式 : 500 rpm/p
  154. ShmFanModuleData->SetFan1Speed = ShmFanModuleData->SetFan2Speed = ShmFanModuleData->SetFan3Speed = ShmFanModuleData->SetFan4Speed = 2000;
  155. if (ShmFanModuleData->PresentFan1Speed != ShmFanModuleData->SetFan1Speed ||
  156. ShmFanModuleData->PresentFan2Speed != ShmFanModuleData->SetFan2Speed ||
  157. ShmFanModuleData->PresentFan3Speed != ShmFanModuleData->SetFan3Speed ||
  158. ShmFanModuleData->PresentFan4Speed != ShmFanModuleData->SetFan4Speed)
  159. {
  160. FanSpeed _fanSpeed;
  161. unsigned short speed = ShmFanModuleData->PresentFan1Speed + fanSpeedSmoothValue;
  162. if (speed >= ShmFanModuleData->SetFan1Speed)
  163. speed = ShmFanModuleData->SetFan1Speed;
  164. _fanSpeed.speed[0] = speed & 0xff;
  165. _fanSpeed.speed[1] = (speed >> 8) & 0xff;
  166. speed = ShmFanModuleData->SetFan2Speed;
  167. _fanSpeed.speed[2] = speed & 0xff;
  168. _fanSpeed.speed[3] = (speed >> 8) & 0xff;
  169. speed = ShmFanModuleData->SetFan3Speed;
  170. _fanSpeed.speed[4] = speed & 0xff;
  171. _fanSpeed.speed[5] = (speed >> 8) & 0xff;
  172. speed = ShmFanModuleData->SetFan4Speed;
  173. _fanSpeed.speed[6] = speed & 0xff;
  174. _fanSpeed.speed[7] = (speed >> 8) & 0xff;
  175. if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS)
  176. {
  177. printf("successfully Fan\n");
  178. }
  179. }
  180. }
  181. // *******************Relay*******************
  182. void GetFwAndHwVersion_Relay()
  183. {
  184. if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
  185. {
  186. // FanModuleData
  187. strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
  188. // SystemInfo
  189. strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
  190. printf("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
  191. }
  192. if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
  193. {
  194. // SystemInfo
  195. strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
  196. printf("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
  197. }
  198. }
  199. void GetTemperature_Relay()
  200. {
  201. memset(temperature.temperature, 0, ARRAY_SIZE(temperature.temperature));
  202. if (Query_Temperature(Uart5Fd, Addr.Relay, &temperature) == PASS)
  203. {
  204. // relay temp
  205. printf("Relay temp = %d,%d,%d,%d,%d,%d,%d,%d \n",
  206. (-60 + temperature.temperature[0]),
  207. (-60 + temperature.temperature[1]),
  208. (-60 + temperature.temperature[2]),
  209. (-60 + temperature.temperature[3]),
  210. (-60 + temperature.temperature[4]),
  211. (-60 + temperature.temperature[5]),
  212. (-60 + temperature.temperature[6]),
  213. (-60 + temperature.temperature[7]));
  214. }
  215. }
  216. // AC 三相輸入電壓
  217. void GetPresentInputVol()
  218. {
  219. if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS)
  220. {
  221. // resolution : 0.1
  222. // printf("InputVoltageR = %f \n", inputVoltage.L1N_L12);
  223. // printf("InputVoltageS = %f \n", inputVoltage.L2N_L23);
  224. // printf("InputVoltageT = %f \n", inputVoltage.L3N_L31);
  225. ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
  226. ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
  227. ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
  228. //********************************************************************************************************//
  229. // VIN < 170
  230. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE)
  231. {
  232. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = 0x01;
  233. }
  234. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE)
  235. {
  236. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = 0x01;
  237. }
  238. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE)
  239. {
  240. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = 0x01;
  241. }
  242. //********************************************************************************************************//
  243. // VIN > 250
  244. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE)
  245. {
  246. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = 0x01;
  247. }
  248. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE)
  249. {
  250. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = 0x01;
  251. }
  252. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE)
  253. {
  254. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = 0x01;
  255. }
  256. //********************************************************************************************************//
  257. // VIN < 150
  258. if (inputVoltage.L1N_L12 < VIN_DROP_VOLTAGE)
  259. {
  260. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = 0x01;
  261. }
  262. if (inputVoltage.L2N_L23 < VIN_DROP_VOLTAGE)
  263. {
  264. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop = 0x01;
  265. }
  266. if (inputVoltage.L3N_L31 < VIN_DROP_VOLTAGE)
  267. {
  268. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop = 0x01;
  269. }
  270. //********************************************************************************************************//
  271. // 150 <= VIN < 160
  272. // if (inputVoltage.L1N_L12 >= VIN_MIN_VOLTAGE && inputVoltage.L1N_L12 <= VIN_LOW_VOLTAGE)
  273. // {
  274. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = 0x00;
  275. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = 0x00;
  276. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = 0x00;
  277. // }
  278. // if (inputVoltage.L2N_L23 >= VIN_MIN_VOLTAGE && inputVoltage.L2N_L23 <= VIN_LOW_VOLTAGE)
  279. // {
  280. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = 0x00;
  281. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = 0x00;
  282. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop = 0x00;
  283. // }
  284. // if (inputVoltage.L3N_L31 >= VIN_MIN_VOLTAGE && inputVoltage.L3N_L31 <= VIN_LOW_VOLTAGE)
  285. // {
  286. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = 0x00;
  287. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = 0x00;
  288. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop = 0x00;
  289. // }
  290. }
  291. }
  292. // 左右槍的 Relay 前後的輸出電壓
  293. void GetPersentOutputVol()
  294. {
  295. if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS)
  296. {
  297. // printf("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
  298. // printf("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
  299. // printf("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
  300. // printf("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
  301. ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  302. ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  303. ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  304. ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  305. //printf("FuseChargingVoltage 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
  306. //printf("FuseChargingVoltage 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
  307. for (int index = 0; index < gunCount; index++)
  308. {
  309. if (index == 0)
  310. {
  311. _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
  312. _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  313. }
  314. else if (index == 1)
  315. {
  316. _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
  317. _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  318. }
  319. unsigned short Ovp = 0;
  320. unsigned short Ocp = 0;
  321. //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] // 最大輸出電壓與電池電壓最大值
  322. //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ] // 最大輸出電流與需求電流最小值
  323. if (_chargingData[index]->Type == _Type_Chademo)
  324. {
  325. Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
  326. Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
  327. if (_chargingData[index]->FireChargingVoltage >= Ovp)
  328. {
  329. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = 0x01;
  330. }
  331. if (_chargingData[index]->PresentChargingCurrent >= Ocp)
  332. {
  333. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOCP = 0x01;
  334. }
  335. }
  336. else if (_chargingData[index]->Type == _Type_CCS)
  337. {
  338. }
  339. }
  340. }
  341. }
  342. // relay 的狀態
  343. void CheckRelayOutput(byte index)
  344. {
  345. if (index == 0)
  346. {
  347. if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES)
  348. _chargingData[0]->RelayK1K2Status = YES;
  349. else
  350. _chargingData[0]->RelayK1K2Status = NO;
  351. if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
  352. _chargingData[0]->RelayKPK2Status = YES;
  353. else
  354. _chargingData[0]->RelayKPK2Status = NO;
  355. }
  356. else if (index == 1)
  357. {
  358. if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
  359. _chargingData[1]->RelayK1K2Status = YES;
  360. else
  361. _chargingData[1]->RelayK1K2Status = NO;
  362. if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
  363. _chargingData[1]->RelayKPK2Status = YES;
  364. else
  365. _chargingData[1]->RelayKPK2Status = NO;
  366. }
  367. }
  368. void GetGfdAdc(byte index)
  369. {
  370. // 0 : wait. 1 : pass, 2 : fail
  371. if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS)
  372. {
  373. printf("Resister = %d, voltage = %f, result = %d +++++++++++++++++++++++++++++++++++++++++++++++++++ \n",
  374. gfd_adc.Resister,
  375. gfd_adc.voltage,
  376. gfd_adc.result);
  377. _chargingData[index]->GroundFaultStatus = gfd_adc.result;
  378. }
  379. else
  380. {
  381. printf("Query_Gfd_Adc return fail. \n");
  382. }
  383. }
  384. void SetGfdConfig(byte index)
  385. {
  386. gfd_config.reqVol = _chargingData[index]->EvBatterytargetVoltage;
  387. gfd_config.resister = GFD_VALUE;
  388. //printf("GFD Vol = %f, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
  389. if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config))
  390. {
  391. // printf("Set reqVol = %f, resister = %d \n",
  392. // gfd_config.reqVol,
  393. // gfd_config.resister);
  394. }
  395. }
  396. void SetRelayModuleFanSpeed()
  397. {
  398. // 調整風扇速度要漸進式 : 100 rpm/p
  399. if (ShmFanModuleData->PresentFan1Speed != ShmFanModuleData->SetFan1Speed)
  400. {
  401. FanSpeed _fanSpeed;
  402. unsigned short speed = 0;
  403. if (ShmFanModuleData->SetFan1Speed > ShmFanModuleData->PresentFan1Speed)
  404. {
  405. speed = ShmFanModuleData->PresentFan1Speed + fanSpeedSmoothValue;
  406. if (speed >= ShmFanModuleData->SetFan1Speed)
  407. speed = ShmFanModuleData->SetFan1Speed;
  408. }
  409. else
  410. {
  411. speed = ShmFanModuleData->PresentFan1Speed - fanSpeedSmoothValue;
  412. if (speed <= 0)
  413. speed = ShmFanModuleData->SetFan1Speed;
  414. }
  415. _fanSpeed.speed[0] = speed & 0xff;
  416. _fanSpeed.speed[1] = (speed >> 8) & 0xff;
  417. ShmFanModuleData->PresentFan1Speed = speed;
  418. Config_Fan_Speed(Uart5Fd, Addr.Relay, &_fanSpeed);
  419. }
  420. }
  421. void GetRelayModuleFanSpeed()
  422. {
  423. printf("Get fan board speed \n");
  424. if (Query_Fan_Speed(Uart5Fd, Addr.Relay, &fanSpeed) == PASS)
  425. {
  426. ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0] + (fanSpeed.speed[1] >> 8);
  427. printf("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
  428. }
  429. }
  430. //==========================================
  431. // Common Function
  432. //==========================================
  433. void SetK1K2RelayStatus(byte index)
  434. {
  435. // 為安全起見~ 切換該槍 relay 的條件一是 relay 前後電壓須都要小於 10V
  436. // 除了做完 CCS 端的 Precharge,因為在做完 Precharge後,車端會直接直接準備拉載,輸出並不會降低
  437. // 另一個是 Complete 狀態,因為火線上的電壓有可能是來自車端電池電壓,導致火線上的電壓並不會降下來
  438. // 於此同時,只要判斷火線上的電流低於 1A 來判斷 Relay 可鬆開
  439. if (_chargingData[index]->SystemStatus != S_CCS_PRECHARGE_ST1 &&
  440. _chargingData[index]->SystemStatus != S_COMPLETE )
  441. {
  442. if (index == 0 &&
  443. (ShmRelayModuleData->Gun1FuseOutputVolt > SELF_TO_CHANGE_RELAY_STATUS ||
  444. ShmRelayModuleData->Gun1RelayOutputVolt > SELF_TO_CHANGE_RELAY_STATUS))
  445. {
  446. return;
  447. }
  448. else if (index == 1 &&
  449. (ShmRelayModuleData->Gun2FuseOutputVolt > SELF_TO_CHANGE_RELAY_STATUS ||
  450. ShmRelayModuleData->Gun2RelayOutputVolt > SELF_TO_CHANGE_RELAY_STATUS))
  451. {
  452. return;
  453. }
  454. }
  455. // 雙槍時,這個要改
  456. if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE)
  457. {
  458. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  459. if (_chargingData[index]->Evboard_id == 0x01)
  460. {
  461. outputRelay.relay_event.bits.Gun1_P = 0x00;
  462. outputRelay.relay_event.bits.Gun1_N = 0x00;
  463. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  464. }
  465. else if (_chargingData[index]->Evboard_id == 0x02)
  466. {
  467. outputRelay.relay_event.bits.Gun2_P = 0x00;
  468. outputRelay.relay_event.bits.Gun2_N = 0x00;
  469. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  470. }
  471. }
  472. else if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_CHARGING))
  473. {
  474. if(_chargingData[index]->Evboard_id == 0x01)
  475. {
  476. // 先搭 D-
  477. if (outputRelay.relay_event.bits.Gun1_N == 0x00)
  478. outputRelay.relay_event.bits.Gun1_N = 0x01;
  479. else
  480. outputRelay.relay_event.bits.Gun1_P = 0x01;
  481. }
  482. else if (_chargingData[index]->Evboard_id == 0x02)
  483. {
  484. // 先搭 D-
  485. if (outputRelay.relay_event.bits.Gun2_N == 0x00)
  486. outputRelay.relay_event.bits.Gun2_N = 0x01;
  487. else
  488. outputRelay.relay_event.bits.Gun2_P = 0x01;
  489. }
  490. }
  491. else if (_chargingData[index]->SystemStatus == S_COMPLETE)
  492. {
  493. //if (_chargingData[index]->PresentChargingCurrent <= SEFETY_SWITCH_RELAY_CUR || _chargingData[index]->StopChargeFlag)
  494. if (_chargingData[index]->PresentChargingCurrent <= SEFETY_SWITCH_RELAY_CUR)
  495. {
  496. if (_chargingData[index]->Evboard_id == 0x01)
  497. {
  498. // 先釋放 D+
  499. if (outputRelay.relay_event.bits.Gun1_P == 0x01)
  500. outputRelay.relay_event.bits.Gun1_P = 0x00;
  501. else
  502. outputRelay.relay_event.bits.Gun1_N = 0x00;
  503. }
  504. else if (_chargingData[index]->Evboard_id == 0x02)
  505. {
  506. // 先釋放 D+
  507. if (outputRelay.relay_event.bits.Gun2_P == 0x01)
  508. outputRelay.relay_event.bits.Gun2_P = 0x00;
  509. else
  510. outputRelay.relay_event.bits.Gun2_N = 0x00;
  511. }
  512. }
  513. }
  514. else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0)
  515. {
  516. if (_chargingData[index]->Evboard_id == 0x01)
  517. {
  518. // 先釋放 D+,在搭 Precharge Relay
  519. if (outputRelay.relay_event.bits.CCS_Precharge == 0x00)
  520. outputRelay.relay_event.bits.CCS_Precharge = 0x01;
  521. else
  522. outputRelay.relay_event.bits.Gun1_P = 0x00;
  523. }
  524. else if (_chargingData[index]->Evboard_id == 0x02)
  525. {
  526. // 先釋放 D+,再搭 Precharge Relay
  527. if (outputRelay.relay_event.bits.CCS_Precharge == 0x00)
  528. outputRelay.relay_event.bits.CCS_Precharge = 0x01;
  529. else
  530. outputRelay.relay_event.bits.Gun2_P = 0x00;
  531. }
  532. }
  533. else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1)
  534. {
  535. if (_chargingData[index]->Evboard_id == 0x01)
  536. {
  537. // 先搭上 D+,再釋放 Precharge Relay
  538. if (outputRelay.relay_event.bits.Gun1_P == 0x00)
  539. outputRelay.relay_event.bits.Gun1_P = 0x01;
  540. else
  541. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  542. }
  543. else if (_chargingData[index]->Evboard_id == 0x02)
  544. {
  545. // 先釋放 D+,在搭 Precharge Relay
  546. if (outputRelay.relay_event.bits.Gun2_P == 0x00)
  547. outputRelay.relay_event.bits.Gun2_P = 0x01;
  548. else
  549. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  550. }
  551. }
  552. }
  553. //==========================================
  554. // Init all share memory
  555. //==========================================
  556. int InitShareMemory()
  557. {
  558. int result = PASS;
  559. int MeterSMId;
  560. //creat ShmSysConfigAndInfo
  561. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  562. {
  563. #ifdef SystemLogMessage
  564. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  565. #endif
  566. result = FAIL;
  567. }
  568. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  569. {
  570. #ifdef SystemLogMessage
  571. DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
  572. #endif
  573. result = FAIL;
  574. }
  575. //creat ShmStatusCodeData
  576. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  577. {
  578. #ifdef SystemLogMessage
  579. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  580. #endif
  581. result = FAIL;
  582. }
  583. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  584. {
  585. #ifdef SystemLogMessage
  586. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  587. #endif
  588. result = FAIL;
  589. }
  590. //creat ShmFanModuleData
  591. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), 0777)) < 0)
  592. {
  593. #ifdef SystemLogMessage
  594. DEBUG_ERROR("shmget ShmFanModuleData NG\n");
  595. #endif
  596. result = FAIL;
  597. }
  598. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  599. {
  600. #ifdef SystemLogMessage
  601. DEBUG_ERROR("shmat ShmFanModuleData NG\n");
  602. #endif
  603. result = FAIL;
  604. }
  605. memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
  606. //creat ShmRelayModuleData
  607. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), 0777)) < 0)
  608. {
  609. #ifdef SystemLogMessage
  610. DEBUG_ERROR("shmget ShmRelayModuleData NG\n");
  611. #endif
  612. result = FAIL;
  613. }
  614. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  615. {
  616. #ifdef SystemLogMessage
  617. DEBUG_ERROR("shmat ShmRelayModuleData NG\n");
  618. #endif
  619. result = FAIL;
  620. }
  621. if(CHAdeMO_QUANTITY > 0)
  622. {
  623. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
  624. {
  625. #ifdef SystemLogMessage
  626. DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
  627. #endif
  628. return FAIL;
  629. }
  630. else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  631. {
  632. #ifdef SystemLogMessage
  633. DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
  634. #endif
  635. return FAIL;
  636. }
  637. }
  638. if(CCS_QUANTITY > 0)
  639. {
  640. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  641. {
  642. #ifdef SystemLogMessage
  643. DEBUG_ERROR("shmget ShmCcsData NG \n");
  644. #endif
  645. return FAIL;
  646. }
  647. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  648. {
  649. #ifdef SystemLogMessage
  650. DEBUG_ERROR("shmat ShmCcsData NG \n");
  651. #endif
  652. return FAIL;
  653. }
  654. }
  655. return result;
  656. }
  657. int InitComPort()
  658. {
  659. int fd;
  660. struct termios tios;
  661. fd = open(relayRs485PortName, O_RDWR);
  662. if(fd <= 0)
  663. {
  664. #ifdef SystemLogMessage
  665. DEBUG_ERROR("Module_InternalComm. InitComPort NG\n");
  666. #endif
  667. if(ShmStatusCodeData!=NULL)
  668. {
  669. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
  670. }
  671. sleep(5);
  672. return -1;
  673. }
  674. ioctl (fd, TCGETS, &tios);
  675. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  676. tios.c_lflag = 0;
  677. tios.c_iflag = 0;
  678. tios.c_oflag = 0;
  679. tios.c_cc[VMIN]=0;
  680. tios.c_cc[VTIME]=(byte)0; // timeout 0.5 second
  681. tios.c_lflag=0;
  682. tcflush(fd, TCIFLUSH);
  683. ioctl (fd, TCSETS, &tios);
  684. return fd;
  685. }
  686. //================================================
  687. // Main process
  688. //================================================
  689. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  690. {
  691. for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
  692. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
  693. == target) {
  694. chargingData[target] =
  695. &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  696. return true;
  697. }
  698. }
  699. for (byte index = 0; index < CCS_QUANTITY; index++) {
  700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
  701. == target) {
  702. chargingData[target] =
  703. &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  704. return true;
  705. }
  706. }
  707. for (byte index = 0; index < GB_QUANTITY; index++) {
  708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
  709. == target) {
  710. chargingData[target] =
  711. &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  712. return true;
  713. }
  714. }
  715. return false;
  716. }
  717. void Initialization()
  718. {
  719. bool isPass = false;
  720. for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++)
  721. {
  722. outputRelay.relay_event.relay_status[index] = 0x00;
  723. }
  724. while(!isPass)
  725. {
  726. isPass = true;
  727. for (byte _index = 0; _index < gunCount; _index++)
  728. {
  729. if (!FindChargingInfoData(_index, &_chargingData[0]))
  730. {
  731. DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
  732. isPass = false;
  733. break;
  734. }
  735. }
  736. }
  737. memset(&regRelay, 0xFF,sizeof(Relay));
  738. outputRelay.relay_event.bits.AC_Contactor = 0x00;
  739. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  740. outputRelay.relay_event.bits.Gun1_P = 0x00;
  741. outputRelay.relay_event.bits.Gun1_N = 0x00;
  742. outputRelay.relay_event.bits.Gun2_P = 0x00;
  743. outputRelay.relay_event.bits.Gun2_N = 0x00;
  744. Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay);
  745. }
  746. bool IsNoneMatchRelayStatus()
  747. {
  748. bool result = false;
  749. if ((regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
  750. (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
  751. (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
  752. (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
  753. (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
  754. (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N))
  755. {
  756. result = true;
  757. }
  758. return result;
  759. }
  760. void MatchRelayStatus()
  761. {
  762. // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
  763. //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  764. ShmSysConfigAndInfo->SysInfo.AcContactorStatus = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  765. regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  766. regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  767. regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  768. regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  769. regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  770. }
  771. void CableCheckDetected(byte index)
  772. {
  773. // Cable Check
  774. // 當火線上的電壓 = 車端要求的電壓電流
  775. // _chargingData[targetGun]->EvBatterytargetVoltage
  776. // 才可以開始偵測 1s
  777. // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
  778. // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
  779. // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
  780. if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_CHARGING) ||
  781. (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
  782. {
  783. // Cable check
  784. SetGfdConfig(index);
  785. GetGfdAdc(index);
  786. }
  787. }
  788. void CheckPresentAndFireVoltage(byte index)
  789. {
  790. if (_chargingData[index]->PresentChargingVoltage >= 2000 &&
  791. (_chargingData[index]->PresentChargingVoltage >= (_chargingData[index]->FireChargingVoltage - 500)))
  792. {
  793. gfdChkFailCount[index] += 1;
  794. printf("CheckPresentAndFireVoltage occur..Count = %d ........................\n", gfdChkFailCount[index]);
  795. if (gfdChkFailCount[index] >= 10)
  796. {
  797. printf("CheckPresentAndFireVoltage occur..........................\n");
  798. if (_chargingData[index]->Type == _Type_Chademo)
  799. {
  800. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = 0x01;
  801. }
  802. else if (_chargingData[index]->Type == _Type_CCS)
  803. {
  804. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = 0x01;
  805. }
  806. }
  807. }
  808. else
  809. gfdChkFailCount[index] = 0;
  810. }
  811. int main(void)
  812. {
  813. if(InitShareMemory() == FAIL)
  814. {
  815. #ifdef SystemLogMessage
  816. DEBUG_ERROR("InitShareMemory NG\n");
  817. #endif
  818. if(ShmStatusCodeData!=NULL)
  819. {
  820. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  821. }
  822. sleep(5);
  823. return 0;
  824. }
  825. // Open Uart5 for RB
  826. Uart5Fd = InitComPort();
  827. Initialization();
  828. sleep(1);
  829. if(Uart5Fd < 0)
  830. {
  831. printf ("open port error. \n");
  832. return 0;
  833. }
  834. outputRelay.relay_event.bits.AC_Contactor = 0x00;
  835. Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay);
  836. usleep(300000);
  837. // while(1)
  838. // {
  839. // printf("(RB) Get Fw and Hw Ver. \n");
  840. // GetFwAndHwVersion_Relay();
  841. // sleep(1);
  842. // }
  843. //
  844. //
  845. // return FAIL;
  846. gettimeofday(&_priority_time, NULL);
  847. for(;;)
  848. {
  849. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  850. if (ShmRelayModuleData->SelfTest_Comp == NO)
  851. {
  852. printf("(RB) Get Fw and Hw Ver. \n");
  853. GetFwAndHwVersion_Relay();
  854. sleep(1);
  855. }
  856. else if (ShmRelayModuleData->SelfTest_Comp == YES)
  857. {
  858. // ==============優先權最高 10 ms ==============
  859. // 輸出電壓
  860. GetPersentOutputVol();
  861. // 三相輸入電壓
  862. GetPresentInputVol();
  863. bool isCharging = false;
  864. for (int i = 0; i < gunCount; i++)
  865. {
  866. // 如果 PSU 的輸出與火線上的電壓不一致
  867. //CheckPresentAndFireVoltage(i);
  868. // Cable check
  869. //CableCheckDetected(i);
  870. // Relay
  871. CheckRelayOutput(i);
  872. // 依據當前各槍的狀態選擇 搭上/放開 Relay
  873. SetK1K2RelayStatus(i);
  874. if (_chargingData[i]->SystemStatus == S_IDLE)
  875. gfdChkFailCount[i] = 0;
  876. // (_chargingData[i]->SystemStatus == S_IDLE && ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
  877. if (_chargingData[i]->SystemStatus == S_BOOTING ||
  878. (_chargingData[i]->SystemStatus == S_IDLE && ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) ||
  879. (_chargingData[i]->SystemStatus >= S_PREPARNING && _chargingData[i]->SystemStatus <= S_COMPLETE) ||
  880. (_chargingData[i]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[i]->SystemStatus <= S_CCS_PRECHARGE_ST1))
  881. {
  882. if(_chargingData[i]->SystemStatus > S_BOOTING)
  883. isSystemBooting = true;
  884. isCharging = true;
  885. }
  886. }
  887. // 搭上 AC Contactor
  888. // if (isCharging)
  889. // {
  890. // isStopChargingCount = false;
  891. // outputRelay.relay_event.bits.AC_Contactor = YES;
  892. // }
  893. // else
  894. // {
  895. // if (!isStopChargingCount)
  896. // {
  897. // gettimeofday(&_close_ac_contactor, NULL);
  898. // isStopChargingCount = true;
  899. // }
  900. // else
  901. // {
  902. // if (!isSystemBooting ||
  903. // (outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(_close_ac_contactor) / 1000 >= 10000))
  904. // outputRelay.relay_event.bits.AC_Contactor = NO;
  905. // }
  906. // }
  907. if (isCharging)
  908. outputRelay.relay_event.bits.AC_Contactor = 0x01;
  909. else
  910. outputRelay.relay_event.bits.AC_Contactor = 0x00;
  911. // 搭上/鬆開 Relay
  912. // 放開 Relay 之前要先確認輸出的電壓電流是否已經降到某個值
  913. if(IsNoneMatchRelayStatus())
  914. {
  915. if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
  916. {
  917. printf("Match Relay............................ \n");
  918. MatchRelayStatus();
  919. printf("reg relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x \n",
  920. regRelay.relay_event.bits.AC_Contactor,
  921. regRelay.relay_event.bits.Gun1_P,
  922. regRelay.relay_event.bits.Gun1_N,
  923. regRelay.relay_event.bits.Gun2_P,
  924. regRelay.relay_event.bits.Gun2_N,
  925. regRelay.relay_event.bits.CCS_Precharge);
  926. }
  927. }
  928. if (GetTimeoutValue(_priority_time) / 1000 >= 1000)
  929. {
  930. gettimeofday(&_priority_time, NULL);
  931. if (isCharging)
  932. {
  933. if (ShmFanModuleData->PresentFan1Speed < MAX_FAN_SPEED)
  934. {
  935. ShmFanModuleData->SetFan1Speed = MAX_FAN_SPEED;
  936. }
  937. }
  938. else
  939. {
  940. if (ShmFanModuleData->PresentFan1Speed > MIN_FAN_SPEED)
  941. {
  942. ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
  943. }
  944. }
  945. SetRelayModuleFanSpeed();
  946. }
  947. }
  948. usleep(10000);
  949. }
  950. return FAIL;
  951. }