ReModule_InternalComm.c 111 KB

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