Module_InternalComm.c 90 KB

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