Module_InternalComm.c 122 KB

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