Module_InternalComm.c 104 KB

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