Module_InternalComm.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819
  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 "internalComm.h"
  31. #include <stdbool.h>
  32. #include "Config.h"
  33. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  34. #define PASS 1
  35. #define FAIL -1
  36. #define YES 1
  37. #define NO 0
  38. #define TEN_MINUTES 600
  39. #define ENV_TEMP_MIN 45
  40. #define ENV_TEMP_MAX 50
  41. #define DEFAULT_AC_INDEX 2
  42. #define EQUAL 0
  43. #define COLOR_MAX_LV 100
  44. #define COLOR_MIN_LV 0
  45. #define AC_DEFAULT_VOL 220
  46. #define NO_DEFINE 255
  47. #define NDEFAULT_AC_INDEX 2
  48. #define OVP_UVP_CHK_COUNT 3
  49. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  50. struct StatusCodeData *ShmStatusCodeData;
  51. struct FanModuleData *ShmFanModuleData;
  52. struct RelayModuleData *ShmRelayModuleData[2];
  53. struct LedModuleData *ShmLedModuleData;
  54. struct PsuData *ShmPsuData;
  55. struct OCPP16Data *ShmOCPP16Data;
  56. ChargerInfoData *ShmChargerInfo;
  57. #define VIN_MAX_VOLTAGE_IEC 285 // 大於該值 : OVP
  58. #define VIN_MAX_REV_VOLTAGE_IEC 275 // 小於賦歸 OVP
  59. #define VIN_MIN_VOLTAGE_IEC 160 // 小於該值 : UVP
  60. #define VIN_MIN_REV_VOLTAGE_IEC 170 // 大於賦歸 UVP
  61. #define VIN_MAX_VOLTAGE_UL 315 // 大於該值 : OVP // 美規 (W)
  62. #define VIN_MAX_REV_VOLTAGE_UL 305 // 小於賦歸 OVP
  63. #define VIN_MIN_VOLTAGE_UL 210 // 小於該值 : UVP
  64. #define VIN_MIN_REV_VOLTAGE_UL 220 // 大於賦歸 UVP
  65. #define VIN_DROP_VOLTAGE 150 // 小於該值 : ac drop
  66. #define VOUT_MAX_VOLTAGE 995
  67. #define VOUT_MIN_VOLTAGE 150
  68. #define IOUT_MAX_CURRENT 50
  69. #define MAX_FAN_SPEED 14000
  70. #define MIN_FAN_SPEED 3000
  71. #define NORMAL_FAN_SPEED 7000
  72. // GFD Status
  73. #define GFD_IDLE 0
  74. #define GFD_CABLECHK 1
  75. #define GFD_PRECHARGE 2
  76. #define GFD_CHARGING 3
  77. // LED Intensity (rate)
  78. #define LED_INTENSITY_DARKEST 0.2
  79. #define LED_INTENSITY_MEDIUM 0.6
  80. #define LED_INTENSITY_BRIGHTEST 1
  81. // EE Spec
  82. #define LED_BRIGHTNESS_LV_HIGH 1
  83. #define LED_BRIGHTNESS_LV_MID 0.5
  84. #define LED_BRIGHTNESS_LV_LOW 0.2
  85. // 最小切換 Relay 電壓
  86. #define SELF_TO_CHANGE_RELAY_STATUS 600
  87. // 透過電壓確認 Relay 是否搭上的依據電壓
  88. #define CHECK_RELAY_STATUS 300
  89. #define CHECK_RELAY_STATUS_GAP 100
  90. // 安全在停止充電程序中斷開 Relay 的電流
  91. #define SEFETY_SWITCH_RELAY_CUR 50
  92. // 確認 Relay Welding 電壓
  93. #define RELAY_WELDING_DET 300
  94. byte gunCount;
  95. byte acgunCount;
  96. // 槍資訊
  97. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + GENERAL_GUN_QUANTITY];
  98. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  99. bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  100. struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  101. bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  102. struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  103. byte _threePhaseOvp[3] = {0, 0, 0};
  104. byte _threePhaseUvp[3] = {0, 0, 0};
  105. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
  106. int Uart5Fd;
  107. char *relayRs485PortName = "/dev/ttyS5";
  108. unsigned short fanSpeedSmoothValue = 500;
  109. struct timeval _close_ac_contactor;
  110. struct timeval _priority_time;
  111. struct timeval _led_priority_time;
  112. struct timeval _ac_charging_comp;
  113. struct timeval _ac_preparing;
  114. struct timeb _ac_startChargingTime;
  115. struct timeb _ac_endChargingTime;
  116. unsigned short _setFanSpeed = 0;
  117. float _beforeChargingTotalEnergy = 0.0;
  118. byte _checkLedChanged = 3;
  119. byte _RelaySelfTestOK;
  120. Ver ver;
  121. PresentInputVoltage inputVoltage;
  122. PresentOutputVoltage outputVoltage;
  123. FanSpeed fanSpeed;
  124. Temperature temperature;
  125. AuxPower auxPower;
  126. Gfd gfd_adc;
  127. Gfd_config gfd_config;
  128. Gpio_in gpio_in;
  129. Gpio_out gpio_out;
  130. Relay outputRelay[2];
  131. Relay regRelay[2];
  132. Relay TempRegRelay[2];
  133. Rtc rtc;
  134. Led_Color cur_led_color;
  135. Led_Color led_color;
  136. Ac_Status acStatus;
  137. Ac_Led_Status ledStatus;
  138. Ac_Alarm_code acAlarmCode;
  139. Ac_Charging_energy acChargingEnergy;
  140. Ac_Charging_current acChargingCurrent;
  141. #define AC_OVP 1
  142. #define AC_UVP 2
  143. #define AC_OCP 4
  144. #define AC_OTP 8
  145. #define AC_GMI_FAULT 16
  146. #define AC_CP_ERROR 32
  147. #define AC_AC_LEAKAGE 64
  148. #define AC_DC_LEAKAGE 128
  149. #define AC_SYSTEM_SELFTEST_FAULT 256
  150. #define AC_HANDSHAKE_TIMEOUT 512
  151. #define AC_EMC_STOP 1024
  152. #define AC_RELAY_WELDING 2048
  153. #define AC_GF_MODULE_FAULT 4096
  154. #define AC_SHUTTER_FAULT 8192
  155. #define AC_LOCKER_FAULT 16384
  156. #define AC_POWER_DROP 32768
  157. #define AC_CIRCUIT_SHORT 65536
  158. #define AC_ROTARY_SWITCH_FAULT 131072
  159. #define AC_RELAY_DRIVE_FAULT 262144
  160. int _alarm_code[] = {AC_OVP, AC_UVP, AC_OCP, AC_OTP, AC_GMI_FAULT, AC_CP_ERROR, AC_AC_LEAKAGE
  161. , AC_DC_LEAKAGE, AC_SYSTEM_SELFTEST_FAULT, AC_HANDSHAKE_TIMEOUT, AC_EMC_STOP, AC_RELAY_WELDING
  162. , AC_GF_MODULE_FAULT, AC_SHUTTER_FAULT, AC_LOCKER_FAULT, AC_POWER_DROP, AC_CIRCUIT_SHORT
  163. , AC_ROTARY_SWITCH_FAULT, AC_RELAY_DRIVE_FAULT};
  164. void PRINTF_FUNC(char *string, ...);
  165. int StoreLogMsg(const char *fmt, ...);
  166. unsigned long GetTimeoutValue(struct timeval _sour_time);
  167. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  168. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  169. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  170. unsigned long GetTimeoutValue(struct timeval _sour_time)
  171. {
  172. struct timeval _end_time;
  173. gettimeofday(&_end_time, NULL);
  174. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  175. }
  176. int StoreLogMsg(const char *fmt, ...)
  177. {
  178. char Buf[4096+256];
  179. char buffer[4096];
  180. va_list args;
  181. struct timeb SeqEndTime;
  182. struct tm *tm;
  183. va_start(args, fmt);
  184. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  185. va_end(args);
  186. memset(Buf,0,sizeof(Buf));
  187. ftime(&SeqEndTime);
  188. SeqEndTime.time = time(NULL);
  189. tm=localtime(&SeqEndTime.time);
  190. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
  191. {
  192. sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
  193. tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
  194. printf("%s \n", Buf);
  195. }
  196. else
  197. {
  198. sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  199. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
  200. buffer,
  201. tm->tm_year+1900,tm->tm_mon+1);
  202. system(Buf);
  203. }
  204. return rc;
  205. }
  206. int DiffTimeb(struct timeb ST, struct timeb ET)
  207. {
  208. //return milli-second
  209. unsigned int StartTime, StopTime;
  210. StartTime = (unsigned int) ST.time;
  211. StopTime = (unsigned int) ET.time;
  212. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  213. return (StopTime - StartTime);
  214. }
  215. unsigned short MaxValue(unsigned short value1, unsigned short value2)
  216. {
  217. return value1 >= value2 ? value1 : value2;
  218. }
  219. void PRINTF_FUNC(char *string, ...)
  220. {
  221. va_list args;
  222. char buffer[4096];
  223. va_start(args, string);
  224. vsnprintf(buffer, sizeof(buffer), string, args);
  225. va_end(args);
  226. DEBUG_INFO("%s \n", buffer);
  227. }
  228. //==========================================
  229. // Communication Function
  230. //==========================================
  231. void GetFwAndHwVersion_Fan()
  232. {
  233. if(Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
  234. {
  235. // FanModuleData
  236. strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
  237. // SystemInfo
  238. strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ver.Version_FW);
  239. PRINTF_FUNC("GetFwAndHwVersion_Fan s1 = %s", ver.Version_FW);
  240. }
  241. if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
  242. {
  243. // SystemInfo
  244. strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
  245. PRINTF_FUNC("GetFwAndHwVersion_Fan s2 = %s", ver.Version_HW);
  246. }
  247. }
  248. void GetFwAndHwVersion_Relay()
  249. {
  250. if (Query_FW_Ver(Uart5Fd, Addr.DO360_RC1, &ver) == PASS)
  251. {
  252. // RelayModuleData
  253. strcpy((char *) ShmRelayModuleData[0]->version, ver.Version_FW);
  254. // SystemInfo
  255. strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
  256. PRINTF_FUNC("GetFwAndHwVersion_RC1 s1 = %s", ver.Version_FW);
  257. }
  258. if (Query_HW_Ver(Uart5Fd, Addr.DO360_RC1, &ver) == PASS)
  259. {
  260. // SystemInfo
  261. strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
  262. PRINTF_FUNC("GetFwAndHwVersion_RC1 s2 = %s", ver.Version_HW);
  263. }
  264. }
  265. void GetFwAndHwVersion_Relay2()
  266. {
  267. // DO360 RC2
  268. if (Query_FW_Ver(Uart5Fd, Addr.DO360_RC2, &ver) == PASS)
  269. {
  270. // RelayModuleData
  271. strcpy((char *) ShmRelayModuleData[1]->version, ver.Version_FW);
  272. // SystemInfo
  273. strcpy((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, ver.Version_FW);
  274. PRINTF_FUNC("GetFwAndHwVersion_RC2 s1 = %s", ver.Version_FW);
  275. }
  276. if (Query_HW_Ver(Uart5Fd, Addr.DO360_RC2, &ver) == PASS)
  277. {
  278. // SystemInfo
  279. strcpy((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleHwRev, ver.Version_FW);
  280. PRINTF_FUNC("GetFwAndHwVersion_RC2 s2 = %s", ver.Version_HW);
  281. }
  282. }
  283. void GetFwAndHwVersion_Led()
  284. {
  285. if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
  286. {
  287. // LedModuleData
  288. strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
  289. // SystemInfo
  290. strcpy((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, ver.Version_FW);
  291. PRINTF_FUNC("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
  292. ShmLedModuleData->SelfTest_Comp = YES;
  293. }
  294. else
  295. {
  296. //PRINTF_FUNC("GetFwAndHwVersion_Led fail \n");
  297. }
  298. // if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
  299. // {
  300. // // SystemInfo
  301. // strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
  302. // //PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
  303. // }
  304. }
  305. void GetFwVersion_AC()
  306. {
  307. if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS)
  308. {
  309. ac_chargingInfo[0]->SelfTest_Comp = YES;
  310. strcpy((char *) ac_chargingInfo[0]->version, ver.Version_FW);
  311. }
  312. }
  313. void GetAcModelName()
  314. {
  315. memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
  316. if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS)
  317. {
  318. PRINTF_FUNC("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
  319. }
  320. }
  321. void SetRtcData_Relay(unsigned char index)
  322. {
  323. struct timeb csuTime;
  324. struct tm *tmCSU;
  325. ftime(&csuTime);
  326. tmCSU = localtime(&csuTime.time);
  327. // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
  328. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  329. // tmCSU->tm_sec);
  330. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  331. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  332. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  333. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  334. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  335. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  336. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  337. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  338. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  339. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  340. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  341. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  342. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  343. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  344. if(index == 0)
  345. {
  346. if (Config_Rtc_Data(Uart5Fd, Addr.DO360_RC1, &rtc) == PASS)
  347. {
  348. //PRINTF_FUNC("SetRtc (RB) sucessfully. \n");
  349. }
  350. }
  351. else
  352. {
  353. if (Config_Rtc_Data(Uart5Fd, Addr.DO360_RC2, &rtc) == PASS)
  354. {
  355. //PRINTF_FUNC("SetRtc (RB) sucessfully. \n");
  356. }
  357. }
  358. }
  359. void SetRtcData_Fan()
  360. {
  361. struct timeb csuTime;
  362. struct tm *tmCSU;
  363. ftime(&csuTime);
  364. tmCSU = localtime(&csuTime.time);
  365. // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
  366. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  367. // tmCSU->tm_sec);
  368. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  369. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  370. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  371. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  372. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  373. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  374. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  375. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  376. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  377. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  378. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  379. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  380. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  381. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  382. if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS)
  383. {
  384. //PRINTF_FUNC("SetRtc (FB) sucessfully. \n");
  385. }
  386. }
  387. void SetModelName_Fan()
  388. {
  389. if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
  390. {
  391. PRINTF_FUNC("Set Model name PASS = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  392. }
  393. }
  394. // AC 三相輸入電壓
  395. void GetPresentInputVol()
  396. {
  397. if (Query_Present_InputVoltage(Uart5Fd, Addr.DO360_RC1, &inputVoltage) == PASS)
  398. {
  399. // resolution : 0.1
  400. ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmRelayModuleData[0]->InputL1Volt = inputVoltage.L1N_L12;
  401. ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmRelayModuleData[0]->InputL2Volt = inputVoltage.L2N_L23;
  402. ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmRelayModuleData[0]->InputL3Volt = inputVoltage.L3N_L31;
  403. //********************************************************************************************************//
  404. // Vin (UVP)
  405. if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
  406. {
  407. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO)
  408. {
  409. if (inputVoltage.L1N_L12 <= VIN_MIN_VOLTAGE_IEC)
  410. {
  411. PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  412. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT)
  413. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
  414. else
  415. _threePhaseUvp[0] += 1;
  416. }
  417. }
  418. else
  419. {
  420. if (inputVoltage.L1N_L12 >= VIN_MIN_REV_VOLTAGE_IEC)
  421. {
  422. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
  423. _threePhaseUvp[0] = 0;
  424. }
  425. }
  426. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO)
  427. {
  428. if (inputVoltage.L2N_L23 <= VIN_MIN_VOLTAGE_IEC)
  429. {
  430. PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  431. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT)
  432. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
  433. else
  434. _threePhaseUvp[1] += 1;
  435. }
  436. }
  437. else
  438. {
  439. if (inputVoltage.L2N_L23 >= VIN_MIN_REV_VOLTAGE_IEC)
  440. {
  441. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
  442. _threePhaseUvp[1] = 0;
  443. }
  444. }
  445. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO)
  446. {
  447. if (inputVoltage.L3N_L31 <= VIN_MIN_VOLTAGE_IEC)
  448. {
  449. PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  450. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT)
  451. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
  452. else
  453. _threePhaseUvp[2] += 1;
  454. }
  455. }
  456. else
  457. {
  458. if (inputVoltage.L3N_L31 >= VIN_MIN_REV_VOLTAGE_IEC)
  459. {
  460. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
  461. _threePhaseUvp[2] = 0;
  462. }
  463. }
  464. }
  465. else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
  466. {
  467. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO)
  468. {
  469. if (inputVoltage.L1N_L12 <= VIN_MIN_VOLTAGE_UL)
  470. {
  471. PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  472. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT)
  473. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
  474. else
  475. _threePhaseUvp[0] += 1;
  476. }
  477. }
  478. else
  479. {
  480. if (inputVoltage.L1N_L12 >= VIN_MIN_REV_VOLTAGE_UL)
  481. {
  482. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
  483. _threePhaseUvp[0] = 0;
  484. }
  485. }
  486. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO)
  487. {
  488. if (inputVoltage.L2N_L23 <= VIN_MIN_VOLTAGE_UL)
  489. {
  490. PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  491. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT)
  492. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
  493. else
  494. _threePhaseUvp[1] += 1;
  495. }
  496. }
  497. else
  498. {
  499. if (inputVoltage.L2N_L23 >= VIN_MIN_REV_VOLTAGE_UL)
  500. {
  501. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
  502. _threePhaseUvp[1] = 0;
  503. }
  504. }
  505. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO)
  506. {
  507. if (inputVoltage.L3N_L31 <= VIN_MIN_VOLTAGE_UL)
  508. {
  509. PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  510. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT)
  511. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
  512. else
  513. _threePhaseUvp[2] += 1;
  514. }
  515. }
  516. else
  517. {
  518. if (inputVoltage.L3N_L31 >= VIN_MIN_REV_VOLTAGE_UL)
  519. {
  520. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
  521. _threePhaseUvp[2] = 0;
  522. }
  523. }
  524. }
  525. //********************************************************************************************************//
  526. // Vin (OVP)
  527. if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
  528. {
  529. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO)
  530. {
  531. if (inputVoltage.L1N_L12 >= VIN_MAX_VOLTAGE_IEC)
  532. {
  533. PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  534. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT)
  535. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
  536. else
  537. _threePhaseOvp[0] += 1;
  538. }
  539. }
  540. else
  541. {
  542. if (inputVoltage.L1N_L12 <= VIN_MAX_REV_VOLTAGE_IEC)
  543. {
  544. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
  545. _threePhaseOvp[0] = 0;
  546. }
  547. }
  548. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO)
  549. {
  550. if (inputVoltage.L2N_L23 >= VIN_MAX_VOLTAGE_IEC)
  551. {
  552. PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  553. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT)
  554. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
  555. else
  556. _threePhaseOvp[1] += 1;
  557. }
  558. }
  559. else
  560. {
  561. if (inputVoltage.L2N_L23 <= VIN_MAX_REV_VOLTAGE_IEC)
  562. {
  563. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
  564. _threePhaseOvp[1] = 0;
  565. }
  566. }
  567. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO)
  568. {
  569. if (inputVoltage.L3N_L31 >= VIN_MAX_VOLTAGE_IEC)
  570. {
  571. PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  572. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT)
  573. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
  574. else
  575. _threePhaseOvp[2] += 1;
  576. }
  577. }
  578. else
  579. {
  580. if (inputVoltage.L3N_L31 <= VIN_MAX_REV_VOLTAGE_IEC)
  581. {
  582. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
  583. _threePhaseOvp[2] = 0;
  584. }
  585. }
  586. }
  587. else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
  588. {
  589. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO)
  590. {
  591. if (inputVoltage.L1N_L12 >= VIN_MAX_VOLTAGE_UL)
  592. {
  593. PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  594. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT)
  595. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
  596. else
  597. _threePhaseOvp[0] += 0;
  598. }
  599. }
  600. else
  601. {
  602. if (inputVoltage.L1N_L12 <= VIN_MAX_REV_VOLTAGE_UL)
  603. {
  604. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
  605. _threePhaseOvp[0] = 0;
  606. }
  607. }
  608. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO)
  609. {
  610. if (inputVoltage.L2N_L23 >= VIN_MAX_VOLTAGE_UL)
  611. {
  612. PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  613. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT)
  614. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
  615. else
  616. _threePhaseOvp[1] += 0;
  617. }
  618. }
  619. else
  620. {
  621. if (inputVoltage.L2N_L23 <= VIN_MAX_REV_VOLTAGE_UL)
  622. {
  623. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
  624. _threePhaseOvp[1] = 0;
  625. }
  626. }
  627. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO)
  628. {
  629. if (inputVoltage.L3N_L31 >= VIN_MAX_VOLTAGE_UL)
  630. {
  631. PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  632. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT)
  633. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
  634. else
  635. _threePhaseOvp[2] += 1;
  636. }
  637. }
  638. else
  639. {
  640. if (inputVoltage.L3N_L31 <= VIN_MAX_REV_VOLTAGE_UL)
  641. {
  642. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
  643. _threePhaseOvp[2] = 0;
  644. }
  645. }
  646. }
  647. }
  648. }
  649. // 左右槍的 Relay 前後的輸出電壓
  650. void GetPersentOutputVol()
  651. {
  652. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  653. {
  654. // two relay board
  655. if (Query_Present_OutputVoltage(Uart5Fd, Addr.DO360_RC1, &outputVoltage) == PASS)
  656. {
  657. ShmRelayModuleData[0]->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  658. ShmRelayModuleData[0]->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  659. ShmRelayModuleData[0]->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  660. ShmRelayModuleData[0]->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  661. _chargingData[0]->FuseChargingVoltage = ShmRelayModuleData[0]->Gun1FuseOutputVolt;
  662. _chargingData[0]->FireChargingVoltage = ShmRelayModuleData[0]->Gun1RelayOutputVolt;
  663. }
  664. // DO360 RC2
  665. if (Query_Present_OutputVoltage(Uart5Fd, Addr.DO360_RC2, &outputVoltage) == PASS)
  666. {
  667. ShmRelayModuleData[1]->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  668. ShmRelayModuleData[1]->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  669. ShmRelayModuleData[1]->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  670. ShmRelayModuleData[1]->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  671. _chargingData[1]->FuseChargingVoltage = ShmRelayModuleData[1]->Gun2FuseOutputVolt;
  672. _chargingData[1]->FireChargingVoltage = ShmRelayModuleData[1]->Gun2RelayOutputVolt;
  673. }
  674. }
  675. else
  676. {
  677. // only one relay board
  678. if (Query_Present_OutputVoltage(Uart5Fd, Addr.DO360_RC1, &outputVoltage) == PASS)
  679. {
  680. ShmRelayModuleData[0]->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  681. ShmRelayModuleData[0]->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  682. ShmRelayModuleData[0]->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  683. ShmRelayModuleData[0]->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  684. _chargingData[0]->FuseChargingVoltage = ShmRelayModuleData[0]->Gun1FuseOutputVolt;
  685. _chargingData[0]->FireChargingVoltage = ShmRelayModuleData[0]->Gun1RelayOutputVolt;
  686. _chargingData[1]->FuseChargingVoltage = ShmRelayModuleData[0]->Gun2FuseOutputVolt;
  687. _chargingData[1]->FireChargingVoltage = ShmRelayModuleData[0]->Gun2RelayOutputVolt;
  688. }
  689. }
  690. }
  691. // 風扇速度
  692. void GetFanSpeed()
  693. {
  694. //PRINTF_FUNC("Get fan board speed \n");
  695. if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS)
  696. {
  697. ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
  698. ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
  699. ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
  700. ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
  701. // PRINTF_FUNC("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
  702. // PRINTF_FUNC("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
  703. // PRINTF_FUNC("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
  704. // PRINTF_FUNC("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
  705. // Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
  706. //SysInfoData (SystemFanRotaSpeed)
  707. }
  708. }
  709. // 讀取 Relay 狀態
  710. void GetRelayOutputStatus()
  711. {
  712. // if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS)
  713. // {
  714. // regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
  715. // }
  716. }
  717. // 確認 K1 K2 relay 的狀態
  718. void CheckK1K2RelayOutput(byte index)
  719. {
  720. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  721. {
  722. // two relay board
  723. if (index == 0)
  724. {
  725. if (regRelay[0].relay_event.bits.Gun1_N == YES && regRelay[0].relay_event.bits.Gun1_P == YES)
  726. _chargingData[index]->RelayK1K2Status = YES;
  727. else
  728. _chargingData[index]->RelayK1K2Status = NO;
  729. }
  730. else if (index == 1)
  731. {
  732. if (regRelay[1].relay_event.bits.Gun2_N == YES && regRelay[1].relay_event.bits.Gun2_P == YES)
  733. _chargingData[index]->RelayK1K2Status = YES;
  734. else
  735. _chargingData[index]->RelayK1K2Status = NO;
  736. }
  737. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES && regRelay[0].relay_event.bits.Gun1_Parallel_P == YES &&
  738. regRelay[0].relay_event.bits.Gun2_Parallel_N == YES && regRelay[0].relay_event.bits.Gun2_Parallel_P == YES &&
  739. regRelay[1].relay_event.bits.Gun1_Parallel_N == YES && regRelay[1].relay_event.bits.Gun1_Parallel_P == YES)
  740. ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
  741. else
  742. ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
  743. }
  744. else
  745. {
  746. // only one relay board
  747. if (index == 0)
  748. {
  749. if (regRelay[0].relay_event.bits.Gun1_N == YES && regRelay[0].relay_event.bits.Gun1_P == YES)
  750. _chargingData[index]->RelayK1K2Status = YES;
  751. else
  752. _chargingData[index]->RelayK1K2Status = NO;
  753. }
  754. else if (index == 1)
  755. {
  756. if (regRelay[0].relay_event.bits.Gun2_N == YES && regRelay[0].relay_event.bits.Gun2_P == YES)
  757. _chargingData[index]->RelayK1K2Status = YES;
  758. else
  759. _chargingData[index]->RelayK1K2Status = NO;
  760. }
  761. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES && regRelay[0].relay_event.bits.Gun1_Parallel_P == YES)
  762. ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
  763. else
  764. ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
  765. }
  766. // PRINTF_FUNC("Check Relay Output. index = %d, RelayKPK2Status = %d, BridgeRelayStatus = %d \n",
  767. // index, _chargingData[index]->RelayKPK2Status, ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus);
  768. }
  769. void GetGfdAdc()
  770. {
  771. // define : 每 0.2 ~ 1 秒一次
  772. // occur : <= 75k 歐姆 @ 150 - 750 Vdc
  773. // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
  774. // if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS)
  775. // {
  776. // for (int i = 0; i < gunCount; i++)
  777. // {
  778. // if (_chargingData[i]->Type == 0x09 && !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)
  779. // {
  780. // if ((_chargingData[i]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE)
  781. // _chargingData[i]->GroundFaultStatus = GFD_PASS;
  782. // continue;
  783. // }
  784. // if (i == 0)
  785. // {
  786. // _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn1;
  787. // PRINTF_FUNC("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
  788. // _chargingData[i]->GroundFaultStatus, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  789. // if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
  790. // {
  791. // PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
  792. // i, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  793. // }
  794. // else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
  795. // _chargingData[i]->GroundFaultStatus == GFD_WARNING)
  796. // {
  797. // if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
  798. // {
  799. // PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
  800. // i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  801. // }
  802. // }
  803. // }
  804. // else if (i == 1)
  805. // {
  806. // _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn2;
  807. // if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
  808. // {
  809. // PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
  810. // i, gfd_adc.rb_step_2, gfd_adc.Resister_conn2, gfd_adc.voltage_conn2);
  811. // }
  812. // else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
  813. // _chargingData[i]->GroundFaultStatus == GFD_WARNING)
  814. // {
  815. // if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
  816. // {
  817. // PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
  818. // i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  819. // }
  820. // }
  821. // }
  822. // }
  823. // }
  824. }
  825. void GetGpioInput()
  826. {
  827. if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS)
  828. {
  829. // AC Contactor Status
  830. if (gpio_in.AC_MainBreaker == 1)
  831. {
  832. // AC Main Breaker ON
  833. PRINTF_FUNC("RB AC Main Breaker. \n");
  834. }
  835. if (gpio_in.SPD == 1)
  836. {
  837. // SPD (雷擊保護) ON
  838. PRINTF_FUNC("RB SPD. \n");
  839. }
  840. if (gpio_in.Door_Open == 1)
  841. {
  842. // Door Open
  843. PRINTF_FUNC("RB Door Open. \n");
  844. }
  845. if (gpio_in.GFD[0] == 1)
  846. {
  847. // GFD_1 Trigger
  848. }
  849. if (gpio_in.GFD[1] == 1)
  850. {
  851. // GFD_2 Trigger
  852. }
  853. if (gpio_in.AC_Drop == 1)
  854. {
  855. // AC Drop
  856. PRINTF_FUNC("RB AC Drop. \n");
  857. }
  858. if (gpio_in.Emergency_IO == 1)
  859. {
  860. // Emergency IO ON
  861. PRINTF_FUNC("RB Emergency IO ON. \n");
  862. }
  863. if (gpio_in.Button_Emergency_Press == 1)
  864. {
  865. // Emergency button Press
  866. }
  867. if (gpio_in.Button_On_Press == 1)
  868. {
  869. // On button Press
  870. }
  871. if (gpio_in.Button_Off_Press == 1)
  872. {
  873. // Off button Press
  874. }
  875. if (gpio_in.Key_1_Press == 1)
  876. {
  877. // key 1 press
  878. }
  879. if (gpio_in.Key_2_Press == 1)
  880. {
  881. // key 2 press
  882. }
  883. if (gpio_in.Key_3_Press == 1)
  884. {
  885. // key 3 press
  886. }
  887. if (gpio_in.Key_4_Press == 1)
  888. {
  889. // key 4 press
  890. }
  891. }
  892. }
  893. // 5V 12V 24V 48V
  894. void GetAuxPower()
  895. {
  896. if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS)
  897. {
  898. ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
  899. ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
  900. //ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
  901. //ShmSysConfigAndInfo->SysInfo.AuxPower5V = auxPower.voltage[6];
  902. // aux power voltage
  903. //PRINTF_FUNC("aux1 = %x, \n", auxPower.voltage[0]);
  904. //PRINTF_FUNC("aux2 = %x, \n", auxPower.voltage[1]);
  905. }
  906. }
  907. void SetFanModuleSpeed()
  908. {
  909. {
  910. FanSpeed _fanSpeed;
  911. _setFanSpeed += fanSpeedSmoothValue;
  912. if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed)
  913. _setFanSpeed = ShmFanModuleData->SetFan1Speed;
  914. //printf("_setFanSpeed = %d \n", _setFanSpeed);
  915. _fanSpeed.speed[0] = _setFanSpeed;
  916. _fanSpeed.speed[1] = _setFanSpeed;
  917. _fanSpeed.speed[2] = _setFanSpeed;
  918. _fanSpeed.speed[3] = _setFanSpeed;
  919. if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS)
  920. {
  921. //PRINTF_FUNC("successfully Fan\n");
  922. }
  923. }
  924. }
  925. //==========================================
  926. // Common Function
  927. //==========================================
  928. void SetK1K2RelayStatus(byte index)
  929. {
  930. if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE)
  931. {
  932. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  933. {
  934. // two relay board
  935. if(index == 0)
  936. {
  937. if(regRelay[0].relay_event.bits.Gun1_P == YES)
  938. outputRelay[0].relay_event.bits.Gun1_P = NO;
  939. if (regRelay[0].relay_event.bits.Gun1_N == YES)
  940. outputRelay[0].relay_event.bits.Gun1_N = NO;
  941. }
  942. if(index == 1)
  943. {
  944. if(regRelay[1].relay_event.bits.Gun2_P == YES)
  945. outputRelay[1].relay_event.bits.Gun2_P = NO;
  946. if (regRelay[1].relay_event.bits.Gun2_N == YES)
  947. outputRelay[1].relay_event.bits.Gun2_N = NO;
  948. }
  949. }
  950. else
  951. {
  952. // only one relay board
  953. if(index == 0)
  954. {
  955. if(regRelay[0].relay_event.bits.Gun1_P == YES)
  956. outputRelay[0].relay_event.bits.Gun1_P = NO;
  957. if (regRelay[0].relay_event.bits.Gun1_N == YES)
  958. outputRelay[0].relay_event.bits.Gun1_N = NO;
  959. }
  960. if(index == 1)
  961. {
  962. if(regRelay[0].relay_event.bits.Gun2_P == YES)
  963. outputRelay[0].relay_event.bits.Gun2_P = NO;
  964. if (regRelay[0].relay_event.bits.Gun2_N == YES)
  965. outputRelay[0].relay_event.bits.Gun2_N = NO;
  966. }
  967. }
  968. }
  969. else if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
  970. _chargingData[index]->SystemStatus <= S_CHARGING))
  971. {
  972. if (_chargingData[index]->RelayWeldingCheck == YES)
  973. {
  974. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  975. {
  976. // two relay board
  977. if(index == 0)
  978. {
  979. if(regRelay[0].relay_event.bits.Gun1_N == NO)
  980. outputRelay[0].relay_event.bits.Gun1_N = YES;
  981. if (regRelay[0].relay_event.bits.Gun1_P == NO)
  982. outputRelay[0].relay_event.bits.Gun1_P = YES;
  983. }
  984. if(index == 1)
  985. {
  986. if(regRelay[1].relay_event.bits.Gun2_N == NO)
  987. outputRelay[1].relay_event.bits.Gun2_N = YES;
  988. if (regRelay[1].relay_event.bits.Gun2_P == NO)
  989. outputRelay[1].relay_event.bits.Gun2_P = YES;
  990. }
  991. }
  992. else
  993. {
  994. // only one relay board
  995. if(index == 0)
  996. {
  997. if(regRelay[0].relay_event.bits.Gun1_N == NO)
  998. outputRelay[0].relay_event.bits.Gun1_N = YES;
  999. if (regRelay[0].relay_event.bits.Gun1_P == NO)
  1000. outputRelay[0].relay_event.bits.Gun1_P = YES;
  1001. }
  1002. if(index == 1)
  1003. {
  1004. if(regRelay[0].relay_event.bits.Gun2_N == NO)
  1005. outputRelay[0].relay_event.bits.Gun2_N = YES;
  1006. if (regRelay[0].relay_event.bits.Gun2_P == NO)
  1007. outputRelay[0].relay_event.bits.Gun2_P = YES;
  1008. }
  1009. }
  1010. }
  1011. }
  1012. else if ((_chargingData[index]->SystemStatus >= S_TERMINATING &&
  1013. _chargingData[index]->SystemStatus <= S_COMPLETE) ||
  1014. _chargingData[index]->SystemStatus == S_ALARM)
  1015. {
  1016. if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR)
  1017. {
  1018. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  1019. {
  1020. // two relay board
  1021. if(index == 0)
  1022. {
  1023. if(regRelay[0].relay_event.bits.Gun1_P == YES)
  1024. outputRelay[0].relay_event.bits.Gun1_P = NO;
  1025. if (regRelay[0].relay_event.bits.Gun1_N == YES)
  1026. outputRelay[0].relay_event.bits.Gun1_N = NO;
  1027. }
  1028. if(index == 1)
  1029. {
  1030. if(regRelay[1].relay_event.bits.Gun2_P == YES)
  1031. outputRelay[1].relay_event.bits.Gun2_P = NO;
  1032. if (regRelay[1].relay_event.bits.Gun2_N == YES)
  1033. outputRelay[1].relay_event.bits.Gun2_N = NO;
  1034. }
  1035. }
  1036. else
  1037. {
  1038. // only one relay board
  1039. if(index == 0)
  1040. {
  1041. if(regRelay[0].relay_event.bits.Gun1_P == YES)
  1042. outputRelay[0].relay_event.bits.Gun1_P = NO;
  1043. if (regRelay[0].relay_event.bits.Gun1_N == YES)
  1044. outputRelay[0].relay_event.bits.Gun1_N = NO;
  1045. }
  1046. if(index == 1)
  1047. {
  1048. if(regRelay[0].relay_event.bits.Gun2_P == YES)
  1049. outputRelay[0].relay_event.bits.Gun2_P = NO;
  1050. if (regRelay[0].relay_event.bits.Gun2_N == YES)
  1051. outputRelay[0].relay_event.bits.Gun2_N = NO;
  1052. }
  1053. }
  1054. }
  1055. }
  1056. else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0)
  1057. {
  1058. }
  1059. else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1)
  1060. {
  1061. }
  1062. }
  1063. void SetParalleRelayStatus()
  1064. {
  1065. // 之後雙槍單模機種,橋接都會上
  1066. if (gunCount >= 2)
  1067. {
  1068. if (_chargingData[0]->SystemStatus == S_BOOTING || _chargingData[1]->SystemStatus == S_BOOTING ||
  1069. ((_chargingData[0]->SystemStatus == S_IDLE || _chargingData[0]->SystemStatus == S_MAINTAIN || _chargingData[0]->SystemStatus == S_FAULT) &&
  1070. (_chargingData[1]->SystemStatus == S_IDLE || _chargingData[1]->SystemStatus == S_MAINTAIN || _chargingData[0]->SystemStatus == S_FAULT)))
  1071. {
  1072. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  1073. {
  1074. // two relay board
  1075. // 初始化~ 不搭橋接
  1076. if (regRelay[0].relay_event.bits.Gun1_Parallel_P == YES)
  1077. outputRelay[0].relay_event.bits.Gun1_Parallel_P = NO;
  1078. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES)
  1079. outputRelay[0].relay_event.bits.Gun1_Parallel_N = NO;
  1080. if (regRelay[0].relay_event.bits.Gun2_Parallel_P == YES)
  1081. outputRelay[0].relay_event.bits.Gun2_Parallel_P = NO;
  1082. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == YES)
  1083. outputRelay[0].relay_event.bits.Gun2_Parallel_N = NO;
  1084. if (regRelay[1].relay_event.bits.Gun1_Parallel_P == YES)
  1085. outputRelay[1].relay_event.bits.Gun1_Parallel_P = NO;
  1086. if (regRelay[1].relay_event.bits.Gun1_Parallel_N == YES)
  1087. outputRelay[1].relay_event.bits.Gun1_Parallel_N = NO;
  1088. }
  1089. else
  1090. {
  1091. // only one relay board
  1092. // 初始化~ 不搭橋接
  1093. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES)
  1094. outputRelay[0].relay_event.bits.Gun1_Parallel_N = NO;
  1095. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == YES)
  1096. outputRelay[0].relay_event.bits.Gun2_Parallel_N = NO;
  1097. }
  1098. }
  1099. else
  1100. {
  1101. if (_chargingData[0]->IsReadyToCharging == YES ||
  1102. _chargingData[1]->IsReadyToCharging == YES)
  1103. {
  1104. // ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
  1105. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  1106. {
  1107. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A)
  1108. {
  1109. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  1110. {
  1111. // two relay board
  1112. // 最大充 - 搭上橋接
  1113. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == NO)
  1114. outputRelay[0].relay_event.bits.Gun1_Parallel_N = YES;
  1115. if (regRelay[0].relay_event.bits.Gun1_Parallel_P == NO)
  1116. outputRelay[0].relay_event.bits.Gun1_Parallel_P = YES;
  1117. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == NO)
  1118. outputRelay[0].relay_event.bits.Gun2_Parallel_N = YES;
  1119. if (regRelay[0].relay_event.bits.Gun2_Parallel_P == NO)
  1120. outputRelay[0].relay_event.bits.Gun2_Parallel_P = YES;
  1121. if (regRelay[1].relay_event.bits.Gun1_Parallel_N == NO)
  1122. outputRelay[1].relay_event.bits.Gun1_Parallel_N = YES;
  1123. if (regRelay[1].relay_event.bits.Gun1_Parallel_P == NO)
  1124. outputRelay[1].relay_event.bits.Gun1_Parallel_P = YES;
  1125. }
  1126. else
  1127. {
  1128. // only one relay board
  1129. // 最大充 - 搭上橋接
  1130. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == NO)
  1131. outputRelay[0].relay_event.bits.Gun1_Parallel_N = YES;
  1132. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == NO)
  1133. outputRelay[0].relay_event.bits.Gun2_Parallel_N = YES;
  1134. }
  1135. }
  1136. else
  1137. {
  1138. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  1139. {
  1140. // two relay board
  1141. // 平均充 - 不搭
  1142. if (regRelay[0].relay_event.bits.Gun1_Parallel_P == YES)
  1143. outputRelay[0].relay_event.bits.Gun1_Parallel_P = NO;
  1144. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES)
  1145. outputRelay[0].relay_event.bits.Gun1_Parallel_N = NO;
  1146. if (regRelay[0].relay_event.bits.Gun2_Parallel_P == YES)
  1147. outputRelay[0].relay_event.bits.Gun2_Parallel_P = NO;
  1148. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == YES)
  1149. outputRelay[0].relay_event.bits.Gun2_Parallel_N = NO;
  1150. if (regRelay[1].relay_event.bits.Gun1_Parallel_P == YES)
  1151. outputRelay[1].relay_event.bits.Gun1_Parallel_P = NO;
  1152. if (regRelay[1].relay_event.bits.Gun1_Parallel_N == YES)
  1153. outputRelay[1].relay_event.bits.Gun1_Parallel_N = NO;
  1154. }
  1155. else
  1156. {
  1157. // only one relay board
  1158. // 平均充 - 不搭
  1159. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES)
  1160. outputRelay[0].relay_event.bits.Gun1_Parallel_N = NO;
  1161. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == YES)
  1162. outputRelay[0].relay_event.bits.Gun2_Parallel_N = NO;
  1163. }
  1164. }
  1165. }
  1166. else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
  1167. {
  1168. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M)
  1169. {
  1170. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  1171. {
  1172. // two relay board
  1173. // 平均充 - 不搭
  1174. if (regRelay[0].relay_event.bits.Gun1_Parallel_P == YES)
  1175. outputRelay[0].relay_event.bits.Gun1_Parallel_P = NO;
  1176. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES)
  1177. outputRelay[0].relay_event.bits.Gun1_Parallel_N = NO;
  1178. if (regRelay[0].relay_event.bits.Gun2_Parallel_P == YES)
  1179. outputRelay[0].relay_event.bits.Gun2_Parallel_P = NO;
  1180. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == YES)
  1181. outputRelay[0].relay_event.bits.Gun2_Parallel_N = NO;
  1182. if (regRelay[1].relay_event.bits.Gun1_Parallel_P == YES)
  1183. outputRelay[1].relay_event.bits.Gun1_Parallel_P = NO;
  1184. if (regRelay[1].relay_event.bits.Gun1_Parallel_N == YES)
  1185. outputRelay[1].relay_event.bits.Gun1_Parallel_N = NO;
  1186. }
  1187. else
  1188. {
  1189. // only one relay board
  1190. // 平均充 - 不搭
  1191. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES)
  1192. outputRelay[0].relay_event.bits.Gun1_Parallel_N = NO;
  1193. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == YES)
  1194. outputRelay[0].relay_event.bits.Gun2_Parallel_N = NO;
  1195. }
  1196. }
  1197. else
  1198. {
  1199. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  1200. {
  1201. // two relay board
  1202. // 最大充 - 搭上橋接
  1203. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == NO)
  1204. outputRelay[0].relay_event.bits.Gun1_Parallel_N = YES;
  1205. if (regRelay[0].relay_event.bits.Gun1_Parallel_P == NO)
  1206. outputRelay[0].relay_event.bits.Gun1_Parallel_P = YES;
  1207. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == NO)
  1208. outputRelay[0].relay_event.bits.Gun2_Parallel_N = YES;
  1209. if (regRelay[0].relay_event.bits.Gun2_Parallel_P == NO)
  1210. outputRelay[0].relay_event.bits.Gun2_Parallel_P = YES;
  1211. if (regRelay[1].relay_event.bits.Gun1_Parallel_N == NO)
  1212. outputRelay[1].relay_event.bits.Gun1_Parallel_N = YES;
  1213. if (regRelay[1].relay_event.bits.Gun1_Parallel_P == NO)
  1214. outputRelay[1].relay_event.bits.Gun1_Parallel_P = YES;
  1215. }
  1216. else
  1217. {
  1218. // only one relay board
  1219. // 最大充 - 搭上橋接
  1220. if (regRelay[0].relay_event.bits.Gun1_Parallel_N == NO)
  1221. outputRelay[0].relay_event.bits.Gun1_Parallel_N = YES;
  1222. if (regRelay[0].relay_event.bits.Gun2_Parallel_N == NO)
  1223. outputRelay[0].relay_event.bits.Gun2_Parallel_N = YES;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. }
  1231. void SetAcContactorStatus(void)
  1232. {
  1233. if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor == YES &&
  1234. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorForceOff == NO)
  1235. {
  1236. outputRelay[0].relay_event.bits.AC_Contactor = YES;
  1237. }
  1238. else
  1239. {
  1240. outputRelay[0].relay_event.bits.AC_Contactor = NO;
  1241. }
  1242. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  1243. {
  1244. if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor == YES &&
  1245. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorForceOff == NO)
  1246. {
  1247. outputRelay[1].relay_event.bits.AC_Contactor = YES;
  1248. }
  1249. else
  1250. {
  1251. outputRelay[1].relay_event.bits.AC_Contactor = NO;
  1252. }
  1253. }
  1254. }
  1255. void CheckAlarmOccur()
  1256. {
  1257. bool isErr = false;
  1258. for(byte count = 0; count < sizeof(_alarm_code)/sizeof(_alarm_code[0]); count++)
  1259. {
  1260. if (acAlarmCode.AcAlarmCode & _alarm_code[count])
  1261. {
  1262. isErr = true;
  1263. switch(_alarm_code[count])
  1264. {
  1265. case AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = YES; break;
  1266. case AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = YES; break;
  1267. case AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = YES; break;
  1268. case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = YES; break;
  1269. case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = YES; break;
  1270. case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = YES; break;
  1271. case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
  1272. case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
  1273. case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = YES; break;
  1274. case AC_HANDSHAKE_TIMEOUT: break;
  1275. //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES; break;
  1276. case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = YES; break;
  1277. case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = YES; break;
  1278. case AC_SHUTTER_FAULT: break;
  1279. case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = YES; break;
  1280. case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = YES; break;
  1281. case AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = YES; break;
  1282. case AC_ROTARY_SWITCH_FAULT: break;
  1283. case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = YES; break;
  1284. }
  1285. }
  1286. else
  1287. {
  1288. switch(_alarm_code[count])
  1289. {
  1290. case AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = NO; break;
  1291. case AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = NO; break;
  1292. case AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = NO; break;
  1293. case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = NO; break;
  1294. case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = NO; break;
  1295. case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = NO; break;
  1296. case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
  1297. case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
  1298. case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = NO; break;
  1299. case AC_HANDSHAKE_TIMEOUT: break;
  1300. //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO; break;
  1301. case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = NO; break;
  1302. case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = NO; break;
  1303. case AC_SHUTTER_FAULT: break;
  1304. case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = NO; break;
  1305. case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = NO; break;
  1306. case AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = NO; break;
  1307. case AC_ROTARY_SWITCH_FAULT: break;
  1308. case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = NO; break;
  1309. }
  1310. }
  1311. }
  1312. ac_chargingInfo[0]->IsErrorOccur = isErr;
  1313. }
  1314. bool IsNoneMatchLedColor()
  1315. {
  1316. bool result = false;
  1317. if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
  1318. cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
  1319. cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
  1320. cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
  1321. cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
  1322. cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue)
  1323. {
  1324. result = true;
  1325. }
  1326. return result;
  1327. }
  1328. void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
  1329. {
  1330. byte _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
  1331. if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_DARKEST)
  1332. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
  1333. else if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_MEDIUM)
  1334. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
  1335. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
  1336. {
  1337. if ((chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION) &&
  1338. (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION))
  1339. {
  1340. led_color.Connect_1_Green = _colorBuf;
  1341. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1342. led_color.Connect_1_Red = COLOR_MIN_LV;
  1343. led_color.Connect_2_Green = _colorBuf;
  1344. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1345. led_color.Connect_2_Red = COLOR_MIN_LV;
  1346. }
  1347. else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
  1348. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1349. (chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
  1350. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1))
  1351. {
  1352. led_color.Connect_1_Green = COLOR_MIN_LV;
  1353. led_color.Connect_1_Blue = _colorBuf;
  1354. led_color.Connect_1_Red = COLOR_MIN_LV;
  1355. led_color.Connect_2_Green = COLOR_MIN_LV;
  1356. led_color.Connect_2_Blue = _colorBuf;
  1357. led_color.Connect_2_Red = COLOR_MIN_LV;
  1358. }
  1359. }
  1360. else
  1361. {
  1362. if (chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION)
  1363. {
  1364. led_color.Connect_1_Green = _colorBuf;
  1365. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1366. led_color.Connect_1_Red = COLOR_MIN_LV;
  1367. }
  1368. else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
  1369. (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1))
  1370. {
  1371. led_color.Connect_1_Green = COLOR_MIN_LV;
  1372. led_color.Connect_1_Blue = _colorBuf;
  1373. led_color.Connect_1_Red = COLOR_MIN_LV;
  1374. }
  1375. // --------------------------------------------------------------------------
  1376. if (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION)
  1377. {
  1378. led_color.Connect_2_Green = _colorBuf;
  1379. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1380. led_color.Connect_2_Red = COLOR_MIN_LV;
  1381. }
  1382. else if ((chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
  1383. (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1))
  1384. {
  1385. led_color.Connect_2_Green = COLOR_MIN_LV;
  1386. led_color.Connect_2_Blue = _colorBuf;
  1387. led_color.Connect_2_Red = COLOR_MIN_LV;
  1388. }
  1389. }
  1390. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
  1391. {
  1392. led_color.Connect_1_Green = COLOR_MIN_LV;
  1393. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1394. led_color.Connect_1_Red = _colorBuf;
  1395. led_color.Connect_2_Green = COLOR_MIN_LV;
  1396. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1397. led_color.Connect_2_Red = _colorBuf;
  1398. }
  1399. if (_checkLedChanged > 0)
  1400. {
  1401. if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS)
  1402. {
  1403. _checkLedChanged--;
  1404. cur_led_color.Connect_1_Red = led_color.Connect_1_Red;
  1405. cur_led_color.Connect_1_Green = led_color.Connect_1_Green;
  1406. cur_led_color.Connect_1_Blue = led_color.Connect_1_Blue;
  1407. cur_led_color.Connect_2_Red = led_color.Connect_2_Red;
  1408. cur_led_color.Connect_2_Green = led_color.Connect_2_Green;
  1409. cur_led_color.Connect_2_Blue = led_color.Connect_2_Blue;
  1410. }
  1411. }
  1412. else if (IsNoneMatchLedColor())
  1413. _checkLedChanged = 3;
  1414. }
  1415. //==========================================
  1416. // Init all share memory
  1417. //==========================================
  1418. int InitShareMemory()
  1419. {
  1420. int result = PASS;
  1421. int MeterSMId;
  1422. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1423. {
  1424. #ifdef SystemLogMessage
  1425. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1426. #endif
  1427. result = FAIL;
  1428. }
  1429. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1430. {
  1431. #ifdef SystemLogMessage
  1432. DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
  1433. #endif
  1434. result = FAIL;
  1435. }
  1436. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1437. {
  1438. #ifdef SystemLogMessage
  1439. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1440. #endif
  1441. result = FAIL;
  1442. }
  1443. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1444. {
  1445. #ifdef SystemLogMessage
  1446. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1447. #endif
  1448. result = FAIL;
  1449. }
  1450. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), 0777)) < 0)
  1451. {
  1452. #ifdef SystemLogMessage
  1453. DEBUG_ERROR("shmget ShmFanModuleData NG\n");
  1454. #endif
  1455. result = FAIL;
  1456. }
  1457. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1458. {
  1459. #ifdef SystemLogMessage
  1460. DEBUG_ERROR("shmat ShmFanModuleData NG\n");
  1461. #endif
  1462. result = FAIL;
  1463. }
  1464. memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
  1465. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), 0777)) < 0)
  1466. {
  1467. #ifdef SystemLogMessage
  1468. DEBUG_ERROR("shmget ShmRelayModuleData NG\n");
  1469. #endif
  1470. result = FAIL;
  1471. }
  1472. else if ((ShmRelayModuleData[0] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1473. {
  1474. #ifdef SystemLogMessage
  1475. DEBUG_ERROR("shmat ShmRelayModuleData NG\n");
  1476. #endif
  1477. result = FAIL;
  1478. }
  1479. memset(ShmRelayModuleData[0],0,sizeof(struct RelayModuleData));
  1480. // DO360 RC2
  1481. if ((MeterSMId = shmget(ShmRelay2BdKey, sizeof(struct RelayModuleData), 0777)) < 0)
  1482. {
  1483. #ifdef SystemLogMessage
  1484. DEBUG_ERROR("shmget ShmRelay2ModuleData NG\n");
  1485. #endif
  1486. result = FAIL;
  1487. }
  1488. else if ((ShmRelayModuleData[1] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1489. {
  1490. #ifdef SystemLogMessage
  1491. DEBUG_ERROR("shmat ShmRelay2ModuleData NG\n");
  1492. #endif
  1493. result = FAIL;
  1494. }
  1495. memset(ShmRelayModuleData[1],0,sizeof(struct RelayModuleData));
  1496. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  1497. {
  1498. #ifdef SystemLogMessage
  1499. DEBUG_ERROR("shmget ShmLedModuleData NG\n");
  1500. #endif
  1501. result = FAIL;
  1502. }
  1503. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1504. {
  1505. #ifdef SystemLogMessage
  1506. DEBUG_ERROR("shmat ShmLedModuleData NG\n");
  1507. #endif
  1508. result = FAIL;
  1509. }
  1510. memset(ShmLedModuleData,0,sizeof(struct LedModuleData));
  1511. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1512. {
  1513. #ifdef SystemLogMessage
  1514. DEBUG_ERROR("shmget ShmPsuData NG \n");
  1515. #endif
  1516. result = FAIL;
  1517. }
  1518. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1519. {
  1520. #ifdef SystemLogMessage
  1521. DEBUG_ERROR("shmat ShmPsuData NG \n");
  1522. #endif
  1523. result = FAIL;
  1524. }
  1525. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1526. {
  1527. #ifdef SystemLogMessage
  1528. DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
  1529. #endif
  1530. result = FAIL;
  1531. }
  1532. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1533. {
  1534. #ifdef SystemLogMessage
  1535. DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
  1536. #endif
  1537. result = FAIL;
  1538. }
  1539. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), 0777)) < 0)
  1540. {
  1541. #ifdef SystemLogMessage
  1542. DEBUG_ERROR("shmat ChargerInfoData NG \n");
  1543. #endif
  1544. result = FAIL;
  1545. }
  1546. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1547. {
  1548. #ifdef SystemLogMessage
  1549. DEBUG_ERROR("shmat ChargerInfoData NG \n");
  1550. #endif
  1551. result = FAIL;
  1552. }
  1553. return result;
  1554. }
  1555. int InitComPort()
  1556. {
  1557. int fd;
  1558. struct termios tios;
  1559. fd = open(relayRs485PortName, O_RDWR);
  1560. if(fd <= 0)
  1561. {
  1562. #ifdef SystemLogMessage
  1563. DEBUG_ERROR("Module_InternalComm. InitComPort NG\n");
  1564. #endif
  1565. if(ShmStatusCodeData!=NULL)
  1566. {
  1567. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
  1568. }
  1569. sleep(5);
  1570. return -1;
  1571. }
  1572. ioctl (fd, TCGETS, &tios);
  1573. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  1574. tios.c_lflag = 0;
  1575. tios.c_iflag = 0;
  1576. tios.c_oflag = 0;
  1577. tios.c_cc[VMIN]=0;
  1578. tios.c_cc[VTIME]=(byte)0; // timeout 0.5 second
  1579. tios.c_lflag=0;
  1580. tcflush(fd, TCIFLUSH);
  1581. ioctl (fd, TCSETS, &tios);
  1582. return fd;
  1583. }
  1584. //================================================
  1585. // Main process
  1586. //================================================
  1587. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  1588. {
  1589. for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
  1590. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
  1591. == target) {
  1592. chargingData[target] =
  1593. &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  1594. return true;
  1595. }
  1596. }
  1597. for (byte index = 0; index < CCS_QUANTITY; index++) {
  1598. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
  1599. == target) {
  1600. chargingData[target] =
  1601. &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  1602. return true;
  1603. }
  1604. }
  1605. for (byte index = 0; index < GB_QUANTITY; index++) {
  1606. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
  1607. == target) {
  1608. chargingData[target] =
  1609. &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  1610. return true;
  1611. }
  1612. }
  1613. //DO360
  1614. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  1615. {
  1616. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData.Index = target;
  1617. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  1618. return true;
  1619. }
  1620. return false;
  1621. }
  1622. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  1623. {
  1624. if (target < AC_QUANTITY)
  1625. {
  1626. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  1627. return true;
  1628. }
  1629. return false;
  1630. }
  1631. void Initialization()
  1632. {
  1633. bool isPass = false;
  1634. for (byte index = 0; index < ARRAY_SIZE(outputRelay[0].relay_event.relay_status); index++)
  1635. {
  1636. outputRelay[0].relay_event.relay_status[index] = 0x00;
  1637. outputRelay[1].relay_event.relay_status[index] = 0x00;
  1638. }
  1639. while(!isPass)
  1640. {
  1641. isPass = true;
  1642. for (byte _index = 0; _index < gunCount; _index++)
  1643. {
  1644. if (!FindChargingInfoData(_index, &_chargingData[0]))
  1645. {
  1646. DEBUG_ERROR("InternalComm : FindChargingInfoData false \n");
  1647. isPass = false;
  1648. break;
  1649. }
  1650. }
  1651. sleep(1);
  1652. }
  1653. isPass = false;
  1654. if (acgunCount > 0)
  1655. {
  1656. while(!isPass)
  1657. {
  1658. isPass = true;
  1659. for (byte _index = 0; _index < acgunCount; _index++)
  1660. {
  1661. if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0]))
  1662. {
  1663. DEBUG_ERROR("EvComm : FindAcChargingInfoData false \n");
  1664. isPass = false;
  1665. break;
  1666. }
  1667. }
  1668. sleep(1);
  1669. }
  1670. }
  1671. }
  1672. bool IsNoneMatchRelayStatus(byte index)
  1673. {
  1674. bool result = false;
  1675. if ((regRelay[index].relay_event.bits.AC_Contactor != outputRelay[index].relay_event.bits.AC_Contactor) ||
  1676. (regRelay[index].relay_event.bits.CCS_Precharge != outputRelay[index].relay_event.bits.CCS_Precharge) ||
  1677. (regRelay[index].relay_event.bits.Gun1_P != outputRelay[index].relay_event.bits.Gun1_P) ||
  1678. (regRelay[index].relay_event.bits.Gun1_N != outputRelay[index].relay_event.bits.Gun1_N) ||
  1679. (regRelay[index].relay_event.bits.Gun2_P != outputRelay[index].relay_event.bits.Gun2_P) ||
  1680. (regRelay[index].relay_event.bits.Gun2_N != outputRelay[index].relay_event.bits.Gun2_N) ||
  1681. (regRelay[index].relay_event.bits.Gun1_Parallel_P != outputRelay[index].relay_event.bits.Gun1_Parallel_P) ||
  1682. (regRelay[index].relay_event.bits.Gun1_Parallel_N != outputRelay[index].relay_event.bits.Gun1_Parallel_N) ||
  1683. (regRelay[index].relay_event.bits.Gun2_Parallel_P != outputRelay[index].relay_event.bits.Gun2_Parallel_P) ||
  1684. (regRelay[index].relay_event.bits.Gun2_Parallel_N != outputRelay[index].relay_event.bits.Gun2_Parallel_N))
  1685. {
  1686. if (regRelay[index].relay_event.bits.AC_Contactor != outputRelay[index].relay_event.bits.AC_Contactor)
  1687. {
  1688. if(TempRegRelay[index].relay_event.bits.AC_Contactor != outputRelay[index].relay_event.bits.AC_Contactor)
  1689. {
  1690. PRINTF_FUNC("[%d]AC Contact Relay none match, need to %s", index,
  1691. outputRelay[index].relay_event.bits.AC_Contactor == YES ? "On" : "Off");
  1692. TempRegRelay[index].relay_event.bits.AC_Contactor = outputRelay[index].relay_event.bits.AC_Contactor;
  1693. }
  1694. }
  1695. if (regRelay[index].relay_event.bits.CCS_Precharge != outputRelay[index].relay_event.bits.CCS_Precharge)
  1696. {
  1697. if(TempRegRelay[index].relay_event.bits.CCS_Precharge != outputRelay[index].relay_event.bits.CCS_Precharge)
  1698. {
  1699. PRINTF_FUNC("[%d]CCS Precharge Relay none match, need to %s", index,
  1700. outputRelay[index].relay_event.bits.CCS_Precharge == YES ? "On" : "Off");
  1701. TempRegRelay[index].relay_event.bits.CCS_Precharge = outputRelay[index].relay_event.bits.CCS_Precharge;
  1702. }
  1703. }
  1704. if (regRelay[index].relay_event.bits.Gun1_P != outputRelay[index].relay_event.bits.Gun1_P)
  1705. {
  1706. if(TempRegRelay[index].relay_event.bits.Gun1_P != outputRelay[index].relay_event.bits.Gun1_P)
  1707. {
  1708. PRINTF_FUNC("[%d]SMR1:D+ Relay none match, need to %s", index,
  1709. outputRelay[index].relay_event.bits.Gun1_P == YES ? "On" : "Off");
  1710. TempRegRelay[index].relay_event.bits.Gun1_P = outputRelay[index].relay_event.bits.Gun1_P;
  1711. }
  1712. }
  1713. if (regRelay[index].relay_event.bits.Gun1_N != outputRelay[index].relay_event.bits.Gun1_N)
  1714. {
  1715. if(TempRegRelay[index].relay_event.bits.Gun1_N != outputRelay[index].relay_event.bits.Gun1_N)
  1716. {
  1717. PRINTF_FUNC("[%d]SMR1:D- Relay none match, need to %s", index,
  1718. outputRelay[index].relay_event.bits.Gun1_N == YES ? "On" : "Off");
  1719. TempRegRelay[index].relay_event.bits.Gun1_N = outputRelay[index].relay_event.bits.Gun1_N;
  1720. }
  1721. }
  1722. if (regRelay[index].relay_event.bits.Gun2_P != outputRelay[index].relay_event.bits.Gun2_P)
  1723. {
  1724. if(TempRegRelay[index].relay_event.bits.Gun2_P != outputRelay[index].relay_event.bits.Gun2_P)
  1725. {
  1726. PRINTF_FUNC("[%d]SMR2:D+ Relay none match, need to %s", index,
  1727. outputRelay[index].relay_event.bits.Gun2_P == YES ? "On" : "Off");
  1728. TempRegRelay[index].relay_event.bits.Gun2_P = outputRelay[index].relay_event.bits.Gun2_P;
  1729. }
  1730. }
  1731. if (regRelay[index].relay_event.bits.Gun2_N != outputRelay[index].relay_event.bits.Gun2_N)
  1732. {
  1733. if(TempRegRelay[index].relay_event.bits.Gun2_N != outputRelay[index].relay_event.bits.Gun2_N)
  1734. {
  1735. PRINTF_FUNC("[%d]SMR2:D- Relay none match, need to %s", index,
  1736. outputRelay[index].relay_event.bits.Gun2_N == YES ? "On" : "Off");
  1737. TempRegRelay[index].relay_event.bits.Gun2_N = outputRelay[index].relay_event.bits.Gun2_N;
  1738. }
  1739. }
  1740. if (regRelay[index].relay_event.bits.Gun1_Parallel_P != outputRelay[index].relay_event.bits.Gun1_Parallel_P)
  1741. {
  1742. if(TempRegRelay[index].relay_event.bits.Gun1_Parallel_P != outputRelay[index].relay_event.bits.Gun1_Parallel_P)
  1743. {
  1744. PRINTF_FUNC("[%d]Parallel:D+ Relay none match, need to %s", index,
  1745. outputRelay[index].relay_event.bits.Gun1_Parallel_P == YES ? "On" : "Off");
  1746. TempRegRelay[index].relay_event.bits.Gun1_Parallel_P = outputRelay[index].relay_event.bits.Gun1_Parallel_P;
  1747. }
  1748. }
  1749. if (regRelay[index].relay_event.bits.Gun1_Parallel_N != outputRelay[index].relay_event.bits.Gun1_Parallel_N)
  1750. {
  1751. if(TempRegRelay[index].relay_event.bits.Gun1_Parallel_N != outputRelay[index].relay_event.bits.Gun1_Parallel_N)
  1752. {
  1753. PRINTF_FUNC("[%d]Parallel:D- Relay none match, need to %s", index,
  1754. outputRelay[index].relay_event.bits.Gun1_Parallel_N == YES ? "On" : "Off");
  1755. TempRegRelay[index].relay_event.bits.Gun1_Parallel_N = outputRelay[index].relay_event.bits.Gun1_Parallel_N;
  1756. }
  1757. }
  1758. if (regRelay[index].relay_event.bits.Gun2_Parallel_P != outputRelay[index].relay_event.bits.Gun2_Parallel_P)
  1759. {
  1760. if(TempRegRelay[index].relay_event.bits.Gun2_Parallel_P != outputRelay[index].relay_event.bits.Gun2_Parallel_P)
  1761. {
  1762. PRINTF_FUNC("[%d]Parallel2:D+ Relay none match, need to %s", index,
  1763. outputRelay[index].relay_event.bits.Gun2_Parallel_P == YES ? "On" : "Off");
  1764. TempRegRelay[index].relay_event.bits.Gun2_Parallel_P = outputRelay[index].relay_event.bits.Gun2_Parallel_P;
  1765. }
  1766. }
  1767. if (regRelay[index].relay_event.bits.Gun2_Parallel_N != outputRelay[index].relay_event.bits.Gun2_Parallel_N)
  1768. {
  1769. if(TempRegRelay[index].relay_event.bits.Gun2_Parallel_N != outputRelay[index].relay_event.bits.Gun2_Parallel_N)
  1770. {
  1771. PRINTF_FUNC("[%d]Parallel2:D- Relay none match, need to %s", index,
  1772. outputRelay[index].relay_event.bits.Gun2_Parallel_N == YES ? "On" : "Off");
  1773. TempRegRelay[index].relay_event.bits.Gun2_Parallel_N = outputRelay[index].relay_event.bits.Gun2_Parallel_N;
  1774. }
  1775. }
  1776. result = true;
  1777. }
  1778. return result;
  1779. }
  1780. void MatchRelayStatus()
  1781. {
  1782. // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
  1783. //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  1784. // ShmSysConfigAndInfo->SysInfo.AcContactorStatus = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  1785. // regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  1786. // regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  1787. // regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  1788. // regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  1789. // regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  1790. // regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  1791. // regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  1792. }
  1793. void CheckRelayStatusByADC()
  1794. {
  1795. if (ShmRelayModuleData[0]->Gun1FuseOutputVolt > 0 && ShmRelayModuleData[0]->Gun1RelayOutputVolt > 0 &&
  1796. (ShmRelayModuleData[0]->Gun1FuseOutputVolt == ShmRelayModuleData[0]->Gun1RelayOutputVolt))
  1797. {
  1798. // Relay 前後電壓一致
  1799. _chargingData[0]->RelayK1K2Status = 0x01;
  1800. }
  1801. else
  1802. _chargingData[0]->RelayK1K2Status = 0x00;
  1803. if (ShmRelayModuleData[1]->Gun2FuseOutputVolt > 0 && ShmRelayModuleData[1]->Gun2RelayOutputVolt > 0 &&
  1804. (ShmRelayModuleData[1]->Gun2FuseOutputVolt == ShmRelayModuleData[1]->Gun2RelayOutputVolt))
  1805. {
  1806. // Relay 前後電壓一致
  1807. _chargingData[1]->RelayK1K2Status = 0x01;
  1808. }
  1809. else
  1810. _chargingData[1]->RelayK1K2Status = 0x00;
  1811. }
  1812. void SetGfdConfig(byte index, byte resister)
  1813. {
  1814. gfd_config.index = index;
  1815. gfd_config.state = resister;
  1816. //PRINTF_FUNC("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
  1817. if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS)
  1818. {
  1819. // PRINTF_FUNC("Set reqVol = %f, resister = %d \n",
  1820. // gfd_config.reqVol,
  1821. // gfd_config.resister);
  1822. }
  1823. }
  1824. /*
  1825. void CableCheckDetected(byte index)
  1826. {
  1827. // Cable Check
  1828. // 當火線上的電壓 = 車端要求的電壓電流
  1829. // _chargingData[targetGun]->EvBatterytargetVoltage
  1830. // 才可以開始偵測 1s
  1831. // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
  1832. // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
  1833. // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
  1834. if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
  1835. (_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag))
  1836. {
  1837. if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_TERMINATING) ||
  1838. (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
  1839. {
  1840. if (_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE &&
  1841. _chargingData[index]->RelayWeldingCheck == YES)
  1842. {
  1843. SetGfdConfig(index, GFD_CABLECHK);
  1844. }
  1845. else if (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1846. _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)
  1847. {
  1848. SetGfdConfig(index, GFD_PRECHARGE);
  1849. }
  1850. else if (_chargingData[index]->SystemStatus >= S_CHARGING &&
  1851. _chargingData[index]->SystemStatus <= S_TERMINATING)
  1852. {
  1853. if (_chargingData[index]->Type == _Type_GB || _chargingData[index]->Type == _Type_Chademo)
  1854. SetGfdConfig(index, GFD_IDLE);
  1855. else
  1856. SetGfdConfig(index, GFD_CHARGING);
  1857. }
  1858. }
  1859. else if(_chargingData[index]->SystemStatus == S_COMPLETE || _chargingData[index]->SystemStatus == S_PREPARNING
  1860. || _chargingData[index]->SystemStatus == S_IDLE)
  1861. {
  1862. SetGfdConfig(index, GFD_IDLE);
  1863. }
  1864. }
  1865. }
  1866. */
  1867. void CheckOutputPowerOverCarReq(byte index)
  1868. {
  1869. float fireV = _chargingData[index]->FireChargingVoltage;
  1870. float carV = _chargingData[index]->EvBatterytargetVoltage * 10;
  1871. if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
  1872. (_chargingData[index]->Type == _Type_Chademo ||
  1873. _chargingData[index]->Type == _Type_CCS_2 ||
  1874. _chargingData[index]->Type == _Type_GB))
  1875. {
  1876. if (fireV >= (carV + (carV * 0.1)))
  1877. {
  1878. PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
  1879. _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
  1880. DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
  1881. _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
  1882. _chargingData[index]->StopChargeFlag = YES;
  1883. }
  1884. }
  1885. }
  1886. void CheckOutputVolNoneMatchFire(byte index)
  1887. {
  1888. if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
  1889. (_chargingData[index]->Type == _Type_Chademo ||
  1890. _chargingData[index]->Type == _Type_CCS_2 ||
  1891. _chargingData[index]->Type == _Type_GB))
  1892. {
  1893. if (((_chargingData[index]->PresentChargingVoltage * 10) < _chargingData[index]->FireChargingVoltage - 300) ||
  1894. ((_chargingData[index]->PresentChargingVoltage * 10) > _chargingData[index]->FireChargingVoltage + 300))
  1895. {
  1896. if (!_isOutputNoneMatch[index])
  1897. {
  1898. _isOutputNoneMatch[index] = YES;
  1899. gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
  1900. }
  1901. else
  1902. {
  1903. if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000)
  1904. {
  1905. PRINTF_FUNC("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
  1906. index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
  1907. DEBUG_ERROR("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f \n",
  1908. index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
  1909. _chargingData[index]->StopChargeFlag = YES;
  1910. }
  1911. }
  1912. }
  1913. else
  1914. _isOutputNoneMatch[index] = NO;
  1915. }
  1916. }
  1917. void CheckRelayWeldingStatus(byte index)
  1918. {
  1919. if (!_isRelayWelding[index])
  1920. {
  1921. if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10)
  1922. {
  1923. gettimeofday(&_checkRelayWeldingTimer[index], NULL);
  1924. _isRelayWelding[index] = YES;
  1925. }
  1926. }
  1927. else
  1928. {
  1929. if ((GetTimeoutValue(_checkRelayWeldingTimer[index]) / 1000) >= 1000)
  1930. {
  1931. _chargingData[index]->RelayWeldingCheck = YES;
  1932. return;
  1933. }
  1934. if (_chargingData[index]->FireChargingVoltage >= VOUT_MIN_VOLTAGE)
  1935. {
  1936. if (_chargingData[index]->Type == _Type_Chademo)
  1937. ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
  1938. else if (_chargingData[index]->Type == _Type_GB)
  1939. ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
  1940. else if (_chargingData[index]->Type == _Type_CCS_2)
  1941. ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
  1942. PRINTF_FUNC("CheckRelayWeldingStatus : fail \n");
  1943. _chargingData[index]->StopChargeFlag = YES;
  1944. }
  1945. }
  1946. }
  1947. void GetPsuTempForFanSpeed()
  1948. {
  1949. char temp = 0;
  1950. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1951. {
  1952. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  1953. {
  1954. if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp)
  1955. temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  1956. }
  1957. }
  1958. ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = temp;
  1959. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
  1960. {
  1961. if (ShmFanModuleData->TestFanSpeed == NORMAL_FAN_SPEED)
  1962. {
  1963. if (temp >= ENV_TEMP_MAX)
  1964. ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
  1965. }
  1966. else if (ShmFanModuleData->TestFanSpeed == MAX_FAN_SPEED)
  1967. {
  1968. if (temp <= ENV_TEMP_MIN)
  1969. ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
  1970. }
  1971. else
  1972. ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
  1973. }
  1974. }
  1975. void GetFanSpeedByFunction()
  1976. {
  1977. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
  1978. return;
  1979. // 風控修改 :
  1980. // ******************************************************* //
  1981. //
  1982. // 當前PSU輸出總 KW PSU Temp
  1983. // 50 x -------------------- x ---------- + 0.5 x (PSU Temp - 70)
  1984. // 當前樁最大功率 KW 50
  1985. //
  1986. // ******************************************************* //
  1987. // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
  1988. unsigned int _maxPower = ShmPsuData->SystemAvailablePower;
  1989. // 當前PSU輸出總 KW & PSU Temp :
  1990. unsigned char temp = 0;
  1991. float power = 0;
  1992. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1993. {
  1994. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  1995. {
  1996. if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp)
  1997. temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  1998. }
  1999. power += (_chargingData[index]->PresentChargingPower * 10);
  2000. }
  2001. double _pw_rate = 0;
  2002. if (_maxPower > 0)
  2003. _pw_rate = power / (double)_maxPower;
  2004. double _temp_rate = 0;
  2005. if (temp > 0)
  2006. _temp_rate = (double)temp / 50;
  2007. unsigned char _temp_diff = 0;
  2008. if (temp > 70)
  2009. _temp_diff = temp - 70;
  2010. ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _temp_diff)) / 100) * MAX_FAN_SPEED;
  2011. if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED)
  2012. ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
  2013. if (ShmFanModuleData->TestFanSpeed < 0)
  2014. ShmFanModuleData->TestFanSpeed = 0;
  2015. // -----------------------------------------------------------------------
  2016. // printf("power = %f \n", power);
  2017. // printf("_maxPower = %d \n", _maxPower);
  2018. // printf("temp = %d \n", temp);
  2019. //
  2020. // printf("_pw_rate = %f \n", _pw_rate);
  2021. // printf("_temp_rate = %f \n", _temp_rate);
  2022. // printf("_temp_diff = %d \n", _temp_diff);
  2023. // printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
  2024. // printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
  2025. }
  2026. void GetAcStatus()
  2027. {
  2028. if (Query_AC_Status(Uart5Fd, Addr.AcPlug, &acStatus) == PASS)
  2029. {
  2030. ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = acStatus.MaxCurrent;
  2031. if(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0)
  2032. ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
  2033. ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
  2034. // PRINTF_FUNC("CpStatus = %d \n", acStatus.CpStatus);
  2035. // printf("CurLimit = %d \n", acStatus.CurLimit);
  2036. // printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
  2037. // printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
  2038. // printf("LockStatus = %d \n", acStatus.LockStatus);
  2039. // printf("RelayStatus = %d \n", acStatus.RelayStatus);
  2040. // printf("ShutterStatus = %d \n", acStatus.ShutterStatus);
  2041. // printf("MeterStatus = %d \n", acStatus.MeterStatus);
  2042. // printf("PpStatus = %d \n", acStatus.PpStatus);
  2043. // printf("MaxCurrent = %d \n", acStatus.MaxCurrent);
  2044. // printf("RotateSwitchStatus = %d \n", acStatus.RelayStatus);
  2045. // printf("============================== \n");
  2046. //
  2047. // ac_chargingInfo[0]->SystemStatus = acStatus.CpStatus;
  2048. }
  2049. // else
  2050. // PRINTF_FUNC("GetAcStatus return fail. \n");
  2051. }
  2052. void GetAcAlarmCode()
  2053. {
  2054. if (Query_AC_Alarm_Code(Uart5Fd, Addr.AcPlug, &acAlarmCode) == PASS)
  2055. {
  2056. CheckAlarmOccur();
  2057. }
  2058. }
  2059. unsigned char GetChargingEnergy()
  2060. {
  2061. return Query_Charging_Energy(Uart5Fd, Addr.AcPlug, &acChargingEnergy);
  2062. }
  2063. unsigned char GetChargingCurrent()
  2064. {
  2065. return Query_Charging_Current(Uart5Fd, Addr.AcPlug, &acChargingCurrent);
  2066. }
  2067. void ChangeLedStatus()
  2068. {
  2069. if (ac_chargingInfo[0]->SystemStatus == S_IDLE)
  2070. ledStatus.ActionMode = 1;
  2071. else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING)
  2072. ledStatus.ActionMode = 3;
  2073. else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
  2074. ledStatus.ActionMode = 4;
  2075. Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
  2076. }
  2077. void SetLegacyReq(byte _switch)
  2078. {
  2079. Config_Legacy_Req(Uart5Fd, Addr.AcPlug, _switch);
  2080. }
  2081. void SetCpDuty(byte _value)
  2082. {
  2083. Config_Ac_Duty(Uart5Fd, Addr.AcPlug, _value);
  2084. }
  2085. void ChangeToCsuMode()
  2086. {
  2087. ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, Addr.AcPlug);
  2088. // if (ac_chargingInfo[0]->IsModeChagned == PASS)
  2089. // {
  2090. // Config_Reset_MCU(Uart5Fd, Addr.AcPlug);
  2091. // }
  2092. }
  2093. void ChangeStartOrStopDateTime(byte isStart)
  2094. {
  2095. char cmdBuf[32];
  2096. struct timeb csuTime;
  2097. struct tm *tmCSU;
  2098. ftime(&csuTime);
  2099. tmCSU = localtime(&csuTime.time);
  2100. sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
  2101. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  2102. tmCSU->tm_sec);
  2103. if (isStart)
  2104. strcpy((char *)ac_chargingInfo[0]->StartDateTime, cmdBuf);
  2105. else
  2106. strcpy((char *)ac_chargingInfo[0]->StopDateTime, cmdBuf);
  2107. }
  2108. void OcppStartTransation(byte gunIndex)
  2109. {
  2110. if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
  2111. strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
  2112. else
  2113. strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
  2114. PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
  2115. ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
  2116. }
  2117. void OcppStopTransation(byte gunIndex)
  2118. {
  2119. if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
  2120. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
  2121. else
  2122. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
  2123. PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
  2124. ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
  2125. }
  2126. bool OcppRemoteStop(byte gunIndex)
  2127. {
  2128. bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
  2129. if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES)
  2130. {
  2131. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
  2132. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
  2133. }
  2134. return result;
  2135. }
  2136. unsigned char isModeChange()
  2137. {
  2138. unsigned char result = NO;
  2139. if(ac_chargingInfo[0]->SystemStatus != ac_chargingInfo[0]->PreviousSystemStatus)
  2140. {
  2141. result = YES;
  2142. ac_chargingInfo[0]->PreviousSystemStatus = ac_chargingInfo[0]->SystemStatus;
  2143. }
  2144. return result;
  2145. }
  2146. void AcChargeTypeProcess()
  2147. {
  2148. if (acgunCount > 0)
  2149. {
  2150. //ac_chargingInfo[0]->SelfTest_Comp = YES;
  2151. //ac_chargingInfo[0]->IsModeChagned = PASS;
  2152. //---------------------------------------------
  2153. if (ac_chargingInfo[0]->SelfTest_Comp == NO)
  2154. {
  2155. ac_chargingInfo[0]->IsModeChagned = NO;
  2156. GetFwVersion_AC();
  2157. GetAcModelName();
  2158. }
  2159. else if (ac_chargingInfo[0]->SelfTest_Comp == YES)
  2160. {
  2161. if (ac_chargingInfo[0]->IsModeChagned != PASS)
  2162. {
  2163. ChangeToCsuMode();
  2164. return;
  2165. }
  2166. GetAcStatus();
  2167. GetAcAlarmCode();
  2168. byte _status = S_NONE;
  2169. if (ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsErrorOccur)
  2170. {
  2171. _status = S_ALARM;
  2172. }
  2173. else if (acStatus.CpStatus == AC_SYS_A || ac_chargingInfo[0]->IsErrorOccur)
  2174. {
  2175. if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
  2176. _status = S_TERMINATING;
  2177. else if (ac_chargingInfo[0]->SystemStatus >= S_TERMINATING)
  2178. {
  2179. if (GetTimeoutValue(_ac_charging_comp) >= 10000000 && acStatus.CpStatus == AC_SYS_A)
  2180. _status = S_IDLE;
  2181. }
  2182. else
  2183. _status = S_IDLE;
  2184. }
  2185. else if (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING &&
  2186. ac_chargingInfo[0]->SystemStatus < S_CHARGING)
  2187. {
  2188. if (acStatus.CpStatus == AC_SYS_C && acStatus.RelayStatus == YES)
  2189. _status = S_CHARGING;
  2190. else if (GetTimeoutValue(_ac_preparing) >= 30000000)
  2191. _status = S_IDLE;
  2192. }
  2193. else if ((acStatus.CpStatus == AC_SYS_B || ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_B) &&
  2194. ac_chargingInfo[0]->IsAvailable &&
  2195. !ac_chargingInfo[0]->IsErrorOccur &&
  2196. (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
  2197. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE))
  2198. {
  2199. if (ac_chargingInfo[0]->RemoteStartFlag == YES)
  2200. {
  2201. PRINTF_FUNC("** AC Remote \n");
  2202. ac_chargingInfo[0]->RemoteStartFlag = NO;
  2203. strcpy((char *)ac_chargingInfo[0]->StartUserId, "");
  2204. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
  2205. _status = S_PREPARNING;
  2206. }
  2207. else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
  2208. {
  2209. PRINTF_FUNC("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  2210. strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2211. PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
  2212. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  2213. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
  2214. _status = S_PREPARNING;
  2215. }
  2216. }
  2217. else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
  2218. {
  2219. if (OcppRemoteStop(1))
  2220. _status = S_TERMINATING;
  2221. }
  2222. //printf("_status = %d \n", _status);
  2223. if (_status != S_NONE && ac_chargingInfo[0]->SystemStatus != _status)
  2224. {
  2225. ac_chargingInfo[0]->SystemStatus = _status;
  2226. }
  2227. // 設定限制最大充電電流 >= 6 ~ <= 32
  2228. switch(ac_chargingInfo[0]->SystemStatus)
  2229. {
  2230. case S_IDLE:
  2231. case S_ALARM:
  2232. {
  2233. if (isModeChange())
  2234. {
  2235. ac_chargingInfo[0]->PresentChargedEnergy = 0.0;
  2236. ac_chargingInfo[0]->PresentChargingVoltage = 0;
  2237. ac_chargingInfo[0]->ChargingFee = 0.0;
  2238. strcpy((char *)ac_chargingInfo[0]->StartDateTime, "");
  2239. strcpy((char *)ac_chargingInfo[0]->StopDateTime, "");
  2240. _beforeChargingTotalEnergy = 0.0;
  2241. }
  2242. ChangeLedStatus();
  2243. }
  2244. break;
  2245. case S_PREPARNING:
  2246. {
  2247. if (isModeChange())
  2248. {
  2249. //ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  2250. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  2251. if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
  2252. ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
  2253. gettimeofday(&_ac_preparing, NULL);
  2254. }
  2255. if (GetChargingEnergy() == PASS)
  2256. {
  2257. //ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
  2258. _beforeChargingTotalEnergy = acChargingEnergy.Energy;
  2259. }
  2260. SetLegacyReq(YES);
  2261. ChangeLedStatus();
  2262. }
  2263. break;
  2264. case S_CHARGING:
  2265. {
  2266. if (isModeChange())
  2267. {
  2268. ftime(&_ac_startChargingTime);
  2269. OcppStartTransation(1);
  2270. ChangeStartOrStopDateTime(YES);
  2271. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  2272. }
  2273. if (GetChargingEnergy() == PASS)
  2274. {
  2275. if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0)
  2276. {
  2277. ac_chargingInfo[0]->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
  2278. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
  2279. {
  2280. ac_chargingInfo[0]->ChargingFee += ac_chargingInfo[0]->PresentChargedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
  2281. }
  2282. }
  2283. _beforeChargingTotalEnergy = acChargingEnergy.Energy;
  2284. }
  2285. if (GetChargingCurrent() == PASS)
  2286. ac_chargingInfo[0]->PresentChargingPower = (((float)(AC_DEFAULT_VOL * acChargingCurrent.OuputCurrentL1) / 10) / 1000);
  2287. ftime(&_ac_endChargingTime);
  2288. ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
  2289. ac_chargingInfo[0]->PresentChargingVoltage = AC_DEFAULT_VOL;
  2290. ac_chargingInfo[0]->PresentChargingCurrent = ((float)acChargingCurrent.OuputCurrentL1 / 10);
  2291. // 用以判斷是否有在輸出
  2292. ac_chargingInfo[0]->IsCharging = acStatus.RelayStatus;
  2293. SetCpDuty(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent);
  2294. ChangeLedStatus();
  2295. }
  2296. break;
  2297. case S_TERMINATING:
  2298. {
  2299. if (isModeChange())
  2300. {
  2301. ChangeStartOrStopDateTime(NO);
  2302. gettimeofday(&_ac_charging_comp, NULL);
  2303. }
  2304. SetLegacyReq(NO);
  2305. if (acStatus.RelayStatus == NO)
  2306. ac_chargingInfo[0]->SystemStatus = S_COMPLETE;
  2307. }
  2308. break;
  2309. case S_COMPLETE:
  2310. {
  2311. if (isModeChange())
  2312. {
  2313. gettimeofday(&_ac_charging_comp, NULL);
  2314. ftime(&_ac_endChargingTime);
  2315. if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL)
  2316. {
  2317. // AC 固定為第2把槍
  2318. OcppStopTransation(1);
  2319. }
  2320. ChangeStartOrStopDateTime(NO);
  2321. ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
  2322. }
  2323. }
  2324. break;
  2325. }
  2326. }
  2327. }
  2328. }
  2329. int main(void)
  2330. {
  2331. if(InitShareMemory() == FAIL)
  2332. {
  2333. #ifdef SystemLogMessage
  2334. DEBUG_ERROR("InitShareMemory NG\n");
  2335. #endif
  2336. if(ShmStatusCodeData!=NULL)
  2337. {
  2338. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2339. }
  2340. sleep(5);
  2341. return 0;
  2342. }
  2343. gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  2344. acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  2345. // Open Uart5 for RB
  2346. Uart5Fd = InitComPort();
  2347. Initialization();
  2348. sleep(1);
  2349. if(Uart5Fd < 0)
  2350. {
  2351. PRINTF_FUNC("(Internal) open port error. \n");
  2352. return 0;
  2353. }
  2354. memset(&outputRelay[0], 0x00, sizeof(Relay));
  2355. memset(&outputRelay[1], 0x00, sizeof(Relay));
  2356. if(ShmChargerInfo->Control.SysCtrl.bits.RelayBoardDisable == false)
  2357. {
  2358. if(Config_Relay_Output(Uart5Fd, Addr.DO360_RC1, &outputRelay[0]) != PASS)
  2359. PRINTF_FUNC("Config_Relay1_Output fail");
  2360. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  2361. {
  2362. if(Config_Relay_Output(Uart5Fd, Addr.DO360_RC2, &outputRelay[1]) != PASS)
  2363. PRINTF_FUNC("Config_Relay2_Output fail");
  2364. }
  2365. }
  2366. _RelaySelfTestOK = NO;
  2367. cur_led_color.Connect_1_Red = COLOR_MIN_LV;
  2368. cur_led_color.Connect_1_Green = COLOR_MIN_LV;
  2369. cur_led_color.Connect_1_Blue = COLOR_MIN_LV;
  2370. cur_led_color.Connect_2_Red = COLOR_MIN_LV;
  2371. cur_led_color.Connect_2_Green = COLOR_MIN_LV;
  2372. cur_led_color.Connect_2_Blue = COLOR_MIN_LV;
  2373. //bool printRelayStatus = true;
  2374. for(;;)
  2375. {
  2376. if(!ShmSysConfigAndInfo->SysInfo.FirmwareUpdate)
  2377. {
  2378. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  2379. if(ShmChargerInfo->Control.SysCtrl.bits.RelayBoardDisable == false)
  2380. {
  2381. if (ShmRelayModuleData[0]->SelfTest_Comp == NO)
  2382. {
  2383. // clena fw version
  2384. memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0x00, 32);
  2385. GetFwAndHwVersion_Relay();
  2386. SetRtcData_Relay(0);
  2387. sleep(1);
  2388. if(strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev))
  2389. {
  2390. ShmRelayModuleData[0]->SelfTest_Comp = YES;
  2391. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable == false)
  2392. {
  2393. _RelaySelfTestOK = YES;
  2394. }
  2395. }
  2396. }
  2397. // DO360 RC2
  2398. if (ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable == true &&
  2399. ShmRelayModuleData[1]->SelfTest_Comp == NO)
  2400. {
  2401. // clena fw version
  2402. memset(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, 0x00, 32);
  2403. GetFwAndHwVersion_Relay2();
  2404. SetRtcData_Relay(1);
  2405. sleep(1);
  2406. if (strlen((char *)ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev) != 0)
  2407. {
  2408. ShmRelayModuleData[1]->SelfTest_Comp = YES;
  2409. if(ShmRelayModuleData[0]->SelfTest_Comp == YES)
  2410. {
  2411. _RelaySelfTestOK = YES;
  2412. }
  2413. }
  2414. }
  2415. }
  2416. if(ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable == false)
  2417. {
  2418. if (ShmFanModuleData->SelfTest_Comp == NO)
  2419. {
  2420. // clena fw version
  2421. memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0x00, 32);
  2422. GetFwAndHwVersion_Fan();
  2423. SetModelName_Fan();
  2424. SetRtcData_Fan();
  2425. sleep(1);
  2426. gettimeofday(&_priority_time, NULL);
  2427. if(strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0)
  2428. {
  2429. ShmFanModuleData->SelfTest_Comp = YES;
  2430. }
  2431. }
  2432. }
  2433. if(_RelaySelfTestOK == YES)
  2434. {
  2435. // ==============優先權最高 10 ms ==============
  2436. // 輸出電壓
  2437. GetPersentOutputVol();
  2438. // 三相輸入電壓
  2439. GetPresentInputVol();
  2440. //GetRelayOutputStatus();
  2441. for (int i = 0; i < gunCount; i++)
  2442. {
  2443. // check k1 k2 relay 狀態
  2444. CheckK1K2RelayOutput(i);
  2445. // 依據當前各槍的狀態選擇 搭上/放開 Relay
  2446. SetK1K2RelayStatus(i);
  2447. if (_chargingData[i]->SystemStatus == S_IDLE)
  2448. {
  2449. _chargingData[i]->RelayWeldingCheck = NO;
  2450. _isRelayWelding[i] = NO;
  2451. }
  2452. if (_chargingData[i]->SystemStatus == S_BOOTING ||
  2453. (_chargingData[i]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[i]->SystemStatus <= S_COMPLETE) ||
  2454. (_chargingData[i]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[i]->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  2455. ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
  2456. (ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG))
  2457. {
  2458. _chargingData[i]->IsReadyToCharging = YES;
  2459. // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
  2460. // if (_chargingData[i]->Type == _Type_GB)
  2461. // {
  2462. // if (_chargingData[i]->SystemStatus >= S_PREPARING_FOR_EVSE &&
  2463. // _chargingData[i]->RelayWeldingCheck == NO)
  2464. // CheckRelayWeldingStatus(i);
  2465. // }
  2466. // else
  2467. _chargingData[i]->RelayWeldingCheck = YES;
  2468. if (_chargingData[i]->SystemStatus == S_CHARGING)
  2469. {
  2470. // DO360 do not check under voltage output & any voltage difference
  2471. //CheckOutputPowerOverCarReq(i);
  2472. //CheckOutputVolNoneMatchFire(i);
  2473. }
  2474. else
  2475. _isOutputNoneMatch[i] = NO;
  2476. }
  2477. else
  2478. _chargingData[i]->IsReadyToCharging = NO;
  2479. }
  2480. // 橋接 relay
  2481. SetParalleRelayStatus();
  2482. SetAcContactorStatus();
  2483. // 搭上/鬆開 Relay
  2484. if(IsNoneMatchRelayStatus(0))
  2485. {
  2486. if (Config_Relay_Output(Uart5Fd, Addr.DO360_RC1, &outputRelay[0]))
  2487. {
  2488. regRelay[0].relay_event.bits.AC_Contactor = outputRelay[0].relay_event.bits.AC_Contactor;
  2489. regRelay[0].relay_event.bits.CCS_Precharge = outputRelay[0].relay_event.bits.CCS_Precharge;
  2490. regRelay[0].relay_event.bits.Gun1_P = outputRelay[0].relay_event.bits.Gun1_P;
  2491. regRelay[0].relay_event.bits.Gun1_N = outputRelay[0].relay_event.bits.Gun1_N;
  2492. regRelay[0].relay_event.bits.Gun2_P = outputRelay[0].relay_event.bits.Gun2_P;
  2493. regRelay[0].relay_event.bits.Gun2_N = outputRelay[0].relay_event.bits.Gun2_N;
  2494. regRelay[0].relay_event.bits.Gun1_Parallel_P = outputRelay[0].relay_event.bits.Gun1_Parallel_P;
  2495. regRelay[0].relay_event.bits.Gun1_Parallel_N = outputRelay[0].relay_event.bits.Gun1_Parallel_N;
  2496. regRelay[0].relay_event.bits.Gun2_Parallel_P = outputRelay[0].relay_event.bits.Gun2_Parallel_P;
  2497. regRelay[0].relay_event.bits.Gun2_Parallel_N = outputRelay[0].relay_event.bits.Gun2_Parallel_N;
  2498. }
  2499. }
  2500. if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
  2501. {
  2502. // 搭上/鬆開 Relay
  2503. if(IsNoneMatchRelayStatus(1))
  2504. {
  2505. if (Config_Relay_Output(Uart5Fd, Addr.DO360_RC2, &outputRelay[1]))
  2506. {
  2507. regRelay[1].relay_event.bits.AC_Contactor = outputRelay[1].relay_event.bits.AC_Contactor;
  2508. regRelay[1].relay_event.bits.CCS_Precharge = outputRelay[1].relay_event.bits.CCS_Precharge;
  2509. regRelay[1].relay_event.bits.Gun1_P = outputRelay[1].relay_event.bits.Gun1_P;
  2510. regRelay[1].relay_event.bits.Gun1_N = outputRelay[1].relay_event.bits.Gun1_N;
  2511. regRelay[1].relay_event.bits.Gun2_P = outputRelay[1].relay_event.bits.Gun2_P;
  2512. regRelay[1].relay_event.bits.Gun2_N = outputRelay[1].relay_event.bits.Gun2_N;
  2513. regRelay[1].relay_event.bits.Gun1_Parallel_P = outputRelay[1].relay_event.bits.Gun1_Parallel_P;
  2514. regRelay[1].relay_event.bits.Gun1_Parallel_N = outputRelay[1].relay_event.bits.Gun1_Parallel_N;
  2515. regRelay[1].relay_event.bits.Gun2_Parallel_P = outputRelay[1].relay_event.bits.Gun2_Parallel_P;
  2516. regRelay[1].relay_event.bits.Gun2_Parallel_N = outputRelay[1].relay_event.bits.Gun2_Parallel_N;
  2517. }
  2518. }
  2519. }
  2520. }
  2521. if (ShmFanModuleData->SelfTest_Comp == YES ||
  2522. strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
  2523. ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
  2524. {
  2525. if (GetTimeoutValue(_priority_time) / 1000 >= 1000)
  2526. {
  2527. //GetPsuTempForFanSpeed();
  2528. GetFanSpeedByFunction();
  2529. GetFanSpeed();
  2530. ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
  2531. gettimeofday(&_priority_time, NULL);
  2532. unsigned short TargetSpeed = ShmFanModuleData->TestFanSpeed;
  2533. if(TargetSpeed != 0 && TargetSpeed < MIN_FAN_SPEED)
  2534. {
  2535. TargetSpeed = MIN_FAN_SPEED;
  2536. }
  2537. ShmFanModuleData->SetFan1Speed = TargetSpeed;
  2538. ShmFanModuleData->SetFan2Speed = TargetSpeed;
  2539. ShmFanModuleData->SetFan3Speed = TargetSpeed;
  2540. ShmFanModuleData->SetFan4Speed = TargetSpeed;
  2541. //PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
  2542. SetFanModuleSpeed();
  2543. }
  2544. }
  2545. }
  2546. usleep(10000);
  2547. }
  2548. return FAIL;
  2549. }