Module_InternalComm.c 92 KB

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