Module_InternalComm.c 96 KB

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