Module_InternalComm.c 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372
  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/mman.h>
  11. #include <linux/wireless.h>
  12. #include <arpa/inet.h>
  13. #include <netinet/in.h>
  14. #include <unistd.h>
  15. #include <stdarg.h>
  16. #include <stdio.h> /*標準輸入輸出定義*/
  17. #include <stdlib.h> /*標準函數庫定義*/
  18. #include <unistd.h> /*Unix 標準函數定義*/
  19. #include <fcntl.h> /*檔控制定義*/
  20. #include <termios.h> /*PPSIX 終端控制定義*/
  21. #include <errno.h> /*錯誤號定義*/
  22. #include <string.h>
  23. #include <time.h>
  24. #include <ctype.h>
  25. #include <ifaddrs.h>
  26. #include <math.h>
  27. #include "../../define.h"
  28. #include "internalComm.h"
  29. #include <stdbool.h>
  30. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  31. #define PASS 1
  32. #define FAIL -1
  33. #define YES 1
  34. #define NO 0
  35. #define STOP 0
  36. #define START 1
  37. #define NORMAL 0
  38. #define ABNORMAL 1
  39. #define RELAY_CHECK_TIME 5 // s
  40. #define OUTPUT_VOL_CHK_TIME 200 // ms
  41. #define TEN_MINUTES 600 // s
  42. #define FORCE_STOP_TIME 30
  43. //#define TEN_MINUTES 5
  44. #define ENV_TEMP_MIN 45
  45. #define ENV_TEMP_MAX 50
  46. #define DEFAULT_AC_INDEX 2
  47. #define EQUAL 0
  48. #define COLOR_MAX_LV 100
  49. #define COLOR_MIN_LV 0
  50. #define AC_DEFAULT_VOL 220
  51. #define NO_DEFINE 255
  52. #define NDEFAULT_AC_INDEX 2
  53. #define OVP_UVP_CHK_COUNT 3
  54. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  55. struct StatusCodeData *ShmStatusCodeData;
  56. struct FanModuleData *ShmFanModuleData;
  57. struct RelayModuleData *ShmRelayModuleData;
  58. struct LedModuleData *ShmLedModuleData;
  59. struct CcsData *ShmCcsData;
  60. struct PsuData *ShmPsuData;
  61. struct OCPP16Data *ShmOCPP16Data;
  62. struct OCPP20Data *ShmOCPP20Data;
  63. struct PrimaryMcuData *ShmPrimaryMcuData;
  64. struct DcCommonInformation *ShmDcCommonData;
  65. #define VIN_MAX_VOLTAGE_IEC 285 // 大於該值 : OVP
  66. #define VIN_MAX_REV_VOLTAGE_IEC 275 // 小於賦歸 OVP
  67. #define VIN_MIN_VOLTAGE_IEC 160 // 小於該值 : UVP
  68. #define VIN_MIN_REV_VOLTAGE_IEC 170 // 大於賦歸 UVP
  69. #define VIN_MAX_VOLTAGE_UL 315 // 大於該值 : OVP // 美規 (W)
  70. #define VIN_MAX_REV_VOLTAGE_UL 305 // 小於賦歸 OVP
  71. #define VIN_MIN_VOLTAGE_UL 210 // 小於該值 : UVP
  72. #define VIN_MIN_REV_VOLTAGE_UL 220 // 大於賦歸 UVP
  73. #define VIN_DROP_VOLTAGE 150 // 小於該值 : ac drop
  74. #define VOUT_MAX_VOLTAGE 995
  75. #define VOUT_MIN_VOLTAGE 150
  76. #define IOUT_MAX_CURRENT 50
  77. #define MAX_FAN_SPEED 14000
  78. #define MIN_FAN_SPEED 3000
  79. #define NORMAL_FAN_SPEED 7000
  80. // GFD Status
  81. #define GFD_IDLE 0
  82. #define GFD_CABLECHK 1
  83. #define GFD_PRECHARGE 2
  84. #define GFD_CHARGING 3
  85. // LED Intensity (rate)
  86. #define LED_INTENSITY_DARKEST 0.2
  87. #define LED_INTENSITY_MEDIUM 0.6
  88. #define LED_INTENSITY_BRIGHTEST 1
  89. // EE Spec
  90. #define LED_BRIGHTNESS_LV_HIGH 1
  91. #define LED_BRIGHTNESS_LV_MID 0.5
  92. #define LED_BRIGHTNESS_LV_LOW 0.2
  93. // 最小切換 Relay 電壓
  94. #define SELF_TO_CHANGE_RELAY_STATUS 600
  95. // 透過電壓確認 Relay 是否搭上的依據電壓
  96. #define CHECK_RELAY_STATUS 300
  97. #define CHECK_RELAY_STATUS_GAP 100
  98. // 安全在停止充電程序中斷開 Relay 的電流
  99. #define SEFETY_SWITCH_RELAY_CUR 50
  100. // 確認 Relay Welding 電壓
  101. #define RELAY_WELDING_DET 300
  102. // CCS minimum precharge voltage
  103. #define CCS_PRECHARGE_VOL 2000
  104. #define CCS_PRECHARGE_STARTU 40
  105. byte gunCount;
  106. byte acgunCount;
  107. // 槍資訊
  108. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  109. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  110. byte ac_startTransationFlag;
  111. Relay acOutputRelay;
  112. bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  113. struct timespec _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  114. //bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  115. //struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  116. bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  117. struct timespec _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  118. // SMR1 *2 + SMR2 * 2 + Parallel * 2
  119. struct timespec _relayStateChkTimer[6];
  120. byte _threePhaseOvp[3] = {0, 0, 0};
  121. byte _threePhaseUvp[3] = {0, 0, 0};
  122. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
  123. int Uart5Fd;
  124. char *relayRs485PortName = "/dev/ttyS5";
  125. unsigned short fanSpeedSmoothValue = 500;
  126. bool isStopChargingCount = false;
  127. struct timespec _close_ac_contactor;
  128. struct timespec _priority_time;
  129. struct timespec _led_priority_time;
  130. struct timespec _led_blink_time;
  131. struct timespec _ac_charging_comp;
  132. struct timespec _ac_preparing;
  133. struct timeb _ac_startChargingTime;
  134. struct timeb _ac_endChargingTime;
  135. byte _ac_duty;
  136. bool isCriticalStop;
  137. struct timespec _psuCriticalStop;
  138. unsigned short _setFanSpeed = 0;
  139. float _beforeChargingTotalEnergy = 0.0;
  140. byte _checkLedChanged = 3;
  141. byte relayMatchFlag = 0;
  142. Ver ver;
  143. PresentInputVoltage inputVoltage;
  144. PresentOutputVoltage outputVoltage;
  145. FanSpeed fanSpeed;
  146. Temperature temperature;
  147. AuxPower auxPower;
  148. Gfd gfd_adc;
  149. Gfd_config gfd_config;
  150. Gpio_in gpio_in;
  151. Gpio_out gpio_out;
  152. Relay outputRelay;
  153. Relay regRelay;
  154. Rtc rtc;
  155. Led_Color cur_led_color;
  156. Led_Color led_color;
  157. Ac_Status acStatus;
  158. Ac_Led_Status ledStatus;
  159. Ac_Alarm_code acAlarmCode;
  160. Ac_Charging_energy acChargingEnergy;
  161. Ac_Charging_current acChargingCurrent;
  162. PresentInputVoltage acChargingVoltage;
  163. #define L1_AC_OVP 1
  164. #define L1_AC_UVP 2
  165. #define L1_AC_OCP 4
  166. #define AC_OTP 8
  167. #define AC_GMI_FAULT 16
  168. #define AC_CP_ERROR 32
  169. #define AC_AC_LEAKAGE 64
  170. #define AC_DC_LEAKAGE 128
  171. #define AC_SYSTEM_SELFTEST_FAULT 256
  172. #define AC_HANDSHAKE_TIMEOUT 512
  173. #define AC_EMC_STOP 1024
  174. #define AC_RELAY_WELDING 2048
  175. #define AC_LEAK_MODULE_FAULT 4096
  176. #define AC_SHUTTER_FAULT 8192
  177. #define AC_LOCKER_FAULT 16384
  178. #define AC_POWER_DROP 32768
  179. #define L1_AC_CIRCUIT_SHORT 65536
  180. #define AC_ROTARY_SWITCH_FAULT 131072
  181. #define AC_RELAY_DRIVE_FAULT 262144
  182. #define L2_AC_OVP 524288
  183. #define L3_AC_OVP 1048576
  184. #define L2_AC_UVP 2097152
  185. #define L3_AC_UVP 4194304
  186. #define L2_AC_OCP 8388608
  187. #define L3_AC_OCP 16777216
  188. #define L2_AC_CIRCUIT_SHORT 33554432
  189. #define L3_AC_CIRCUIT_SHORT 67108864
  190. #define AC_METER_TIMEOUT 134217728
  191. #define METER_IC_COMM_TIMEOUT 268435456
  192. int _alarm_code[] = {L1_AC_OVP, L1_AC_UVP, L1_AC_OCP, AC_OTP, AC_GMI_FAULT, AC_CP_ERROR, AC_AC_LEAKAGE
  193. , AC_DC_LEAKAGE, AC_SYSTEM_SELFTEST_FAULT, AC_HANDSHAKE_TIMEOUT, AC_EMC_STOP, AC_RELAY_WELDING
  194. , AC_LEAK_MODULE_FAULT, AC_SHUTTER_FAULT, AC_LOCKER_FAULT, AC_POWER_DROP, L1_AC_CIRCUIT_SHORT
  195. , AC_ROTARY_SWITCH_FAULT, AC_RELAY_DRIVE_FAULT, L2_AC_OVP, L3_AC_OVP, L2_AC_UVP, L3_AC_UVP
  196. , L2_AC_OCP, L3_AC_OCP, L2_AC_CIRCUIT_SHORT, L3_AC_CIRCUIT_SHORT, AC_METER_TIMEOUT
  197. };
  198. void PRINTF_FUNC(char *string, ...);
  199. int StoreLogMsg(const char *fmt, ...);
  200. int GetTimeoutValue(struct timespec *startTime);
  201. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  202. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  203. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  204. long int GetTimeoutMValue(struct timespec *startTime)
  205. {
  206. struct timespec endTime;
  207. clock_gettime(CLOCK_MONOTONIC, &endTime);
  208. return 1000 * (endTime.tv_sec - startTime->tv_sec) + (endTime.tv_nsec - startTime->tv_nsec) / 1000000;
  209. }
  210. void GetTimespecMFunc(struct timespec *time)
  211. {
  212. clock_gettime(CLOCK_MONOTONIC, time);
  213. }
  214. int GetTimeoutValue(struct timespec *startTime)
  215. {
  216. struct timespec endTime;
  217. clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
  218. return endTime.tv_sec - startTime->tv_sec;
  219. }
  220. void GetTimespecFunc(struct timespec *time)
  221. {
  222. clock_gettime(CLOCK_MONOTONIC_COARSE, time);
  223. }
  224. int StoreLogMsg(const char *fmt, ...)
  225. {
  226. char Buf[4096+256];
  227. char buffer[4096];
  228. va_list args;
  229. struct timeb SeqEndTime;
  230. struct tm *tm;
  231. va_start(args, fmt);
  232. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  233. va_end(args);
  234. memset(Buf,0,sizeof(Buf));
  235. ftime(&SeqEndTime);
  236. SeqEndTime.time = time(NULL);
  237. tm=localtime(&SeqEndTime.time);
  238. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
  239. {
  240. sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
  241. tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
  242. printf("%s \n", Buf);
  243. }
  244. else
  245. {
  246. sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
  247. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
  248. buffer,
  249. tm->tm_year+1900,tm->tm_mon+1,
  250. ShmSysConfigAndInfo->SysConfig.SerialNumber);
  251. system(Buf);
  252. }
  253. return rc;
  254. }
  255. int DiffTimeb(struct timeb ST, struct timeb ET)
  256. {
  257. //return milli-second
  258. unsigned int StartTime, StopTime;
  259. StartTime = (unsigned int) ST.time;
  260. StopTime = (unsigned int) ET.time;
  261. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  262. return (StopTime - StartTime);
  263. }
  264. unsigned short MaxValue(unsigned short value1, unsigned short value2)
  265. {
  266. return value1 >= value2 ? value1 : value2;
  267. }
  268. void PRINTF_FUNC(char *string, ...)
  269. {
  270. va_list args;
  271. char buffer[4096];
  272. va_start(args, string);
  273. vsnprintf(buffer, sizeof(buffer), string, args);
  274. va_end(args);
  275. DEBUG_INFO("%s ", buffer);
  276. }
  277. //==========================================
  278. // Communication Function
  279. //==========================================
  280. void GetFwAndHwVersion_Fan()
  281. {
  282. if(Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
  283. {
  284. // FanModuleData
  285. strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
  286. // SystemInfo
  287. strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ver.Version_FW);
  288. //PRINTF_FUNC("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
  289. }
  290. if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
  291. {
  292. // SystemInfo
  293. strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
  294. //PRINTF_FUNC("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
  295. }
  296. }
  297. void GetFwAndHwVersion_Relay()
  298. {
  299. if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
  300. {
  301. // RelayModuleData
  302. strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
  303. // SystemInfo
  304. strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
  305. //PRINTF_FUNC("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
  306. }
  307. if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
  308. {
  309. // SystemInfo
  310. strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
  311. //PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
  312. }
  313. }
  314. void GetFwAndHwVersion_Led()
  315. {
  316. if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
  317. {
  318. // LedModuleData
  319. strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
  320. // SystemInfo
  321. strcpy((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, ver.Version_FW);
  322. ShmLedModuleData->SelfTest_Comp = YES;
  323. }
  324. else
  325. {
  326. //PRINTF_FUNC("GetFwAndHwVersion_Led fail \n");
  327. }
  328. // if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
  329. // {
  330. // // SystemInfo
  331. // strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
  332. // //PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
  333. // }
  334. }
  335. void GetFwVersion_AC()
  336. {
  337. if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS)
  338. {
  339. ac_chargingInfo[0]->SelfTest_Comp = YES;
  340. strcpy((char *) ac_chargingInfo[0]->version, ver.Version_FW);
  341. }
  342. }
  343. void GetAcModelName()
  344. {
  345. memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
  346. if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS)
  347. {
  348. PRINTF_FUNC("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
  349. }
  350. }
  351. void SetRtcData_Relay()
  352. {
  353. struct timeb csuTime;
  354. struct tm *tmCSU;
  355. ftime(&csuTime);
  356. tmCSU = localtime(&csuTime.time);
  357. // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
  358. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  359. // tmCSU->tm_sec);
  360. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  361. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  362. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  363. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  364. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  365. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  366. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  367. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  368. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  369. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  370. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  371. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  372. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  373. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  374. if (Config_Rtc_Data(Uart5Fd, Addr.Relay, &rtc) == PASS)
  375. {
  376. //PRINTF_FUNC("SetRtc (RB) sucessfully. \n");
  377. }
  378. }
  379. void SetModelName_Relay()
  380. {
  381. if (Config_Model_Name(Uart5Fd, Addr.Relay, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
  382. {
  383. //PRINTF_FUNC("Set Model name (RB) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  384. }
  385. }
  386. void SetRtcData_Fan()
  387. {
  388. struct timeb csuTime;
  389. struct tm *tmCSU;
  390. ftime(&csuTime);
  391. tmCSU = localtime(&csuTime.time);
  392. // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
  393. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  394. // tmCSU->tm_sec);
  395. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  396. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  397. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  398. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  399. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  400. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  401. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  402. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  403. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  404. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  405. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  406. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  407. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  408. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  409. if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS)
  410. {
  411. //PRINTF_FUNC("SetRtc (FB) sucessfully. \n");
  412. }
  413. }
  414. void SetModelName_Fan()
  415. {
  416. if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
  417. {
  418. //PRINTF_FUNC("Set Model name (FAN) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  419. }
  420. }
  421. // AC 三相輸入電壓
  422. void GetPresentInputVol()
  423. {
  424. if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS)
  425. {
  426. // resolution : 0.1
  427. ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
  428. ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
  429. ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
  430. //********************************************************************************************************//
  431. // Vin (UVP)
  432. if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
  433. {
  434. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO)
  435. {
  436. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC)
  437. {
  438. PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  439. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT)
  440. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
  441. else
  442. _threePhaseUvp[0] += 1;
  443. }
  444. }
  445. else
  446. {
  447. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC)
  448. {
  449. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
  450. _threePhaseUvp[0] = 0;
  451. }
  452. }
  453. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO)
  454. {
  455. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC)
  456. {
  457. PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  458. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT)
  459. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
  460. else
  461. _threePhaseUvp[1] += 1;
  462. }
  463. }
  464. else
  465. {
  466. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC)
  467. {
  468. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
  469. _threePhaseUvp[1] = 0;
  470. }
  471. }
  472. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO)
  473. {
  474. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC)
  475. {
  476. PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  477. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT)
  478. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
  479. else
  480. _threePhaseUvp[2] += 1;
  481. }
  482. }
  483. else
  484. {
  485. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC)
  486. {
  487. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
  488. _threePhaseUvp[2] = 0;
  489. }
  490. }
  491. }
  492. else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
  493. {
  494. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO)
  495. {
  496. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL)
  497. {
  498. PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  499. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT)
  500. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
  501. else
  502. _threePhaseUvp[0] += 1;
  503. }
  504. }
  505. else
  506. {
  507. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL)
  508. {
  509. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
  510. _threePhaseUvp[0] = 0;
  511. }
  512. }
  513. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO)
  514. {
  515. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL)
  516. {
  517. PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  518. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT)
  519. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
  520. else
  521. _threePhaseUvp[1] += 1;
  522. }
  523. }
  524. else
  525. {
  526. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL)
  527. {
  528. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
  529. _threePhaseUvp[1] = 0;
  530. }
  531. }
  532. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO)
  533. {
  534. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL)
  535. {
  536. PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  537. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT)
  538. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
  539. else
  540. _threePhaseUvp[2] += 1;
  541. }
  542. }
  543. else
  544. {
  545. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL)
  546. {
  547. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
  548. _threePhaseUvp[2] = 0;
  549. }
  550. }
  551. }
  552. //********************************************************************************************************//
  553. // Vin (OVP)
  554. if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
  555. {
  556. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO)
  557. {
  558. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC)
  559. {
  560. PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  561. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT)
  562. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
  563. else
  564. _threePhaseOvp[0] += 1;
  565. }
  566. }
  567. else
  568. {
  569. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC)
  570. {
  571. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
  572. _threePhaseOvp[0] = 0;
  573. }
  574. }
  575. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO)
  576. {
  577. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC)
  578. {
  579. PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  580. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT)
  581. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
  582. else
  583. _threePhaseOvp[1] += 1;
  584. }
  585. }
  586. else
  587. {
  588. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC)
  589. {
  590. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
  591. _threePhaseOvp[1] = 0;
  592. }
  593. }
  594. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO)
  595. {
  596. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC)
  597. {
  598. PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  599. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT)
  600. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
  601. else
  602. _threePhaseOvp[2] += 1;
  603. }
  604. }
  605. else
  606. {
  607. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC)
  608. {
  609. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
  610. _threePhaseOvp[2] = 0;
  611. }
  612. }
  613. }
  614. else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
  615. {
  616. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO)
  617. {
  618. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL)
  619. {
  620. PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  621. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT)
  622. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
  623. else
  624. _threePhaseOvp[0] += 0;
  625. }
  626. }
  627. else
  628. {
  629. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL)
  630. {
  631. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
  632. _threePhaseOvp[0] = 0;
  633. }
  634. }
  635. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO)
  636. {
  637. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL)
  638. {
  639. PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  640. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT)
  641. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
  642. else
  643. _threePhaseOvp[1] += 0;
  644. }
  645. }
  646. else
  647. {
  648. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL)
  649. {
  650. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
  651. _threePhaseOvp[1] = 0;
  652. }
  653. }
  654. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO)
  655. {
  656. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL)
  657. {
  658. PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  659. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT)
  660. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
  661. else
  662. _threePhaseOvp[2] += 1;
  663. }
  664. }
  665. else
  666. {
  667. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL)
  668. {
  669. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
  670. _threePhaseOvp[2] = 0;
  671. }
  672. }
  673. }
  674. }
  675. }
  676. // 左右槍的 Relay 前後的輸出電壓
  677. void GetPersentOutputVol()
  678. {
  679. if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS)
  680. {
  681. // PRINTF_FUNC("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
  682. // PRINTF_FUNC("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
  683. // PRINTF_FUNC("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
  684. // PRINTF_FUNC("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
  685. //PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
  686. //PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
  687. ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  688. ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  689. ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  690. ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  691. for (int index = 0; index < gunCount; index++)
  692. {
  693. if (index == 0)
  694. {
  695. if (_chargingData[index]->Evboard_id == 0x01)
  696. {
  697. _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
  698. _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  699. }
  700. else if (_chargingData[index]->Evboard_id == 0x02)
  701. {
  702. _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
  703. _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  704. }
  705. }
  706. else if (index == 1)
  707. {
  708. _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
  709. _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  710. }
  711. //unsigned short Ovp = 0;
  712. //unsigned short Ocp = 0;
  713. //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] // 最大輸出電壓與電池電壓最大值
  714. //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ] // 最大輸出電流與需求電流最小值
  715. if (_chargingData[index]->Type == _Type_Chademo)
  716. {
  717. //Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
  718. //Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
  719. }
  720. else if (_chargingData[index]->Type == _Type_CCS)
  721. {
  722. }
  723. }
  724. }
  725. }
  726. // 風扇速度
  727. void GetFanSpeed()
  728. {
  729. //PRINTF_FUNC("Get fan board speed \n");
  730. if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS)
  731. {
  732. ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
  733. ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
  734. ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
  735. ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
  736. // PRINTF_FUNC("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
  737. // PRINTF_FUNC("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
  738. // PRINTF_FUNC("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
  739. // PRINTF_FUNC("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
  740. // Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
  741. //SysInfoData (SystemFanRotaSpeed)
  742. }
  743. }
  744. // 讀取 Relay 狀態
  745. void GetRelayOutputStatus()
  746. {
  747. if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS)
  748. {
  749. //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
  750. }
  751. }
  752. // 確認 K1 K2 relay 的狀態
  753. void CheckK1K2RelayOutput(byte index)
  754. {
  755. if (index == 0)
  756. {
  757. if (_chargingData[index]->Evboard_id == 0x01)
  758. {
  759. if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES)
  760. _chargingData[index]->RelayK1K2Status = YES;
  761. else
  762. _chargingData[index]->RelayK1K2Status = NO;
  763. if(_chargingData[index]->Type == _Type_CCS)
  764. {
  765. // if (gunCount == 1)
  766. // {
  767. // if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
  768. // _chargingData[index]->RelayKPK2Status = YES;
  769. // else
  770. // _chargingData[index]->RelayKPK2Status = NO;
  771. // }
  772. // else
  773. {
  774. if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
  775. _chargingData[index]->RelayKPK2Status = YES;
  776. else
  777. _chargingData[index]->RelayKPK2Status = NO;
  778. }
  779. }
  780. }
  781. else if (_chargingData[index]->Evboard_id == 0x02)
  782. {
  783. if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
  784. _chargingData[index]->RelayK1K2Status = YES;
  785. else
  786. _chargingData[index]->RelayK1K2Status = NO;
  787. if(_chargingData[index]->Type == _Type_CCS)
  788. {
  789. // if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
  790. // _chargingData[index]->RelayKPK2Status = YES;
  791. // else
  792. // _chargingData[index]->RelayKPK2Status = NO;
  793. if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
  794. _chargingData[index]->RelayKPK2Status = YES;
  795. else
  796. _chargingData[index]->RelayKPK2Status = NO;
  797. }
  798. }
  799. }
  800. else if (index == 1)
  801. {
  802. if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
  803. _chargingData[index]->RelayK1K2Status = YES;
  804. else
  805. _chargingData[index]->RelayK1K2Status = NO;
  806. if(_chargingData[index]->Type == _Type_CCS)
  807. {
  808. // if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
  809. // _chargingData[index]->RelayKPK2Status = YES;
  810. // else
  811. // _chargingData[index]->RelayKPK2Status = NO;
  812. if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
  813. _chargingData[index]->RelayKPK2Status = YES;
  814. else
  815. _chargingData[index]->RelayKPK2Status = NO;
  816. }
  817. }
  818. if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
  819. {
  820. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
  821. regRelay.relay_event.bits.Gun1_Parallel_P == NO)
  822. ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
  823. }
  824. else if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
  825. {
  826. if (regRelay.relay_event.bits.Gun1_Parallel_N == YES &&
  827. regRelay.relay_event.bits.Gun1_Parallel_P == YES)
  828. ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
  829. }
  830. // PRINTF_FUNC("Check Relay Output. index = %d, RelayKPK2Status = %d, BridgeRelayStatus = %d \n",
  831. // index, _chargingData[index]->RelayKPK2Status, ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus);
  832. }
  833. void GetGfdAdc()
  834. {
  835. // define : 每 0.2 ~ 1 秒一次
  836. // occur : <= 75k 歐姆 @ 150 - 750 Vdc
  837. // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
  838. if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS)
  839. {
  840. for (int i = 0; i < gunCount; i++)
  841. {
  842. if (_chargingData[i]->Type == 0x09 && !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)
  843. {
  844. if (_chargingData[i]->FireChargingVoltage >= VOUT_MIN_VOLTAGE)
  845. _chargingData[i]->GroundFaultStatus = GFD_PASS;
  846. continue;
  847. }
  848. if (i == 0)
  849. {
  850. _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn1;
  851. // PRINTF_FUNC("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
  852. // _chargingData[i]->GroundFaultStatus, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  853. if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
  854. {
  855. PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
  856. i, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  857. }
  858. else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
  859. _chargingData[i]->GroundFaultStatus == GFD_WARNING)
  860. {
  861. if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
  862. {
  863. PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
  864. i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  865. }
  866. }
  867. }
  868. else if (i == 1)
  869. {
  870. _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn2;
  871. if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
  872. {
  873. PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
  874. i, gfd_adc.rb_step_2, gfd_adc.Resister_conn2, gfd_adc.voltage_conn2);
  875. }
  876. else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
  877. _chargingData[i]->GroundFaultStatus == GFD_WARNING)
  878. {
  879. if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
  880. {
  881. PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
  882. i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
  883. }
  884. }
  885. }
  886. }
  887. }
  888. }
  889. void GetGpioInput()
  890. {
  891. if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS)
  892. {
  893. // AC Contactor Status
  894. if (gpio_in.AC_MainBreaker == 1)
  895. {
  896. // AC Main Breaker ON
  897. PRINTF_FUNC("RB AC Main Breaker. \n");
  898. }
  899. if (gpio_in.SPD == 1)
  900. {
  901. // SPD (雷擊保護) ON
  902. PRINTF_FUNC("RB SPD. \n");
  903. }
  904. if (gpio_in.Door_Open == 1)
  905. {
  906. // Door Open
  907. PRINTF_FUNC("RB Door Open. \n");
  908. }
  909. if (gpio_in.GFD[0] == 1)
  910. {
  911. // GFD_1 Trigger
  912. }
  913. if (gpio_in.GFD[1] == 1)
  914. {
  915. // GFD_2 Trigger
  916. }
  917. if (gpio_in.AC_Drop == 1)
  918. {
  919. // AC Drop
  920. PRINTF_FUNC("RB AC Drop. \n");
  921. }
  922. if (gpio_in.Emergency_IO == 1)
  923. {
  924. // Emergency IO ON
  925. PRINTF_FUNC("RB Emergency IO ON. \n");
  926. }
  927. if (gpio_in.Button_Emergency_Press == 1)
  928. {
  929. // Emergency button Press
  930. }
  931. if (gpio_in.Button_On_Press == 1)
  932. {
  933. // On button Press
  934. }
  935. if (gpio_in.Button_Off_Press == 1)
  936. {
  937. // Off button Press
  938. }
  939. if (gpio_in.Key_1_Press == 1)
  940. {
  941. // key 1 press
  942. }
  943. if (gpio_in.Key_2_Press == 1)
  944. {
  945. // key 2 press
  946. }
  947. if (gpio_in.Key_3_Press == 1)
  948. {
  949. // key 3 press
  950. }
  951. if (gpio_in.Key_4_Press == 1)
  952. {
  953. // key 4 press
  954. }
  955. }
  956. }
  957. // 5V 12V 24V 48V
  958. void GetAuxPower()
  959. {
  960. if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS)
  961. {
  962. ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
  963. ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
  964. //ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
  965. //ShmSysConfigAndInfo->SysInfo.AuxPower5V = auxPower.voltage[6];
  966. // aux power voltage
  967. //PRINTF_FUNC("aux1 = %x, \n", auxPower.voltage[0]);
  968. //PRINTF_FUNC("aux2 = %x, \n", auxPower.voltage[1]);
  969. }
  970. }
  971. void SetFanModuleSpeed()
  972. {
  973. {
  974. FanSpeed _fanSpeed;
  975. _setFanSpeed += fanSpeedSmoothValue;
  976. if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed)
  977. _setFanSpeed = ShmFanModuleData->SetFan1Speed;
  978. //printf("_setFanSpeed = %d \n", _setFanSpeed);
  979. _fanSpeed.speed[0] = _setFanSpeed;
  980. _fanSpeed.speed[1] = _setFanSpeed;
  981. _fanSpeed.speed[2] = _setFanSpeed;
  982. _fanSpeed.speed[3] = _setFanSpeed;
  983. if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS)
  984. {
  985. //PRINTF_FUNC("successfully Fan\n");
  986. }
  987. }
  988. }
  989. //==========================================
  990. // Common Function
  991. //==========================================
  992. void SetK1K2RelayStatus(byte index)
  993. {
  994. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  995. {
  996. if(regRelay.relay_event.bits.Gun1_N == NO)
  997. outputRelay.relay_event.bits.Gun1_N = YES;
  998. else if (regRelay.relay_event.bits.Gun1_P == NO)
  999. outputRelay.relay_event.bits.Gun1_P = YES;
  1000. return;
  1001. }
  1002. if (_chargingData[index]->SystemStatus < SYS_MODE_PREPARE_FOR_EVSE ||
  1003. _chargingData[index]->SystemStatus == SYS_MODE_FAULT)
  1004. {
  1005. if (_chargingData[index]->Evboard_id == 0x01)
  1006. {
  1007. outputRelay.relay_event.bits.Gun1_P = NO;
  1008. outputRelay.relay_event.bits.Gun1_N = NO;
  1009. if (gunCount == 1 && _chargingData[index]->Type == _Type_CCS)
  1010. {
  1011. if(regRelay.relay_event.bits.CCS_Precharge == YES)
  1012. outputRelay.relay_event.bits.CCS_Precharge = NO;
  1013. }
  1014. }
  1015. else if (_chargingData[index]->Evboard_id == 0x02)
  1016. {
  1017. outputRelay.relay_event.bits.Gun2_P = NO;
  1018. outputRelay.relay_event.bits.Gun2_N = NO;
  1019. if (_chargingData[index]->Type == _Type_CCS)
  1020. {
  1021. if(regRelay.relay_event.bits.CCS_Precharge == YES)
  1022. outputRelay.relay_event.bits.CCS_Precharge = NO;
  1023. }
  1024. }
  1025. }
  1026. else if ((_chargingData[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE &&
  1027. _chargingData[index]->SystemStatus <= SYS_MODE_CHARGING))
  1028. {
  1029. //if (_chargingData[index]->RelayWeldingCheck == YES)
  1030. {
  1031. if (_chargingData[index]->Evboard_id == 0x01)
  1032. {
  1033. if(regRelay.relay_event.bits.Gun1_N == NO)
  1034. outputRelay.relay_event.bits.Gun1_N = YES;
  1035. else if (regRelay.relay_event.bits.Gun1_P == NO)
  1036. outputRelay.relay_event.bits.Gun1_P = YES;
  1037. }
  1038. else if (_chargingData[index]->Evboard_id == 0x02)
  1039. {
  1040. if(regRelay.relay_event.bits.Gun2_N == NO)
  1041. outputRelay.relay_event.bits.Gun2_N = YES;
  1042. else if (regRelay.relay_event.bits.Gun2_P == NO)
  1043. outputRelay.relay_event.bits.Gun2_P = YES;
  1044. }
  1045. }
  1046. }
  1047. else if (_chargingData[index]->SystemStatus >= SYS_MODE_TERMINATING &&
  1048. _chargingData[index]->SystemStatus <= SYS_MODE_ALARM)
  1049. {
  1050. if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR)
  1051. {
  1052. if (_chargingData[index]->Evboard_id == 0x01)
  1053. {
  1054. if(regRelay.relay_event.bits.Gun1_P == YES)
  1055. outputRelay.relay_event.bits.Gun1_P = NO;
  1056. else if (regRelay.relay_event.bits.Gun1_N == YES)
  1057. outputRelay.relay_event.bits.Gun1_N = NO;
  1058. }
  1059. else if (_chargingData[index]->Evboard_id == 0x02)
  1060. {
  1061. if(regRelay.relay_event.bits.Gun2_P == YES)
  1062. outputRelay.relay_event.bits.Gun2_P = NO;
  1063. else if (regRelay.relay_event.bits.Gun2_N == YES)
  1064. outputRelay.relay_event.bits.Gun2_N = NO;
  1065. }
  1066. }
  1067. }
  1068. else if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
  1069. {
  1070. // if (_chargingData[index]->Evboard_id == 0x01)
  1071. // {
  1072. // if (_chargingData[index]->Type == _Type_CCS_2)
  1073. // {
  1074. // if (gunCount == 1)
  1075. // {
  1076. // if (regRelay.relay_event.bits.CCS_Precharge == NO)
  1077. // outputRelay.relay_event.bits.CCS_Precharge = YES;
  1078. // else if (regRelay.relay_event.bits.CCS_Precharge == YES)
  1079. // outputRelay.relay_event.bits.Gun1_P = NO;
  1080. // }
  1081. // }
  1082. // }
  1083. // else if (_chargingData[index]->Evboard_id == 0x02)
  1084. // {
  1085. // if (_chargingData[index]->Type == _Type_CCS_2)
  1086. // {
  1087. // if (regRelay.relay_event.bits.CCS_Precharge == NO)
  1088. // outputRelay.relay_event.bits.CCS_Precharge = YES;
  1089. // else if (regRelay.relay_event.bits.CCS_Precharge == YES)
  1090. // outputRelay.relay_event.bits.Gun2_P = NO;
  1091. // }
  1092. // }
  1093. }
  1094. else if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP1)
  1095. {
  1096. // if (_chargingData[index]->Evboard_id == 0x01)
  1097. // {
  1098. // if (_chargingData[index]->Type == _Type_CCS_2)
  1099. // {
  1100. // if (gunCount == 1)
  1101. // {
  1102. // if (regRelay.relay_event.bits.Gun1_P == NO)
  1103. // outputRelay.relay_event.bits.Gun1_P = YES;
  1104. // else if(regRelay.relay_event.bits.Gun1_P == YES)
  1105. // outputRelay.relay_event.bits.CCS_Precharge = NO;
  1106. // }
  1107. // }
  1108. // }
  1109. // else if (_chargingData[index]->Evboard_id == 0x02)
  1110. // {
  1111. // if (_chargingData[index]->Type == _Type_CCS_2)
  1112. // {
  1113. // if (regRelay.relay_event.bits.Gun2_P == NO)
  1114. // outputRelay.relay_event.bits.Gun2_P = YES;
  1115. // else if(regRelay.relay_event.bits.Gun2_P == YES)
  1116. // outputRelay.relay_event.bits.CCS_Precharge = NO;
  1117. // }
  1118. // }
  1119. }
  1120. }
  1121. void SetParalleRelayStatus()
  1122. {
  1123. // 之後雙槍單模機種,橋接都會上
  1124. if (gunCount >= 2 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
  1125. {
  1126. if (_chargingData[0]->SystemStatus == SYS_MODE_BOOTING || _chargingData[1]->SystemStatus == SYS_MODE_BOOTING ||
  1127. ((_chargingData[0]->SystemStatus == SYS_MODE_IDLE || _chargingData[0]->SystemStatus == SYS_MODE_MAINTAIN) &&
  1128. (_chargingData[1]->SystemStatus == SYS_MODE_IDLE || _chargingData[1]->SystemStatus == SYS_MODE_MAINTAIN)))
  1129. {
  1130. // 初始化~ 不搭橋接
  1131. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
  1132. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  1133. else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
  1134. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  1135. }
  1136. else
  1137. {
  1138. if (_chargingData[0]->IsReadyToCharging == YES ||
  1139. _chargingData[1]->IsReadyToCharging == YES)
  1140. {
  1141. // ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
  1142. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  1143. {
  1144. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A)
  1145. {
  1146. // 最大充 - 搭上橋接
  1147. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO)
  1148. outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
  1149. else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO)
  1150. outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
  1151. }
  1152. else
  1153. {
  1154. // 平均充 - 不搭
  1155. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
  1156. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  1157. else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
  1158. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  1159. }
  1160. }
  1161. else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
  1162. {
  1163. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M)
  1164. {
  1165. // 平均充 - 不搭
  1166. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
  1167. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  1168. else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
  1169. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  1170. }
  1171. else
  1172. {
  1173. // 最大充 - 搭上橋接
  1174. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO)
  1175. outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
  1176. else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO)
  1177. outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
  1178. }
  1179. }
  1180. }
  1181. }
  1182. }
  1183. }
  1184. void CheckAlarmOccur()
  1185. {
  1186. bool isErr = false;
  1187. for(byte count = 0; count < sizeof(_alarm_code)/sizeof(_alarm_code[0]); count++)
  1188. {
  1189. if (acAlarmCode.AcAlarmCode & _alarm_code[count])
  1190. {
  1191. isErr = true;
  1192. switch(_alarm_code[count])
  1193. {
  1194. case L1_AC_OVP:
  1195. case L2_AC_OVP:
  1196. case L3_AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = YES; break;
  1197. case L1_AC_UVP:
  1198. case L2_AC_UVP:
  1199. case L3_AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = YES; break;
  1200. case L2_AC_OCP:
  1201. case L3_AC_OCP:
  1202. case L1_AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = YES; break;
  1203. case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = YES; break;
  1204. case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = YES; break;
  1205. case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = YES; break;
  1206. case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
  1207. case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
  1208. case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = YES; break;
  1209. case AC_HANDSHAKE_TIMEOUT: break;
  1210. //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES; break;
  1211. case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = YES; break;
  1212. case AC_LEAK_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = YES; break;
  1213. case AC_SHUTTER_FAULT: break;
  1214. case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = YES; break;
  1215. case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = YES; break;
  1216. case L1_AC_CIRCUIT_SHORT:
  1217. case L2_AC_CIRCUIT_SHORT:
  1218. case L3_AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = YES; break;
  1219. case AC_ROTARY_SWITCH_FAULT: break;
  1220. case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = YES; break;
  1221. case AC_METER_TIMEOUT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = YES; break;
  1222. case METER_IC_COMM_TIMEOUT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = YES; break;
  1223. }
  1224. }
  1225. else
  1226. {
  1227. switch(_alarm_code[count])
  1228. {
  1229. case L1_AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = NO; break;
  1230. case L1_AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = NO; break;
  1231. case L1_AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = NO; break;
  1232. case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = NO; break;
  1233. case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = NO; break;
  1234. case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = NO; break;
  1235. case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
  1236. case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
  1237. case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = NO; break;
  1238. case AC_HANDSHAKE_TIMEOUT: break;
  1239. //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO; break;
  1240. case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = NO; break;
  1241. case AC_LEAK_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = NO; break;
  1242. case AC_SHUTTER_FAULT: break;
  1243. case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = NO; break;
  1244. case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = NO; break;
  1245. case L1_AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = NO; break;
  1246. case AC_ROTARY_SWITCH_FAULT: break;
  1247. case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = NO; break;
  1248. case AC_METER_TIMEOUT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = NO; break;
  1249. case METER_IC_COMM_TIMEOUT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = NO; break;
  1250. }
  1251. }
  1252. }
  1253. ac_chargingInfo[0]->IsErrorOccur = isErr;
  1254. }
  1255. bool IsNoneMatchLedColor()
  1256. {
  1257. bool result = false;
  1258. if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
  1259. cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
  1260. cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
  1261. cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
  1262. cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
  1263. cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue)
  1264. {
  1265. result = true;
  1266. }
  1267. return result;
  1268. }
  1269. void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
  1270. {
  1271. byte _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
  1272. if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_DARKEST)
  1273. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
  1274. else if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_MEDIUM)
  1275. _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
  1276. if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL ||
  1277. (chargingData_1->SystemStatus == SYS_MODE_UPDATE && chargingData_2->SystemStatus == SYS_MODE_UPDATE))
  1278. {
  1279. led_color.Connect_1_Green = COLOR_MIN_LV;
  1280. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1281. led_color.Connect_1_Red = _colorBuf;
  1282. led_color.Connect_2_Green = COLOR_MIN_LV;
  1283. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1284. led_color.Connect_2_Red = _colorBuf;
  1285. }
  1286. else
  1287. {
  1288. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
  1289. {
  1290. if ((chargingData_1->SystemStatus == SYS_MODE_BOOTING || chargingData_1->SystemStatus == SYS_MODE_IDLE || chargingData_1->SystemStatus == SYS_MODE_RESERVATION || chargingData_1->SystemStatus == SYS_MODE_MAINTAIN) &&
  1291. (chargingData_2->SystemStatus == SYS_MODE_BOOTING || chargingData_2->SystemStatus == SYS_MODE_IDLE || chargingData_2->SystemStatus == SYS_MODE_RESERVATION || chargingData_2->SystemStatus == SYS_MODE_MAINTAIN))
  1292. {
  1293. led_color.Connect_1_Green = _colorBuf;
  1294. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1295. led_color.Connect_1_Red = COLOR_MIN_LV;
  1296. led_color.Connect_2_Green = _colorBuf;
  1297. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1298. led_color.Connect_2_Red = COLOR_MIN_LV;
  1299. if (chargingData_1->SystemStatus == SYS_MODE_RESERVATION ||
  1300. chargingData_2->SystemStatus == SYS_MODE_RESERVATION)
  1301. {
  1302. if (GetTimeoutValue(&_led_blink_time) > 3)
  1303. {
  1304. led_color.Connect_1_Green = COLOR_MIN_LV;
  1305. led_color.Connect_2_Green = COLOR_MIN_LV;
  1306. }
  1307. }
  1308. else if (chargingData_1->SystemStatus == SYS_MODE_MAINTAIN ||
  1309. chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
  1310. {
  1311. led_color.Connect_1_Green = COLOR_MIN_LV;
  1312. led_color.Connect_2_Green = COLOR_MIN_LV;
  1313. led_color.Connect_1_Red = _colorBuf;
  1314. led_color.Connect_2_Red = _colorBuf;
  1315. }
  1316. }
  1317. else if ((chargingData_1->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_1->SystemStatus <= SYS_MODE_COMPLETE) ||
  1318. (chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
  1319. (chargingData_2->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_2->SystemStatus <= SYS_MODE_COMPLETE) ||
  1320. (chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1321. {
  1322. led_color.Connect_1_Green = COLOR_MIN_LV;
  1323. led_color.Connect_1_Blue = _colorBuf;
  1324. led_color.Connect_1_Red = COLOR_MIN_LV;
  1325. led_color.Connect_2_Green = COLOR_MIN_LV;
  1326. led_color.Connect_2_Blue = _colorBuf;
  1327. led_color.Connect_2_Red = COLOR_MIN_LV;
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if (chargingData_1->SystemStatus == SYS_MODE_BOOTING ||
  1333. chargingData_1->SystemStatus == SYS_MODE_IDLE ||
  1334. chargingData_1->SystemStatus == SYS_MODE_RESERVATION ||
  1335. chargingData_1->SystemStatus == SYS_MODE_MAINTAIN)
  1336. {
  1337. led_color.Connect_1_Green = _colorBuf;
  1338. led_color.Connect_1_Blue = COLOR_MIN_LV;
  1339. led_color.Connect_1_Red = COLOR_MIN_LV;
  1340. if (chargingData_1->SystemStatus == SYS_MODE_RESERVATION)
  1341. {
  1342. if (GetTimeoutValue(&_led_blink_time) > 3)
  1343. {
  1344. led_color.Connect_1_Green = COLOR_MIN_LV;
  1345. }
  1346. }
  1347. else if (chargingData_1->SystemStatus == SYS_MODE_MAINTAIN)
  1348. {
  1349. led_color.Connect_1_Green = COLOR_MIN_LV;
  1350. led_color.Connect_1_Red = _colorBuf;
  1351. }
  1352. }
  1353. else if ((chargingData_1->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_1->SystemStatus <= SYS_MODE_COMPLETE) ||
  1354. (chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1355. {
  1356. led_color.Connect_1_Green = COLOR_MIN_LV;
  1357. led_color.Connect_1_Blue = _colorBuf;
  1358. led_color.Connect_1_Red = COLOR_MIN_LV;
  1359. }
  1360. // --------------------------------------------------------------------------
  1361. if (chargingData_2->SystemStatus == SYS_MODE_BOOTING ||
  1362. chargingData_2->SystemStatus == SYS_MODE_IDLE ||
  1363. chargingData_2->SystemStatus == SYS_MODE_RESERVATION ||
  1364. chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
  1365. {
  1366. led_color.Connect_2_Green = _colorBuf;
  1367. led_color.Connect_2_Blue = COLOR_MIN_LV;
  1368. led_color.Connect_2_Red = COLOR_MIN_LV;
  1369. if (chargingData_2->SystemStatus == SYS_MODE_RESERVATION)
  1370. {
  1371. if (GetTimeoutValue(&_led_blink_time) > 3)
  1372. {
  1373. led_color.Connect_2_Green = COLOR_MIN_LV;
  1374. }
  1375. }
  1376. else if (chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
  1377. {
  1378. led_color.Connect_2_Green = COLOR_MIN_LV;
  1379. led_color.Connect_2_Red = _colorBuf;
  1380. }
  1381. }
  1382. else if ((chargingData_2->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_2->SystemStatus <= SYS_MODE_COMPLETE) ||
  1383. (chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1384. {
  1385. led_color.Connect_2_Green = COLOR_MIN_LV;
  1386. led_color.Connect_2_Blue = _colorBuf;
  1387. led_color.Connect_2_Red = COLOR_MIN_LV;
  1388. }
  1389. }
  1390. }
  1391. if (_checkLedChanged > 0)
  1392. {
  1393. if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS)
  1394. {
  1395. _checkLedChanged--;
  1396. cur_led_color.Connect_1_Red = led_color.Connect_1_Red;
  1397. cur_led_color.Connect_1_Green = led_color.Connect_1_Green;
  1398. cur_led_color.Connect_1_Blue = led_color.Connect_1_Blue;
  1399. cur_led_color.Connect_2_Red = led_color.Connect_2_Red;
  1400. cur_led_color.Connect_2_Green = led_color.Connect_2_Green;
  1401. cur_led_color.Connect_2_Blue = led_color.Connect_2_Blue;
  1402. }
  1403. }
  1404. else if (IsNoneMatchLedColor())
  1405. _checkLedChanged = 3;
  1406. }
  1407. //==========================================
  1408. // Init all share memory
  1409. //==========================================
  1410. int InitShareMemory()
  1411. {
  1412. int result = PASS;
  1413. int MeterSMId;
  1414. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1415. {
  1416. #ifdef SystemLogMessage
  1417. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1418. #endif
  1419. result = FAIL;
  1420. }
  1421. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1422. {
  1423. #ifdef SystemLogMessage
  1424. DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
  1425. #endif
  1426. result = FAIL;
  1427. }
  1428. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1429. {
  1430. #ifdef SystemLogMessage
  1431. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1432. #endif
  1433. result = FAIL;
  1434. }
  1435. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1436. {
  1437. #ifdef SystemLogMessage
  1438. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1439. #endif
  1440. result = FAIL;
  1441. }
  1442. if(CCS_QUANTITY > 0)
  1443. {
  1444. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  1445. {
  1446. #ifdef SystemLogMessage
  1447. DEBUG_ERROR("shmget ShmCcsData NG \n");
  1448. #endif
  1449. return FAIL;
  1450. }
  1451. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1452. {
  1453. #ifdef SystemLogMessage
  1454. DEBUG_ERROR("shmat ShmCcsData NG \n");
  1455. #endif
  1456. return FAIL;
  1457. }
  1458. }
  1459. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), 0777)) < 0)
  1460. {
  1461. #ifdef SystemLogMessage
  1462. DEBUG_ERROR("shmget ShmFanModuleData NG\n");
  1463. #endif
  1464. result = FAIL;
  1465. }
  1466. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1467. {
  1468. #ifdef SystemLogMessage
  1469. DEBUG_ERROR("shmat ShmFanModuleData NG\n");
  1470. #endif
  1471. result = FAIL;
  1472. }
  1473. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), 0777)) < 0)
  1474. {
  1475. #ifdef SystemLogMessage
  1476. DEBUG_ERROR("shmget ShmRelayModuleData NG\n");
  1477. #endif
  1478. result = FAIL;
  1479. }
  1480. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1481. {
  1482. #ifdef SystemLogMessage
  1483. DEBUG_ERROR("shmat ShmRelayModuleData NG\n");
  1484. #endif
  1485. result = FAIL;
  1486. }
  1487. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  1488. {
  1489. #ifdef SystemLogMessage
  1490. DEBUG_ERROR("shmget ShmLedModuleData NG\n");
  1491. #endif
  1492. result = FAIL;
  1493. }
  1494. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1495. {
  1496. #ifdef SystemLogMessage
  1497. DEBUG_ERROR("shmat ShmLedModuleData NG\n");
  1498. #endif
  1499. result = FAIL;
  1500. }
  1501. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1502. {
  1503. #ifdef SystemLogMessage
  1504. DEBUG_ERROR("shmget ShmPsuData NG \n");
  1505. #endif
  1506. result = FAIL;
  1507. }
  1508. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1509. {
  1510. #ifdef SystemLogMessage
  1511. DEBUG_ERROR("shmat ShmPsuData NG \n");
  1512. #endif
  1513. result = FAIL;
  1514. }
  1515. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1516. {
  1517. #ifdef SystemLogMessage
  1518. DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
  1519. #endif
  1520. result = FAIL;
  1521. }
  1522. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1523. {
  1524. #ifdef SystemLogMessage
  1525. DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
  1526. #endif
  1527. result = FAIL;
  1528. }
  1529. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
  1530. {
  1531. #ifdef SystemLogMessage
  1532. DEBUG_ERROR("shmat ShmOCPP20Data NG \n");
  1533. #endif
  1534. result = FAIL;
  1535. }
  1536. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1537. {
  1538. #ifdef SystemLogMessage
  1539. DEBUG_ERROR("shmat ShmOCPP20Data NG \n");
  1540. #endif
  1541. result = FAIL;
  1542. }
  1543. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
  1544. {
  1545. #ifdef SystemLogMessage
  1546. DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
  1547. #endif
  1548. result = FAIL;
  1549. }
  1550. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1551. {
  1552. #ifdef ShmPrimaryMcuData
  1553. DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
  1554. #endif
  1555. result = FAIL;
  1556. }
  1557. if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
  1558. {
  1559. #ifdef SystemLogMessage
  1560. DEBUG_ERROR("shmget ShmCommonKey NG \n");
  1561. #endif
  1562. return 0;
  1563. }
  1564. else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1565. {
  1566. #ifdef SystemLogMessage
  1567. DEBUG_ERROR("shmat ShmCommonKey NG \n");
  1568. #endif
  1569. return 0;
  1570. }
  1571. return result;
  1572. }
  1573. int InitComPort()
  1574. {
  1575. int fd;
  1576. struct termios tios;
  1577. fd = open(relayRs485PortName, O_RDWR);
  1578. if(fd <= 0)
  1579. {
  1580. #ifdef SystemLogMessage
  1581. DEBUG_ERROR("Module_InternalComm. InitComPort NG\n");
  1582. #endif
  1583. if(ShmStatusCodeData!=NULL)
  1584. {
  1585. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
  1586. }
  1587. sleep(5);
  1588. return -1;
  1589. }
  1590. ioctl (fd, TCGETS, &tios);
  1591. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  1592. tios.c_lflag = 0;
  1593. tios.c_iflag = 0;
  1594. tios.c_oflag = 0;
  1595. tios.c_cc[VMIN]=0;
  1596. tios.c_cc[VTIME]=(byte)0; // timeout 0.5 second
  1597. tios.c_lflag=0;
  1598. tcflush(fd, TCIFLUSH);
  1599. ioctl (fd, TCSETS, &tios);
  1600. return fd;
  1601. }
  1602. //================================================
  1603. // Main process
  1604. //================================================
  1605. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  1606. {
  1607. for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
  1608. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
  1609. == target) {
  1610. chargingData[target] =
  1611. &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  1612. return true;
  1613. }
  1614. }
  1615. for (byte index = 0; index < CCS_QUANTITY; index++) {
  1616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
  1617. == target) {
  1618. chargingData[target] =
  1619. &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  1620. return true;
  1621. }
  1622. }
  1623. for (byte index = 0; index < GB_QUANTITY; index++) {
  1624. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
  1625. == target) {
  1626. chargingData[target] =
  1627. &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  1628. return true;
  1629. }
  1630. }
  1631. return false;
  1632. }
  1633. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  1634. {
  1635. if (target < AC_QUANTITY)
  1636. {
  1637. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  1638. return true;
  1639. }
  1640. return false;
  1641. }
  1642. void Initialization()
  1643. {
  1644. bool isPass = false;
  1645. for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++)
  1646. {
  1647. outputRelay.relay_event.relay_status[index] = 0x00;
  1648. }
  1649. while(!isPass)
  1650. {
  1651. isPass = true;
  1652. for (byte _index = 0; _index < gunCount; _index++)
  1653. {
  1654. if (!FindChargingInfoData(_index, &_chargingData[0]))
  1655. {
  1656. DEBUG_ERROR("InternalComm : FindChargingInfoData false (%d) \n", gunCount);
  1657. isPass = false;
  1658. break;
  1659. }
  1660. }
  1661. sleep(1);
  1662. }
  1663. isPass = false;
  1664. if (acgunCount > 0)
  1665. {
  1666. while(!isPass)
  1667. {
  1668. isPass = true;
  1669. for (byte _index = 0; _index < acgunCount; _index++)
  1670. {
  1671. if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0]))
  1672. {
  1673. DEBUG_ERROR("EvComm : FindAcChargingInfoData false \n");
  1674. isPass = false;
  1675. break;
  1676. }
  1677. }
  1678. sleep(1);
  1679. }
  1680. }
  1681. }
  1682. void StartCheckRelayInfo(byte _chkIndex, byte toState)
  1683. {
  1684. if (ShmDcCommonData->RelayCheckStatus[_chkIndex] == STOP)
  1685. {
  1686. GetTimespecFunc(&_relayStateChkTimer[_chkIndex]);
  1687. ShmDcCommonData->RelayCheckStatus[_chkIndex] = START;
  1688. }
  1689. else
  1690. {
  1691. int _timebuf = GetTimeoutValue(&_relayStateChkTimer[_chkIndex]);
  1692. if (_timebuf < 0)
  1693. GetTimespecFunc(&_relayStateChkTimer[_chkIndex]);
  1694. else
  1695. {
  1696. if (_timebuf > RELAY_CHECK_TIME)
  1697. {
  1698. //PRINTF_FUNC ("relay welding or driving fault = %d \n", _chkIndex);
  1699. if (toState == 1)
  1700. ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
  1701. else
  1702. ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
  1703. }
  1704. }
  1705. }
  1706. }
  1707. void StopCheckRelayInfo(byte _chkIndex)
  1708. {
  1709. if (ShmDcCommonData->RelayCheckStatus[_chkIndex] != STOP)
  1710. {
  1711. ShmDcCommonData->RelayCheckStatus[_chkIndex] = STOP;
  1712. }
  1713. }
  1714. bool IsNoneMatchRelayStatus()
  1715. {
  1716. bool result = false;
  1717. if ((regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
  1718. (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
  1719. (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
  1720. (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
  1721. (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
  1722. (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) ||
  1723. (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) ||
  1724. (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N))
  1725. {
  1726. result = true;
  1727. }
  1728. if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor)
  1729. {
  1730. //PRINTF_FUNC("AC Contact Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.AC_Contactor);
  1731. }
  1732. if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge)
  1733. {
  1734. //PRINTF_FUNC("CCS Precharge Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.CCS_Precharge);
  1735. }
  1736. if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P)
  1737. {
  1738. StartCheckRelayInfo(RELAY_SMR1_P_STATUS, outputRelay.relay_event.bits.Gun1_P);
  1739. //PRINTF_FUNC("SMR1:D+ Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_P);
  1740. }
  1741. else
  1742. {
  1743. StopCheckRelayInfo(RELAY_SMR1_P_STATUS);
  1744. //PRINTF_FUNC("SMR1:D+ Release %d \n");
  1745. }
  1746. if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N)
  1747. {
  1748. StartCheckRelayInfo(RELAY_SMR1_N_STATUS, outputRelay.relay_event.bits.Gun1_N);
  1749. //PRINTF_FUNC("SMR1:D- Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_N);
  1750. }
  1751. else
  1752. {
  1753. StopCheckRelayInfo(RELAY_SMR1_N_STATUS);
  1754. }
  1755. if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P)
  1756. {
  1757. StartCheckRelayInfo(RELAY_SMR2_P_STATUS, outputRelay.relay_event.bits.Gun2_P);
  1758. //PRINTF_FUNC("SMR2:D+ Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun2_P);
  1759. }
  1760. else
  1761. {
  1762. StopCheckRelayInfo(RELAY_SMR2_P_STATUS);
  1763. }
  1764. if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N)
  1765. {
  1766. StartCheckRelayInfo(RELAY_SMR2_N_STATUS, outputRelay.relay_event.bits.Gun2_N);
  1767. //PRINTF_FUNC("SMR2:D- Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun2_N);
  1768. }
  1769. else
  1770. {
  1771. StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
  1772. }
  1773. if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P)
  1774. {
  1775. StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
  1776. //PRINTF_FUNC("Parallel:D+ Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_Parallel_P);
  1777. }
  1778. else
  1779. {
  1780. StopCheckRelayInfo(RELAY_PARA_P_STATUS);
  1781. }
  1782. if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N)
  1783. {
  1784. StartCheckRelayInfo(RELAY_PARA_N_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_N);
  1785. //PRINTF_FUNC("Parallel:D- Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_Parallel_N);
  1786. }
  1787. else
  1788. {
  1789. StopCheckRelayInfo(RELAY_PARA_N_STATUS);
  1790. }
  1791. return result;
  1792. }
  1793. void MatchRelayStatus()
  1794. {
  1795. // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
  1796. //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  1797. ShmSysConfigAndInfo->SysInfo.AcContactorStatus = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  1798. regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  1799. regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  1800. regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  1801. regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  1802. regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  1803. regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  1804. regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  1805. }
  1806. void CheckRelayStatusByADC()
  1807. {
  1808. if (ShmRelayModuleData->Gun1FuseOutputVolt > 0 && ShmRelayModuleData->Gun1RelayOutputVolt > 0 &&
  1809. (ShmRelayModuleData->Gun1FuseOutputVolt == ShmRelayModuleData->Gun1RelayOutputVolt))
  1810. {
  1811. // Relay 前後電壓一致
  1812. _chargingData[0]->RelayK1K2Status = 0x01;
  1813. }
  1814. else
  1815. _chargingData[0]->RelayK1K2Status = 0x00;
  1816. if (ShmRelayModuleData->Gun2FuseOutputVolt > 0 && ShmRelayModuleData->Gun2RelayOutputVolt > 0 &&
  1817. (ShmRelayModuleData->Gun2FuseOutputVolt == ShmRelayModuleData->Gun2RelayOutputVolt))
  1818. {
  1819. // Relay 前後電壓一致
  1820. _chargingData[1]->RelayK1K2Status = 0x01;
  1821. }
  1822. else
  1823. _chargingData[1]->RelayK1K2Status = 0x00;
  1824. }
  1825. void SetGfdConfig(byte index, byte resister)
  1826. {
  1827. gfd_config.index = index;
  1828. gfd_config.state = resister;
  1829. //PRINTF_FUNC("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
  1830. if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS)
  1831. {
  1832. // PRINTF_FUNC("Set reqVol = %f, resister = %d \n",
  1833. // gfd_config.reqVol,
  1834. // gfd_config.resister);
  1835. }
  1836. }
  1837. //===============================================
  1838. // Common Detect Chk - CCS
  1839. //===============================================
  1840. byte isPrechargeStatus_ccs(byte gunIndex)
  1841. {
  1842. byte result = 0x00;
  1843. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
  1844. {
  1845. result = ShmCcsData->V2GMessage_DIN70121[_chargingData[gunIndex]->type_index].PresentMsgFlowStatus;
  1846. }
  1847. return result;
  1848. }
  1849. void CableCheckDetected(byte index)
  1850. {
  1851. // Cable Check
  1852. // 當火線上的電壓 = 車端要求的電壓電流
  1853. // _chargingData[targetGun]->EvBatterytargetVoltage
  1854. // 主要驗證阻值為 100 與 500 當小於 100 * 950 時,為 Alarm,介於 100 * 950 與 500 * 950 時為 Warning
  1855. // 950 為系統最大電壓
  1856. // Alarm : Rgfd <= 95K
  1857. // Warning : 95K < Rgfd <= 475
  1858. // Normal : Rgfd > 475K
  1859. if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
  1860. (_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag))
  1861. {
  1862. if ((_chargingData[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && _chargingData[index]->SystemStatus < SYS_MODE_TERMINATING) ||
  1863. (_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1864. {
  1865. if (_chargingData[index]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
  1866. {
  1867. SetGfdConfig(index, GFD_CABLECHK);
  1868. }
  1869. else if (_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
  1870. _chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1 &&
  1871. _chargingData[index]->PresentChargingVoltage >= CCS_PRECHARGE_VOL &&
  1872. isPrechargeStatus_ccs(index) >= CCS_PRECHARGE_STARTU)
  1873. {
  1874. SetGfdConfig(index, GFD_PRECHARGE);
  1875. }
  1876. else if (_chargingData[index]->SystemStatus >= SYS_MODE_CHARGING &&
  1877. _chargingData[index]->SystemStatus < SYS_MODE_TERMINATING)
  1878. {
  1879. if (_chargingData[index]->Type == _Type_GB || _chargingData[index]->Type == _Type_Chademo)
  1880. SetGfdConfig(index, GFD_IDLE);
  1881. else
  1882. SetGfdConfig(index, GFD_CHARGING);
  1883. }
  1884. }
  1885. else
  1886. {
  1887. SetGfdConfig(index, GFD_IDLE);
  1888. }
  1889. }
  1890. }
  1891. void CheckOutputPowerOverCarReq(byte index)
  1892. {
  1893. float fireV = _chargingData[index]->FireChargingVoltage;
  1894. float carV = _chargingData[index]->EvBatteryMaxVoltage * 10 > _chargingData[index]->ConnectorMaxVoltage ?
  1895. _chargingData[index]->ConnectorMaxVoltage : _chargingData[index]->EvBatteryMaxVoltage * 10;
  1896. if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
  1897. (_chargingData[index]->Type == _Type_Chademo ||
  1898. _chargingData[index]->Type == _Type_CCS ||
  1899. _chargingData[index]->Type == _Type_GB))
  1900. {
  1901. if (fireV >= (carV + (carV * 0.02)))
  1902. {
  1903. if (!_isOvpChkTimeFlag[index])
  1904. {
  1905. if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10)
  1906. {
  1907. GetTimespecMFunc(&_checkOutputVolProtectTimer[index]);
  1908. _isOvpChkTimeFlag[index] = YES;
  1909. PRINTF_FUNC("First time : CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
  1910. _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
  1911. }
  1912. }
  1913. else
  1914. {
  1915. int _timebuf = GetTimeoutMValue(&_checkOutputVolProtectTimer[index]);
  1916. if (_timebuf < 0)
  1917. GetTimespecMFunc(&_checkOutputVolProtectTimer[index]);
  1918. else
  1919. {
  1920. if (GetTimeoutMValue(&_checkOutputVolProtectTimer[index]) >= OUTPUT_VOL_CHK_TIME)
  1921. {
  1922. PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
  1923. _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
  1924. DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
  1925. _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
  1926. if (_chargingData[index]->Type == _Type_Chademo)
  1927. {
  1928. ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
  1929. if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
  1930. memcpy(_chargingData[index]->ConnectorAlarmCode, "012217", 6);
  1931. }
  1932. else if (_chargingData[index]->Type == _Type_CCS)
  1933. {
  1934. ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
  1935. if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
  1936. memcpy(_chargingData[index]->ConnectorAlarmCode, "012219", 6);
  1937. }
  1938. else if (_chargingData[index]->Type == _Type_GB)
  1939. {
  1940. ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = YES;
  1941. if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
  1942. memcpy(_chargingData[index]->ConnectorAlarmCode, "012221", 6);
  1943. }
  1944. _chargingData[index]->StopChargeFlag = YES;
  1945. }
  1946. }
  1947. }
  1948. }
  1949. else
  1950. _isOvpChkTimeFlag[index] = NO;
  1951. }
  1952. }
  1953. void CheckOutputVolNoneMatchFire(byte index)
  1954. {
  1955. if (((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 ||
  1956. _chargingData[index]->RelayK1K2Status == NO) &&
  1957. (_chargingData[index]->Type == _Type_CCS))
  1958. {
  1959. if (((_chargingData[index]->PresentChargingVoltage * 10) < _chargingData[index]->FireChargingVoltage - 300) ||
  1960. ((_chargingData[index]->PresentChargingVoltage * 10) > _chargingData[index]->FireChargingVoltage + 300))
  1961. {
  1962. if (!_isOutputNoneMatch[index])
  1963. {
  1964. _isOutputNoneMatch[index] = YES;
  1965. GetTimespecFunc(&_checkOutputNoneMatchTimer[index]);
  1966. }
  1967. else
  1968. {
  1969. if (GetTimeoutValue(&_checkOutputNoneMatchTimer[index]) >= 2)
  1970. {
  1971. PRINTF_FUNC("Abnormal voltage on the Output at the stage of GFD. (%d) : pre = %.1f, fire = %.1f \n",
  1972. index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
  1973. if (index == 0)
  1974. {
  1975. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_1 = YES;
  1976. if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
  1977. memcpy(_chargingData[index]->ConnectorAlarmCode, "012324", 6);
  1978. }
  1979. else if (index == 1)
  1980. {
  1981. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_2 = YES;
  1982. if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
  1983. memcpy(_chargingData[index]->ConnectorAlarmCode, "012325", 6);
  1984. }
  1985. _chargingData[index]->StopChargeFlag = YES;
  1986. }
  1987. }
  1988. }
  1989. else
  1990. _isOutputNoneMatch[index] = NO;
  1991. }
  1992. }
  1993. void GetPsuTempForFanSpeed()
  1994. {
  1995. char temp = 0;
  1996. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1997. {
  1998. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  1999. {
  2000. if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp)
  2001. temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  2002. }
  2003. }
  2004. ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = temp;
  2005. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
  2006. {
  2007. if (ShmFanModuleData->TestFanSpeed == NORMAL_FAN_SPEED)
  2008. {
  2009. if (temp >= ENV_TEMP_MAX)
  2010. ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
  2011. }
  2012. else if (ShmFanModuleData->TestFanSpeed == MAX_FAN_SPEED)
  2013. {
  2014. if (temp <= ENV_TEMP_MIN)
  2015. ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
  2016. }
  2017. else
  2018. ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
  2019. }
  2020. }
  2021. void GetFanSpeedByFunction()
  2022. {
  2023. // 風控修改 :
  2024. // ******************************************************* //
  2025. //
  2026. // 當前PSU輸出總 KW PSU Temp
  2027. // 50 x -------------------- x ---------- + 0.5 x (PSU Temp - 70)
  2028. // 當前樁最大功率 KW 50
  2029. //
  2030. // ******************************************************* //
  2031. // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
  2032. unsigned int _maxPower = ShmPsuData->SystemAvailablePower;
  2033. // 當前PSU輸出總 KW & PSU Temp :
  2034. unsigned char temp = 0;
  2035. float power = 0;
  2036. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2037. {
  2038. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  2039. {
  2040. if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp)
  2041. temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  2042. }
  2043. }
  2044. for (byte gunIndex = 0; gunIndex < gunCount; gunIndex++)
  2045. {
  2046. power += (_chargingData[gunIndex]->PresentChargingPower * 10);
  2047. }
  2048. double _pw_rate = 0;
  2049. if (_maxPower > 0)
  2050. _pw_rate = power / (double)_maxPower;
  2051. double _temp_rate = 0;
  2052. if (temp > 0)
  2053. _temp_rate = (double)temp / 50;
  2054. unsigned char _temp_diff = 0;
  2055. if (temp > 70)
  2056. _temp_diff = temp - 70;
  2057. // debug mode 直接印出資訊後離開
  2058. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
  2059. {
  2060. // printf("Fan Speed Information: power = %f, _maxPower = %d, temp = %d -- _pw_rate = %f, _temp_rate = %f, _temp_diff = %d \n",
  2061. // power, _maxPower, temp, _pw_rate, _temp_rate, _temp_diff);
  2062. return;
  2063. }
  2064. ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _temp_diff)) / 100) * MAX_FAN_SPEED;
  2065. if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED)
  2066. ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
  2067. if (ShmFanModuleData->TestFanSpeed < 0)
  2068. ShmFanModuleData->TestFanSpeed = 0;
  2069. // -----------------------------------------------------------------------
  2070. // printf("power = %f \n", power);
  2071. // printf("_maxPower = %d \n", _maxPower);
  2072. // printf("temp = %d \n", temp);
  2073. //
  2074. // printf("_pw_rate = %f \n", _pw_rate);
  2075. // printf("_temp_rate = %f \n", _temp_rate);
  2076. // printf("_temp_diff = %d \n", _temp_diff);
  2077. // printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
  2078. // printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
  2079. }
  2080. void GetAcStatus()
  2081. {
  2082. if (Query_AC_Status(Uart5Fd, Addr.AcPlug, &acStatus) == PASS)
  2083. {
  2084. ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = (unsigned short)acStatus.MaxCurrent;
  2085. //if(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0)
  2086. ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
  2087. ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
  2088. // if (acStatus.CpStatus == AC_SYS_F)
  2089. // {
  2090. // printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
  2091. // printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
  2092. // }
  2093. // PRINTF_FUNC("CpStatus = %d \n", acStatus.CpStatus);
  2094. // printf("CurLimit = %d \n", acStatus.CurLimit);
  2095. // printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
  2096. // printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
  2097. // printf("LockStatus = %d \n", acStatus.LockStatus);
  2098. // printf("RelayStatus = %d \n", acStatus.RelayStatus);
  2099. // printf("ShutterStatus = %d \n", acStatus.ShutterStatus);
  2100. // printf("MeterStatus = %d \n", acStatus.MeterStatus);
  2101. // printf("PpStatus = %d \n", acStatus.PpStatus);
  2102. // printf("MaxCurrent = %d \n", acStatus.MaxCurrent);
  2103. // printf("RotateSwitchStatus = %d \n", acStatus.RelayStatus);
  2104. // printf("============================== \n");
  2105. //
  2106. // ac_chargingInfo[0]->SystemStatus = acStatus.CpStatus;
  2107. }
  2108. // else
  2109. // PRINTF_FUNC("GetAcStatus return fail. \n");
  2110. }
  2111. void GetAcAlarmCode()
  2112. {
  2113. if (Query_AC_Alarm_Code(Uart5Fd, Addr.AcPlug, &acAlarmCode) == PASS)
  2114. {
  2115. CheckAlarmOccur();
  2116. }
  2117. }
  2118. unsigned char GetChargingEnergy()
  2119. {
  2120. return Query_Charging_Energy(Uart5Fd, Addr.AcPlug, &acChargingEnergy);
  2121. }
  2122. unsigned char GetAcChargingVoltage()
  2123. {
  2124. return Query_Present_InputVoltage(Uart5Fd, Addr.AcPlug, &acChargingVoltage);
  2125. }
  2126. unsigned char GetAcChargingCurrent()
  2127. {
  2128. return Query_Charging_Current(Uart5Fd, Addr.AcPlug, &acChargingCurrent);
  2129. }
  2130. void ChangeLedStatus()
  2131. {
  2132. if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
  2133. ledStatus.ActionMode = 1;
  2134. else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING)
  2135. ledStatus.ActionMode = 3;
  2136. else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
  2137. ledStatus.ActionMode = 4;
  2138. Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
  2139. }
  2140. void SetLegacyReq(byte _switch)
  2141. {
  2142. if (Config_Legacy_Req(Uart5Fd, Addr.AcPlug, _switch))
  2143. {
  2144. PRINTF_FUNC("SetLegacyReq Pass. \n");
  2145. }
  2146. else
  2147. {
  2148. PRINTF_FUNC("SetLegacyReq Fail. \n");
  2149. }
  2150. }
  2151. void SetCpDuty(byte _value)
  2152. {
  2153. if (_ac_duty != _value)
  2154. {
  2155. _ac_duty = _value;
  2156. PRINTF_FUNC("********Duty : %d \n", _ac_duty);
  2157. }
  2158. Config_Ac_Duty(Uart5Fd, Addr.AcPlug, _value);
  2159. }
  2160. void SetModelName_AC()
  2161. {
  2162. if (Config_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
  2163. {
  2164. PRINTF_FUNC("Set Model name (AC) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  2165. }
  2166. }
  2167. void ChangeToCsuMode()
  2168. {
  2169. ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, Addr.AcPlug);
  2170. // if (ac_chargingInfo[0]->IsModeChagned == PASS)
  2171. // {
  2172. // Config_Reset_MCU(Uart5Fd, Addr.AcPlug);
  2173. // }
  2174. }
  2175. void ChangeStartOrStopDateTime(byte isStart)
  2176. {
  2177. char cmdBuf[32];
  2178. struct timeb csuTime;
  2179. struct tm *tmCSU;
  2180. ftime(&csuTime);
  2181. tmCSU = localtime(&csuTime.time);
  2182. sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
  2183. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  2184. tmCSU->tm_sec);
  2185. if (isStart)
  2186. strcpy((char *)ac_chargingInfo[0]->StartDateTime, cmdBuf);
  2187. else
  2188. strcpy((char *)ac_chargingInfo[0]->StopDateTime, cmdBuf);
  2189. }
  2190. unsigned char isModeChange()
  2191. {
  2192. unsigned char result = NO;
  2193. if(ac_chargingInfo[0]->SystemStatus != ac_chargingInfo[0]->PreviousSystemStatus)
  2194. {
  2195. result = YES;
  2196. ac_chargingInfo[0]->PreviousSystemStatus = ac_chargingInfo[0]->SystemStatus;
  2197. }
  2198. return result;
  2199. }
  2200. void SetAcModuleRelay(byte value)
  2201. {
  2202. acOutputRelay.relay_event.bits.AC_L1_Relay = value;
  2203. acOutputRelay.relay_event.bits.AC_L2_Relay = value;
  2204. acOutputRelay.relay_event.bits.AC_L3_Relay = value;
  2205. Config_Relay_Output(Uart5Fd, Addr.AcPlug, &acOutputRelay);
  2206. }
  2207. //===============================================
  2208. // AC OCPP routine
  2209. //===============================================
  2210. void ocpp_ac_startTransation_cmd()
  2211. {
  2212. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2213. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2214. {
  2215. if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
  2216. strcpy((char *)ShmOCPP16Data->StartTransaction[hasDc].IdTag, (char *)ShmOCPP16Data->StartTransaction[hasDc].IdTag);
  2217. else
  2218. strcpy((char *)ShmOCPP16Data->StartTransaction[hasDc].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
  2219. PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[hasDc].IdTag);
  2220. ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionReq = YES;
  2221. }
  2222. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2223. {
  2224. if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
  2225. strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
  2226. else
  2227. strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ac_chargingInfo[0]->StartUserId);
  2228. PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
  2229. ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventReq = YES;
  2230. }
  2231. }
  2232. void ocpp_ac_stopTransation_cmd()
  2233. {
  2234. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2235. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2236. {
  2237. if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
  2238. strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].IdTag, (char *)ShmOCPP16Data->StopTransaction[hasDc].IdTag);
  2239. else
  2240. strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
  2241. PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[hasDc].IdTag);
  2242. ShmOCPP16Data->CpMsg.bits[hasDc].StopTransactionReq = YES;
  2243. }
  2244. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2245. {
  2246. if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
  2247. strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
  2248. else
  2249. strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ac_chargingInfo[0]->StartUserId);
  2250. PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
  2251. ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventReq = YES;
  2252. }
  2253. }
  2254. bool ocpp_ac_remoteStopReq_cmd()
  2255. {
  2256. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2257. bool result = false;
  2258. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2259. {
  2260. result = ShmOCPP16Data->CsMsg.bits[hasDc].RemoteStopTransactionReq;
  2261. if (ShmOCPP16Data->CsMsg.bits[hasDc].RemoteStopTransactionReq == YES)
  2262. {
  2263. strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, "Remote");
  2264. ShmOCPP16Data->CsMsg.bits[hasDc].RemoteStopTransactionReq = NO;
  2265. }
  2266. }
  2267. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2268. {
  2269. result = ShmOCPP20Data->CsMsg.bits[hasDc].RequestStopTransactionReq;
  2270. if (ShmOCPP20Data->CsMsg.bits[hasDc].RequestStopTransactionReq == YES)
  2271. {
  2272. strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, "Remote");
  2273. ShmOCPP20Data->CsMsg.bits[hasDc].RequestStopTransactionReq = NO;
  2274. }
  2275. }
  2276. return result;
  2277. }
  2278. bool ocpp_ac_is_resPass_StartTransationConf()
  2279. {
  2280. bool result = false;
  2281. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2282. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2283. {
  2284. result = ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionConf;
  2285. }
  2286. else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2287. {
  2288. result = ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventConf;
  2289. }
  2290. return result;
  2291. }
  2292. bool ocpp_ac_chk_invalid_id_cmd()
  2293. {
  2294. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2295. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2296. {
  2297. if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE"))
  2298. {
  2299. if (strcmp((char *)ShmOCPP16Data->StartTransaction[hasDc].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
  2300. strcmp((char *)ShmOCPP16Data->StartTransaction[hasDc].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
  2301. strcmp((char *)ShmOCPP16Data->StartTransaction[hasDc].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
  2302. return true;
  2303. }
  2304. }
  2305. else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2306. {
  2307. if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE"))
  2308. {
  2309. if (strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Blocked") == EQUAL ||
  2310. strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Expired") == EQUAL ||
  2311. strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Invalid") == EQUAL ||
  2312. strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
  2313. strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
  2314. strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
  2315. strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
  2316. strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Unknown") == EQUAL)
  2317. return true;
  2318. }
  2319. }
  2320. return false;
  2321. }
  2322. bool ocpp_ac_get_startTransation_req()
  2323. {
  2324. bool result = false;
  2325. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2326. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  2327. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2328. {
  2329. result = ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionReq;
  2330. }
  2331. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2332. {
  2333. result = ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventReq;
  2334. }
  2335. return result;
  2336. }
  2337. void ocpp_ac_set_stopReason_by_cmd(char *reason)
  2338. {
  2339. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2340. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2341. {
  2342. if (strcmp((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, "") == EQUAL)
  2343. {
  2344. strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, reason);
  2345. }
  2346. }
  2347. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2348. {
  2349. if (strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, "") == EQUAL)
  2350. {
  2351. strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, reason);
  2352. }
  2353. }
  2354. }
  2355. void ocpp_ac_auto_response_StartTransationConf()
  2356. {
  2357. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2358. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2359. {
  2360. if (ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionConf)
  2361. ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionConf = NO;
  2362. }
  2363. else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2364. {
  2365. if (ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventConf)
  2366. ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventConf = NO;
  2367. }
  2368. }
  2369. void ocpp_ac_set_errCode_cmd()
  2370. {
  2371. byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
  2372. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  2373. {
  2374. strcpy((char *)ShmOCPP16Data->StatusNotification[hasDc].ErrorCode, "InternalError");
  2375. strcpy((char *)ShmOCPP16Data->StatusNotification[hasDc].VendorErrorCode, (char *)ac_chargingInfo[0]->ConnectorAlarmCode);
  2376. }
  2377. else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  2378. {
  2379. }
  2380. }
  2381. //===============================================
  2382. // AC Main Process
  2383. //===============================================
  2384. byte _SystemStatus = 255;
  2385. byte _CpStatus = 255;
  2386. void AcChargeTypeProcess()
  2387. {
  2388. if (acgunCount > 0)
  2389. {
  2390. //ac_chargingInfo[0]->SelfTest_Comp = YES;
  2391. //ac_chargingInfo[0]->IsModeChagned = PASS;
  2392. //---------------------------------------------
  2393. if (ac_chargingInfo[0]->SelfTest_Comp == NO)
  2394. {
  2395. ac_chargingInfo[0]->IsModeChagned = NO;
  2396. SetModelName_AC();
  2397. GetFwVersion_AC();
  2398. GetAcModelName();
  2399. }
  2400. else if (ac_chargingInfo[0]->SelfTest_Comp == YES)
  2401. {
  2402. GetAcStatus();
  2403. GetAcAlarmCode();
  2404. byte _status = SYS_MODE_BOOTING;
  2405. if (ac_chargingInfo[0]->IsAvailable == NO)
  2406. {
  2407. _status = SYS_MODE_MAINTAIN;
  2408. }
  2409. //printf("SystemStatus = %d, err = %d \n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsErrorOccur);
  2410. if ((ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE || ac_chargingInfo[0]->SystemStatus == SYS_MODE_MAINTAIN) &&
  2411. ac_chargingInfo[0]->IsErrorOccur)
  2412. {
  2413. _status = SYS_MODE_FAULT;
  2414. }
  2415. else if (_status == SYS_MODE_MAINTAIN)
  2416. {
  2417. // do nothing
  2418. }
  2419. else if (acStatus.CpStatus == AC_SYS_A)
  2420. {
  2421. if (ac_chargingInfo[0]->IsErrorOccur &&
  2422. (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING ||
  2423. ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING))
  2424. _status = SYS_MODE_ALARM;
  2425. else if (!ac_chargingInfo[0]->IsErrorOccur &&
  2426. (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_TERMINATING ||
  2427. ac_chargingInfo[0]->SystemStatus <= SYS_MODE_ALARM))
  2428. {
  2429. if (GetTimeoutValue(&_ac_charging_comp) >= 10 && acStatus.CpStatus == AC_SYS_A)
  2430. _status = SYS_MODE_IDLE;
  2431. }
  2432. // else
  2433. // _status = SYS_MODE_IDLE;
  2434. }
  2435. else if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING &&
  2436. ac_chargingInfo[0]->SystemStatus < SYS_MODE_CHARGING)
  2437. {
  2438. if (acStatus.CpStatus == AC_SYS_C)
  2439. _status = SYS_MODE_CHARGING;
  2440. else if (GetTimeoutValue(&_ac_preparing) >= 120)
  2441. _status = SYS_MODE_IDLE;
  2442. }
  2443. else if ((acStatus.CpStatus == AC_SYS_B || ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_B) &&
  2444. ac_chargingInfo[0]->IsAvailable &&
  2445. !ac_chargingInfo[0]->IsErrorOccur &&
  2446. (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
  2447. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE))
  2448. {
  2449. if (ac_chargingInfo[0]->RemoteStartFlag == YES)
  2450. {
  2451. PRINTF_FUNC("** AC Remote \n");
  2452. ac_chargingInfo[0]->RemoteStartFlag = NO;
  2453. strcpy((char *)ac_chargingInfo[0]->StartUserId, "");
  2454. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
  2455. _status = SYS_MODE_PREPARING;
  2456. }
  2457. else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
  2458. {
  2459. PRINTF_FUNC("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  2460. strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2461. PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
  2462. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  2463. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
  2464. _status = SYS_MODE_PREPARING;
  2465. }
  2466. }
  2467. if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING ||
  2468. ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
  2469. {
  2470. if (ocpp_ac_remoteStopReq_cmd())
  2471. {
  2472. ocpp_ac_set_stopReason_by_cmd("Remote");
  2473. _status = SYS_MODE_TERMINATING;
  2474. }
  2475. else if (ac_chargingInfo[0]->StopChargeFlag ||
  2476. acStatus.CpStatus == AC_SYS_F)
  2477. {
  2478. _status = SYS_MODE_TERMINATING;
  2479. }
  2480. }
  2481. if (_status != SYS_MODE_BOOTING && ac_chargingInfo[0]->SystemStatus != _status)
  2482. {
  2483. ac_chargingInfo[0]->SystemStatus = _status;
  2484. }
  2485. if (ac_chargingInfo[0]->SystemStatus != _SystemStatus)
  2486. {
  2487. PRINTF_FUNC("ac_chargingInfo[0]->SystemStatus = %d", ac_chargingInfo[0]->SystemStatus);
  2488. _SystemStatus = ac_chargingInfo[0]->SystemStatus;
  2489. }
  2490. if (acStatus.CpStatus != _CpStatus)
  2491. {
  2492. PRINTF_FUNC("acStatus.CpStatus = %d", acStatus.CpStatus);
  2493. _CpStatus = acStatus.CpStatus;
  2494. }
  2495. // 設定限制最大充電電流 >= 6 ~ <= 32
  2496. switch(ac_chargingInfo[0]->SystemStatus)
  2497. {
  2498. case SYS_MODE_IDLE:
  2499. case SYS_MODE_MAINTAIN:
  2500. case SYS_MODE_RESERVATION:
  2501. case SYS_MODE_FAULT:
  2502. {
  2503. if (isModeChange())
  2504. {
  2505. if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
  2506. PRINTF_FUNC("================== SYS_MODE_IDLE (AC Gun) ================ \n");
  2507. else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_MAINTAIN)
  2508. PRINTF_FUNC("================== SYS_MODE_MAINTAIN (AC Gun) ================ \n");
  2509. else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_FAULT)
  2510. PRINTF_FUNC("================== SYS_MODE_FAULT (AC Gun) ================ \n");
  2511. SetCpDuty(100);
  2512. ac_chargingInfo[0]->PresentChargedEnergy = 0.0;
  2513. ac_chargingInfo[0]->PresentChargingVoltage = 0;
  2514. ac_chargingInfo[0]->ChargingFee = 0.0;
  2515. strcpy((char *)ac_chargingInfo[0]->StartDateTime, "");
  2516. strcpy((char *)ac_chargingInfo[0]->StopDateTime, "");
  2517. _beforeChargingTotalEnergy = 0.0;
  2518. ac_startTransationFlag = START_TRANSATION_STATUS_WAIT;
  2519. }
  2520. ac_chargingInfo[0]->ChargingProfilePower = -1;
  2521. ac_chargingInfo[0]->ChargingProfileCurrent = -1;
  2522. ac_chargingInfo[0]->StopChargeFlag = NO;
  2523. ChangeLedStatus();
  2524. }
  2525. break;
  2526. case SYS_MODE_PREPARING:
  2527. {
  2528. if (isModeChange())
  2529. {
  2530. PRINTF_FUNC("================== SYS_MODE_PREPARING (AC Gun) ================ \n");
  2531. SetLegacyReq(YES);
  2532. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  2533. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  2534. if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
  2535. ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
  2536. GetTimespecFunc(&_ac_preparing);
  2537. }
  2538. if (GetChargingEnergy() == PASS)
  2539. {
  2540. //ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
  2541. _beforeChargingTotalEnergy = acChargingEnergy.Energy;
  2542. }
  2543. ac_startTransationFlag = ocpp_ac_is_resPass_StartTransationConf();
  2544. if (ac_startTransationFlag == START_TRANSATION_STATUS_PASS)
  2545. {
  2546. if (ocpp_ac_chk_invalid_id_cmd())
  2547. ac_startTransationFlag = START_TRANSATION_STATUS_FAIL;
  2548. }
  2549. else
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO)
  2552. {
  2553. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING ||
  2554. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
  2555. !ocpp_ac_get_startTransation_req() ||
  2556. strcmp((char *)ac_chargingInfo[0]->StartUserId, "") != EQUAL)
  2557. {
  2558. ac_startTransationFlag = START_TRANSATION_STATUS_PASS;
  2559. }
  2560. }
  2561. }
  2562. if (ac_startTransationFlag == START_TRANSATION_STATUS_PASS)
  2563. {
  2564. // 充電前須給 duty : 依照 Charging profile
  2565. if (ac_chargingInfo[0]->ChargingProfileCurrent > 0 &&
  2566. (ac_chargingInfo[0]->ChargingProfileCurrent / 10) <= ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent)
  2567. SetCpDuty(ac_chargingInfo[0]->ChargingProfileCurrent / 10);
  2568. else
  2569. SetCpDuty(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent);
  2570. }
  2571. else if (ac_startTransationFlag == START_TRANSATION_STATUS_FAIL ||
  2572. (ac_startTransationFlag == START_TRANSATION_STATUS_WAIT && GetTimeoutValue(&_ac_preparing) > 10))
  2573. {
  2574. PRINTF_FUNC("StartTransaction Fail / Timeout. \n");
  2575. ac_chargingInfo[0]->StopChargeFlag = YES;
  2576. }
  2577. ChangeLedStatus();
  2578. }
  2579. break;
  2580. case SYS_MODE_CHARGING:
  2581. {
  2582. if (isModeChange())
  2583. {
  2584. PRINTF_FUNC("================== SYS_MODE_CHARGING (AC Gun) ================ \n");
  2585. ftime(&_ac_startChargingTime);
  2586. ocpp_ac_startTransation_cmd();
  2587. ChangeStartOrStopDateTime(YES);
  2588. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  2589. }
  2590. // 用以判斷是否有在輸出
  2591. ac_chargingInfo[0]->IsCharging = acStatus.RelayStatus;
  2592. ftime(&_ac_endChargingTime);
  2593. ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
  2594. if (ac_chargingInfo[0]->IsCharging)
  2595. {
  2596. if (GetChargingEnergy() == PASS)
  2597. {
  2598. if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0)
  2599. {
  2600. ac_chargingInfo[0]->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
  2601. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
  2602. {
  2603. ac_chargingInfo[0]->ChargingFee += ac_chargingInfo[0]->PresentChargedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
  2604. }
  2605. }
  2606. _beforeChargingTotalEnergy = acChargingEnergy.Energy;
  2607. }
  2608. //GetAcChargingPower();
  2609. if (GetAcChargingVoltage() == PASS && GetAcChargingCurrent() == PASS)
  2610. {
  2611. // PRINTF_FUNC("L1N_L12 = %f, L1N_L12 = %f, L1N_L12 = %f \n",
  2612. // acChargingVoltage.L1N_L12,
  2613. // acChargingVoltage.L2N_L23,
  2614. // acChargingVoltage.L3N_L31);
  2615. // PRINTF_FUNC("c1 = %d, c2 = %d, c3 = %d \n",
  2616. // acChargingCurrent.OuputCurrentL1,
  2617. // acChargingCurrent.OuputCurrentL2,
  2618. // acChargingCurrent.OuputCurrentL3);
  2619. ac_chargingInfo[0]->PresentChargingPower =
  2620. (acChargingVoltage.L1N_L12 * acChargingCurrent.OuputCurrentL1 +
  2621. acChargingVoltage.L2N_L23 * acChargingCurrent.OuputCurrentL2 +
  2622. acChargingVoltage.L3N_L31 * acChargingCurrent.OuputCurrentL3) / 1000;
  2623. }
  2624. //ac_chargingInfo[0]->PresentChargingPower = (((float)(220 * acChargingCurrent.OuputCurrentL1) / 10) / 1000);
  2625. ac_chargingInfo[0]->PresentChargingVoltage = AC_DEFAULT_VOL;
  2626. ac_chargingInfo[0]->PresentChargingCurrent = ((float)acChargingCurrent.OuputCurrentL1 / 10);
  2627. // 充電中須給 duty : 依照 Charging profile
  2628. if (ac_chargingInfo[0]->ChargingProfileCurrent > 0 &&
  2629. (ac_chargingInfo[0]->ChargingProfileCurrent / 10) <= ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent)
  2630. SetCpDuty(ac_chargingInfo[0]->ChargingProfileCurrent / 10);
  2631. else
  2632. SetCpDuty(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent);
  2633. }
  2634. else
  2635. {
  2636. // 搭上 relay
  2637. if (acStatus.CpStatus == AC_SYS_C)
  2638. {
  2639. PRINTF_FUNC("Set relay ON (AC Type). \n");
  2640. SetAcModuleRelay(YES);
  2641. }
  2642. }
  2643. ChangeLedStatus();
  2644. }
  2645. break;
  2646. case SYS_MODE_TERMINATING:
  2647. case SYS_MODE_ALARM:
  2648. {
  2649. //ocpp_set_errCode_cmd
  2650. if (isModeChange())
  2651. {
  2652. if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
  2653. PRINTF_FUNC("================== SYS_MODE_TERMINATING (AC Gun) ================ \n");
  2654. else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
  2655. PRINTF_FUNC("================== SYS_MODE_ALARM (AC Gun) ================ \n");
  2656. ChangeStartOrStopDateTime(NO);
  2657. GetTimespecFunc(&_ac_charging_comp);
  2658. ocpp_ac_set_stopReason_by_cmd("Local");
  2659. SetCpDuty(100);
  2660. if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
  2661. PRINTF_FUNC("================== SYS_MODE_TERMINATING (AC Gun) ================ \n");
  2662. else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
  2663. {
  2664. ftime(&_ac_endChargingTime);
  2665. ocpp_ac_set_errCode_cmd();
  2666. if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL)
  2667. {
  2668. ocpp_ac_auto_response_StartTransationConf();
  2669. // AC 固定為第2把槍
  2670. ocpp_ac_stopTransation_cmd();
  2671. }
  2672. }
  2673. }
  2674. SetLegacyReq(NO);
  2675. if (acStatus.RelayStatus == NO)
  2676. {
  2677. if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
  2678. ac_chargingInfo[0]->SystemStatus = SYS_MODE_COMPLETE;
  2679. }
  2680. else
  2681. {
  2682. // 搭上 relay
  2683. PRINTF_FUNC("Set relay OFF (AC Type). \n");
  2684. SetAcModuleRelay(NO);
  2685. }
  2686. if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
  2687. ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
  2688. }
  2689. break;
  2690. case SYS_MODE_COMPLETE:
  2691. {
  2692. if (isModeChange())
  2693. {
  2694. PRINTF_FUNC("================== SYS_MODE_COMPLETE (AC Gun) ================ \n");
  2695. GetTimespecFunc(&_ac_charging_comp);
  2696. ftime(&_ac_endChargingTime);
  2697. ocpp_ac_set_errCode_cmd();
  2698. if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL)
  2699. {
  2700. ocpp_ac_auto_response_StartTransationConf();
  2701. // AC 固定為第2把槍
  2702. ocpp_ac_stopTransation_cmd();
  2703. }
  2704. ChangeStartOrStopDateTime(NO);
  2705. ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
  2706. }
  2707. }
  2708. break;
  2709. }
  2710. }
  2711. }
  2712. }
  2713. void RunForceStopProcess()
  2714. {
  2715. if (isCriticalStop == NO)
  2716. {
  2717. isCriticalStop = YES;
  2718. GetTimespecFunc(&_psuCriticalStop);
  2719. }
  2720. else
  2721. {
  2722. int _timebuf = GetTimeoutValue(&_psuCriticalStop);
  2723. if (_timebuf < 0)
  2724. GetTimespecFunc(&_psuCriticalStop);
  2725. else
  2726. {
  2727. if (_timebuf >= FORCE_STOP_TIME)
  2728. {
  2729. isCriticalStop = NO;
  2730. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NORMAL;
  2731. system("/usr/bin/run_evse_restart.sh");
  2732. }
  2733. }
  2734. }
  2735. }
  2736. int main(void)
  2737. {
  2738. if(InitShareMemory() == FAIL)
  2739. {
  2740. #ifdef SystemLogMessage
  2741. DEBUG_ERROR("InitShareMemory NG\n");
  2742. #endif
  2743. if(ShmStatusCodeData!=NULL)
  2744. {
  2745. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2746. }
  2747. sleep(5);
  2748. return 0;
  2749. }
  2750. gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  2751. acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  2752. // Open Uart5 for RB
  2753. Uart5Fd = InitComPort();
  2754. Initialization();
  2755. sleep(1);
  2756. if(Uart5Fd < 0)
  2757. {
  2758. PRINTF_FUNC("(Internal) open port error. \n");
  2759. return 0;
  2760. }
  2761. if (acgunCount > 0)
  2762. {
  2763. acOutputRelay.relay_event.bits.AC_L1_Relay = 0x00;
  2764. acOutputRelay.relay_event.bits.AC_L2_Relay = 0x00;
  2765. acOutputRelay.relay_event.bits.AC_L3_Relay = 0x00;
  2766. Config_Relay_Output(Uart5Fd, Addr.AcPlug, &acOutputRelay);
  2767. }
  2768. outputRelay.relay_event.bits.AC_Contactor = 0x00;
  2769. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  2770. outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00;
  2771. outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
  2772. outputRelay.relay_event.bits.Gun1_P = 0x00;
  2773. outputRelay.relay_event.bits.Gun1_N = 0x00;
  2774. outputRelay.relay_event.bits.Gun2_N = 0x00;
  2775. outputRelay.relay_event.bits.Gun2_P = 0x00;
  2776. if(Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS)
  2777. PRINTF_FUNC("Config_Relay_Output fail \n");
  2778. cur_led_color.Connect_1_Red = COLOR_MIN_LV;
  2779. cur_led_color.Connect_1_Green = COLOR_MIN_LV;
  2780. cur_led_color.Connect_1_Blue = COLOR_MIN_LV;
  2781. cur_led_color.Connect_2_Red = COLOR_MIN_LV;
  2782. cur_led_color.Connect_2_Green = COLOR_MIN_LV;
  2783. cur_led_color.Connect_2_Blue = COLOR_MIN_LV;
  2784. relayMatchFlag = NO;
  2785. isCriticalStop = NO;
  2786. GetTimespecFunc(&_led_blink_time);
  2787. for(;;)
  2788. {
  2789. bool isCharging = false;
  2790. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  2791. if (ShmRelayModuleData->SelfTest_Comp == NO)
  2792. {
  2793. GetFwAndHwVersion_Relay();
  2794. SetModelName_Relay();
  2795. SetRtcData_Relay();
  2796. sleep(1);
  2797. }
  2798. if (ShmFanModuleData->SelfTest_Comp == NO)
  2799. {
  2800. GetFwAndHwVersion_Fan();
  2801. SetModelName_Fan();
  2802. SetRtcData_Fan();
  2803. sleep(1);
  2804. GetTimespecFunc(&_priority_time);
  2805. }
  2806. // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
  2807. if (ShmLedModuleData->SelfTest_Comp == NO)
  2808. {
  2809. // 自檢階段
  2810. if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq <= _STEST_PSU_CAP)
  2811. {
  2812. GetFwAndHwVersion_Led();
  2813. sleep(1);
  2814. GetTimespecFunc(&_led_priority_time);
  2815. }
  2816. else
  2817. {
  2818. // 自檢階段沒有問到版號
  2819. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail == NO)
  2820. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES;
  2821. }
  2822. }
  2823. AcChargeTypeProcess();
  2824. if (ShmRelayModuleData->SelfTest_Comp == YES)
  2825. {
  2826. // ==============優先權最高 10 ms ==============
  2827. // 輸出電壓
  2828. GetPersentOutputVol();
  2829. // 三相輸入電壓
  2830. GetPresentInputVol();
  2831. // 讀取當前 AC relay 狀態
  2832. regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
  2833. GetRelayOutputStatus();
  2834. for (int i = 0; i < gunCount; i++)
  2835. {
  2836. // Cable check (Set)
  2837. CableCheckDetected(i);
  2838. // check k1 k2 relay 狀態
  2839. CheckK1K2RelayOutput(i);
  2840. // 依據當前各槍的狀態選擇 搭上/放開 Relay
  2841. SetK1K2RelayStatus(i);
  2842. if (_chargingData[i]->SystemStatus == SYS_MODE_IDLE ||
  2843. _chargingData[i]->SystemStatus == SYS_MODE_RESERVATION ||
  2844. _chargingData[i]->SystemStatus == SYS_MODE_MAINTAIN)
  2845. {
  2846. _isOvpChkTimeFlag[i] = NO;
  2847. }
  2848. if (_chargingData[i]->SystemStatus == SYS_MODE_BOOTING ||
  2849. (_chargingData[i]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && _chargingData[i]->SystemStatus <= SYS_MODE_COMPLETE) ||
  2850. (_chargingData[i]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[i]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
  2851. ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
  2852. (ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG))
  2853. {
  2854. _chargingData[i]->IsReadyToCharging = YES;
  2855. isCharging = true;
  2856. if (_chargingData[i]->SystemStatus == SYS_MODE_CHARGING)
  2857. {
  2858. // OVP
  2859. CheckOutputPowerOverCarReq(i);
  2860. }
  2861. else if (_chargingData[i]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
  2862. {
  2863. // abnormal voltage at the stage of GFD
  2864. CheckOutputVolNoneMatchFire(i);
  2865. }
  2866. else
  2867. _isOutputNoneMatch[i] = NO;
  2868. }
  2869. else
  2870. _chargingData[i]->IsReadyToCharging = NO;
  2871. }
  2872. // Cable check (Get)
  2873. GetGfdAdc();
  2874. // 橋接 relay
  2875. SetParalleRelayStatus();
  2876. // 搭上 AC Contactor
  2877. // if (isCharging)
  2878. // outputRelay.relay_event.bits.AC_Contactor = YES;
  2879. // else
  2880. // outputRelay.relay_event.bits.AC_Contactor = NO;
  2881. if (isCharging || (ShmPsuData->Work_Step == _TEST_MODE))
  2882. {
  2883. isStopChargingCount = false;
  2884. outputRelay.relay_event.bits.AC_Contactor = YES;
  2885. }
  2886. else
  2887. {
  2888. if (!isStopChargingCount)
  2889. {
  2890. GetTimespecFunc(&_close_ac_contactor);
  2891. isStopChargingCount = true;
  2892. }
  2893. else
  2894. {
  2895. if ((outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(&_close_ac_contactor) >= TEN_MINUTES))
  2896. outputRelay.relay_event.bits.AC_Contactor = NO;
  2897. }
  2898. }
  2899. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
  2900. outputRelay.relay_event.bits.AC_Contactor = NO;
  2901. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == ABNORMAL)
  2902. {
  2903. RunForceStopProcess();
  2904. outputRelay.relay_event.bits.AC_Contactor = NO;
  2905. }
  2906. ShmDcCommonData->acContactSwitch = outputRelay.relay_event.bits.AC_Contactor;
  2907. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  2908. outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
  2909. // 搭上/鬆開 Relay
  2910. if(IsNoneMatchRelayStatus())
  2911. {
  2912. relayMatchFlag = NO;
  2913. if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
  2914. {
  2915. //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
  2916. // regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  2917. // regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  2918. // regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  2919. // regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  2920. // regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  2921. // regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  2922. // regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  2923. }
  2924. }
  2925. else if (relayMatchFlag == NO)
  2926. {
  2927. relayMatchFlag = YES;
  2928. PRINTF_FUNC("======== Relay Status Start========\n");
  2929. if (regRelay.relay_event.bits.AC_Contactor == YES)
  2930. PRINTF_FUNC("AC Power : ON \n");
  2931. else
  2932. PRINTF_FUNC("AC Power : OFF \n");
  2933. if (regRelay.relay_event.bits.Gun1_P == YES)
  2934. PRINTF_FUNC("Conn1(+) : ON \n");
  2935. else
  2936. PRINTF_FUNC("Conn1(+) : OFF \n");
  2937. if (regRelay.relay_event.bits.Gun1_N == YES)
  2938. PRINTF_FUNC("Conn1(-) : ON \n");
  2939. else
  2940. PRINTF_FUNC("Conn1(-) : OFF \n");
  2941. if (regRelay.relay_event.bits.Gun2_P == YES)
  2942. PRINTF_FUNC("Conn2(+) : ON \n");
  2943. else
  2944. PRINTF_FUNC("Conn2(+) : OFF \n");
  2945. if (regRelay.relay_event.bits.Gun2_N == YES)
  2946. PRINTF_FUNC("Conn2(-) : ON \n");
  2947. else
  2948. PRINTF_FUNC("Conn2(-) : OFF \n");
  2949. if (regRelay.relay_event.bits.CCS_Precharge == YES)
  2950. PRINTF_FUNC("Precharge : ON \n");
  2951. else
  2952. PRINTF_FUNC("Precharge : OFF \n");
  2953. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
  2954. PRINTF_FUNC("Parallel(+) : ON \n");
  2955. else
  2956. PRINTF_FUNC("Parallel(+) : OFF \n");
  2957. if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
  2958. PRINTF_FUNC("Parallel(-) : ON \n");
  2959. else
  2960. PRINTF_FUNC("Parallel(-) : OFF \n");
  2961. PRINTF_FUNC("======== Relay Status End========\n");
  2962. }
  2963. }
  2964. if (ShmFanModuleData->SelfTest_Comp == YES ||
  2965. strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
  2966. ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
  2967. {
  2968. ShmFanModuleData->SelfTest_Comp = YES;
  2969. int _timebuf = GetTimeoutValue(&_priority_time);
  2970. if (_timebuf < 0)
  2971. GetTimespecFunc(&_priority_time);
  2972. else
  2973. {
  2974. if (_timebuf >= 1)
  2975. {
  2976. //GetPsuTempForFanSpeed();
  2977. GetFanSpeedByFunction();
  2978. GetFanSpeed();
  2979. ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
  2980. GetTimespecFunc(&_priority_time);
  2981. ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
  2982. ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
  2983. ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
  2984. ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
  2985. //PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
  2986. SetFanModuleSpeed();
  2987. }
  2988. }
  2989. }
  2990. if (ShmLedModuleData->SelfTest_Comp == YES)
  2991. {
  2992. int _timebuf = GetTimeoutValue(&_led_priority_time);
  2993. if (_timebuf < 0)
  2994. GetTimespecFunc(&_led_priority_time);
  2995. else
  2996. {
  2997. if (GetTimeoutValue(&_led_blink_time) > 6)
  2998. GetTimespecFunc(&_led_blink_time);
  2999. if (_timebuf >= 1)
  3000. {
  3001. if(gunCount == 1)
  3002. {
  3003. SetLedColor(_chargingData[0], _chargingData[0]);
  3004. }
  3005. else if (gunCount == 2)
  3006. {
  3007. SetLedColor(_chargingData[0], _chargingData[1]);
  3008. }
  3009. GetTimespecFunc(&_led_priority_time);
  3010. }
  3011. }
  3012. }
  3013. usleep(10000);
  3014. }
  3015. return FAIL;
  3016. }