Module_InternalComm.c 89 KB

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