main.c 180 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <sys/time.h>
  4. #include <sys/timeb.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 <errno.h>
  23. #include <string.h>
  24. #include <stdint.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include <math.h>
  29. #include <stdbool.h>
  30. #include <dirent.h>
  31. #include <signal.h>
  32. #include "../Config.h"
  33. #include "main.h"
  34. #include "../common.h"
  35. #include "../timeout.h"
  36. #include "../Log/log.h"
  37. #include "../DataBase/DataBase.h"
  38. #include "../Define/define.h"
  39. #include "../ShareMemory/shmMem.h"
  40. #include "../SelectGun/SelectGun.h"
  41. //------------------------------------------------------------------------------
  42. static struct SysInfoData *pSysInfo = NULL;
  43. static struct SysConfigData *pSysConfig = NULL;
  44. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  45. static struct AlarmCodeData *pAlarmCode = NULL;
  46. static struct FaultCodeData *pFaultCode = NULL;
  47. static struct InfoCodeData *pInfoCode = NULL;
  48. static struct PsuData *ShmPsuData = NULL;
  49. static struct CHAdeMOData *ShmCHAdeMOData = NULL;
  50. static struct GBTData *ShmGBTData = NULL;
  51. static struct CcsData *ShmCcsData = NULL;
  52. static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
  53. static struct FanModuleData *ShmFanModuleData = NULL;
  54. static struct RelayModuleData *ShmRelayModuleData = NULL;
  55. static struct LedModuleData *ShmLedModuleData = NULL;
  56. static struct OCPP16Data *ShmOCPP16Data = NULL;
  57. static DcCommonInfo *ShmDcCommonData = NULL;
  58. static struct ChargingInfoData *pDcChargingInfo = NULL;
  59. static struct ChargingInfoData *pAcChargingInfo = NULL;
  60. static struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  61. static struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  62. static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
  63. static EvBoardErrMsg gEvBoardErr = {0};
  64. static ChillerTempErr gChillerTempErr = {0};
  65. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  66. struct StatusCodeData *ShmStatusCodeData;
  67. // for initial index to check EV board type is correct
  68. uint8_t bd0_1_status = 0;
  69. uint8_t bd0_2_status = 0;
  70. uint8_t bd1_1_status = 0;
  71. uint8_t bd1_2_status = 0;
  72. char *fwVersion = "V2.09.00.0000.00"; // Phihong version
  73. char* DebugVersion = "V2.09.00"; // Software debug version
  74. //sqlite3 *localDb;
  75. bool isDb_ready;
  76. //------------------------------------------------------------------------------
  77. void ClearDetectPluginFlag(int gunIndex);
  78. long long DiffTimebWithNow(struct timeb ST);
  79. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
  80. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
  81. unsigned long GetTimeoutValue(struct timespec _start_time);
  82. void GetClockTime(struct timespec *_now_time, void *null);
  83. unsigned long GetClockTimeoutValue(struct timespec _start_time);
  84. void gpio_set_value(unsigned int gpio, unsigned int value);
  85. void InformOcppErrOccur(uint8_t codeType);
  86. void RecordAlarmCode(uint8_t gunIndex, char *code);
  87. void ReleaseAlarmCode(uint8_t gunIndex);
  88. void ResetChargerAlarmCode(uint8_t gunIndex, char *code);
  89. void AdjustChargerCurrent(void);
  90. void UpdateErrorCodeToOcpp(uint8_t index);
  91. //------------------------------------------------------------------------------
  92. //Primary.c
  93. extern void ChkPrimaryStatus(void);
  94. //RFID.c
  95. extern void CreateRfidFork(void);
  96. extern void ScannerCardProcess(void);
  97. extern bool RfidStopCharging(void);
  98. extern bool GetIsCardScan(void);
  99. extern void SetIsCardScan(bool value);
  100. //SelfTest.c
  101. extern void SelfTestRun(void);
  102. //UpgradeFW.c
  103. /*extern void CheckFwUpdateFunction(void);*/
  104. //Ethernet.c
  105. extern void InitEthernet(void);
  106. extern void GetMacAddress(void);
  107. //WatchDog.c
  108. extern void CreateWatchdog(void);
  109. extern void TryCloseWatchdog(void);
  110. extern void TryFeedWatchdog(void);
  111. //ZipFile.c
  112. extern void zipLogFiles(void);
  113. //------------------------------------------------------------------------------
  114. //--- share memory value ---
  115. //------------------------------------------------------------------------------
  116. static void changeLcmPage(uint8_t index)
  117. {
  118. pSysInfo->SystemPage = index;
  119. }
  120. static uint8_t getCurLcmPage(void)
  121. {
  122. return pSysInfo->SystemPage;
  123. }
  124. static void systemPageRestoreInit(void)
  125. {
  126. pSysInfo->SystemPage = _LCM_VIEW;
  127. }
  128. //------------------------------------------------------------------------------
  129. void destroySelGun(uint8_t curGun)
  130. {
  131. uint8_t i = 0;
  132. uint8_t totalGun = pSysConfig->TotalConnectorCount;
  133. //for status timeout
  134. if (curGun == DESTROY_ALL_SEL) {
  135. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  136. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  137. log_info("destroy all gun = %d, %d",
  138. ShmSelectGunInfo->SelGunInfo.LeftGun,
  139. ShmSelectGunInfo->SelGunInfo.RightGun);
  140. for (i = 0; i < totalGun; i++) {
  141. StopGunInfoTimeoutDet(i);
  142. memset(&ShmSelectGunInfo->PricesInfo[i], 0, sizeof(PricesInfo));
  143. }
  144. pSysInfo->CurGunSelected = 0;
  145. strcpy((char *)pSysConfig->UserId, "");
  146. //changeLcmPage(_LCM_VIEW);
  147. return;
  148. }
  149. //for charging timeout or complete
  150. if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
  151. if (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
  152. ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
  153. changeLcmPage(_LCM_VIEW);
  154. }
  155. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  156. StopGunInfoTimeoutDet(LEFT_GUN_NUM);
  157. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  158. ClearAuthorizedFlag();
  159. }
  160. log_info("destroy left gun, cur page = %d", getCurLcmPage());
  161. if (getCurLcmPage() == pSysInfo->SystemPage) {
  162. log_info("clear left balance");
  163. memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  164. ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  165. }
  166. }
  167. if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
  168. if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
  169. ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
  170. changeLcmPage(_LCM_VIEW);
  171. }
  172. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  173. StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
  174. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  175. ClearAuthorizedFlag();
  176. }
  177. log_info("destroy right gun, cur page = %d", getCurLcmPage());
  178. if (getCurLcmPage() == pSysInfo->SystemPage) {
  179. log_info("clear right balance");
  180. memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  181. ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  182. }
  183. }
  184. }
  185. static int waitRightGunPlugIt(uint8_t curGun)
  186. {
  187. if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
  188. return PASS;
  189. }
  190. return FAIL;
  191. }
  192. static int waitLeftGunPlugIt(uint8_t curGun)
  193. {
  194. if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
  195. return PASS;
  196. }
  197. return FAIL;
  198. }
  199. void setSelGunWaitToAuthor(uint8_t curSel)
  200. {
  201. if (curSel == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
  202. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
  203. log_info("setSelGunWaitToAuthor left");
  204. StopGunInfoTimeoutDet(curSel);
  205. } else if (curSel == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
  206. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
  207. log_info("setSelGunWaitToAuthor right");
  208. StopGunInfoTimeoutDet(curSel);
  209. }
  210. }
  211. int getConfirmSelectedGun(uint8_t curSel)
  212. {
  213. if (((curSel == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
  214. ((curSel == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
  215. return PASS;
  216. }
  217. return FAIL;
  218. }
  219. void confirmSelGun(uint8_t selGun)
  220. {
  221. if (selGun == LEFT_GUN_NUM) {
  222. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  223. //printf("confirmSelGun left");
  224. } else if (selGun == RIGHT_GUN_NUM) {
  225. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  226. //printf("confirmSelGun right");
  227. }
  228. changeLcmPage(_LCM_START_SCAN);
  229. //StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
  230. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  231. }
  232. static void GetFirmwareVersion(void)
  233. {
  234. // Get CSU root file system version
  235. sprintf((char *)pSysInfo->CsuRootFsFwRev, fwVersion);
  236. sprintf((char*)ShmDcCommonData->DebugVersion, DebugVersion);
  237. uint8_t count = 0, chademo = 0, ccs = 0, gb = 0;
  238. for (uint8_t idx = 0; idx < 3; idx++) {
  239. if (pSysConfig->ModelName[7 + idx] == 'J') {
  240. chademo++;
  241. count++;
  242. } else if (pSysConfig->ModelName[7 + idx] == 'G') {
  243. gb++;
  244. count++;
  245. } else if (pSysConfig->ModelName[7 + idx] == 'U' ||
  246. pSysConfig->ModelName[7 + idx] == 'V' ||
  247. pSysConfig->ModelName[7 + idx] == 'E') {
  248. ccs++;
  249. count++;
  250. }
  251. }
  252. if (count == 1) {
  253. if (chademo > 0) {
  254. pSysInfo->CsuRootFsFwRev[7] = '1';
  255. } else if (ccs > 0) {
  256. pSysInfo->CsuRootFsFwRev[7] = '2';
  257. } else if (gb > 0) {
  258. pSysInfo->CsuRootFsFwRev[7] = '3';
  259. }
  260. } else {
  261. if (chademo > 0 && ccs > 0) {
  262. pSysInfo->CsuRootFsFwRev[7] = '4';
  263. } else if (chademo > 0 && gb > 0) {
  264. pSysInfo->CsuRootFsFwRev[7] = '5';
  265. } else if (ccs > 0 && gb > 0) {
  266. pSysInfo->CsuRootFsFwRev[7] = '6';
  267. }
  268. }
  269. // Get network option from model name
  270. switch (pSysConfig->ModelName[10]) {
  271. case 'B':
  272. case 'U':
  273. //Blue tooth
  274. pSysInfo->CsuRootFsFwRev[9] = '3';
  275. break;
  276. case 'W':
  277. // WIFI
  278. pSysInfo->CsuRootFsFwRev[9] = '1';
  279. break;
  280. case 'T':
  281. // 3G/4G
  282. pSysInfo->CsuRootFsFwRev[9] = '2';
  283. break;
  284. case 'D': //DS60-120 add
  285. pSysInfo->CsuRootFsFwRev[9] = '5';
  286. break;
  287. default:
  288. // LAN
  289. pSysInfo->CsuRootFsFwRev[9] = '0';
  290. break;
  291. }
  292. // Get rating power from model name
  293. memcpy(&pSysInfo->CsuRootFsFwRev[10], &pSysConfig->ModelName[4], 0x03);
  294. // Get IEC or UL
  295. char _buf[3] = {0};
  296. memcpy(_buf, &pSysConfig->ModelName[2], 2);
  297. if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
  298. pSysInfo->ChargerType = _CHARGER_TYPE_IEC;
  299. log_info("IEC model");
  300. } else if (strcmp(_buf, "WU") == EQUAL) {
  301. pSysInfo->ChargerType = _CHARGER_TYPE_UL;
  302. log_info("UL model");
  303. }
  304. }
  305. static void checkGunOTPState(uint8_t gunIndex)
  306. {
  307. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  308. //水冷機溫度檢測
  309. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  310. if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
  311. // 單水冷機
  312. // Chiller OTP
  313. if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
  314. // 溫度為255時判斷Sensor fail
  315. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  316. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  317. } else {
  318. //判斷OTP
  319. if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
  320. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  321. RecordAlarmCode(gunIndex, "012323");
  322. } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR &&
  323. ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
  324. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  325. }
  326. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  327. }
  328. // Chiller Tube OTP
  329. if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
  330. // 溫度為255時判斷Sensor fail
  331. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  332. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  333. } else {
  334. //判斷OTP
  335. if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
  336. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
  337. RecordAlarmCode(gunIndex, "012332");
  338. } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR &&
  339. ShmDcCommonData->SystemTemp[3] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
  340. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  341. }
  342. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  343. }
  344. } else {
  345. // 雙水冷機
  346. if (gunIndex == LEFT_GUN_NUM) {
  347. if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP) {
  348. // 溫度為255時判斷Sensor fail
  349. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  350. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  351. } else {
  352. //判斷OTP
  353. if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp) {
  354. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  355. RecordAlarmCode(gunIndex, "012323");
  356. } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR) {
  357. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  358. }
  359. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  360. }
  361. if (ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
  362. // 溫度為255時判斷Sensor fail
  363. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  364. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  365. } else {
  366. //判斷OTP
  367. if (ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
  368. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
  369. RecordAlarmCode(gunIndex, "012332");
  370. } else if (ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
  371. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  372. }
  373. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  374. }
  375. } else {
  376. if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP) {
  377. // 溫度為255時判斷Sensor fail
  378. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  379. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  380. } else {
  381. //判斷OTP
  382. if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp) {
  383. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  384. RecordAlarmCode(gunIndex, "012323");
  385. } else if ( ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR) {
  386. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  387. }
  388. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  389. }
  390. if (ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
  391. // 溫度為255時判斷Sensor fail
  392. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  393. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  394. } else {
  395. //判斷OTP
  396. if (ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
  397. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
  398. RecordAlarmCode(gunIndex, "012332");
  399. } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
  400. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  401. }
  402. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  403. }
  404. }
  405. }
  406. if(pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES) {
  407. RecordAlarmCode(gunIndex, "011037");
  408. }
  409. }
  410. switch (pDcChargingInfo->Type) {
  411. case _Type_Chademo:
  412. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  413. if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
  414. RecordAlarmCode(gunIndex, "012229");
  415. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
  416. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  417. pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
  418. //ResetChargerAlarmCode(gunIndex, "012229");
  419. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  420. }
  421. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  422. } else {
  423. // 沒接上 Sensor or 異常
  424. //RecordAlarmCode(gunIndex, "011018");
  425. //ResetChargerAlarmCode(gunIndex, "012229");
  426. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  427. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
  428. if ((gunIndex == 0) &&
  429. (strncmp((char *)&pSysConfig->ModelName[7], "J", 1) == 0)) {
  430. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  431. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  432. } else if ((gunIndex == 1) &&
  433. ((strncmp((char *)&pSysConfig->ModelName[9], "J", 1) == 0) )) {
  434. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  435. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  436. }
  437. }
  438. break;
  439. case _Type_CCS_2:
  440. // CCS 不管甚麼輸出都會有槍溫偵測!!~
  441. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  442. //ResetChargerAlarmCode(gunIndex, "011019");
  443. if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
  444. RecordAlarmCode(gunIndex, "012230");
  445. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
  446. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  447. pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
  448. //ResetChargerAlarmCode(gunIndex, "012230");
  449. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  450. }
  451. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
  452. //ResetChargerAlarmCode(gunIndex, "011019");
  453. } else {
  454. // 沒接上 Sensor or 異常
  455. //RecordAlarmCode(gunIndex, "011019");
  456. //ResetChargerAlarmCode(gunIndex, "012230");
  457. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  458. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
  459. }
  460. break;
  461. case _Type_GB:
  462. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  463. if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
  464. RecordAlarmCode(gunIndex, "012231");
  465. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
  466. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  467. pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
  468. //ResetChargerAlarmCode(gunIndex, "012231");
  469. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  470. }
  471. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
  472. } else {
  473. // 沒接上 Sensor or 異常
  474. //RecordAlarmCode(gunIndex, "011020");
  475. //ResetChargerAlarmCode(gunIndex, "012231");
  476. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  477. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
  478. }
  479. break;
  480. }
  481. }
  482. static void collectError(uint8_t gunIndex)
  483. {
  484. gEvBoardErr.GunErrMessage |= ShmDcCommonData->ConnectErrList[gunIndex].GunErrMessage;
  485. gChillerTempErr.TempErrMsg |= ShmDcCommonData->ChillerTempErr[gunIndex].TempErrMsg;
  486. }
  487. static void checkGBTAlarmState(uint8_t gunType)
  488. {
  489. // GFD Trip
  490. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  491. pAlarmCode->AlarmEvents.bits.GbGfdTrip = YES;
  492. } else {
  493. pAlarmCode->AlarmEvents.bits.GbGfdTrip = NO;
  494. }
  495. // UVP
  496. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  497. pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = YES;
  498. } else {
  499. pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = NO;
  500. }
  501. // OTP
  502. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  503. pAlarmCode->AlarmEvents.bits.GbConnectorOTP = YES;
  504. } else {
  505. pAlarmCode->AlarmEvents.bits.GbConnectorOTP = NO;
  506. }
  507. // OVP
  508. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  509. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
  510. } else {
  511. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  512. }
  513. // GFD Warning
  514. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  515. pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = YES;
  516. } else {
  517. pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = NO;
  518. }
  519. // Relay Welding
  520. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  521. pFaultCode->FaultEvents.bits.GbOutputRelayWelding = YES;
  522. } else {
  523. pFaultCode->FaultEvents.bits.GbOutputRelayWelding = NO;
  524. }
  525. // Relay Driving
  526. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  527. pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = YES;
  528. } else {
  529. pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = NO;
  530. }
  531. // Connect temp Sensor broken
  532. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  533. pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = YES;
  534. } else {
  535. pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = NO;
  536. }
  537. }
  538. static void checkCCSAlarmState(uint8_t gunType)
  539. {
  540. // GFD Trip
  541. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  542. pAlarmCode->AlarmEvents.bits.CcsGfdTrip = YES;
  543. } else {
  544. pAlarmCode->AlarmEvents.bits.CcsGfdTrip = NO;
  545. }
  546. // UVP
  547. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  548. pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES;
  549. } else {
  550. pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = NO;
  551. }
  552. // OTP
  553. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  554. pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = YES;
  555. } else {
  556. pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = NO;
  557. }
  558. // OVP
  559. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  560. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
  561. } else {
  562. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  563. }
  564. // GFD Warning
  565. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  566. pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = YES;
  567. } else {
  568. pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = NO;
  569. }
  570. // Relay Welding
  571. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  572. pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = YES;
  573. } else {
  574. pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = NO;
  575. }
  576. // Relay Driving
  577. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  578. pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
  579. } else {
  580. pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
  581. }
  582. // Connect temp Sensor broken
  583. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  584. pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
  585. } else {
  586. pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
  587. }
  588. }
  589. static void checkChaDeMoAlarmState(uint8_t gunType)
  590. {
  591. // GFD Trip
  592. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  593. pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = YES;
  594. } else {
  595. pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = NO;
  596. }
  597. // UVP
  598. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  599. pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = YES;
  600. } else {
  601. pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = NO;
  602. }
  603. // OTP
  604. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  605. pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = YES;
  606. } else {
  607. pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = NO;
  608. }
  609. // OVP
  610. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  611. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
  612. } else {
  613. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  614. }
  615. // GFD Warning
  616. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  617. pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = YES;
  618. } else {
  619. pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = NO;
  620. }
  621. // Relay Welding
  622. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  623. pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = YES;
  624. } else {
  625. pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = NO;
  626. }
  627. // Relay Driving
  628. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  629. pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
  630. } else {
  631. pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
  632. }
  633. // Connect temp Sensor broken
  634. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  635. pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
  636. } else {
  637. pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
  638. }
  639. }
  640. static void checkChillerAlarmState(void)
  641. {
  642. if (DetectBitValue(gChillerTempErr.TempErrMsg, 0)) {
  643. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = YES;
  644. } else {
  645. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = NO;
  646. }
  647. if (DetectBitValue(gChillerTempErr.TempErrMsg, 1)) {
  648. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = YES;
  649. } else {
  650. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = NO;
  651. }
  652. if (DetectBitValue(gChillerTempErr.TempErrMsg, 2)) {
  653. pAlarmCode->AlarmEvents.bits.ChillerTubeOTP = YES;
  654. } else {
  655. pAlarmCode->AlarmEvents.bits.ChillerTubeOTP = NO;
  656. }
  657. }
  658. static void checkEvBoardAlarmState(uint8_t gunType)
  659. {
  660. switch (gunType) {
  661. case _Type_Chademo:
  662. checkChaDeMoAlarmState(gunType);
  663. break;
  664. case _Type_CCS_2:
  665. checkCCSAlarmState(gunType);
  666. break;
  667. case _Type_GB:
  668. checkGBTAlarmState(gunType);
  669. break;
  670. }
  671. }
  672. unsigned long GetSecTimeoutValue(struct timespec _start_time)
  673. {
  674. struct timespec ts_end;
  675. unsigned long ret = 0;
  676. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  677. ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000) + ((unsigned long)((ts_end.tv_nsec / 1000000) - (_start_time.tv_nsec / 1000000)));
  678. /*
  679. printf("\r\n TimeInterval: %ld.%09ld - %ld.%09ld = %ld.%03ld ms",
  680. ts_end.tv_sec, ts_end.tv_nsec, _start_time.tv_sec, _start_time.tv_nsec,
  681. (ret / 1000), (ret % 1000));
  682. */
  683. ret /= 1000;
  684. return ret;
  685. }
  686. void GetClockTime(struct timespec *_now_time, void *null)
  687. {
  688. clock_gettime(CLOCK_MONOTONIC, _now_time);
  689. }
  690. unsigned long GetTimeoutValue(struct timespec _start_time)
  691. {
  692. struct timespec ts_end;
  693. unsigned long ret = 0;
  694. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  695. ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
  696. return ret;
  697. }
  698. // return value unit: 1us
  699. unsigned long GetClockTimeoutValue(struct timespec _start_time)
  700. {
  701. struct timespec ts_end;
  702. unsigned long ret = 0;
  703. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  704. ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
  705. return ret;
  706. }
  707. int DiffTimeb(struct timeb ST, struct timeb ET)
  708. {
  709. //return milli-second
  710. unsigned int StartTime, StopTime;
  711. StartTime = (unsigned int)ST.time;
  712. StopTime = (unsigned int)ET.time;
  713. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  714. return (StopTime - StartTime);
  715. }
  716. bool CheckTimeOut(struct timeb ST)
  717. {
  718. struct timeb ET;
  719. unsigned int StartTime, StopTime;
  720. ftime(&ET);
  721. StartTime = (unsigned int) ST.time;
  722. StopTime = (unsigned int) ET.time;
  723. return (StopTime > StartTime) ? YES : NO;
  724. }
  725. void setChargerMode(uint8_t gunIndex, uint8_t mode)
  726. {
  727. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  728. pDcChargingInfo->SystemStatus = mode;
  729. }
  730. long long DiffTimebWithNow(struct timeb ST)
  731. {
  732. //return milli-second
  733. struct timeb ET;
  734. long long StartTime, StopTime;
  735. ftime(&ET);
  736. StartTime = (long long)ST.time;
  737. StopTime = (long long)ET.time;
  738. return ((StopTime - StartTime) * 1000) + (ET.millitm - ST.millitm);
  739. }
  740. //==========================================
  741. // Log
  742. //==========================================
  743. void CheckFwSlotStatusLog(void)
  744. {
  745. if (bd0_1_status == 0 && bd0_2_status == 1) {
  746. log_info("Connector 1 : Chademo");
  747. } else if (bd0_1_status == 1 && bd0_2_status == 0) {
  748. log_info("Connector 1 : CCS");
  749. } else if (bd0_1_status == 1 && bd0_2_status == 1) {
  750. log_info("Connector 1 : GB");
  751. }
  752. if (bd1_1_status == 0 && bd1_2_status == 1) {
  753. log_info("Connector 2 : Chademo");
  754. } else if (bd1_1_status == 1 && bd1_2_status == 0) {
  755. log_info("Connector 2 : CCS");
  756. } else if (bd1_1_status == 1 && bd1_2_status == 1) {
  757. log_info("Connector 2 : GB");
  758. }
  759. }
  760. void CheckHwSlotStatusLog(uint8_t index)
  761. {
  762. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  763. if (pDcChargingInfo->Type == _Type_Chademo) {
  764. log_info("Hw check : Connector %d, Type : Chademo, Evboard_id = %d ",
  765. index, pDcChargingInfo->Evboard_id);
  766. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  767. log_info("Hw check : Connector %d, Type : CCS, Evboard_id = %d ",
  768. index, pDcChargingInfo->Evboard_id);
  769. } else if (pDcChargingInfo->Type == _Type_GB) {
  770. log_info("Hw check : Connector %d, Type : GB, Evboard_id = %d ",
  771. index, pDcChargingInfo->Evboard_id);
  772. }
  773. }
  774. //=================================
  775. // LCM Page
  776. //=================================
  777. void ChangeLcmByIndex(uint8_t page_index)
  778. {
  779. if (pSysWarning->Level != WARN_LV_ER ||
  780. page_index == _LCM_SUMMARY ||
  781. page_index == _LCM_ERROR
  782. ) {
  783. pSysInfo->PageIndex = page_index;
  784. //log_info("LCM index:%d",pSysInfo->PageIndex);
  785. }
  786. }
  787. //======================================================
  788. // Peripheral initial
  789. //======================================================
  790. void InitGPIO()
  791. {
  792. /*****************0~3, 4 bank, bank x 32+ num*********************/
  793. /***************************************************************/
  794. /*************** GPIO 0 ***************************************/
  795. /***************************************************************/
  796. /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/
  797. system("echo 22 > /sys/class/gpio/export");
  798. system("echo \"in\" > /sys/class/gpio/gpio22/direction");
  799. /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/
  800. system("echo 23 > /sys/class/gpio/export");
  801. system("echo \"in\" > /sys/class/gpio/gpio23/direction");
  802. /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/
  803. system("echo 26 > /sys/class/gpio/export");
  804. system("echo \"out\" > /sys/class/gpio/gpio26/direction");
  805. system("echo 1 > /sys/class/gpio/gpio26/value");
  806. /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/
  807. system("echo 27 > /sys/class/gpio/export");
  808. system("echo \"in\" > /sys/class/gpio/gpio27/direction");
  809. /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
  810. system("echo 29 > /sys/class/gpio/export");
  811. system("echo \"in\" > /sys/class/gpio/gpio29/direction");
  812. /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/
  813. system("echo 19 > /sys/class/gpio/export");
  814. system("echo \"out\" > /sys/class/gpio/gpio19/direction");
  815. system("echo 1 > /sys/class/gpio/gpio19/value");
  816. /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/
  817. system("echo 20 > /sys/class/gpio/export");
  818. system("echo \"in\" > /sys/class/gpio/gpio20/direction");
  819. /***************************************************************/
  820. /*************** GPIO 1 ***************************************/
  821. /***************************************************************/
  822. /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/
  823. system("echo 44 > /sys/class/gpio/export");
  824. system("echo \"in\" > /sys/class/gpio/gpio44/direction");
  825. /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/
  826. system("echo 45 > /sys/class/gpio/export");
  827. system("echo \"in\" > /sys/class/gpio/gpio45/direction");
  828. /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/
  829. system("echo 46 > /sys/class/gpio/export");
  830. system("echo \"out\" > /sys/class/gpio/gpio46/direction");
  831. system("echo 0 > /sys/class/gpio/gpio46/value");
  832. /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/
  833. system("echo 47 > /sys/class/gpio/export");
  834. system("echo \"in\" > /sys/class/gpio/gpio47/direction");
  835. /***************************************************************/
  836. /*************** GPIO 2 ***************************************/
  837. /***************************************************************/
  838. /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
  839. system("echo 89 > /sys/class/gpio/export");
  840. system("echo \"out\" > /sys/class/gpio/gpio89/direction");
  841. system("echo 1 > /sys/class/gpio/gpio89/value");
  842. /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
  843. system("echo 87 > /sys/class/gpio/export");
  844. system("echo \"out\" > /sys/class/gpio/gpio87/direction");
  845. system("echo 0 > /sys/class/gpio/gpio87/value");
  846. /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/
  847. system("echo 88 > /sys/class/gpio/export");
  848. system("echo \"in\" > /sys/class/gpio/gpio88/direction");
  849. /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/
  850. system("echo 86 > /sys/class/gpio/export");
  851. system("echo \"in\" > /sys/class/gpio/gpio86/direction");
  852. /***************************************************************/
  853. /*************** GPIO 3 ***************************************/
  854. /***************************************************************/
  855. /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
  856. system("echo 111 > /sys/class/gpio/export");
  857. system("echo \"in\" > /sys/class/gpio/gpio111/direction");
  858. /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
  859. system("echo 114 > /sys/class/gpio/export");
  860. system("echo \"in\" > /sys/class/gpio/gpio114/direction");
  861. /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
  862. system("echo 113 > /sys/class/gpio/export");
  863. system("echo \"in\" > /sys/class/gpio/gpio113/direction");
  864. /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
  865. system("echo 110 > /sys/class/gpio/export");
  866. system("echo \"out\" > /sys/class/gpio/gpio110/direction");
  867. system("echo 0 > /sys/class/gpio/gpio110/value");
  868. /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
  869. system("echo 115 > /sys/class/gpio/export");
  870. system("echo \"out\" > /sys/class/gpio/gpio115/direction");
  871. system("echo 0 > /sys/class/gpio/gpio115/value");
  872. /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
  873. system("echo 112 > /sys/class/gpio/export");
  874. system("echo \"out\" > /sys/class/gpio/gpio112/direction");
  875. system("echo 1 > /sys/class/gpio/gpio112/value");
  876. /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
  877. system("echo 116 > /sys/class/gpio/export");
  878. system("echo \"out\" > /sys/class/gpio/gpio116/direction");
  879. system("echo 0 > /sys/class/gpio/gpio116/value");
  880. log_info("Initial GPIO OK");
  881. return ;
  882. }
  883. int LoadSysConfigAndInfo()
  884. {
  885. int fd, wrd;
  886. unsigned char *buf;
  887. unsigned int ChkSum, ChkSumOrg;
  888. if ((buf = malloc(MtdBlockSize)) == NULL) {
  889. log_error("malloc buffer NG,rebooting..");
  890. if (pAlarmCode != NULL) {
  891. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  892. }
  893. sleep(5);
  894. system("reboot -f");
  895. sleep(5);
  896. system("reboot -f");
  897. }
  898. memset(buf, 0, MtdBlockSize);
  899. //================================================
  900. // Load configuration from mtdblock10
  901. //================================================
  902. system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
  903. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  904. if (fd < 0) {
  905. free(buf);
  906. log_error("open mtdblock10 NG,rebooting..");
  907. if (pAlarmCode != NULL) {
  908. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  909. }
  910. sleep(5);
  911. system("reboot -f");
  912. sleep(5);
  913. system("reboot -f");
  914. }
  915. wrd = read(fd, buf, MtdBlockSize);
  916. close(fd);
  917. if (wrd < MtdBlockSize) {
  918. free(buf);
  919. log_error("read SysConfigData data NG,rebooting..");
  920. if (pAlarmCode != NULL) {
  921. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  922. }
  923. sleep(5);
  924. system("reboot -f");
  925. sleep(5);
  926. system("reboot -f");
  927. }
  928. ChkSum = 0;
  929. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  930. ChkSum += buf[wrd];
  931. }
  932. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  933. memcpy(&pSysConfig->ModelName, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), ARRAY_SIZE(pSysConfig->ModelName));
  934. memcpy(&pSysConfig->SerialNumber, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), ARRAY_SIZE(pSysConfig->SerialNumber));
  935. //================================================
  936. // Load configuration from mtdblock11
  937. //================================================
  938. if (ChkSum != ChkSumOrg) {
  939. log_error("Primary SysConfigData checksum NG, read backup");
  940. system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
  941. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  942. if (fd < 0) {
  943. free(buf);
  944. log_error("open mtdblock11 (backup) NG,rebooting..");
  945. if (pAlarmCode != NULL) {
  946. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  947. }
  948. sleep(5);
  949. system("reboot -f");
  950. sleep(5);
  951. system("reboot -f");
  952. }
  953. memset(buf, 0, MtdBlockSize);
  954. wrd = read(fd, buf, MtdBlockSize);
  955. close(fd);
  956. if (wrd < MtdBlockSize) {
  957. free(buf);
  958. log_error("read backup SysConfigData data NG,rebooting..");
  959. if (pAlarmCode != NULL) {
  960. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  961. }
  962. sleep(5);
  963. system("reboot -f");
  964. sleep(5);
  965. system("reboot -f");
  966. }
  967. ChkSum = 0;
  968. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  969. ChkSum += buf[wrd];
  970. }
  971. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  972. //================================================
  973. // Load configuration from mtdblock12 (Factory default)
  974. //================================================
  975. if (ChkSum != ChkSumOrg) {
  976. log_warn("backup SysConfigData checksum NG, read Factory default");
  977. system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
  978. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  979. if (fd < 0) {
  980. log_error("open mtdblock12 (Factory default) NG,rebooting..");
  981. free(buf);
  982. if (pAlarmCode != NULL) {
  983. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  984. }
  985. sleep(5);
  986. system("reboot -f");
  987. sleep(5);
  988. system("reboot -f");
  989. }
  990. memset(buf, 0, MtdBlockSize);
  991. wrd = read(fd, buf, MtdBlockSize);
  992. close(fd);
  993. if (wrd < MtdBlockSize) {
  994. log_error("read factory default SysConfigData data NG,rebooting..");
  995. free(buf);
  996. if (pAlarmCode != NULL) {
  997. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  998. }
  999. sleep(5);
  1000. system("reboot -f");
  1001. sleep(5);
  1002. system("reboot -f");
  1003. }
  1004. ChkSum = 0;
  1005. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  1006. ChkSum += buf[wrd];
  1007. }
  1008. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  1009. memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), &pSysConfig->ModelName, ARRAY_SIZE(pSysConfig->ModelName));
  1010. memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), &pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
  1011. if (ChkSum != ChkSumOrg) {
  1012. log_warn("factory default SysConfigData checksum NG, restore factory default");
  1013. free(buf);
  1014. system("cd /root;./FactoryConfig -m");
  1015. system("rm -f /Storage/OCPP/OCPPConfiguration");
  1016. system("sync");
  1017. sleep(5);
  1018. system("reboot -f");
  1019. sleep(5);
  1020. system("reboot -f");
  1021. return FAIL;
  1022. }
  1023. }
  1024. }
  1025. //load OK
  1026. memcpy(pSysConfig, buf, sizeof(struct SysConfigData));
  1027. free(buf);
  1028. system("rm -f /mnt/EvseConfig.bin");
  1029. // SysConfig in flash is empty (0xffffffff)
  1030. if ((strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) ||
  1031. (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) ||
  1032. (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) ||
  1033. (pSysConfig->Eth0Interface.EthDhcpClient == 0xff)) {
  1034. if (strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) {
  1035. memset(pSysConfig->ModelName, 0x00, ARRAY_SIZE(pSysConfig->ModelName));
  1036. }
  1037. if (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) {
  1038. memset(pSysConfig->SerialNumber, 0x00, ARRAY_SIZE(pSysConfig->SerialNumber));
  1039. }
  1040. if (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) {
  1041. memset(pSysConfig->SystemId, 0x00, ARRAY_SIZE(pSysConfig->SystemId));
  1042. }
  1043. if (pSysConfig->Eth0Interface.EthDhcpClient == 0xff) {
  1044. log_info("Ethernet dhcp config is null.");
  1045. }
  1046. if (strlen((char *)pSysConfig->ModelName) == 0x00) {
  1047. log_info("Model name over length.");
  1048. }
  1049. if (strlen((char *)pSysConfig->SerialNumber) == 0x00) {
  1050. log_info("Model serial number over length.");
  1051. }
  1052. if (strlen((char *)pSysConfig->SystemId) == 0x00) {
  1053. log_info("SystemId over length.");
  1054. }
  1055. system("cd /root;./FactoryConfig -m");
  1056. sleep(3);
  1057. system("/usr/bin/run_evse_restart.sh");
  1058. }
  1059. log_info("Load SysConfigData OK");
  1060. return PASS;
  1061. }
  1062. int Initialization(void)
  1063. {
  1064. uint8_t count = 0;
  1065. uint8_t pinOut[2] = {116, 115};
  1066. // 初始化卡號驗證的 Flag
  1067. ClearAuthorizedFlag();
  1068. // 初始化插槍驗證的 Flag
  1069. ClearDetectPluginFlag(pSysInfo->CurGunSelected);
  1070. for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  1071. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  1072. pDcChargingInfo->RemoteStartFlag = NO;
  1073. if (pDcChargingInfo->Type == _Type_Chademo) {
  1074. gpio_set_value(pinOut[count], 0x00);
  1075. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1076. } else if (pDcChargingInfo->Type == _Type_GB) {
  1077. gpio_set_value(pinOut[count], 0x00);
  1078. ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1079. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1080. //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
  1081. if (pSysConfig->TotalConnectorCount == 1) {
  1082. gpio_set_value(pinOut[1], 0x01);
  1083. } else {
  1084. gpio_set_value(pinOut[count], 0x01);
  1085. }
  1086. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1087. //}
  1088. }
  1089. strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
  1090. }
  1091. for (count = 0; count < pSysConfig->AcConnectorCount; count++) {
  1092. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
  1093. pAcChargingInfo->RemoteStartFlag = NO;
  1094. if (pAcChargingInfo->Type == _Type_AC) {
  1095. pAcChargingInfo->SelfTest_Comp = NO;
  1096. strcpy((char *)ShmOCPP16Data->StatusNotification[count + pSysConfig->TotalConnectorCount].ErrorCode, "NoError");
  1097. }
  1098. }
  1099. return PASS;
  1100. }
  1101. bool InitialSystemDefaultConfig()
  1102. {
  1103. bool result = true;
  1104. LoadSysConfigAndInfo();
  1105. InitGPIO();
  1106. InitEthernet();
  1107. GetMacAddress();
  1108. return result;
  1109. }
  1110. //顯示自檢錯誤原因,觸發對應的flag
  1111. bool DisplaySelfTestFailReason()
  1112. {
  1113. bool result = false;
  1114. uint8_t index = 0;
  1115. // RB、FB、407、EV 小板中有些板子無回應
  1116. if (ShmRelayModuleData->SelfTest_Comp == NO) {
  1117. pAlarmCode->AlarmEvents.bits.RelayboardStestFail = true;
  1118. }
  1119. if (ShmFanModuleData->SelfTest_Comp == NO) {
  1120. pAlarmCode->AlarmEvents.bits.FanboardStestFail = true;
  1121. }
  1122. if (ShmPrimaryMcuData->SelfTest_Comp == NO) {
  1123. pAlarmCode->AlarmEvents.bits.PrimaryStestFail = true;
  1124. }
  1125. if (ShmLedModuleData->SelfTest_Comp == NO) {
  1126. pAlarmCode->AlarmEvents.bits.LedboardStestFail = true;
  1127. }
  1128. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  1129. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1130. if (pDcChargingInfo->Type == _Type_Chademo) {
  1131. if (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1132. pAlarmCode->AlarmEvents.bits.ChademoboardStestFail = true;
  1133. }
  1134. } else if (pDcChargingInfo->Type == _Type_GB) {
  1135. if (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1136. pAlarmCode->AlarmEvents.bits.GbtboardStestFail = true;
  1137. }
  1138. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1139. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  1140. if (ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1141. pAlarmCode->AlarmEvents.bits.CCSboardStestFail = true;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
  1147. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
  1148. // 先借 GBT 顯示
  1149. if (pAcChargingInfo->SelfTest_Comp == NO) {
  1150. pAlarmCode->AlarmEvents.bits.AcConnectorStestFail = true;
  1151. }
  1152. }
  1153. if (pSysInfo->AcContactorStatus == NO) {
  1154. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox &&!defined DD360UCar
  1155. // AC Contact 未搭上
  1156. pAlarmCode->AlarmEvents.bits.AcContactStestFail = true;
  1157. result = true;
  1158. #endif // !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1159. }
  1160. //else if (pAlarmCode->AlarmEvents.bits.PsuDipSwitchStestFail == YES) { //DS60-120 add
  1161. // result = true;
  1162. //}
  1163. else if (ShmPsuData->SystemAvailablePower <= 0 &&
  1164. ShmPsuData->SystemAvailableCurrent <= 0) {
  1165. // PSU 通訊問題
  1166. pAlarmCode->AlarmEvents.bits.PsuModuleStestFail = true;
  1167. result = true;
  1168. }
  1169. return result;
  1170. }
  1171. //===============================================
  1172. // Common Detect Chk - Stop Charging ?
  1173. //===============================================
  1174. int isEvBoardStopChargeFlag(uint8_t gunIndex)
  1175. {
  1176. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1177. //printf("StopChargeFlag = %d", chargingInfo[gunIndex]->StopChargeFlag);
  1178. return pDcChargingInfo->StopChargeFlag;
  1179. }
  1180. bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
  1181. {
  1182. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1183. return pDcChargingInfo->NormalStopChargeFlag;
  1184. }
  1185. //===============================================
  1186. // 掃描插槍狀況
  1187. //===============================================
  1188. void ClearDetectPluginFlag(int gunIndex)
  1189. {
  1190. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  1191. if (pDcChargingInfo->RemoteStartFlag == YES) {
  1192. pDcChargingInfo->RemoteStartFlag = NO;
  1193. }
  1194. ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
  1195. if (pSysInfo->OrderCharging != NO_DEFINE) {
  1196. pSysInfo->OrderCharging = NO_DEFINE;
  1197. }
  1198. }
  1199. void DetectPluginStart(int gunIndex)
  1200. {
  1201. //pSysInfo->WaitForPlugit = YES;
  1202. ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
  1203. }
  1204. bool isDetectPlugin(int gunIndex)
  1205. {
  1206. if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
  1207. return true;
  1208. }
  1209. return false;
  1210. }
  1211. //===============================================
  1212. // Common Detect Chk - Chademo
  1213. //===============================================
  1214. bool isEvGunLocked_chademo(uint8_t gunIndex)
  1215. {
  1216. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1217. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1218. }
  1219. bool isEvContactorWelding_chademo(uint8_t gunIndex)
  1220. {
  1221. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1222. return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 3);
  1223. }
  1224. bool isEvStopReq_chademo(uint8_t gunIndex)
  1225. {
  1226. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1227. return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 4);
  1228. }
  1229. bool isEvStopCharging_chademo(uint8_t gunIndex)
  1230. {
  1231. if (isEvGunLocked_chademo(gunIndex) == NO) {
  1232. // 無鎖槍 = 停止
  1233. //log_info("gun locked none (%d) ", gunIndex);
  1234. return YES;
  1235. }
  1236. return NO;
  1237. }
  1238. uint8_t isPrechargeStatus_chademo(uint8_t gunIndex)
  1239. {
  1240. uint8_t result = 0x00;
  1241. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1242. result = ShmCHAdeMOData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
  1243. return result;
  1244. }
  1245. //===============================================
  1246. // Common Detect Chk - GB
  1247. //===============================================
  1248. bool isEvGunLocked_gb(uint8_t gunIndex)
  1249. {
  1250. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1251. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1252. }
  1253. bool isEvStopCharging_gb(uint8_t gunIndex)
  1254. {
  1255. if (isEvGunLocked_gb(gunIndex) == NO) {
  1256. // 無鎖槍 = 停止
  1257. //log_info("gun locked none. ");
  1258. return YES;
  1259. }
  1260. return NO;
  1261. }
  1262. uint8_t isPrechargeStatus_gb(uint8_t gunIndex)
  1263. {
  1264. uint8_t result = 0x00;
  1265. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1266. result = ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
  1267. return result;
  1268. }
  1269. //===============================================
  1270. // Common Detect Chk - CCS
  1271. //===============================================
  1272. bool isEvGunLocked_ccs(uint8_t gunIndex)
  1273. {
  1274. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1275. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1276. }
  1277. uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
  1278. {
  1279. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1280. return ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;
  1281. }
  1282. bool isEvStopCharging_ccs(uint8_t gunIndex)
  1283. {
  1284. if (isEvGunLocked_ccs(gunIndex) == NO) {
  1285. // 無鎖槍 = 停止
  1286. //log_info("gun locked none. ");
  1287. return YES;
  1288. }
  1289. return NO;
  1290. }
  1291. //===============================================
  1292. // Callback
  1293. //===============================================
  1294. void DisplayChargingInfo()
  1295. {
  1296. uint8_t i = 0;
  1297. log_info("*********** DisplayChargingInfo *********** ");
  1298. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1299. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1300. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  1301. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  1302. ChangeGunSelectByIndex(i);
  1303. return;
  1304. }
  1305. }
  1306. if (pSysConfig->AcConnectorCount > 0 &&
  1307. pSysInfo->CurGunSelectedByAc == NO_DEFINE)
  1308. {
  1309. pAcChargingInfo = (struct ChargingInfoData*)GetAcChargingInfoData(0);
  1310. if (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
  1311. pAcChargingInfo->SystemStatus <= S_COMPLETE)
  1312. {
  1313. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  1314. }
  1315. }
  1316. usleep(50000);
  1317. systemPageRestoreInit();
  1318. }
  1319. void _AutoReturnTimeout(void)
  1320. {
  1321. log_info("*********** _AutoReturnTimeout(%d) *********** ", pSysInfo->PageIndex);
  1322. if (pSysInfo->PageIndex == _LCM_PRECHARGE) {
  1323. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  1324. pDcChargingInfo->SystemStatus = S_ALARM;
  1325. //pSysInfo->SystemPage = _LCM_ERROR;
  1326. pSysInfo->SystemPage = _LCM_MAINTAIN;
  1327. ClearDetectPluginFlag(pSysInfo->CurGunSelected);
  1328. } else if (pSysInfo->SystemPage ==_LCM_START_AUTHORIZE_FAIL) {
  1329. pSysInfo->SystemPage = _LCM_START_SCAN;
  1330. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1331. strcpy((char *)pSysConfig->UserId, "");
  1332. setChargerMode(pSysInfo->CurGunSelected,MODE_AUTHORIZING);
  1333. }
  1334. }
  1335. void _SelfTestTimeout(void)
  1336. {
  1337. if (pSysInfo->BootingStatus != BOOT_COMPLETE) {
  1338. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  1339. setChargerMode(gunIndex, MODE_ALARM);
  1340. }
  1341. }
  1342. ShmPsuData->Work_Step = _NO_WORKING;
  1343. pSysInfo->SelfTestSeq = _STEST_FAIL;
  1344. log_info("Self test timeout. ");
  1345. }
  1346. void _AuthorizedTimeout(void)
  1347. {
  1348. //if (IsAuthorizingMode()) {
  1349. log_info("*********** _AuthorizedTimeout *********** ");
  1350. StopSystemTimeoutDet();
  1351. //isCardScan = false;
  1352. SetIsCardScan(false);
  1353. pSysInfo->SystemPage = _LCM_START_AUTHORIZE_FAIL;
  1354. //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
  1355. strcpy((char *)pSysConfig->UserId, "");
  1356. ClearAuthorizedFlag();
  1357. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1358. //}
  1359. }
  1360. void _DetectPlugInTimeout(int gunIndex)
  1361. {
  1362. log_info("*********** _DetectPlugInTimeout *********** ");
  1363. strcpy((char *)pSysConfig->UserId, "");
  1364. //pSysInfo->SystemPage = _LCM_LINK_ERROR;
  1365. //StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1366. ClearDetectPluginFlag(gunIndex);
  1367. setChargerMode(gunIndex, S_IDLE);
  1368. if (pSysInfo->CurGunSelected == gunIndex)
  1369. systemPageRestoreInit();
  1370. }
  1371. void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
  1372. {
  1373. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1374. if (pDcChargingInfo->Type == _Type_Chademo) {
  1375. if (!isEvGunLocked_chademo(gunIndex)) {
  1376. log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********");
  1377. }
  1378. } else if (pDcChargingInfo->Type == _Type_GB) {
  1379. if (!isEvGunLocked_ccs(gunIndex)) {
  1380. log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********");
  1381. }
  1382. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1383. if (!isEvGunLocked_ccs(gunIndex)) {
  1384. log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********");
  1385. }
  1386. }
  1387. //pSysInfo->SystemPage = _LCM_ERROR;
  1388. pSysInfo->SystemPage = _LCM_MAINTAIN;
  1389. ChargingTerminalProcess(gunIndex);
  1390. _AutoReturnTimeout();
  1391. }
  1392. void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
  1393. {
  1394. log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********");
  1395. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1396. //pSysInfo->SystemPage = _LCM_ERROR;
  1397. pSysInfo->SystemPage = _LCM_MAINTAIN;
  1398. _AutoReturnTimeout();
  1399. }
  1400. void _PrepareTimeout(uint8_t gunIndex)
  1401. {
  1402. log_info("*********** _PrepareTimeout ***********");
  1403. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1404. pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
  1405. //pSysInfo->SystemPage = _LCM_ERROR;
  1406. pSysInfo->SystemPage = _LCM_MAINTAIN;
  1407. _AutoReturnTimeout();
  1408. }
  1409. void _CcsPrechargeTimeout(uint8_t gunIndex)
  1410. {
  1411. log_info("*********** _CcsPrechargeTimeout ***********");
  1412. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1413. //pSysInfo->SystemPage = _LCM_ERROR;
  1414. pSysInfo->SystemPage = _LCM_MAINTAIN;
  1415. }
  1416. void _LinkErrorTimeout(uint8_t gunIndex)
  1417. {
  1418. log_info("*********** _LinkErrorTimeout ***********");
  1419. pSysInfo->SystemPage = _LCM_VIEW;
  1420. }
  1421. //===============================================
  1422. // 取得卡號與卡號驗證
  1423. //===============================================
  1424. void AuthorizingStart(void)
  1425. {
  1426. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
  1427. pSysInfo->AuthorizeFlag = YES;
  1428. }
  1429. void ClearAuthorizedFlag(void)
  1430. {
  1431. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
  1432. pSysInfo->AuthorizeFlag = NO;
  1433. }
  1434. bool isAuthorizedComplete(void)
  1435. {
  1436. if (pSysInfo->AuthorizeFlag == YES) {
  1437. return false;
  1438. }
  1439. return true;
  1440. }
  1441. bool IsAuthorizingMode()
  1442. {
  1443. if (pSysInfo->AuthorizeFlag == NO) {
  1444. return false;
  1445. }
  1446. return true;
  1447. }
  1448. //===============================================
  1449. // 紀錄 Alarm Code
  1450. //===============================================
  1451. void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
  1452. {
  1453. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1454. if (strcmp(code, "012234") == EQUAL) {
  1455. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  1456. } else if (strcmp(code, "012235") == EQUAL) {
  1457. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  1458. } else if (strcmp(code, "012236") == EQUAL) {
  1459. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  1460. } else if (strcmp(code, "012288") == EQUAL) {
  1461. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
  1462. } else if (strcmp(code, "012289") == EQUAL) {
  1463. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
  1464. } else if (strcmp(code, "012290") == EQUAL) {
  1465. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
  1466. } else if (strcmp(code, "012229") == EQUAL) {
  1467. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  1468. } else if (strcmp(code, "012230") == EQUAL) {
  1469. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  1470. } else if (strcmp(code, "012231") == EQUAL) {
  1471. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  1472. } else if (strcmp(code, "011011") == EQUAL) {
  1473. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  1474. } else if (strcmp(code, "011013") == EQUAL) {
  1475. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  1476. } else if (strcmp(code, "011015") == EQUAL) {
  1477. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  1478. } else if (strcmp(code, "011012") == EQUAL) {
  1479. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  1480. } else if (strcmp(code, "011014") == EQUAL) {
  1481. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  1482. } else if (strcmp(code, "011016") == EQUAL) {
  1483. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  1484. } else if (strcmp(code, "011018") == EQUAL) {
  1485. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  1486. } else if (strcmp(code, "011019") == EQUAL) {
  1487. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
  1488. } else if (strcmp(code, "011020") == EQUAL) {
  1489. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
  1490. } else if (strcmp(code, "012323") == EQUAL) {
  1491. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  1492. } else if (strcmp(code, "011038") == EQUAL) {
  1493. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  1494. } else if (strcmp(code, "012332") == EQUAL) {
  1495. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  1496. }
  1497. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012229", 6) == EQUAL ||
  1498. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012230", 6) == EQUAL ||
  1499. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012231", 6) == EQUAL ||
  1500. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011011", 6) == EQUAL ||
  1501. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011013", 6) == EQUAL ||
  1502. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011015", 6) == EQUAL ||
  1503. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011012", 6) == EQUAL ||
  1504. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011014", 6) == EQUAL ||
  1505. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011016", 6) == EQUAL ||
  1506. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011018", 6) == EQUAL ||
  1507. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011019", 6) == EQUAL ||
  1508. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011020", 6) == EQUAL ||
  1509. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012323", 6) == EQUAL ||
  1510. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL ||
  1511. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012332", 6) == EQUAL) {
  1512. strncpy((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1513. }
  1514. }
  1515. void RecordAlarmCode(uint8_t gunIndex, char *code)
  1516. {
  1517. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1518. if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1519. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
  1520. {
  1521. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1522. memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
  1523. }
  1524. if (pDcChargingInfo->StopChargeFlag == NO)
  1525. {
  1526. pDcChargingInfo->StopChargeFlag = YES;
  1527. }
  1528. }
  1529. }
  1530. void ReleaseAlarmCode(uint8_t gunIndex)
  1531. {
  1532. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1533. //if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1534. // return;
  1535. //}
  1536. switch (pDcChargingInfo->Type) {
  1537. case _Type_Chademo:
  1538. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  1539. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
  1540. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
  1541. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  1542. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  1543. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  1544. break;
  1545. case _Type_CCS_2:
  1546. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  1547. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
  1548. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
  1549. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  1550. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  1551. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  1552. break;
  1553. case _Type_GB:
  1554. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  1555. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
  1556. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
  1557. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  1558. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  1559. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  1560. break;
  1561. }
  1562. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1563. }
  1564. //===============================================
  1565. // EmergencyStop and Charging Stop
  1566. //===============================================
  1567. void ChargingTerminalProcess(uint8_t gunIndex)
  1568. {
  1569. setChargerMode(gunIndex, MODE_TERMINATING);
  1570. }
  1571. void ChargingAlarmProcess(uint8_t gunIndex)
  1572. {
  1573. UpdateErrorCodeToOcpp(gunIndex);
  1574. setChargerMode(gunIndex, MODE_ALARM);
  1575. }
  1576. void AcChargingTerminalProcess(void)
  1577. {
  1578. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  1579. pAcChargingInfo->SystemStatus = MODE_TERMINATING;
  1580. }
  1581. void StopChargingProcessByString(uint8_t level)
  1582. {
  1583. if (level > pSysWarning->Level) {
  1584. pSysWarning->Level = level;
  1585. }
  1586. }
  1587. void ReleaseChargingProcessByString(uint8_t level)
  1588. {
  1589. if (level >= pSysWarning->Level) {
  1590. pSysWarning->Level = WARN_LV_NL;
  1591. }
  1592. }
  1593. // 一般錯誤停止充電處理函式
  1594. void BoardErrOccurByString(uint8_t index, char *code)
  1595. {
  1596. uint8_t level = 1;
  1597. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1598. if ((pDcChargingInfo->SystemStatus > S_IDLE &&
  1599. pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1600. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1601. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1602. if (strncmp(code, "023730", 6) == EQUAL &&
  1603. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == NO
  1604. ) {
  1605. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
  1606. }
  1607. ChargingTerminalProcess(index);
  1608. }
  1609. StopChargingProcessByString(level);
  1610. }
  1611. void ReleaseBoardErrOccurByString(uint8_t index, char *code)
  1612. {
  1613. bool isTrigger = false;
  1614. uint8_t level = 1;
  1615. if (strncmp(code, "023730", 6) == 0 &&
  1616. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
  1617. isTrigger = true;
  1618. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
  1619. }
  1620. if (isTrigger) {
  1621. ReleaseChargingProcessByString(level);
  1622. }
  1623. }
  1624. // 急停狀況的停止充電處理函式
  1625. void EmcOccureByString(char *code)
  1626. {
  1627. uint8_t level = 2;
  1628. // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
  1629. // 其錯誤等級為 2
  1630. //DS60-120 remove
  1631. if (strncmp(code, "012251", 6) == EQUAL ||
  1632. strncmp(code, "012252", 6) == EQUAL ||
  1633. strncmp(code, "012238", 6) == EQUAL ||
  1634. strncmp(code, "042251", 6) == EQUAL ||
  1635. strncmp(code, "042252", 6) == EQUAL ||
  1636. strncmp(code, "012304", 6) == EQUAL ||
  1637. strncmp(code, "042327", 6) == EQUAL ||
  1638. strncmp(code, "042328", 6) == EQUAL ||
  1639. strncmp(code, "042200", 6) == EQUAL ||
  1640. strncmp(code, "042201", 6) == EQUAL ||
  1641. strncmp(code, "042202", 6) == EQUAL ||
  1642. strncmp(code, "042267", 6) == EQUAL) {
  1643. for (uint8_t gun = 0; gun < pSysConfig->TotalConnectorCount; gun++) {
  1644. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  1645. //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
  1646. if ((pDcChargingInfo->SystemStatus > S_IDLE &&
  1647. pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1648. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1649. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1650. //ChargingTerminalProcess(gun);
  1651. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1652. memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
  1653. }
  1654. ChargingAlarmProcess(gun);
  1655. }
  1656. }
  1657. StopChargingProcessByString(level);
  1658. InformOcppErrOccur(4);
  1659. }
  1660. }
  1661. void ReleaseEmsOccureByString(uint8_t index, char *code)
  1662. {
  1663. bool isTrigger = false;
  1664. uint8_t level = 2;
  1665. if (strncmp(code, "042251", 6) == 0 ) {
  1666. isTrigger = true;
  1667. } else if (strncmp(code, "012251", 6) == 0 &&
  1668. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
  1669. isTrigger = true;
  1670. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
  1671. } else if (strncmp(code, "012252", 6) == 0 &&
  1672. pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
  1673. isTrigger = true;
  1674. pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
  1675. } else if (strncmp(code, "012237", 6) == 0 &&
  1676. pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
  1677. isTrigger = true;
  1678. pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
  1679. } else if (strncmp(code, "012238", 6) == 0 &&
  1680. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  1681. isTrigger = true;
  1682. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
  1683. }
  1684. if (isTrigger) {
  1685. ReleaseChargingProcessByString(level);
  1686. InformOcppErrOccur(6);
  1687. }
  1688. }
  1689. static void checkOvpState(uint8_t gunIndex, uint8_t gunType)
  1690. {
  1691. switch(gunType) {
  1692. case _Type_Chademo:
  1693. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP == YES)
  1694. RecordAlarmCode(gunIndex, "012217");
  1695. break;
  1696. case _Type_CCS_2:
  1697. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP == YES)
  1698. RecordAlarmCode(gunIndex, "012219");
  1699. break;
  1700. case _Type_GB:
  1701. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP == YES)
  1702. RecordAlarmCode(gunIndex, "012221");
  1703. break;
  1704. }
  1705. }
  1706. //===============================================
  1707. // 確認各小板偵測的錯誤狀況
  1708. //===============================================
  1709. void CheckErrorOccurStatus(uint8_t index)
  1710. {
  1711. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1712. // RB
  1713. if (pSysConfig->PhaseLossPolicy == YES) {
  1714. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES ||
  1715. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES ||
  1716. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  1717. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  1718. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
  1719. StopChargingProcessByString(2);
  1720. InformOcppErrOccur(13);
  1721. }
  1722. //DS60-120 add -----
  1723. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1724. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES) {
  1725. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012203", 6);
  1726. } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES) {
  1727. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012204", 6);
  1728. } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  1729. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012205", 6);
  1730. }
  1731. }
  1732. //log_info("1 CheckErrorOccurStatus");
  1733. pDcChargingInfo->StopChargeFlag = YES;
  1734. //------------------------------------------------------------------
  1735. } else {
  1736. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  1737. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  1738. ReleaseChargingProcessByString(2);
  1739. InformOcppErrOccur(6);
  1740. }
  1741. }
  1742. } else {
  1743. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  1744. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  1745. ReleaseChargingProcessByString(2);
  1746. InformOcppErrOccur(6);
  1747. }
  1748. }
  1749. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
  1750. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
  1751. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  1752. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  1753. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
  1754. StopChargingProcessByString(2);
  1755. InformOcppErrOccur(14);
  1756. }
  1757. //DS60-120 -----
  1758. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1759. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES) {
  1760. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012200", 6);
  1761. } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES) {
  1762. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012201", 6);
  1763. } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  1764. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012202", 6);
  1765. }
  1766. }
  1767. //log_info("2 CheckErrorOccurStatus");
  1768. pDcChargingInfo->StopChargeFlag = YES;
  1769. //----------------------------------------------------------------------
  1770. } else {
  1771. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
  1772. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  1773. ReleaseChargingProcessByString(2);
  1774. InformOcppErrOccur(6);
  1775. }
  1776. }
  1777. checkOvpState(index, pDcChargingInfo->Type);
  1778. //--------------------------------------------------------------------------
  1779. if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == 0) {
  1780. //Primary
  1781. if (pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
  1782. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012251", 6);
  1783. } else if (pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
  1784. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012252", 6);
  1785. } else if (pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  1786. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012238", 6);
  1787. } else if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
  1788. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012304", 6);
  1789. }
  1790. //Chiller temperature
  1791. //else if (pAlarmCode->AlarmEvents.bits.SystemChillerOTP == YES) {
  1792. // memcpy(pDcChargingInfo->ConnectorAlarmCode, "012323", 6);
  1793. //} else if (pFaultCode->FaultEvents.bits.ChillerTempSensorBroken == YES) {
  1794. // memcpy(pDcChargingInfo->ConnectorAlarmCode, "011038", 6);
  1795. //}
  1796. }
  1797. }
  1798. //===============================================
  1799. // 確認 GPIO 狀態
  1800. //===============================================
  1801. void gpio_set_value(unsigned int gpio, unsigned int value)
  1802. {
  1803. int fd;
  1804. char buf[MAX_BUF];
  1805. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  1806. fd = open(buf, O_WRONLY);
  1807. if (fd < 0) {
  1808. perror("gpio/set-value");
  1809. return;
  1810. }
  1811. if (value) {
  1812. write(fd, "1", 2);
  1813. } else {
  1814. write(fd, "0", 2);
  1815. }
  1816. close(fd);
  1817. }
  1818. int gpio_get_value(unsigned int gpio, unsigned int *value)
  1819. {
  1820. int fd;
  1821. char buf[MAX_BUF];
  1822. char ch;
  1823. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  1824. fd = open(buf, O_RDONLY);
  1825. if (fd < 0) {
  1826. perror("gpio/get-value");
  1827. return fd;
  1828. }
  1829. read(fd, &ch, 1);
  1830. if (ch != '0') {
  1831. *value = 1;
  1832. } else {
  1833. *value = 0;
  1834. }
  1835. close(fd);
  1836. return 0;
  1837. }
  1838. void CheckGunTypeFromHw()
  1839. {
  1840. uint8_t i = 0;
  1841. int pinIn[4] = {22, 23, 44, 45};
  1842. unsigned int gpioValue = 0;
  1843. uint8_t tmp[2] = {0};
  1844. log_info("ModelName = %s", pSysConfig->ModelName);
  1845. for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
  1846. gpio_get_value(pinIn[i], &gpioValue);
  1847. switch (pinIn[i]) {
  1848. //right slot
  1849. case 22:
  1850. bd1_1_status = gpioValue;
  1851. break;
  1852. case 23:
  1853. bd1_2_status = gpioValue;
  1854. break;
  1855. //left slot
  1856. case 44:
  1857. bd0_1_status = gpioValue;
  1858. break;
  1859. case 45:
  1860. bd0_2_status = gpioValue;
  1861. break;
  1862. }
  1863. }
  1864. //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
  1865. //CcsChargingData [0至1] 分別為 Right至Left
  1866. //model name 槍順序左至右分別為Right至Left
  1867. tmp[1] = (bd0_1_status << 4 | bd0_2_status);
  1868. tmp[0] = (bd1_1_status << 4 | bd1_2_status);
  1869. for (i = 0; i < 2; i++) {
  1870. switch (tmp[i]) {
  1871. case 0x01:
  1872. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
  1873. break;
  1874. case 0x10:
  1875. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
  1876. break;
  1877. case 0x11:
  1878. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
  1879. break;
  1880. case 0x00:
  1881. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
  1882. break;
  1883. }
  1884. }
  1885. }
  1886. void CheckGpioInStatus()
  1887. {
  1888. int i = 0;
  1889. int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
  1890. unsigned int gpioValue = 0;
  1891. for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
  1892. gpio_get_value(pinIn[i], &gpioValue);
  1893. if (gpioValue == 0x01) {
  1894. switch (pinIn[i]) {
  1895. // 小板緊急停止
  1896. case 47:
  1897. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1898. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1899. if (pDcChargingInfo->slotsIndex == 1) {
  1900. if (pDcChargingInfo->Type == _Type_Chademo) {
  1901. BoardErrOccurByString(i, "023730");
  1902. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1903. BoardErrOccurByString(i, "013627");
  1904. }
  1905. break;
  1906. }
  1907. }
  1908. break;
  1909. case 27:
  1910. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1911. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1912. if (pDcChargingInfo->slotsIndex == 3) {
  1913. if (pDcChargingInfo->Type == _Type_Chademo) {
  1914. BoardErrOccurByString(i, "023730");
  1915. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1916. BoardErrOccurByString(i, "013627");
  1917. }
  1918. break;
  1919. }
  1920. }
  1921. break;
  1922. }
  1923. } else {
  1924. switch (pinIn[i]) {
  1925. // 小板解除緊急停止
  1926. case 47:
  1927. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1928. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1929. if (pDcChargingInfo->slotsIndex == 1) {
  1930. if (pDcChargingInfo->Type == _Type_Chademo) {
  1931. ReleaseBoardErrOccurByString(i, "023730");
  1932. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1933. ReleaseBoardErrOccurByString(i, "013627");
  1934. }
  1935. break;
  1936. }
  1937. }
  1938. break;
  1939. case 27:
  1940. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1941. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1942. if (pDcChargingInfo->slotsIndex == 3) {
  1943. if (pDcChargingInfo->Type == _Type_Chademo) {
  1944. ReleaseBoardErrOccurByString(i, "023730");
  1945. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1946. ReleaseBoardErrOccurByString(i, "013627");
  1947. }
  1948. break;
  1949. }
  1950. }
  1951. break;
  1952. }
  1953. }
  1954. }
  1955. }
  1956. //===============================================
  1957. // Main process
  1958. //===============================================
  1959. // 檢查 uint8_t 中某個 Bit 的值
  1960. // _byte : 欲改變的 byte
  1961. // _bit : 該 byte 的第幾個 bit
  1962. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit)
  1963. {
  1964. uint8_t mask_table[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
  1965. return ( _byte & mask_table[_bit] ) != 0x00;
  1966. }
  1967. // 設定 Byte 中某個 Bit的值
  1968. // _byte : 欲改變的 byte
  1969. // _bit : 該 byte 的第幾個 bit
  1970. // value : 修改的值為 0 or 1
  1971. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value)
  1972. {
  1973. if (value == 1) {
  1974. *_byte |= (1 << _bit);
  1975. } else if (value == 0) {
  1976. *_byte ^= (1 << _bit);
  1977. }
  1978. }
  1979. uint8_t isModeChange(uint8_t gunIndex)
  1980. {
  1981. uint8_t result = NO;
  1982. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1983. if (pDcChargingInfo->SystemStatus == pDcChargingInfo->PreviousSystemStatus) {
  1984. return result;
  1985. }
  1986. pDcChargingInfo->PreviousSystemStatus = pDcChargingInfo->SystemStatus;
  1987. ShmDcCommonData->SystemModeChange[gunIndex] = YES; //for Module_EvRxComm print temperature message
  1988. return YES;
  1989. }
  1990. static int checkSlotGpioMappingGunType(uint8_t gunIndex, uint8_t gunType)
  1991. {
  1992. uint8_t slot1 = 0, slot2 = 0;
  1993. if (gunIndex == 0) {
  1994. slot1 = bd0_1_status;
  1995. slot2 = bd0_2_status;
  1996. } else if (gunIndex == 1) {
  1997. slot1 = bd1_1_status;
  1998. slot2 = bd1_2_status;
  1999. }
  2000. log_info("slot %d gpio1 = %d, gpio2 = %d, type = %d",
  2001. gunIndex,
  2002. slot1,
  2003. slot2,
  2004. gunType);
  2005. switch (gunType) {
  2006. case _Type_Chademo:
  2007. if (slot1 != NO && slot2 != YES) {
  2008. return FAIL;
  2009. }
  2010. break;
  2011. case _Type_CCS_2:
  2012. if (slot1 != YES && slot2 != NO) {
  2013. return FAIL;
  2014. }
  2015. break;
  2016. case _Type_GB:
  2017. if (slot1 != YES && slot2 != YES) {
  2018. return FAIL;
  2019. }
  2020. break;
  2021. }
  2022. return PASS;
  2023. }
  2024. bool CheckConnectorTypeStatus(void)
  2025. {
  2026. bool result = true;
  2027. uint8_t gunIndex = 0;
  2028. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  2029. struct ChargingInfoData *pDcChargingInfo = NULL;
  2030. if (!MappingGunChargingInfo("CSU Task")) {
  2031. log_error("CheckConnectorTypeStatus MappingGunChargingInfo failed");
  2032. return false;
  2033. }
  2034. // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
  2035. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  2036. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2037. if (checkSlotGpioMappingGunType(gunIndex, pDcChargingInfo->Type) == FAIL) {
  2038. return false;
  2039. }
  2040. pDcChargingInfo->SystemStatus = S_BOOTING;
  2041. switch (gunIndex) {
  2042. case 0:
  2043. if (pSysConfig->TotalConnectorCount == 1) {
  2044. if ((bd0_1_status == YES || bd0_2_status == YES) &&
  2045. (bd1_1_status == NO && bd1_2_status == NO)) {
  2046. pDcChargingInfo->Evboard_id = 0x01;
  2047. }
  2048. if ((bd0_1_status == NO && bd0_2_status == NO) &&
  2049. (bd1_1_status == YES || bd1_2_status == YES)
  2050. ) {
  2051. pDcChargingInfo->Evboard_id = 0x02;
  2052. }
  2053. break;
  2054. }
  2055. pDcChargingInfo->Evboard_id = 0x01;
  2056. break;
  2057. case 1:
  2058. pDcChargingInfo->Evboard_id = 0x02;
  2059. break;
  2060. }
  2061. CheckHwSlotStatusLog(gunIndex);
  2062. if (pDcChargingInfo->Evboard_id == 0x00) {
  2063. return false;
  2064. }
  2065. }
  2066. AdjustChargerCurrent();
  2067. return result;
  2068. }
  2069. int SpawnTask(void)
  2070. {
  2071. if(SIMULATION)
  2072. system("/root/simulation &");
  2073. sleep(2);
  2074. system("/root/Module_EventLogging &");
  2075. system("/root/Module_PrimaryComm &");
  2076. system("/root/Module_EvComm &");
  2077. system("/root/Module_LcmControl &");
  2078. system("/root/Module_InternalComm &");
  2079. system("/root/Module_ProduceUtils &");
  2080. system("/root/Module_UpdateFW &");
  2081. system("/root/Module_DoComm &");
  2082. return PASS;
  2083. }
  2084. void KillTask(void)
  2085. {
  2086. //ChangeLcmByIndex(_LCM_ERROR);
  2087. ChangeLcmByIndex(_LCM_MAINTAIN);
  2088. system("killall Module_EventLogging");
  2089. system("killall Module_PrimaryComm");
  2090. system("killall Module_EvComm");
  2091. system("killall Module_LcmControl");
  2092. system("killall Module_InternalComm");
  2093. system("killall Module_UpdateFW");
  2094. system("killall Module_ChkSysTask");
  2095. //system("killall Module_DoComm");
  2096. return ;
  2097. }
  2098. void KillTaskExceptPrimary(void)
  2099. {
  2100. //ChangeLcmByIndex(_LCM_ERROR);
  2101. ChangeLcmByIndex(_LCM_MAINTAIN);
  2102. system("killall Module_EvComm");
  2103. system("killall Module_InternalComm");
  2104. return;
  2105. }
  2106. void KillAllTask(void)
  2107. {
  2108. //ChangeLcmByIndex(_LCM_ERROR);
  2109. ChangeLcmByIndex(_LCM_MAINTAIN);
  2110. system("killall Module_EventLogging");
  2111. system("killall Module_PrimaryComm");
  2112. system("killall Module_EvComm");
  2113. system("killall Module_LcmControl");
  2114. system("killall Module_InternalComm");
  2115. system("killall Module_UpdateFW");
  2116. system("killall Module_ChkSysTask");
  2117. system("killall Module_DoComm");
  2118. return ;
  2119. }
  2120. void StartSystemTimeoutDet(uint8_t flag)
  2121. {
  2122. if (pSysInfo->SystemTimeoutFlag != flag) {
  2123. //log_info("Set System Timeout Flag %d", flag);
  2124. GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
  2125. }
  2126. pSysInfo->SystemTimeoutFlag = flag;
  2127. }
  2128. void StopSystemTimeoutDet(void)
  2129. {
  2130. GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
  2131. pSysInfo->SystemTimeoutFlag = Timeout_None;
  2132. }
  2133. void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
  2134. {
  2135. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2136. if (gunIndex < pSysConfig->TotalConnectorCount) {
  2137. if (pDcChargingInfo->TimeoutFlag != flag) {
  2138. GetClockTime(&pDcChargingInfo->ConnectorTimeout, NULL);
  2139. //log_info("Set Gun%d Timeout Flag %d", gunIndex,flag);
  2140. }
  2141. pDcChargingInfo->TimeoutFlag = flag;
  2142. }
  2143. }
  2144. void StopGunInfoTimeoutDet(uint8_t gunIndex)
  2145. {
  2146. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2147. if (gunIndex < pSysConfig->TotalConnectorCount) {
  2148. pDcChargingInfo->TimeoutFlag = Timeout_None;
  2149. }
  2150. }
  2151. void CheckConnectionTimeout(void)
  2152. {
  2153. if (ShmSelectGunInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
  2154. _connectionTimeout = ShmSelectGunInfo->RemoteSetup.ConnectionTimeout;
  2155. } else {
  2156. _connectionTimeout = CONN_PLUG_TIMEOUT;
  2157. }
  2158. return;
  2159. }
  2160. void _evccidlinktimeout(uint8_t gunIndex)
  2161. {
  2162. log_info("Getting EVCCID Timeout");
  2163. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2164. pDcChargingInfo->isEVCCIDVerify = true;
  2165. StopGunInfoTimeoutDet(gunIndex);
  2166. destroySelGun(pSysInfo->CurGunSelected);
  2167. systemPageRestoreInit();
  2168. }
  2169. void CreateTimeoutFork(void)
  2170. {
  2171. pid_t timeoutPid;
  2172. timeoutPid = fork();
  2173. if (timeoutPid == 0) {
  2174. GetClockTime(&_cmdSubPriority_time, NULL);
  2175. CheckConnectionTimeout();
  2176. //log_info("Timeout Fork Child's PID is %d", getpid());
  2177. while (1) {
  2178. if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
  2179. CheckConnectionTimeout();
  2180. GetClockTime(&_cmdSubPriority_time, NULL);
  2181. }
  2182. //if (pSysInfo->SystemTimeoutFlag != 0)
  2183. //log_info("Timeout ***********SystemTimeoutFlag = %d(%d) ********",pSysInfo->SystemTimeoutFlag,
  2184. // GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL);
  2185. // 系統
  2186. switch (pSysInfo->SystemTimeoutFlag) {
  2187. case Timeout_SelftestChk:
  2188. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
  2189. _SelfTestTimeout();
  2190. StopSystemTimeoutDet();
  2191. destroySelGun(DESTROY_ALL_SEL); //jerry add
  2192. }
  2193. break;
  2194. case Timeout_ReturnViewPage:
  2195. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_VIEWPAGE_TIMEOUT) {
  2196. log_error("Timeout_ReturnViewPage");
  2197. StopSystemTimeoutDet();
  2198. pSysInfo->SystemPage = _LCM_VIEW;
  2199. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  2200. if (pDcChargingInfo->SystemStatus == S_AUTHORIZING || pDcChargingInfo->SystemStatus == S_COMPLETE ||
  2201. pDcChargingInfo->SystemStatus == S_ALARM) {
  2202. setChargerMode(pSysInfo->CurGunSelected, MODE_IDLE);
  2203. }
  2204. }
  2205. break;
  2206. case Timeout_Authorizing:
  2207. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
  2208. log_error("Authorizing Timeout");
  2209. _AuthorizedTimeout();
  2210. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2211. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2212. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2213. log_error("Author timeout restart DoComm");
  2214. system("killall Module_DoComm");
  2215. }
  2216. }
  2217. break;
  2218. case Timeout_WaitBalance:
  2219. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= BALANCE_TIMEOUT) {
  2220. log_error("Wait Balance timeout");
  2221. _AuthorizedTimeout();
  2222. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2223. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2224. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2225. log_error("Author timeout restart DoComm");
  2226. system("killall Module_DoComm");
  2227. }
  2228. }
  2229. break;
  2230. case Timeout_VerifyFail:
  2231. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
  2232. if (pSysInfo->SystemPage ==_LCM_START_AUTHORIZE_FAIL ) {
  2233. log_error("Timeout_VerifyFail authorize fail");
  2234. StopSystemTimeoutDet();
  2235. _AutoReturnTimeout();
  2236. //destroySelGun(pSysInfo->CurGunSelected);
  2237. /*
  2238. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2239. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2240. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2241. log_error("Author timeout restart DoComm");
  2242. system("killall Module_DoComm");
  2243. //sleep(1);
  2244. //system("/root/Module_DoComm &");
  2245. }*/
  2246. } /*else if (pSysInfo->SystemPage == _LCM_STOP_RFID_FAIL) {
  2247. log_error("Timeout_VerifyFail stop RFID fail");
  2248. StopSystemTimeoutDet();
  2249. pSysInfo->SystemPage = _LCM_VIEW;
  2250. }*/
  2251. }
  2252. break;
  2253. /*
  2254. case Timeout_ReturnToChargingGunDet:
  2255. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
  2256. if (getCurLcmPage() != _LCM_VIEW &&
  2257. getCurLcmPage() != _LCM_DETAIL_VIEW ) {
  2258. destroySelGun(pSysInfo->CurGunSelected); //jerry add
  2259. }
  2260. DisplayChargingInfo();
  2261. StopSystemTimeoutDet();
  2262. }
  2263. break;
  2264. */
  2265. case Timeout_AuthorizingForStop:
  2266. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
  2267. strcpy((char *)pSysConfig->UserId, "");
  2268. ClearAuthorizedFlag();
  2269. StopSystemTimeoutDet();
  2270. }
  2271. break;
  2272. case Timeout_LinkError:
  2273. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= LINKERROR_TIMEOUT) {
  2274. StopSystemTimeoutDet();
  2275. _LinkErrorTimeout(pSysInfo->CurGunSelected);
  2276. destroySelGun(pSysInfo->CurGunSelected);
  2277. }
  2278. break;
  2279. }
  2280. // 各槍
  2281. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  2282. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2283. /*
  2284. if (pDcChargingInfo->TimeoutFlag != 0)
  2285. log_info("Timeout ***********GunTimeoutFlag = %d(%d) ********",pDcChargingInfo->TimeoutFlag,
  2286. GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL);
  2287. */
  2288. switch (pDcChargingInfo->TimeoutFlag) {
  2289. case Timeout_EVCCID_Link:
  2290. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= EVCCID_LINK_TIMEOUT) {
  2291. _evccidlinktimeout(gunIndex);
  2292. }
  2293. break;
  2294. case Timeout_Preparing:
  2295. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
  2296. _PrepareTimeout(gunIndex);
  2297. StopGunInfoTimeoutDet(gunIndex);
  2298. destroySelGun(gunIndex); //jerry add
  2299. }
  2300. break;
  2301. case Timeout_EvChargingDet:
  2302. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
  2303. _DetectEvChargingEnableTimeout(gunIndex);
  2304. StopGunInfoTimeoutDet(gunIndex);
  2305. destroySelGun(gunIndex); //jerry add
  2306. }
  2307. break;
  2308. case Timeout_EvseChargingDet:
  2309. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
  2310. _DetectEvseChargingEnableTimeout(gunIndex);
  2311. StopGunInfoTimeoutDet(gunIndex);
  2312. destroySelGun(gunIndex); //jerry add
  2313. }
  2314. break;
  2315. case Timeout_EvseCompleteDet:
  2316. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
  2317. StopGunInfoTimeoutDet(gunIndex);
  2318. destroySelGun(gunIndex); //jerry add
  2319. }
  2320. break;
  2321. case Timeout_ForCcsPrechargeDet:
  2322. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
  2323. _CcsPrechargeTimeout(gunIndex);
  2324. StopGunInfoTimeoutDet(gunIndex);
  2325. destroySelGun(gunIndex); //jerry add
  2326. }
  2327. break;
  2328. /*
  2329. case Timeout_SelectGun: //Jerry add
  2330. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
  2331. log_info("Timeout_SelectGun");
  2332. StopGunInfoTimeoutDet(gunIndex);
  2333. destroySelGun(gunIndex); //jerry add
  2334. }
  2335. break;
  2336. */
  2337. case Timeout_PlugOut:
  2338. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= PLUGOUT_TIMEOUT) {
  2339. StopGunInfoTimeoutDet(gunIndex);
  2340. destroySelGun(gunIndex); //jerry add
  2341. setChargerMode(gunIndex, S_IDLE);
  2342. }
  2343. break;
  2344. case Timeout_GunAuthorizePage:
  2345. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_AUTHORIZE_PAGE) {
  2346. StopGunInfoTimeoutDet(gunIndex);
  2347. destroySelGun(gunIndex); //jerry add
  2348. pDcChargingInfo->SystemStatus = S_IDLE;
  2349. }
  2350. break;
  2351. case Timeout_Terminating:
  2352. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= TERMINATING_TIMEOUT) {
  2353. StopGunInfoTimeoutDet(gunIndex);
  2354. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  2355. ShmDcCommonData->pGunInfo[gunIndex].finalcost_flag = TRUE;
  2356. setChargerMode(gunIndex, S_COMPLETE);
  2357. }
  2358. break;
  2359. case Timeout_WaitPlug:
  2360. if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= _connectionTimeout) {
  2361. StopGunInfoTimeoutDet(gunIndex);
  2362. _DetectPlugInTimeout(gunIndex);
  2363. destroySelGun(gunIndex);
  2364. }
  2365. break;
  2366. }
  2367. }
  2368. sleep(1);
  2369. }
  2370. }
  2371. }
  2372. void CheckFactoryConfigFunction(void)
  2373. {
  2374. char Buf[256] = {0};
  2375. if (pSysInfo->FactoryConfiguration) {
  2376. sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
  2377. pSysConfig->ModelName,
  2378. pSysConfig->SerialNumber);
  2379. system(Buf);
  2380. system("rm -f /Storage/OCPP/OCPPConfiguration");
  2381. system("sync");
  2382. sleep(5);
  2383. system("reboot -f");
  2384. sleep(5);
  2385. system("reboot -f");
  2386. }
  2387. }
  2388. //===============================================
  2389. // Check reservation date is expired
  2390. //===============================================
  2391. int isReservationExpired(uint8_t gunIndex)
  2392. {
  2393. int result = NO;
  2394. struct tm expiredDate;
  2395. struct timeb expiredTime;
  2396. if (sscanf((char *) ShmOCPP16Data->ReserveNow[gunIndex].ExpiryDate,
  2397. "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
  2398. &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
  2399. &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
  2400. expiredDate.tm_year -= 1900;
  2401. expiredDate.tm_mon -= 1;
  2402. expiredTime.time = mktime(&expiredDate);
  2403. if (!CheckTimeOut(expiredTime)) {
  2404. result = YES;
  2405. }
  2406. }
  2407. log_info("Reservation result:%s", result == NO ? "cancel" : "confirm");
  2408. return result;
  2409. }
  2410. //===============================================
  2411. // OCPP
  2412. //===============================================
  2413. void CheckOcppStatus(void)
  2414. {
  2415. bool canReset = true;
  2416. //bool canHardReset = true; //DS60-120 add
  2417. if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
  2418. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
  2419. }
  2420. if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
  2421. if (pSysWarning->Level != WARN_LV_ER) {
  2422. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  2423. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  2424. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  2425. pDcChargingInfo->SystemStatus != S_RESERVATION &&
  2426. pDcChargingInfo->SystemStatus != S_MAINTAIN) {
  2427. canReset = false;
  2428. if (pDcChargingInfo->SystemStatus >= S_REASSIGN &&
  2429. pDcChargingInfo->SystemStatus < S_TERMINATING) {
  2430. //canHardReset = false;
  2431. ChargingTerminalProcess(_index);
  2432. //restartFlag = 1;
  2433. }
  2434. }
  2435. }
  2436. }
  2437. if (canReset) {
  2438. ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
  2439. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
  2440. if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
  2441. log_error("****** Hard Reboot ****** ");
  2442. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  2443. sleep(3);
  2444. system("reboot -f");
  2445. } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
  2446. log_error("****** Soft Reboot ****** ");
  2447. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  2448. sleep(3);
  2449. system("killall OcppBackend &");
  2450. KillAllTask();
  2451. TryCloseWatchdog();
  2452. system("/usr/bin/run_evse_restart.sh");
  2453. }
  2454. }
  2455. }
  2456. }
  2457. void OcppStopTransation(uint8_t gunIndex)
  2458. {
  2459. uint8_t _OcppGunIndex = gunIndex;
  2460. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2461. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  2462. if (pSysConfig->AcConnectorCount == 1 && gunIndex == 1) {
  2463. _OcppGunIndex = 2;
  2464. }
  2465. if (strcmp((char *)pDcChargingInfo->StartUserId, "") == EQUAL) {
  2466. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  2467. } else {
  2468. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)pDcChargingInfo->StartUserId);
  2469. }
  2470. log_info("IdTag = %s ", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  2471. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
  2472. }
  2473. bool OcppRemoteStop(uint8_t gunIndex)
  2474. {
  2475. uint8_t acDirIndex = pSysConfig->AcConnectorCount;
  2476. // 有 AC 槍的話
  2477. if (acDirIndex > 0 && gunIndex > 0) {
  2478. gunIndex += acDirIndex;
  2479. }
  2480. bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
  2481. if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
  2482. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
  2483. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
  2484. }
  2485. return result;
  2486. }
  2487. bool WifiScheduleStop(uint8_t gunIndex)
  2488. {
  2489. bool result = false;
  2490. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2491. result = pDcChargingInfo->schedule.isTriggerStop;
  2492. pDcChargingInfo->schedule.isTriggerStop = NO;
  2493. return result;
  2494. }
  2495. void OcppRemoteStartChk()
  2496. {
  2497. if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
  2498. } else {
  2499. // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
  2500. uint8_t acDirIndex = pSysConfig->AcConnectorCount;
  2501. if (!isDetectPlugin(acDirIndex)) {
  2502. for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
  2503. pAcChargingInfo = (struct ChargingInfoData*)GetAcChargingInfoData(ac_index);
  2504. if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
  2505. if (pAcChargingInfo->SystemStatus == S_IDLE ||
  2506. pAcChargingInfo->SystemStatus == S_RESERVATION) {
  2507. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  2508. pAcChargingInfo->RemoteStartFlag = YES;
  2509. pSysInfo->OrderCharging = YES;
  2510. //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
  2511. ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
  2512. DetectPluginStart(acDirIndex);
  2513. return;
  2514. }
  2515. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  2516. }
  2517. }
  2518. }
  2519. //uint8_t threeGunIndex = 0;
  2520. //uint8_t dcIndex = 0;
  2521. //bool isGunUsingStatus = false;
  2522. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  2523. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
  2524. /*
  2525. // 如果有 AC 槍,且 DC 槍也有兩把
  2526. if (acDirIndex == 1 && _index == 1) {
  2527. threeGunIndex = 1;
  2528. }
  2529. if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES) {
  2530. dcIndex = _index;
  2531. }
  2532. if (pDcChargingInfo->SystemStatus != S_IDLE) {
  2533. isGunUsingStatus = true;
  2534. }
  2535. if (pDcChargingInfo->RemoteStartFlag == YES) {
  2536. //_remotestarting = true;
  2537. }
  2538. }
  2539. // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
  2540. if (isGunUsingStatus && pSysInfo->IsAlternatvieConf) {
  2541. if (dcIndex == 0) {
  2542. threeGunIndex = 0;
  2543. }
  2544. ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
  2545. return;
  2546. }
  2547. if (dcIndex == 0) {
  2548. threeGunIndex = 0;
  2549. }
  2550. */
  2551. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
  2552. if (ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq == YES &&
  2553. !isDetectPlugin(_index)) {
  2554. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2555. pDcChargingInfo->SystemStatus == MODE_AUTHORIZING ||
  2556. pDcChargingInfo->SystemStatus == S_RESERVATION) {
  2557. pDcChargingInfo->RemoteStartFlag = YES;
  2558. //ShmDcCommonData->is_RemoteStart[_index] = TRUE;
  2559. //pSysInfo->OrderCharging = YES;
  2560. //pDcChargingInfo->SystemStatus = S_AUTHORIZING;
  2561. //pSysInfo->OrderCharging = gunIndex;
  2562. ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
  2563. DetectPluginStart(_index);
  2564. setSelGunWaitToAuthor(_index);
  2565. log_info("Ocpp Remote Start Gun%d Pass", _index);
  2566. }
  2567. ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
  2568. }
  2569. }
  2570. }
  2571. }
  2572. void ChkOcppStatus(uint8_t gunIndex)
  2573. {
  2574. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2575. if (pDcChargingInfo->SystemStatus == S_IDLE &&
  2576. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
  2577. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
  2578. if (isReservationExpired(gunIndex)) {
  2579. log_error("***************ChkOcppStatus : OcppReservedStatus******************** ");
  2580. pDcChargingInfo->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
  2581. pDcChargingInfo->SystemStatus = S_RESERVATION;
  2582. }
  2583. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  2584. }
  2585. if (pDcChargingInfo->SystemStatus == S_RESERVATION &&
  2586. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
  2587. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
  2588. if (isReservationExpired(gunIndex)) {
  2589. log_error("***************ChkOcppStatus : Cancel OcppReservedStatus******************** ");
  2590. pDcChargingInfo->ReservationId = 0;
  2591. pDcChargingInfo->SystemStatus = S_IDLE;
  2592. }
  2593. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
  2594. }
  2595. if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
  2596. log_error("***************ChkOcppStatus : OcppChangeAvailability******************** ");
  2597. ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
  2598. if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
  2599. if (isDb_ready) {
  2600. DB_Update_Operactive(gunIndex, true);
  2601. }
  2602. pDcChargingInfo->IsAvailable = YES;
  2603. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2604. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2605. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  2606. setChargerMode(gunIndex, MODE_IDLE);
  2607. }
  2608. } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
  2609. if (isDb_ready) {
  2610. DB_Update_Operactive(gunIndex, false);
  2611. }
  2612. pDcChargingInfo->IsAvailable = NO;
  2613. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2614. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2615. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  2616. setChargerMode(gunIndex, MODE_MAINTAIN);
  2617. }
  2618. }
  2619. }
  2620. if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
  2621. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
  2622. if (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
  2623. pDcChargingInfo->SystemStatus <= S_CHARGING) {
  2624. // 充電中,需停止充電
  2625. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
  2626. ChargingTerminalProcess(gunIndex);
  2627. }
  2628. strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
  2629. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
  2630. }
  2631. }
  2632. bool CheckBackendChargingTimeout(uint8_t gunIndex)
  2633. {
  2634. bool result = false;
  2635. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2636. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  2637. if (pSysConfig->MaxChargingDuration > 0) {
  2638. if (pDcChargingInfo->PresentChargedDuration > (pSysConfig->MaxChargingDuration * 60)) {
  2639. result = true;
  2640. }
  2641. }
  2642. }
  2643. return result;
  2644. }
  2645. bool CheckBackendChargingEnergy(uint8_t gunIndex)
  2646. {
  2647. bool result = false;
  2648. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2649. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  2650. if (pSysConfig->MaxChargingEnergy > 0) {
  2651. if (pDcChargingInfo->PresentChargedEnergy > pSysConfig->MaxChargingEnergy) {
  2652. result = true;
  2653. }
  2654. }
  2655. }
  2656. return result;
  2657. }
  2658. void InformOcppErrOccur(uint8_t codeType)
  2659. {
  2660. char _error[25];
  2661. switch (codeType) {
  2662. case 4:
  2663. strcpy(_error, "InternalError");
  2664. break;
  2665. case 6:
  2666. strcpy(_error, "NoError");
  2667. break;
  2668. case 7:
  2669. strcpy(_error, "OtherError");
  2670. break;
  2671. case 13:
  2672. strcpy(_error, "UnderVoltage");
  2673. break;
  2674. case 14:
  2675. strcpy(_error, "OverVoltage");
  2676. break;
  2677. }
  2678. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  2679. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, _error);
  2680. }
  2681. }
  2682. //===============================================
  2683. // Config process
  2684. //===============================================
  2685. /*
  2686. void AddPlugInTimes(uint8_t gunIndex)
  2687. {
  2688. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2689. if (pDcChargingInfo->Type == _Type_Chademo) {
  2690. pSysConfig->ChademoPlugInTimes += 1;
  2691. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2692. pSysConfig->Ccs2PlugInTimes += 1;
  2693. } else if (pDcChargingInfo->Type == _Type_GB) {
  2694. pSysConfig->GbPlugInTimes += 1;
  2695. }
  2696. }*/
  2697. void ChangeStartOrStopDateTime(uint8_t isStart, uint8_t gunIndex)
  2698. {
  2699. char cmdBuf[32];
  2700. struct timeb csuTime;
  2701. struct tm *tmCSU;
  2702. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2703. ftime(&csuTime);
  2704. tmCSU = localtime(&csuTime.time);
  2705. sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
  2706. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  2707. tmCSU->tm_sec);
  2708. if (isStart) {
  2709. strcpy((char *)pDcChargingInfo->StartDateTime, cmdBuf);
  2710. } else {
  2711. strcpy((char *)pDcChargingInfo->StopDateTime, cmdBuf);
  2712. }
  2713. }
  2714. void GetChargeTranscationDateTime(uint8_t gunIndex)
  2715. {
  2716. struct timeb csuTime;
  2717. struct tm* tmCSU;
  2718. ftime(&csuTime);
  2719. tmCSU = localtime(&csuTime.time);
  2720. sprintf(ShmDcCommonData->pGunInfo[gunIndex].ChargeDuration, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
  2721. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  2722. tmCSU->tm_sec);
  2723. }
  2724. void ChangeGunSelectByIndex(uint8_t sel)
  2725. {
  2726. pSysInfo->CurGunSelected = sel;
  2727. pSysInfo->CurGunSelectedByAc = NO_DEFINE;
  2728. }
  2729. void CheckIsAlternatvieByModelName()
  2730. {
  2731. if (pSysConfig->ModelName[1] == 'W') { //DS60-120
  2732. // 壁掛
  2733. pSysInfo->IsAlternatvieConf = YES;
  2734. } else {
  2735. pSysInfo->IsAlternatvieConf = NO;
  2736. }
  2737. }
  2738. void StopProcessingLoop()
  2739. {
  2740. for (;;) {
  2741. CheckFactoryConfigFunction();
  2742. //CheckFwUpdateFunction();
  2743. if (pSysWarning->Level == WARN_LV_ER) {
  2744. ChkPrimaryStatus();
  2745. if (pSysWarning->Level == WARN_LV_NL) {
  2746. log_info("Soft reboot for retry self-tets (Primary). ");
  2747. KillAllTask();
  2748. sleep(3);
  2749. TryCloseWatchdog();
  2750. system("/usr/bin/run_evse_restart.sh");
  2751. return;
  2752. }
  2753. }
  2754. sleep(1);
  2755. TryFeedWatchdog();
  2756. }
  2757. }
  2758. bool IsConnectorWholeIdle()
  2759. {
  2760. bool result = true;
  2761. for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  2762. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  2763. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  2764. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  2765. result = false;
  2766. break;
  2767. }
  2768. }
  2769. for (uint8_t count = 0; count < pSysConfig->AcConnectorCount; count++) {
  2770. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
  2771. if (pAcChargingInfo->SystemStatus != S_IDLE &&
  2772. pAcChargingInfo->IsErrorOccur == NO) {
  2773. result = false;
  2774. break;
  2775. }
  2776. }
  2777. return result;
  2778. }
  2779. void ClearAlarmCodeWhenAcOff()
  2780. {
  2781. if (!pSysInfo->AcContactorStatus) {
  2782. pAlarmCode->AlarmEvents.bits.PsuNoResource = NO;
  2783. }
  2784. }
  2785. //==========================================
  2786. // Check Smart Charging Profile
  2787. //==========================================
  2788. int GetStartScheduleTime(uint8_t *time)
  2789. {
  2790. int result = -1;
  2791. struct tm tmScheduleStart;
  2792. struct timeb tbScheduleStart;
  2793. if ((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6)) {
  2794. tmScheduleStart.tm_year -= 1900;
  2795. tmScheduleStart.tm_mon -= 1;
  2796. tbScheduleStart.time = mktime(&tmScheduleStart);
  2797. tbScheduleStart.millitm = 0;
  2798. result = DiffTimebWithNow(tbScheduleStart) / 1000;
  2799. }
  2800. return result;
  2801. }
  2802. void CheckSmartChargeProfile(uint8_t _index)
  2803. {
  2804. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  2805. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  2806. // Get Charging Profile
  2807. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  2808. if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
  2809. ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
  2810. ) {
  2811. int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  2812. uint8_t _startCount = NO_DEFINE;
  2813. uint8_t _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
  2814. for (uint8_t _count = 0; _count < _maxCount; _count++) {
  2815. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  2816. if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
  2817. if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
  2818. ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
  2819. _startCount = _count;
  2820. }
  2821. }
  2822. }
  2823. log_info("_startCount = %d ", _startCount);
  2824. if (_startCount < _maxCount) {
  2825. //DS60-120 add
  2826. log_info("Profile Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  2827. pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
  2828. if (pDcChargingInfo->EvBatterytargetVoltage > 0 && pDcChargingInfo->PresentChargingVoltage > 0) {
  2829. pDcChargingInfo->ChargingProfileCurrent = (pDcChargingInfo->ChargingProfilePower / pDcChargingInfo->PresentChargingVoltage) * 10;
  2830. } else {
  2831. pDcChargingInfo->ChargingProfileCurrent = 0;
  2832. }
  2833. } else {
  2834. pDcChargingInfo->ChargingProfilePower = -1;
  2835. pDcChargingInfo->ChargingProfileCurrent = -1;
  2836. }
  2837. } else {
  2838. pDcChargingInfo->ChargingProfilePower = -1;
  2839. pDcChargingInfo->ChargingProfileCurrent = -1;
  2840. }
  2841. log_info("ChargingProfilePower = %f ", pDcChargingInfo->ChargingProfilePower);
  2842. log_info("ChargingProfileCurrent = %f ", pDcChargingInfo->ChargingProfileCurrent);
  2843. }
  2844. }
  2845. void ChargingProfileFlat(uint8_t _index)
  2846. {
  2847. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
  2848. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
  2849. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
  2850. }
  2851. }
  2852. }
  2853. /*
  2854. void CheckReturnToChargingConn()
  2855. {
  2856. if ((pSysConfig->TotalConnectorCount + pSysConfig->AcConnectorCount) > 1 &&
  2857. pSysInfo->PageIndex != _LCM_START_AUTHORIZING &&
  2858. pSysInfo->PageIndex != _LCM_START_AUTHORIZE_FAIL &&
  2859. pSysInfo->PageIndex != _LCM_WAIT_PLUGIN) {
  2860. bool isReturnTimeout = false;
  2861. for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  2862. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  2863. // 如果選的 DC 槍在充電~ 則 DC 槍不改變
  2864. if (count == pSysInfo->CurGunSelected) {
  2865. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  2866. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  2867. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  2868. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  2869. ) {
  2870. isReturnTimeout = false;
  2871. break;
  2872. }
  2873. } else if (count != pSysInfo->CurGunSelected) {
  2874. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  2875. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  2876. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  2877. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  2878. ) {
  2879. isReturnTimeout = true;
  2880. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  2881. }
  2882. }
  2883. }
  2884. // AC 槍
  2885. if (!isReturnTimeout && pSysConfig->AcConnectorCount > 0) {
  2886. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  2887. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  2888. // 沒有選中 AC,且 AC 在充電中
  2889. if (pSysInfo->CurGunSelectedByAc == NO_DEFINE &&
  2890. (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
  2891. pAcChargingInfo->SystemStatus <= S_COMPLETE)) {
  2892. // 當前 DC 充電槍在 idle 狀態
  2893. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2894. pDcChargingInfo->SystemStatus == S_RESERVATION) {
  2895. isReturnTimeout = true;
  2896. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  2897. }
  2898. } else if (pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
  2899. ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  2900. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  2901. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  2902. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))) {
  2903. // 當前 DC 充電槍在 idle 狀態
  2904. if (pAcChargingInfo->SystemStatus == S_IDLE ||
  2905. pAcChargingInfo->SystemStatus == S_RESERVATION) {
  2906. isReturnTimeout = true;
  2907. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  2908. }
  2909. }
  2910. }
  2911. if (!isReturnTimeout) {
  2912. StopSystemTimeoutDet();
  2913. }
  2914. }
  2915. }
  2916. bool GetStartChargingByAlterMode(uint8_t _gun)
  2917. {
  2918. bool result = true;
  2919. if (pSysConfig->TotalConnectorCount == 2 &&
  2920. pSysInfo->IsAlternatvieConf == YES) {
  2921. for (uint8_t _select = 0; _select < pSysConfig->TotalConnectorCount; _select++) {
  2922. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_select);
  2923. if (_select != _gun) {
  2924. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  2925. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  2926. result = false;
  2927. break;
  2928. }
  2929. }
  2930. }
  2931. }
  2932. return result;
  2933. }
  2934. */
  2935. void TheEndCharging(uint8_t gunIndex)
  2936. {
  2937. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2938. ftime(&endChargingTime[gunIndex]);
  2939. if (pDcChargingInfo->PresentChargedDuration != 0) {
  2940. pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
  2941. }
  2942. pDcChargingInfo->isRemoteStart = NO;
  2943. StopGunInfoTimeoutDet(gunIndex);
  2944. //StartGunInfoTimeoutDet(gunIndex, Timeout_EvseCompleteDet);
  2945. ChangeStartOrStopDateTime(NO, gunIndex);
  2946. DB_Insert_Record(gunIndex);
  2947. }
  2948. void UpdateErrorCodeToOcpp(uint8_t index)
  2949. {
  2950. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  2951. //log_info("%d = ConnectorAlarmCode = %s", index, pDcChargingInfo->ConnectorAlarmCode);
  2952. //log_info("%d = EvConnAlarmCode = %s", index, pDcChargingInfo->EvConnAlarmCode);
  2953. if (strcmp((char *)pDcChargingInfo->ConnectorAlarmCode, "") != EQUAL) {
  2954. //if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == EQUAL) {
  2955. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
  2956. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->ConnectorAlarmCode);
  2957. } else if (strcmp((char *)pDcChargingInfo->EvConnAlarmCode, "") != EQUAL) {
  2958. //} else if (strlen((char *)pDcChargingInfo->EvConnAlarmCode) == EQUAL) {
  2959. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
  2960. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->EvConnAlarmCode);
  2961. }
  2962. //log_info("Gun %d = VendorErrorCode = %s", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
  2963. }
  2964. void AdjustChargerCurrent()
  2965. {
  2966. pSysConfig->RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
  2967. // 設定的電流~ 如超過可輸出的電流,則 bypass
  2968. if (pSysConfig->RatingCurrent < pSysConfig->MaxChargingCurrent ||
  2969. pSysConfig->RatingCurrent == 0) {
  2970. pSysConfig->MaxChargingCurrent = 0;
  2971. }
  2972. log_info("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
  2973. ShmPsuData->SystemAvailablePower / 10,
  2974. ShmPsuData->SystemAvailableCurrent / 10
  2975. );
  2976. log_info("Config : ChargingPower = %d, ChargingCurrent = %d",
  2977. pSysConfig->MaxChargingPower,
  2978. pSysConfig->MaxChargingCurrent
  2979. );
  2980. }
  2981. void ResetDetAlarmStatus(uint8_t gun)
  2982. {
  2983. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  2984. if (pDcChargingInfo->Type == _Type_Chademo) {
  2985. if (pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  2986. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  2987. }
  2988. } else if (pDcChargingInfo->Type == _Type_GB) {
  2989. if (pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP == YES) {
  2990. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  2991. }
  2992. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2993. if (pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  2994. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  2995. }
  2996. }
  2997. }
  2998. static void autoStartCharging(uint8_t gunIndex)
  2999. {
  3000. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3001. if ( (pSysInfo->SystemPage >= _LCM_START_AUTHORIZING && pSysInfo->SystemPage <= _LCM_LINK_ERROR) ||
  3002. pDcChargingInfo->isEVCCIDVerify && strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL) {
  3003. return;
  3004. }
  3005. if ((pDcChargingInfo->ConnectorPlugIn == YES) &&
  3006. (pDcChargingInfo->SystemStatus == S_IDLE )
  3007. ) {
  3008. if(!pSysConfig->AuthorisationMode) {
  3009. if (pSysConfig->isAuthrizeByEVCCID && !pDcChargingInfo->isEVCCIDVerify &&
  3010. pDcChargingInfo->Type == _Type_CCS_2) {
  3011. // LCM show linking pic. & timeout 2 min
  3012. if( pSysInfo->CurGunSelected == gunIndex ) {
  3013. systemPageRestoreInit();
  3014. pSysInfo->SystemPage = _LCM_PRECHARGE;
  3015. }
  3016. StartGunInfoTimeoutDet(gunIndex,Timeout_EVCCID_Link);
  3017. // Getting EVCCID
  3018. if( strcmp( (char *)pDcChargingInfo->EVCCID, "" ) != EQUAL ) {
  3019. log_info("Authorizing EVCCID");
  3020. StopSystemTimeoutDet();
  3021. strcpy((char *)pSysConfig->UserId, (char *)pDcChargingInfo->EVCCID);
  3022. ChangeGunSelectByIndex(gunIndex);
  3023. confirmSelGun(gunIndex);
  3024. pDcChargingInfo->isEVCCIDVerify = true;
  3025. ShmDcCommonData->AuthroizeType = IdTokenType_MacAddress;
  3026. pSysInfo->SystemPage = _LCM_START_AUTHORIZING;
  3027. log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
  3028. setChargerMode(gunIndex, MODE_AUTHORIZING);
  3029. }
  3030. } else
  3031. return;
  3032. } else {
  3033. strcpy((char *)&pSysConfig->UserId, "AutoStartCharging");
  3034. ChangeGunSelectByIndex(gunIndex);
  3035. confirmSelGun(gunIndex);
  3036. pSysInfo->SystemPage = _LCM_START_AUTHORIZING;
  3037. ShmDcCommonData->AuthroizeType = IdTokenType_NoAuthorization;
  3038. setChargerMode(gunIndex, MODE_AUTHORIZING);
  3039. log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
  3040. }
  3041. }
  3042. }
  3043. static bool PrecheckIsPass(uint8_t gunIndex)
  3044. {
  3045. bool result = true;
  3046. // relay welding or driving 是反向
  3047. result = !ShmDcCommonData->GunRelayWeldingOccur[gunIndex];
  3048. return result;
  3049. }
  3050. static void ReviewCriticalAlarm(void)
  3051. {
  3052. if (
  3053. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES ||
  3054. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES ||
  3055. pAlarmCode->AlarmEvents.bits.DoorOpen == YES ||
  3056. pSysWarning->ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
  3057. pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == YES ||
  3058. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES ||
  3059. //Power cabinet alarm status
  3060. ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop == YES ||
  3061. ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen == YES ||
  3062. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP == YES ||
  3063. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP == YES ||
  3064. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP == YES ||
  3065. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP == YES ||
  3066. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP == YES ||
  3067. ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure == YES
  3068. ) {
  3069. pSysWarning->Level = WARN_LV_ER;
  3070. } else {
  3071. pSysWarning->Level = WARN_LV_NL;
  3072. }
  3073. }
  3074. static void CheckRelayWeldingOrDrivingFault(uint8_t gunIndex)
  3075. {
  3076. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3077. // relay welding fault then stop the charging process.
  3078. uint8_t faultCode = RELAY_STATUS_ERROR_NONE;
  3079. //static uint8_t drivingCount = 0;
  3080. if (gunIndex == 0) {
  3081. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3082. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3083. faultCode = RELAY_STATUS_ERROR_WELDING;
  3084. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3085. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3086. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3087. }
  3088. } else if (gunIndex == 1) {
  3089. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3090. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3091. faultCode = RELAY_STATUS_ERROR_WELDING;
  3092. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3093. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3094. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3095. }
  3096. }
  3097. if (pSysConfig->TotalConnectorCount >= 2 &&
  3098. !pSysInfo->IsAlternatvieConf) {
  3099. // 橋接
  3100. if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3101. ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3102. faultCode = RELAY_STATUS_ERROR_WELDING;
  3103. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3104. ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3105. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3106. }
  3107. }
  3108. if (faultCode == RELAY_STATUS_ERROR_WELDING) {
  3109. // welding
  3110. if (pDcChargingInfo->Type == _Type_Chademo) {
  3111. RecordAlarmCode(gunIndex, "011011");
  3112. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
  3113. } else if (pDcChargingInfo->Type == _Type_GB) {
  3114. RecordAlarmCode(gunIndex, "011015");
  3115. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
  3116. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3117. RecordAlarmCode(gunIndex, "011013");
  3118. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
  3119. }
  3120. ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = YES;
  3121. //EmcOccureByString("");
  3122. } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
  3123. //if (drivingCount++ != 2) {
  3124. // return;
  3125. //}
  3126. // driving
  3127. if (pDcChargingInfo->Type == _Type_Chademo) {
  3128. RecordAlarmCode(gunIndex, "011012");
  3129. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
  3130. } else if (pDcChargingInfo->Type == _Type_GB) {
  3131. RecordAlarmCode(gunIndex, "011016");
  3132. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
  3133. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3134. RecordAlarmCode(gunIndex, "011014");
  3135. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
  3136. }
  3137. ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = YES;
  3138. //EmcOccureByString("");
  3139. } else {
  3140. ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = NO;
  3141. ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = NO;
  3142. //drivingCount = 0;
  3143. }
  3144. }
  3145. static void isChargingAverageState(void)
  3146. {
  3147. if (pSysInfo->MainChargingMode != _MAIN_CHARGING_MODE_AVER) {
  3148. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3149. return;
  3150. }
  3151. // 均充 -> 最大充
  3152. if (pSysInfo->BridgeRelayStatus == NO) {
  3153. if (pSysInfo->ReAssignedFlag == _REASSIGNED_NONE) {
  3154. log_info("=============Smart Charging============= Step 11 ");
  3155. pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
  3156. }
  3157. } else if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
  3158. pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
  3159. log_info("=============Smart Charging============= Step 14 ");
  3160. pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
  3161. } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
  3162. pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  3163. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3164. }
  3165. }
  3166. bool Taskconutstring(char *src, char *taskname)
  3167. {
  3168. bool result = false;
  3169. if (src == NULL || strlen(src) == 0)
  3170. return result;
  3171. if (strstr(src, taskname) != NULL &&
  3172. strstr(src, "grep") == NULL &&
  3173. strstr(src, "[") == NULL)
  3174. {
  3175. result = true;
  3176. }
  3177. return result;
  3178. }
  3179. int GetProcessCount(char *procName)
  3180. {
  3181. int result = 0;
  3182. FILE *fp;
  3183. char cmd[256];
  3184. char buf[256];
  3185. sprintf(cmd, "ps -ef |grep %s", procName);
  3186. fp = popen(cmd, "r");
  3187. if(fp != NULL)
  3188. {
  3189. while(fgets(buf, sizeof(buf), fp) != NULL)
  3190. {
  3191. if (Taskconutstring(buf, procName))
  3192. result++;
  3193. }
  3194. }
  3195. pclose(fp);
  3196. return result;
  3197. }
  3198. void CheckTaskAlive()
  3199. {
  3200. pid_t Pid = fork();
  3201. if ( Pid == 0 ) {
  3202. //log_info("CheckTaskAlive fork Child's PID is %d", getpid());
  3203. while(1) {
  3204. sleep(3);
  3205. unsigned char count = GetProcessCount("Module_ChkSysTask");
  3206. if( count != 1 ) {
  3207. system("pkill Module_ChkSysTask");
  3208. sleep(10);
  3209. log_info("Create Check System Task");
  3210. system("/root/Module_ChkSysTask &");
  3211. }
  3212. }
  3213. return;
  3214. }
  3215. log_info("Create Check Systam fork:%d",Pid);
  3216. return;
  3217. }
  3218. /**
  3219. * [checkPileEndGfdResult 確認充電樁GFD狀態]
  3220. * @Author Jerry
  3221. * @DateTime 2021-07-01
  3222. * @param gunIndex [當前的槍]
  3223. * @param gunType [槍的類型]
  3224. * @param sysStatus [槍的系統狀態]
  3225. */
  3226. static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sysStatus)
  3227. {
  3228. switch (gunType) {
  3229. case _Type_Chademo:
  3230. // 檢查樁端的 GFD 結果
  3231. if (sysStatus == S_PREPARING_FOR_EVSE &&
  3232. isPrechargeStatus_chademo(gunIndex) >= 6
  3233. ) {
  3234. // 當前操作的槍號,進入 Charging
  3235. setChargerMode(gunIndex, MODE_CHARGING);
  3236. }
  3237. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3238. // GFD 錯誤停止
  3239. RecordAlarmCode(gunIndex, "012234");
  3240. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
  3241. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  3242. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3243. // GFD 警告
  3244. //RecordAlarmCode(gunIndex, "012296");
  3245. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  3246. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
  3247. }
  3248. else {
  3249. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  3250. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  3251. }
  3252. break;
  3253. case _Type_GB:
  3254. // 檢查樁端的 GFD 結果
  3255. //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
  3256. if (sysStatus == S_PREPARING_FOR_EVSE &&
  3257. isPrechargeStatus_gb(gunIndex) >= 6) {
  3258. setChargerMode(gunIndex, MODE_CHARGING);
  3259. }
  3260. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3261. // GFD 錯誤停止
  3262. RecordAlarmCode(gunIndex, "012236");
  3263. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
  3264. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  3265. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3266. // GFD 警告
  3267. //RecordAlarmCode(gunIndex, "012298");
  3268. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  3269. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
  3270. }
  3271. else {
  3272. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  3273. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  3274. }
  3275. break;
  3276. case _Type_CCS_2:
  3277. // 檢查樁端的 GFD 結果
  3278. if (sysStatus == S_PREPARING_FOR_EVSE &&
  3279. (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
  3280. pDcChargingInfo->GroundFaultStatus == GFD_WARNING)
  3281. ) {
  3282. setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP0);
  3283. }
  3284. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3285. // GFD 錯誤停止
  3286. RecordAlarmCode(gunIndex, "012235");
  3287. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  3288. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  3289. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3290. // GFD 警告
  3291. //RecordAlarmCode(gunIndex, "012297");
  3292. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  3293. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
  3294. }
  3295. else {
  3296. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  3297. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  3298. }
  3299. break;
  3300. }
  3301. }
  3302. static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
  3303. {
  3304. uint8_t evBoardStopState = 0;
  3305. if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
  3306. // 板端要求停止 (錯誤)
  3307. if (sysStatus != S_CCS_PRECHARGE_ST0 &&
  3308. sysStatus != S_CCS_PRECHARGE_ST1) {
  3309. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3310. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  3311. }
  3312. }
  3313. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  3314. log_info("EV Board Stop Charging with some error");
  3315. ChargingAlarmProcess(gunIndex);
  3316. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  3317. log_info("Power Cabient Stop Charging");
  3318. ChargingTerminalProcess(gunIndex);
  3319. }
  3320. } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
  3321. // 板端要求停止 (正常)
  3322. if (sysStatus != S_CCS_PRECHARGE_ST0 &&
  3323. sysStatus != S_CCS_PRECHARGE_ST1) {
  3324. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3325. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  3326. }
  3327. }
  3328. log_info("EV Board Normal Stop Charging");
  3329. ChargingTerminalProcess(gunIndex);
  3330. } else if (OcppRemoteStop(gunIndex) == YES ||
  3331. WifiScheduleStop(gunIndex)) {
  3332. // 後臺要求停止
  3333. log_info("OCPP Stop Charging");
  3334. ChargingTerminalProcess(gunIndex);
  3335. }
  3336. }
  3337. static void checkOCPPReqStop(uint8_t gunIndex)
  3338. {
  3339. if (OcppRemoteStop(gunIndex) == YES ||
  3340. WifiScheduleStop(gunIndex) ||
  3341. CheckBackendChargingTimeout(gunIndex) ||
  3342. CheckBackendChargingEnergy(gunIndex) ||
  3343. strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
  3344. // 後臺要求停止
  3345. ChargingTerminalProcess(gunIndex);
  3346. }
  3347. }
  3348. void ResetIdleData(uint8_t gunIndex)
  3349. {
  3350. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3351. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  3352. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  3353. float powerconsumption = ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption;
  3354. pDcChargingInfo->PresentChargedDuration = 0;
  3355. pDcChargingInfo->RemainChargingDuration = 0;
  3356. pDcChargingInfo->PresentChargingVoltage = 0;//DS60-120 add
  3357. pDcChargingInfo->PresentChargingCurrent = 0;//DS60-120 add
  3358. pDcChargingInfo->RemoteStartFlag = NO;
  3359. strcpy((char *)pDcChargingInfo->StartDateTime, "");
  3360. strcpy((char *)pDcChargingInfo->StopDateTime, "");
  3361. strcpy((char *)pDcChargingInfo->StartUserId, "");
  3362. strcpy((char *)pSysConfig->UserId, "");
  3363. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "");
  3364. ShmDcCommonData->isIntoCharge[gunIndex] = FALSE;
  3365. ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
  3366. ClearDetectPluginFlag(gunIndex);
  3367. //Jerry add
  3368. memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
  3369. memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
  3370. ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = powerconsumption;
  3371. ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
  3372. destroySelGun(gunIndex);
  3373. ResetDetAlarmStatus(gunIndex); //recovery OVP status code
  3374. if (ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] == YES) {
  3375. ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] = NO;
  3376. }
  3377. //strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
  3378. ReleaseAlarmCode(gunIndex);
  3379. pSysInfo->SystemPage = _LCM_VIEW;
  3380. }
  3381. void CheckErrorCode(uint8_t gunIndex)
  3382. {
  3383. struct ChargingInfoData *pSelectedDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  3384. if (gunIndex == pSysInfo->CurGunSelected) {
  3385. pSysInfo->SystemPage = _LCM_MAINTAIN;
  3386. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton)
  3387. pSysInfo->SystemPage = _LCM_EMERGENCY;
  3388. } else if (pSelectedDcChargingInfo->SystemStatus != S_IDLE &&
  3389. pSelectedDcChargingInfo->SystemStatus != S_RESERVATION &&
  3390. pSelectedDcChargingInfo->SystemStatus != S_MAINTAIN &&
  3391. pSelectedDcChargingInfo->SystemStatus != S_FAULT) {
  3392. if (pSelectedDcChargingInfo->SystemStatus == S_CHARGING) {
  3393. pSysInfo->SystemPage = _LCM_SUMMARY;
  3394. } else {
  3395. systemPageRestoreInit();
  3396. }
  3397. }
  3398. ClearDetectPluginFlag(gunIndex);
  3399. if (pDcChargingInfo->SystemStatus != S_FAULT)
  3400. {
  3401. UpdateErrorCodeToOcpp(gunIndex);
  3402. setChargerMode(gunIndex, MODE_FAULT);
  3403. }
  3404. }
  3405. void AuthorizeStopCharging(uint8_t gunIndex)
  3406. {
  3407. checkOCPPReqStop(gunIndex);
  3408. /*
  3409. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3410. if ( pSysInfo->SystemPage == _LCM_STOP_APP ) {
  3411. checkOCPPReqStop(gunIndex);
  3412. }
  3413. else if (pSysInfo->SystemPage == _LCM_STOP_RFID ){
  3414. if (!RfidStopCharging() && strlen((char *)pSysConfig->UserId) > 0) {
  3415. // Different Card
  3416. log_info("RFID Authorize fail.");
  3417. strcpy((char *)pSysConfig->UserId, "");
  3418. StopSystemTimeoutDet();
  3419. pSysInfo->SystemPage = _LCM_STOP_RFID_FAIL;
  3420. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  3421. }
  3422. }
  3423. */
  3424. }
  3425. void showversion()
  3426. {
  3427. uint8_t index = 0;
  3428. log_info("\t=========== Dispenser info =========== ");
  3429. log_info("\tSW Version = %s", fwVersion);
  3430. log_info("\tDebug Version = %s",DebugVersion);
  3431. log_info("\tModelName = %s", pSysConfig->ModelName);
  3432. log_info("\tRelay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
  3433. log_info("\tFan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
  3434. log_info("\tPrimary FW Rev = %s", pSysInfo->CsuPrimFwRev);
  3435. log_info("\tLCM HW Rev = %s", pSysInfo->LcmHwRev);
  3436. log_info("\tLED FW Rev = %s", pSysInfo->LedModuleFwRev);
  3437. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  3438. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  3439. if (pDcChargingInfo->Type == _Type_Chademo) {
  3440. log_info("\tCHAdeMO[%d] FW Rev = %s",
  3441. pDcChargingInfo->type_index,
  3442. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
  3443. } else if (pDcChargingInfo->Type == _Type_GB) {
  3444. log_info("\tGBT[%d] FW Rev = %s",
  3445. pDcChargingInfo->type_index,
  3446. ShmGBTData->evse[pDcChargingInfo->type_index].version);
  3447. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3448. log_info("\tCCS[%d] FW Rev = %s",
  3449. pDcChargingInfo->type_index,
  3450. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
  3451. }
  3452. }
  3453. log_info("\t==================================== ");
  3454. }
  3455. int main(void)
  3456. {
  3457. bool isModelNameMatch = true;
  3458. uint8_t _ocppProfileChkFlag;
  3459. uint8_t gunIndex = 0;
  3460. if (CreateAllCsuShareMemory() == FAIL) {
  3461. log_error("create share memory error");
  3462. return FAIL;
  3463. }
  3464. ClearAllShmMemParameter();
  3465. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  3466. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  3467. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  3468. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  3469. pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  3470. pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
  3471. ShmPsuData = (struct PsuData *)GetShmPsuData();
  3472. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  3473. ShmGBTData = (struct GBTData *)GetShmGBTData();
  3474. ShmCcsData = (struct CcsData *)GetShmCcsData();
  3475. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  3476. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  3477. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  3478. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  3479. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  3480. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  3481. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  3482. ShmSysConfigAndInfo = (struct SysConfigAndInfo *)GetShmSysConfigAndInfo();
  3483. ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();
  3484. log_info(" ********************************************************");
  3485. log_info(" ****************** FileSystem Boot up *****************");
  3486. log_info(" ********************************************************");
  3487. log_info(" ****************** Project:DD360UCar *****************");
  3488. log_info(" ********************************************************");
  3489. if (!InitialSystemDefaultConfig()) {
  3490. log_error("InitialSystemDefaultConfig NG ");
  3491. //StopProcessingLoop();
  3492. sleep(5);
  3493. system("reboot -f");
  3494. }
  3495. CheckGunTypeFromHw();
  3496. CheckIsAlternatvieByModelName();
  3497. InitialShareMemoryInfo();
  3498. GetFirmwareVersion();
  3499. if (!CheckConnectorTypeStatus()) {
  3500. isModelNameMatch = false;
  3501. }
  3502. Initialization();
  3503. SpawnTask();
  3504. log_info("Spawned all Task");
  3505. if (!isModelNameMatch) {
  3506. pAlarmCode->AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
  3507. //ChangeLcmByIndex(_LCM_ERROR);
  3508. ChangeLcmByIndex(_LCM_MAINTAIN);
  3509. // Module Name 與硬體對應不正確
  3510. log_error("Module Name & HW info none match. ");
  3511. sleep(3);
  3512. KillAllTask();
  3513. StopProcessingLoop();
  3514. }
  3515. CreateTimeoutFork();
  3516. log_info("Start self test... ");
  3517. SelfTestRun();
  3518. StopSystemTimeoutDet();
  3519. log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
  3520. pSysInfo->SelfTestSeq,
  3521. ShmPsuData->Work_Step);
  3522. if (pSysInfo->SelfTestSeq == _STEST_FAIL ||ShmPsuData->Work_Step == _NO_WORKING ||
  3523. pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES ) {
  3524. ChangeLcmByIndex(_LCM_MAINTAIN);
  3525. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  3526. setChargerMode(gunIndex, MODE_MAINTAIN);
  3527. }
  3528. } else {
  3529. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  3530. setChargerMode(gunIndex, MODE_IDLE);
  3531. }
  3532. }
  3533. // Local DB
  3534. if (DB_Open() != PASS) {
  3535. log_info("DB_Open fail. ");
  3536. isDb_ready = false;
  3537. } else {
  3538. isDb_ready = true;
  3539. for (int _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  3540. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  3541. pDcChargingInfo->IsAvailable = DB_Get_Operactive(_index);
  3542. if (!DB_Get_PowerConsumption(_index)) {
  3543. DB_Insert_PowerConsumption(_index,0);
  3544. }
  3545. }
  3546. DB_Reboot_Record();
  3547. }
  3548. log_info("===== Create DB End ===== ");
  3549. ChangeLcmByIndex(_LCM_VIEW);
  3550. sleep(1);
  3551. //***** 須新增的偵測 *****//
  3552. // 1. Thernal - 控制風扇轉速
  3553. // 2. ouput fuse - 控制風扇轉速
  3554. CreateRfidFork();
  3555. // Main loop
  3556. showversion();
  3557. CheckFwSlotStatusLog();
  3558. //AdjustChargerCurrent();
  3559. GetClockTime(&_cmdMainPriority_time, NULL);
  3560. //GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
  3561. CheckTaskAlive();
  3562. CreateWatchdog();
  3563. int is_prepare0 = FALSE;
  3564. int is_prepare1 = FALSE;
  3565. pSysInfo->OTPTemp = GUN_OTP_VALUE;
  3566. pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
  3567. for (;;) {
  3568. CheckOcppStatus();
  3569. ChkPrimaryStatus();
  3570. if ((IsConnectorWholeIdle() ||
  3571. //(pSysInfo->PageIndex == _LCM_ERROR)) &&
  3572. (pSysInfo->PageIndex == _LCM_MAINTAIN)) &&
  3573. (pSysInfo->SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
  3574. ) {
  3575. CheckFactoryConfigFunction();
  3576. //CheckFwUpdateFunction();
  3577. }
  3578. // OCPP 邏輯
  3579. OcppRemoteStartChk();
  3580. // 當 AC 沒有搭上時,清除一些錯誤碼
  3581. ClearAlarmCodeWhenAcOff();
  3582. if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
  3583. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  3584. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3585. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  3586. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  3587. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  3588. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  3589. if (pDcChargingInfo->SystemStatus == S_CHARGING &&
  3590. _ocppProfileChkFlag == 12) {
  3591. ChargingProfileFlat(gunIndex);
  3592. _ocppProfileChkFlag = 0;
  3593. } else if (pDcChargingInfo->SystemStatus != S_CHARGING) {
  3594. ChargingProfileFlat(gunIndex);
  3595. _ocppProfileChkFlag = 0;
  3596. } else {
  3597. _ocppProfileChkFlag++;
  3598. }
  3599. }
  3600. checkGunOTPState(gunIndex); //check gun OTP
  3601. }
  3602. GetClockTime(&_cmdMainPriority_time, NULL);
  3603. }
  3604. gEvBoardErr.GunErrMessage = 0; //清除系統執行中的錯誤訊息
  3605. gChillerTempErr.TempErrMsg = 0;//清除系統執行中的錯誤訊息
  3606. is_prepare0 = FALSE;
  3607. is_prepare1 = FALSE;
  3608. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  3609. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3610. // 重新收集各槍的錯誤狀態
  3611. collectError(gunIndex);
  3612. checkEvBoardAlarmState(pDcChargingInfo->Type);
  3613. if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
  3614. pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EVSE) ||
  3615. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
  3616. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
  3617. (gunIndex == LEFT_GUN_NUM) ? (is_prepare0 = TRUE) : (is_prepare1 = TRUE);
  3618. }
  3619. }
  3620. // 檢查是否有槍處於Preparing & precharging 狀態
  3621. if (is_prepare0 && !is_prepare1) {
  3622. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
  3623. if (pDcChargingInfo->SystemStatus != S_AUTHORIZING)
  3624. pSysInfo->CurGunSelected = LEFT_GUN_NUM;
  3625. else if (pDcChargingInfo->SystemStatus == S_AUTHORIZING) {
  3626. pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
  3627. }
  3628. } else if (!is_prepare0 && is_prepare1) {
  3629. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
  3630. if (pDcChargingInfo->SystemStatus != S_AUTHORIZING)
  3631. pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
  3632. else if (pDcChargingInfo->SystemStatus == S_AUTHORIZING) {
  3633. pSysInfo->CurGunSelected = LEFT_GUN_NUM;
  3634. }
  3635. }
  3636. ////////////////////////////////////////
  3637. checkChillerAlarmState();
  3638. // 確認當前錯誤 Level = 2 ?
  3639. ReviewCriticalAlarm();
  3640. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  3641. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3642. CheckGpioInStatus();
  3643. CheckErrorOccurStatus(gunIndex);
  3644. // 確認 Relay Welding or Driving Fault
  3645. CheckRelayWeldingOrDrivingFault(gunIndex);
  3646. ChkOcppStatus(gunIndex);
  3647. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  3648. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  3649. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  3650. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  3651. CheckSmartChargeProfile(gunIndex);
  3652. }
  3653. switch (pDcChargingInfo->SystemStatus) {
  3654. case S_IDLE:
  3655. if (isModeChange(gunIndex)) {
  3656. log_info("============================= S_IDLE(%x) ============================= ", gunIndex);
  3657. ResetIdleData(gunIndex);
  3658. }
  3659. isChargingAverageState();
  3660. // For RemoteStart Using
  3661. if (pDcChargingInfo->RemoteStartFlag == YES && pDcChargingInfo->IsAvailable) {
  3662. log_info("-------- IDLE Remote Start(%d) --------", gunIndex);
  3663. ChangeGunSelectByIndex(gunIndex);
  3664. setChargerMode(gunIndex, MODE_AUTHORIZING);
  3665. break;
  3666. }
  3667. autoStartCharging(gunIndex);
  3668. goto CheckStatus;
  3669. // 檢查預約
  3670. if (ShmDcCommonData->pGunInfo[gunIndex].ReservationStatus) {
  3671. setChargerMode(gunIndex, MODE_RESERVATION);
  3672. }
  3673. break;
  3674. case S_RESERVATION:
  3675. if (isModeChange(gunIndex)) {
  3676. log_info("============================= S_RESERVATION(%x) ============================= ", gunIndex);
  3677. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  3678. }
  3679. /*
  3680. if (!isReservationExpired(gunIndex)) {
  3681. pDcChargingInfo->SystemStatus = S_IDLE;
  3682. }*/
  3683. // 檢查預約
  3684. if (!ShmDcCommonData->pGunInfo[gunIndex].ReservationStatus) {
  3685. setChargerMode(gunIndex, MODE_IDLE);
  3686. }
  3687. goto CheckStatus;
  3688. break;
  3689. case S_FAULT:
  3690. if (isModeChange(gunIndex)) {
  3691. if(pDcChargingInfo->SystemStatus == S_FAULT) {
  3692. log_info("============================= S_FAULT(%x) ============================= ", gunIndex);
  3693. //pSysInfo->SystemPage = _LCM_ERROR;
  3694. pSysInfo->SystemPage = _LCM_MAINTAIN;
  3695. }
  3696. }
  3697. CheckStatus:
  3698. if (pDcChargingInfo->IsAvailable == NO) {
  3699. setChargerMode(gunIndex, MODE_MAINTAIN);
  3700. break;
  3701. }
  3702. // Refresh Error Status
  3703. if (pSysWarning->Level == WARN_LV_ER) {
  3704. pSysInfo->SystemPage = _LCM_MAINTAIN;
  3705. CheckErrorCode(gunIndex);
  3706. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton)
  3707. pSysInfo->SystemPage = _LCM_EMERGENCY;
  3708. continue;;
  3709. }
  3710. if (PrecheckIsPass(gunIndex) == false) {
  3711. log_error("Relay welding");
  3712. setChargerMode(gunIndex, MODE_FAULT);
  3713. if (gunIndex == pSysInfo->CurGunSelected) {
  3714. //pSysInfo->SystemPage = _LCM_ERROR;
  3715. pSysInfo->SystemPage = _LCM_MAINTAIN;
  3716. }
  3717. continue;
  3718. }
  3719. if (pDcChargingInfo->SystemStatus == S_FAULT) {
  3720. systemPageRestoreInit();
  3721. setChargerMode(gunIndex, MODE_IDLE);
  3722. break;
  3723. }
  3724. break;
  3725. case S_AUTHORIZING:
  3726. if (isModeChange(gunIndex)) {
  3727. log_info("============================= S_AUTHORIZING(%x) ============================= ", gunIndex);
  3728. pSysInfo->SystemPage = _LCM_START_SCAN;
  3729. StartGunInfoTimeoutDet(gunIndex, Timeout_GunAuthorizePage);
  3730. }
  3731. // 讀卡邏輯
  3732. ScannerCardProcess();
  3733. // 隨插即充
  3734. //autoStartCharging(gunIndex);
  3735. if (isDetectPlugin(gunIndex) && pSysInfo->SystemPage != _LCM_LINK_ERROR) {
  3736. StartGunInfoTimeoutDet(gunIndex, Timeout_WaitPlug);
  3737. // 卡號驗證成功後,等待充電槍插入充電車
  3738. if (pDcChargingInfo->RemoteStartFlag == YES) {
  3739. if (pDcChargingInfo->ConnectorPlugIn == YES &&
  3740. pDcChargingInfo->IsAvailable ) {
  3741. log_info("-------- S_AUTHORIZING Remote Start(%d) --------", gunIndex);
  3742. pDcChargingInfo->RemoteStartFlag = NO;
  3743. pDcChargingInfo->isRemoteStart = YES; //DS60-120
  3744. ChangeGunSelectByIndex(gunIndex);
  3745. //AddPlugInTimes(gunIndex);
  3746. setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
  3747. StopGunInfoTimeoutDet(gunIndex);
  3748. strcpy((char *)pDcChargingInfo->StartUserId, "");
  3749. ClearDetectPluginFlag(gunIndex);
  3750. continue;
  3751. }
  3752. } else if (pSysInfo->OrderCharging == NO_DEFINE) {
  3753. if (pDcChargingInfo->ConnectorPlugIn == YES &&
  3754. pDcChargingInfo->IsAvailable &&
  3755. pDcChargingInfo->SystemStatus == S_AUTHORIZING &&
  3756. //waitSelectGunPlugIt(gunIndex)
  3757. (waitRightGunPlugIt(gunIndex) == PASS ||
  3758. waitLeftGunPlugIt(gunIndex) == PASS)
  3759. ) {
  3760. log_info("-------- RFID/Auto Start(%d) --------", gunIndex);
  3761. ChangeGunSelectByIndex(gunIndex);
  3762. //AddPlugInTimes(gunIndex);
  3763. pDcChargingInfo->isRemoteStart = NO;
  3764. strcpy((char *)pDcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
  3765. log_info("index = %d, CardNumber = %s ",
  3766. gunIndex,
  3767. pDcChargingInfo->StartUserId);
  3768. strcpy((char *)pSysConfig->UserId, "");
  3769. // 當前操作的槍號,進入 Preparing
  3770. setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
  3771. StopGunInfoTimeoutDet(gunIndex);
  3772. ClearDetectPluginFlag(gunIndex);
  3773. continue;
  3774. }
  3775. }
  3776. if (!GetIsCardScan() && pSysInfo->CurGunSelected == gunIndex && !pDcChargingInfo->ConnectorPlugIn) {
  3777. pSysInfo->SystemPage = _LCM_WAIT_PLUGIN;
  3778. break;
  3779. }
  3780. }
  3781. if (pSysInfo->CurGunSelected == gunIndex &&
  3782. (pSysInfo->SystemPage != _LCM_START_AUTHORIZING &&
  3783. pSysInfo->SystemPage != _LCM_START_AUTHORIZE_FAIL )) {
  3784. pSysInfo->SystemPage = _LCM_START_SCAN;
  3785. }
  3786. break;
  3787. case S_REASSIGN_CHECK: {
  3788. if (isModeChange(gunIndex)) {
  3789. log_info("============================= S_REASSIGN_CHECK(%x) ============================= ", gunIndex);
  3790. if (pSysInfo->OrderCharging != NO_DEFINE) {
  3791. pSysInfo->OrderCharging = NO_DEFINE;
  3792. }
  3793. StopSystemTimeoutDet();
  3794. }
  3795. setChargerMode(gunIndex, S_PREPARNING);
  3796. if (pSysInfo->CurGunSelected == gunIndex) {
  3797. pSysInfo->SystemPage = _LCM_COMMUNICATION;
  3798. }
  3799. }
  3800. break;
  3801. case S_PREPARNING:
  3802. if (isModeChange(gunIndex)) {
  3803. log_info("============================= S_PREPARNING(%x) ============================= ", gunIndex);
  3804. StopGunInfoTimeoutDet(gunIndex);
  3805. StartGunInfoTimeoutDet(gunIndex, Timeout_Preparing);
  3806. }
  3807. if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
  3808. ShmPsuData->SystemAvailablePower > 10 &&
  3809. GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) >= 1000000) {
  3810. setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
  3811. }
  3812. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  3813. if (pSysInfo->CurGunSelected == gunIndex) {
  3814. pSysInfo->SystemPage = _LCM_COMMUNICATION;
  3815. }
  3816. break;
  3817. case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
  3818. if (isModeChange(gunIndex)) {
  3819. log_info("============================= S_PREPARING_FOR_EV(%x) ============================= ", gunIndex);
  3820. log_info("Waitting for Gun locked.");
  3821. StopGunInfoTimeoutDet(gunIndex);
  3822. StartGunInfoTimeoutDet(gunIndex, Timeout_EvChargingDet);
  3823. }
  3824. if (pDcChargingInfo->Type == _Type_Chademo) {
  3825. if (isEvGunLocked_chademo(gunIndex) == YES) {
  3826. log_info("Gun Locked");
  3827. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  3828. }
  3829. } else if (pDcChargingInfo->Type == _Type_GB) {
  3830. if (isEvGunLocked_gb(gunIndex) == YES) {
  3831. log_info("Gun Locked");
  3832. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  3833. }
  3834. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3835. if (isEvGunLocked_ccs(gunIndex) == YES) {
  3836. log_info("Gun Locked");
  3837. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  3838. }
  3839. }
  3840. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  3841. if (pSysInfo->CurGunSelected == gunIndex) {
  3842. pSysInfo->SystemPage = _LCM_COMMUNICATION;
  3843. }
  3844. break;
  3845. case S_PREPARING_FOR_EVSE: // Ground fault test, 等待 Relay Board 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
  3846. if (isModeChange(gunIndex)) {
  3847. log_info("============================= S_PREPARING_FOR_EVSE(%x) ============================= ", gunIndex);
  3848. StopGunInfoTimeoutDet(gunIndex);
  3849. StartGunInfoTimeoutDet(gunIndex, Timeout_EvseChargingDet);
  3850. }
  3851. checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  3852. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  3853. if (pSysInfo->CurGunSelected == gunIndex) {
  3854. pSysInfo->SystemPage = _LCM_CHARGING_DETECT;
  3855. }
  3856. break;
  3857. case S_CCS_PRECHARGE_ST0:
  3858. if (isModeChange(gunIndex)) {
  3859. log_info("============================= CCS Precharge Processing 1(%x) ============================= ", gunIndex);
  3860. StopGunInfoTimeoutDet(gunIndex);
  3861. StartGunInfoTimeoutDet(gunIndex, Timeout_ForCcsPrechargeDet);
  3862. }
  3863. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3864. // GFD 錯誤停止
  3865. RecordAlarmCode(gunIndex, "012235");
  3866. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  3867. }
  3868. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  3869. // 等待 EV 小板 (CCS) 通知可以開始 Precharge
  3870. // 切換 D+ Relay to Precharge Relay
  3871. if (isPrechargeStatus_ccs(gunIndex) == 39 ||
  3872. isPrechargeStatus_ccs(gunIndex) == 40) {
  3873. if ((pDcChargingInfo->RelayKPK2Status == YES || pDcChargingInfo->PantographFlag == YES) &&
  3874. pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
  3875. //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
  3876. {
  3877. //log_info("Send precharge ready 1..........%x, status = %d ",
  3878. // gunIndex,
  3879. // isPrechargeStatus_ccs(gunIndex));
  3880. if (isPrechargeStatus_ccs(gunIndex) == 39) {
  3881. log_info("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) ",
  3882. gunIndex,
  3883. isPrechargeStatus_ccs(gunIndex));
  3884. } else if (isPrechargeStatus_ccs(gunIndex) == 40) {
  3885. log_info("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) ",
  3886. gunIndex,
  3887. isPrechargeStatus_ccs(gunIndex));
  3888. }
  3889. pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
  3890. }
  3891. } else if (isPrechargeStatus_ccs(gunIndex) == 45 ||
  3892. isPrechargeStatus_ccs(gunIndex) == 46
  3893. ) {
  3894. setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP1);
  3895. }
  3896. if (pSysInfo->CurGunSelected == gunIndex) {
  3897. pSysInfo->SystemPage = _LCM_PREPARECHARE;
  3898. }
  3899. break;
  3900. case S_CCS_PRECHARGE_ST1:
  3901. if (isModeChange(gunIndex)) {
  3902. log_info("============================= CCS Precharge Processing 2(%x) ============================= ", gunIndex);
  3903. }
  3904. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3905. // GFD 錯誤停止
  3906. RecordAlarmCode(gunIndex, "012235");
  3907. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  3908. }
  3909. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  3910. // 等待小板通知進入充電
  3911. // 切換 D+ Relay to Precharge Relay
  3912. if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
  3913. pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
  3914. pSysInfo->CurGunSelected = gunIndex;
  3915. setChargerMode(gunIndex, MODE_CHARGING);
  3916. }
  3917. if (pSysInfo->CurGunSelected == gunIndex) {
  3918. pSysInfo->SystemPage = _LCM_PREPARECHARE;
  3919. }
  3920. break;
  3921. case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
  3922. if (isModeChange(gunIndex)) {
  3923. log_info("============================= S_CHARGING(%x) ============================= ", gunIndex);
  3924. StopGunInfoTimeoutDet(gunIndex);
  3925. ftime(&startChargingTime[gunIndex]);
  3926. strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
  3927. ChangeStartOrStopDateTime(YES, gunIndex);
  3928. if (pSysInfo->CurGunSelected == gunIndex)
  3929. pSysInfo->SystemPage = _LCM_VIEW;
  3930. ShmDcCommonData->isIntoCharge[gunIndex] = TRUE;
  3931. }
  3932. if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
  3933. ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf = NO;
  3934. }
  3935. ftime(&endChargingTime[gunIndex]);
  3936. pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
  3937. GetChargeTranscationDateTime(gunIndex);
  3938. checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  3939. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  3940. if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime) >= 5) {
  3941. ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
  3942. if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
  3943. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  3944. }
  3945. // Check Stop Charging
  3946. AuthorizeStopCharging(gunIndex);
  3947. // LCM => Charging
  3948. /*
  3949. if (pSysInfo->CurGunSelected == gunIndex ) {
  3950. pSysInfo->SystemPage = _LCM_VIEW;
  3951. }*/
  3952. break;
  3953. case S_ALARM:
  3954. if (isModeChange(gunIndex)) {
  3955. log_info("============================= S_ALARM(%x) ============================= ", gunIndex);
  3956. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3957. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  3958. }
  3959. UpdateErrorCodeToOcpp(gunIndex);
  3960. if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
  3961. OcppStopTransation(gunIndex);
  3962. }
  3963. TheEndCharging(gunIndex);
  3964. StopGunInfoTimeoutDet(gunIndex);
  3965. if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
  3966. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  3967. }
  3968. if (pSysWarning->Level == WARN_LV_ER) {
  3969. pSysInfo->SystemPage = _LCM_MAINTAIN;
  3970. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton)
  3971. pSysInfo->SystemPage = _LCM_EMERGENCY;
  3972. break;
  3973. }
  3974. if (!pDcChargingInfo->ConnectorPlugIn) {
  3975. if (ShmDcCommonData->isIntoCharge[gunIndex]) {
  3976. if (pSysInfo->CurGunSelected == gunIndex)
  3977. pSysInfo->SystemPage = _LCM_SUMMARY;
  3978. StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOut);
  3979. } else {
  3980. setChargerMode(gunIndex, MODE_IDLE);
  3981. }
  3982. } else {
  3983. if (pSysInfo->CurGunSelected == gunIndex) {
  3984. if (ShmDcCommonData->isIntoCharge[gunIndex]) {
  3985. if (!ShmDcCommonData->pGunInfo[gunIndex].finalcost_flag) {
  3986. pSysInfo->SystemPage = _LCM_STOPPING;
  3987. } else if (pSysInfo->SystemPage != _LCM_SUMMARY) {
  3988. pSysInfo->SystemPage = _LCM_VIEW;
  3989. }
  3990. } else {
  3991. if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _LCM_LINK_ERROR) {
  3992. pSysInfo->SystemPage = _LCM_VIEW;
  3993. }
  3994. }
  3995. }
  3996. }
  3997. break;
  3998. case S_TERMINATING:
  3999. if (isModeChange(gunIndex)) {
  4000. log_info("============================= S_TERMINATING(%x) ============================= ", gunIndex);
  4001. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  4002. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  4003. }
  4004. StopGunInfoTimeoutDet(gunIndex);
  4005. //pSysInfo->CurGunSelected = gunIndex;
  4006. StartGunInfoTimeoutDet(gunIndex, Timeout_Terminating);
  4007. if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
  4008. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4009. }
  4010. // For Precharging timeout
  4011. if (pDcChargingInfo->Type == _Type_Chademo) {
  4012. if (isEvStopCharging_chademo(gunIndex) == YES ||
  4013. isPrechargeStatus_chademo(gunIndex) <= 0 ) {
  4014. setChargerMode(gunIndex, MODE_COMPLETE);
  4015. }
  4016. } else if (pDcChargingInfo->Type == _Type_GB) {
  4017. if (isEvStopCharging_gb(gunIndex) == YES ||
  4018. isPrechargeStatus_gb(gunIndex) <= 0){
  4019. setChargerMode(gunIndex, MODE_COMPLETE);
  4020. }
  4021. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  4022. if (isEvStopCharging_ccs(gunIndex) == YES &&
  4023. (isPrechargeStatus_ccs(gunIndex) >= 53 ||
  4024. isPrechargeStatus_ccs(gunIndex) == 0 ||
  4025. isPrechargeStatus_ccs(gunIndex) == 13 ||
  4026. isPrechargeStatus_ccs(gunIndex) == 14) ) {
  4027. setChargerMode(gunIndex, MODE_COMPLETE);
  4028. }
  4029. }
  4030. if (pSysInfo->CurGunSelected == gunIndex && !ShmDcCommonData->pGunInfo[gunIndex].finalcost_flag) {
  4031. pSysInfo->SystemPage = _LCM_STOPPING;
  4032. }
  4033. break;
  4034. case S_COMPLETE:
  4035. if (isModeChange(gunIndex)) {
  4036. log_info ("============================= S_COMPLETE(%x) ============================= ", gunIndex);
  4037. if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
  4038. OcppStopTransation(gunIndex);
  4039. }
  4040. TheEndCharging(gunIndex);
  4041. StopSystemTimeoutDet();
  4042. if (pSysInfo->CurGunSelected == gunIndex) {
  4043. pSysInfo->SystemPage = _LCM_VIEW;
  4044. }
  4045. }
  4046. if (pSysInfo->SystemPage == _LCM_MAINTAIN) {
  4047. break;
  4048. }
  4049. if (!pDcChargingInfo->ConnectorPlugIn) {
  4050. if (pSysInfo->CurGunSelected == gunIndex) {
  4051. pSysInfo->SystemPage = _LCM_SUMMARY;
  4052. }
  4053. StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOut);
  4054. } else {
  4055. if (pSysInfo->CurGunSelected == gunIndex) {
  4056. if (!ShmDcCommonData->pGunInfo[gunIndex].finalcost_flag) {
  4057. pSysInfo->SystemPage = _LCM_STOPPING;
  4058. } else if(pSysInfo->SystemPage != _LCM_SUMMARY) {
  4059. pSysInfo->SystemPage = _LCM_VIEW;
  4060. }
  4061. }
  4062. }
  4063. break;
  4064. case S_MAINTAIN:
  4065. if (isModeChange(gunIndex)) {
  4066. log_info("============================= S_MAINTAIN(%x) ============================= ", gunIndex);
  4067. if (pSysInfo->FirmwareUpdate == YES) {
  4068. pSysInfo->SystemPage = _LCM_MAINTAIN;
  4069. continue;
  4070. }
  4071. if (pDcChargingInfo->IsAvailable == NO) {
  4072. break;
  4073. }
  4074. if (pSysWarning->Level != WARN_LV_ER) {
  4075. if (!DisplaySelfTestFailReason()) { //DS60-120 add
  4076. log_info("Soft reboot for retry self-tets. ");
  4077. sleep(3);
  4078. system("killall OcppBackend &");
  4079. KillAllTask();
  4080. system("/usr/bin/run_evse_restart.sh");
  4081. }
  4082. }
  4083. sleep(3);
  4084. if (pSysWarning->Level == WARN_LV_ER) { //DS60-120 add
  4085. KillTaskExceptPrimary();
  4086. } else {
  4087. KillTask();
  4088. }
  4089. //if (pSysInfo->SelfTestSeq == _STEST_FAIL)
  4090. // StopProcessingLoop();
  4091. }
  4092. if (pSysInfo->SelfTestSeq == _STEST_FAIL && pSysInfo->SystemTimeoutFlag != Timeout_SelftestChk) {
  4093. SelfTestRun();
  4094. StopSystemTimeoutDet();
  4095. sleep(3);
  4096. break;
  4097. }
  4098. if (pDcChargingInfo->IsAvailable && pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
  4099. setChargerMode(gunIndex, MODE_IDLE);
  4100. }
  4101. if (pSysInfo->CurGunSelected == gunIndex) {
  4102. pSysInfo->SystemPage = _LCM_VIEW;
  4103. }
  4104. break;
  4105. case S_UPDATE:
  4106. if (isModeChange(gunIndex)) {
  4107. log_info("============================= S_UPDATE ============================= ");
  4108. }
  4109. if (pSysInfo->FirmwareUpdate == YES) {
  4110. pSysInfo->SystemPage = _LCM_MAINTAIN;
  4111. continue;
  4112. } else {
  4113. }
  4114. break;
  4115. }//switch
  4116. }//for
  4117. //if (pSysInfo->SystemPage != _LCM_VIEW)
  4118. //ChangeLcmByIndex(pSysInfo->SystemPage);
  4119. TryFeedWatchdog();
  4120. usleep(WHILE_LOOP_TIME);
  4121. }
  4122. return FAIL;
  4123. }