Module_InternalComm.c 77 KB

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