main.c 231 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697
  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 struct OCPP20Data* ShmOCPP20Data = NULL;
  58. static DcCommonInfo *ShmDcCommonData = NULL;
  59. static struct ChargingInfoData *pDcChargingInfo = NULL;
  60. static struct ChargingInfoData *pAcChargingInfo = NULL;
  61. static struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  62. static struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  63. static SelectGunInfo *ShmSelectGunInfo = NULL;
  64. static EvBoardErrMsg gEvBoardErr = {0};
  65. static ChillerTempErr gChillerTempErr = {0};
  66. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  67. struct StatusCodeData *ShmStatusCodeData;
  68. #define DERATING_TARGET_LEVEL 5
  69. // for initial index to check EV board type is correct
  70. uint8_t bd0_1_status = 0;
  71. uint8_t bd0_2_status = 0;
  72. uint8_t bd1_1_status = 0;
  73. uint8_t bd1_2_status = 0;
  74. char *fwVersion = "V2.00.00.0000.00";
  75. char* DebugVersion = "V2.00.12";
  76. //sqlite3 *localDb;
  77. bool isDb_ready;
  78. //------------------------------------------------------------------------------
  79. void ClearDetectPluginFlag(int gunIndex);
  80. long long DiffTimebWithNow(struct timeb ST);
  81. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
  82. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
  83. unsigned long GetTimeoutValue(struct timeval _sour_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 PrimaryLedIndicatorCtrlFork(void);
  94. extern void ChkPrimaryStatus(void);
  95. //RFID.c
  96. extern void CreateRfidFork(void);
  97. extern void ScannerCardProcess(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. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  127. pSysInfo->SystemPage = _LCM_NONE;
  128. return;
  129. }
  130. pSysInfo->SystemPage = _LCM_NONE;
  131. }
  132. static void connectorPageRestoreIdle(void)
  133. {
  134. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  135. pSysInfo->ConnectorPage = _LCM_NONE;
  136. return;
  137. }
  138. pSysInfo->ConnectorPage = _LCM_IDLE;
  139. }
  140. //------------------------------------------------------------------------------
  141. void destroySelGun(uint8_t curGun)
  142. {
  143. uint8_t i = 0;
  144. uint8_t totalGun = pSysConfig->TotalConnectorCount;
  145. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  146. return;
  147. }
  148. //for status timeout
  149. if (curGun == DESTROY_ALL_SEL) {
  150. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  151. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  152. log_info("destroy all gun = %d, %d",
  153. ShmSelectGunInfo->SelGunInfo.LeftGun,
  154. ShmSelectGunInfo->SelGunInfo.RightGun);
  155. for (i = 0; i < totalGun; i++) {
  156. StopGunInfoTimeoutDet(i);
  157. memset(&ShmSelectGunInfo->PricesInfo[i], 0, sizeof(PricesInfo));
  158. }
  159. pSysInfo->CurGunSelected = 0;
  160. strcpy((char *)pSysConfig->UserId, "");
  161. //changeLcmPage(_LCM_SELECT_GUN);
  162. return;
  163. }
  164. //for charging timeout or complete
  165. if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
  166. if (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
  167. ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
  168. #ifdef DD360Audi
  169. changeLcmPage(_LCM_SELECT_GUN);
  170. #endif
  171. }
  172. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  173. StopGunInfoTimeoutDet(LEFT_GUN_NUM);
  174. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  175. ClearAuthorizedFlag();
  176. }
  177. log_info("destroy left gun, cur page = %d", getCurLcmPage());
  178. if (getCurLcmPage() == pSysInfo->SystemPage) {
  179. log_info("clear left balance");
  180. memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  181. ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  182. }
  183. }
  184. if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
  185. if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
  186. ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
  187. #ifdef DD360Audi
  188. changeLcmPage(_LCM_SELECT_GUN);
  189. #endif
  190. }
  191. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  192. StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
  193. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  194. ClearAuthorizedFlag();
  195. }
  196. log_info("destroy right gun, cur page = %d", getCurLcmPage());
  197. if (getCurLcmPage() == pSysInfo->SystemPage) {
  198. log_info("clear right balance");
  199. memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  200. ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  201. }
  202. }
  203. }
  204. static int waitRightGunPlugIt(uint8_t curGun)
  205. {
  206. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  207. return PASS;
  208. }
  209. if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
  210. return PASS;
  211. }
  212. return FAIL;
  213. }
  214. static int waitLeftGunPlugIt(uint8_t curGun)
  215. {
  216. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  217. return PASS;
  218. }
  219. if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
  220. return PASS;
  221. }
  222. return FAIL;
  223. }
  224. void setSelGunWaitToAuthor(uint8_t curSel)
  225. {
  226. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  227. return;
  228. }
  229. if (curSel == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
  230. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
  231. //printf("setSelGunWaitToAuthor left");
  232. StopGunInfoTimeoutDet(curSel);
  233. } else if (curSel == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
  234. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
  235. //printf("setSelGunWaitToAuthor right");
  236. StopGunInfoTimeoutDet(curSel);
  237. }
  238. }
  239. int getConfirmSelectedGun(uint8_t curSel)
  240. {
  241. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  242. return PASS;
  243. }
  244. if (((curSel == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
  245. ((curSel == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
  246. return PASS;
  247. }
  248. return FAIL;
  249. }
  250. void confirmSelGun(uint8_t selGun)
  251. {
  252. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  253. return;
  254. }
  255. if (selGun == LEFT_GUN_NUM) {
  256. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  257. StopGunInfoTimeoutDet(selGun);
  258. //printf("confirmSelGun left");
  259. } else if (selGun == RIGHT_GUN_NUM) {
  260. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  261. StopGunInfoTimeoutDet(selGun);
  262. //printf("confirmSelGun right");
  263. }
  264. // AUDI_LCM_CHANGE
  265. changeLcmPage(_LCM_IDLE);
  266. StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
  267. }
  268. static void GetFirmwareVersion(void)
  269. {
  270. // Get CSU root file system version
  271. sprintf((char *)pSysInfo->CsuRootFsFwRev, fwVersion);
  272. sprintf((char *)ShmDcCommonData->DebugVersion, DebugVersion);
  273. uint8_t count = 0, chademo = 0, ccs = 0, gb = 0;
  274. for (uint8_t idx = 0; idx < 3; idx++) {
  275. if (pSysConfig->ModelName[7 + idx] == 'J' ||
  276. pSysConfig->ModelName[7 + idx] == 'K' ||
  277. pSysConfig->ModelName[7 + idx] == 'O' ||
  278. pSysConfig->ModelName[7 + idx] == 'S' ||
  279. pSysConfig->ModelName[7 + idx] == 'L') {
  280. chademo++;
  281. count++;
  282. } else if (pSysConfig->ModelName[7 + idx] == 'G' ||
  283. pSysConfig->ModelName[7 + idx] == 'B' ||
  284. pSysConfig->ModelName[7 + idx] == 'A' ||
  285. pSysConfig->ModelName[7 + idx] == 'H') {
  286. gb++;
  287. count++;
  288. } else if (pSysConfig->ModelName[7 + idx] == 'U' ||
  289. pSysConfig->ModelName[7 + idx] == 'V' ||
  290. pSysConfig->ModelName[7 + idx] == 'F' ||
  291. pSysConfig->ModelName[7 + idx] == 'E' ||
  292. pSysConfig->ModelName[7 + idx] == 'T' ||
  293. pSysConfig->ModelName[7 + idx] == 'D' ||
  294. pSysConfig->ModelName[7 + idx] == 'Y' ||
  295. pSysConfig->ModelName[7 + idx] == 'Z' ||
  296. pSysConfig->ModelName[7 + idx] == 'I' ||
  297. pSysConfig->ModelName[7 + idx] == 'Q') {
  298. ccs++;
  299. count++;
  300. }
  301. }
  302. if (count == 1) {
  303. if (chademo > 0) {
  304. pSysInfo->CsuRootFsFwRev[7] = '1';
  305. } else if (ccs > 0) {
  306. pSysInfo->CsuRootFsFwRev[7] = '2';
  307. } else if (gb > 0) {
  308. pSysInfo->CsuRootFsFwRev[7] = '3';
  309. }
  310. } else {
  311. if (chademo > 0 && ccs > 0) {
  312. pSysInfo->CsuRootFsFwRev[7] = '4';
  313. } else if (chademo > 0 && gb > 0) {
  314. pSysInfo->CsuRootFsFwRev[7] = '5';
  315. } else if (ccs > 0 && gb > 0) {
  316. pSysInfo->CsuRootFsFwRev[7] = '6';
  317. }
  318. }
  319. // Get network option from model name
  320. switch (pSysConfig->ModelName[10]) {
  321. case 'B':
  322. case 'U':
  323. //Blue tooth
  324. pSysInfo->CsuRootFsFwRev[9] = '3';
  325. break;
  326. case 'W':
  327. // WIFI
  328. pSysInfo->CsuRootFsFwRev[9] = '1';
  329. break;
  330. case 'T':
  331. // 3G/4G
  332. pSysInfo->CsuRootFsFwRev[9] = '2';
  333. break;
  334. case 'D': //DS60-120 add
  335. pSysInfo->CsuRootFsFwRev[9] = '5';
  336. break;
  337. default:
  338. // LAN
  339. pSysInfo->CsuRootFsFwRev[9] = '0';
  340. break;
  341. }
  342. // Get rating power from model name
  343. memcpy(&pSysInfo->CsuRootFsFwRev[10], &pSysConfig->ModelName[4], 0x03);
  344. // Get IEC or UL
  345. char _buf[3] = {0};
  346. memcpy(_buf, &pSysConfig->ModelName[2], 2);
  347. if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
  348. pSysInfo->ChargerType = _CHARGER_TYPE_IEC;
  349. log_info("IEC model");
  350. } else if (strcmp(_buf, "WU") == EQUAL) {
  351. pSysInfo->ChargerType = _CHARGER_TYPE_UL;
  352. log_info("UL model");
  353. }
  354. }
  355. bool isCharging(uint8_t status)
  356. {
  357. if ((status >= S_REASSIGN_CHECK && status <= S_CHARGING) ||
  358. status == S_CCS_PRECHARGE_ST0 || status == S_CCS_PRECHARGE_ST1 ) {
  359. return TRUE;
  360. }
  361. return FALSE;
  362. }
  363. static void checkGunOTPState(uint8_t gunIndex)
  364. {
  365. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  366. //log_info("OTP:%d OTPR%d",pSysInfo->OTPTemp,pSysInfo->OTPTempR);
  367. //水冷機溫度檢測
  368. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  369. if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
  370. // 單水冷機
  371. // Chiller OTP
  372. if (pDcChargingInfo->ChillerTemp == UNDEFINED_TEMP) {
  373. // 溫度為255時判斷Sensor fail
  374. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  375. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  376. } else {
  377. //判斷OTP
  378. if ((ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[0] != UNDEFINED_TEMP) ||
  379. (ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[1] != UNDEFINED_TEMP)) {
  380. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  381. RecordAlarmCode(gunIndex, "012323");
  382. } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR &&
  383. ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
  384. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  385. }
  386. //判斷Tube OTP
  387. if ((ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[2] != UNDEFINED_TEMP)||
  388. (ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[3] != UNDEFINED_TEMP)) {
  389. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
  390. RecordAlarmCode(gunIndex, "012332");
  391. } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR &&
  392. ShmDcCommonData->SystemTemp[3] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
  393. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  394. }
  395. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  396. }
  397. } else {
  398. // 雙水冷機
  399. if (pDcChargingInfo->ChillerTemp == UNDEFINED_TEMP) {
  400. // 溫度為255時判斷Sensor fail
  401. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  402. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  403. } else {
  404. //判斷OTP
  405. if (ShmDcCommonData->SystemTemp[gunIndex*2] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[gunIndex*2] != UNDEFINED_TEMP) {
  406. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  407. RecordAlarmCode(gunIndex, "012323");
  408. } else if (ShmDcCommonData->SystemTemp[gunIndex*2] != 0 && ShmDcCommonData->SystemTemp[gunIndex*2] < pSysInfo->OTPTempR) {
  409. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  410. }
  411. if (ShmDcCommonData->SystemTemp[gunIndex*2+1] >= pSysInfo->OTPTemp && ShmDcCommonData->SystemTemp[gunIndex*2+1] != UNDEFINED_TEMP) {
  412. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
  413. RecordAlarmCode(gunIndex, "012332");
  414. } else if (ShmDcCommonData->SystemTemp[gunIndex*2+1] != 0 && ShmDcCommonData->SystemTemp[gunIndex*2+1] < pSysInfo->OTPTempR) {
  415. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
  416. }
  417. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  418. }
  419. }
  420. if (pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES) {
  421. RecordAlarmCode(gunIndex, "011037");
  422. }
  423. }
  424. switch (pDcChargingInfo->Type) {
  425. case _Type_Chademo:
  426. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  427. if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
  428. RecordAlarmCode(gunIndex, "012229");
  429. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
  430. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  431. pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
  432. //ResetChargerAlarmCode(gunIndex, "012229");
  433. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  434. }
  435. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  436. } else {
  437. // 沒接上 Sensor or 異常
  438. //RecordAlarmCode(gunIndex, "011018");
  439. //ResetChargerAlarmCode(gunIndex, "012229");
  440. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  441. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
  442. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail == NO) {
  443. if (((gunIndex == 0) &&
  444. (strncmp((char *)&pSysConfig->ModelName[7], "J", 1) != 0)) ||
  445. ((gunIndex == 1) &&
  446. ((strncmp((char *)&pSysConfig->ModelName[9], "J", 1) != 0) ))) {
  447. log_info("Gun%d TempSensor Fail",gunIndex);
  448. }
  449. }
  450. if ((gunIndex == 0) &&
  451. (strncmp((char *)&pSysConfig->ModelName[7], "J", 1) == 0)) {
  452. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  453. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  454. } else if ((gunIndex == 1) &&
  455. ((strncmp((char *)&pSysConfig->ModelName[9], "J", 1) == 0) )) {
  456. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  457. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  458. }
  459. }
  460. break;
  461. case _Type_CCS_2:
  462. // CCS 不管甚麼輸出都會有槍溫偵測!!~
  463. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  464. //ResetChargerAlarmCode(gunIndex, "011019");
  465. if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
  466. RecordAlarmCode(gunIndex, "012230");
  467. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
  468. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  469. pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
  470. //ResetChargerAlarmCode(gunIndex, "012230");
  471. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  472. }
  473. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
  474. //ResetChargerAlarmCode(gunIndex, "011019");
  475. } else {
  476. // 沒接上 Sensor or 異常
  477. //RecordAlarmCode(gunIndex, "011019");
  478. //ResetChargerAlarmCode(gunIndex, "012230");
  479. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  480. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail == NO) {
  481. log_info("Gun%d TempSensor Fail",gunIndex);
  482. }
  483. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
  484. }
  485. break;
  486. case _Type_GB:
  487. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  488. if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
  489. RecordAlarmCode(gunIndex, "012231");
  490. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
  491. } else if (pDcChargingInfo->ConnectorTemp != 0 &&
  492. pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
  493. //ResetChargerAlarmCode(gunIndex, "012231");
  494. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  495. }
  496. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
  497. } else {
  498. // 沒接上 Sensor or 異常
  499. //RecordAlarmCode(gunIndex, "011020");
  500. //ResetChargerAlarmCode(gunIndex, "012231");
  501. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  502. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
  503. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail == NO) {
  504. log_info("Gun%d TempSensor Fail",gunIndex);
  505. }
  506. }
  507. break;
  508. }
  509. }
  510. static void collectError(uint8_t gunIndex)
  511. {
  512. gEvBoardErr.GunErrMessage |= ShmDcCommonData->ConnectErrList[gunIndex].GunErrMessage;
  513. gChillerTempErr.TempErrMsg |= ShmDcCommonData->ChillerTempErr[gunIndex].TempErrMsg;
  514. }
  515. static void checkGBTAlarmState(uint8_t gunType)
  516. {
  517. // GFD Trip
  518. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  519. pAlarmCode->AlarmEvents.bits.GbGfdTrip = YES;
  520. } else {
  521. pAlarmCode->AlarmEvents.bits.GbGfdTrip = NO;
  522. }
  523. // UVP
  524. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  525. pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = YES;
  526. } else {
  527. pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = NO;
  528. }
  529. // OTP
  530. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  531. pAlarmCode->AlarmEvents.bits.GbConnectorOTP = YES;
  532. } else {
  533. pAlarmCode->AlarmEvents.bits.GbConnectorOTP = NO;
  534. }
  535. // OVP
  536. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  537. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
  538. } else {
  539. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  540. }
  541. // GFD Warning
  542. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  543. pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = YES;
  544. } else {
  545. pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = NO;
  546. }
  547. // Relay Welding
  548. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  549. pFaultCode->FaultEvents.bits.GbOutputRelayWelding = YES;
  550. } else {
  551. pFaultCode->FaultEvents.bits.GbOutputRelayWelding = NO;
  552. }
  553. // Relay Driving
  554. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  555. pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = YES;
  556. } else {
  557. pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = NO;
  558. }
  559. // Connect temp Sensor broken
  560. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  561. pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = YES;
  562. } else {
  563. pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = NO;
  564. }
  565. }
  566. static void checkCCSAlarmState(uint8_t gunType)
  567. {
  568. // GFD Trip
  569. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  570. pAlarmCode->AlarmEvents.bits.CcsGfdTrip = YES;
  571. } else {
  572. pAlarmCode->AlarmEvents.bits.CcsGfdTrip = NO;
  573. }
  574. // UVP
  575. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  576. pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES;
  577. } else {
  578. pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = NO;
  579. }
  580. // OTP
  581. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  582. pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = YES;
  583. } else {
  584. pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = NO;
  585. }
  586. // OVP
  587. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  588. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
  589. } else {
  590. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  591. }
  592. // GFD Warning
  593. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  594. pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = YES;
  595. } else {
  596. pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = NO;
  597. }
  598. // Relay Welding
  599. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  600. pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = YES;
  601. } else {
  602. pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = NO;
  603. }
  604. // Relay Driving
  605. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  606. pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
  607. } else {
  608. pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
  609. }
  610. // Connect temp Sensor broken
  611. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  612. pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
  613. } else {
  614. pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
  615. }
  616. }
  617. static void checkChaDeMoAlarmState(uint8_t gunType)
  618. {
  619. // GFD Trip
  620. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  621. pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = YES;
  622. } else {
  623. pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = NO;
  624. }
  625. // UVP
  626. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  627. pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = YES;
  628. } else {
  629. pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = NO;
  630. }
  631. // OTP
  632. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  633. pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = YES;
  634. } else {
  635. pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = NO;
  636. }
  637. // OVP
  638. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  639. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
  640. } else {
  641. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  642. }
  643. // GFD Warning
  644. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  645. pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = YES;
  646. } else {
  647. pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = NO;
  648. }
  649. // Relay Welding
  650. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  651. pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = YES;
  652. } else {
  653. pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = NO;
  654. }
  655. // Relay Driving
  656. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  657. pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
  658. } else {
  659. pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
  660. }
  661. // Connect temp Sensor broken
  662. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  663. pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
  664. } else {
  665. pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
  666. }
  667. }
  668. static void checkChillerAlarmState(void)
  669. {
  670. if (DetectBitValue(gChillerTempErr.TempErrMsg, 0)) {
  671. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = YES;
  672. } else {
  673. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = NO;
  674. }
  675. if (DetectBitValue(gChillerTempErr.TempErrMsg, 1)) {
  676. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = YES;
  677. } else {
  678. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = NO;
  679. }
  680. #if 0
  681. //uint8_t gunIndex = 0;
  682. //for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  683. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  684. if (ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP == YES) {
  685. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = YES;
  686. //log_info("SystemChillerOTP = %d", pAlarmCode->AlarmEvents.bits.SystemChillerOTP);
  687. return ABNORMAL;
  688. } else {
  689. pAlarmCode->AlarmEvents.bits.SystemChillerOTP = NO;
  690. }
  691. if (ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail == YES) {
  692. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = YES;
  693. return ABNORMAL;
  694. } else {
  695. pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = NO;
  696. }
  697. //}
  698. //
  699. return NORMAL;
  700. #endif //0
  701. }
  702. static void checkEvBoardAlarmState(uint8_t gunType)
  703. {
  704. switch (gunType) {
  705. case _Type_Chademo:
  706. checkChaDeMoAlarmState(gunType);
  707. break;
  708. case _Type_CCS_2:
  709. checkCCSAlarmState(gunType);
  710. break;
  711. case _Type_GB:
  712. checkGBTAlarmState(gunType);
  713. break;
  714. }
  715. }
  716. unsigned long GetTimeoutValue(struct timeval _sour_time)
  717. {
  718. struct timeval _end_time;
  719. gettimeofday(&_end_time, NULL);
  720. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  721. }
  722. int DiffTimeb(struct timeb ST, struct timeb ET)
  723. {
  724. //return milli-second
  725. unsigned int StartTime, StopTime;
  726. StartTime = (unsigned int)ST.time;
  727. StopTime = (unsigned int)ET.time;
  728. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  729. return (StopTime - StartTime);
  730. }
  731. bool CheckTimeOut(struct timeb ST)
  732. {
  733. struct timeb ET;
  734. unsigned int StartTime, StopTime;
  735. ftime(&ET);
  736. StartTime = (unsigned int) ST.time;
  737. StopTime = (unsigned int) ET.time;
  738. return (StopTime > StartTime) ? YES : NO;
  739. }
  740. void setChargerMode(uint8_t gunIndex, uint8_t mode)
  741. {
  742. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  743. pDcChargingInfo->SystemStatus = mode;
  744. if (mode == S_FAULT) {
  745. UpdateErrorCodeToOcpp(gunIndex);
  746. }
  747. }
  748. long long DiffTimebWithNow(struct timeb ST)
  749. {
  750. //return milli-second
  751. struct timeb ET;
  752. long long StartTime, StopTime;
  753. ftime(&ET);
  754. StartTime = (long long)ST.time;
  755. StopTime = (long long)ET.time;
  756. return ((StopTime - StartTime) * 1000) + (ET.millitm - ST.millitm);
  757. }
  758. //==========================================
  759. // Log
  760. //==========================================
  761. void CheckFwSlotStatusLog(void)
  762. {
  763. if (bd0_1_status == 0 && bd0_2_status == 1) {
  764. log_info("Connector 1 : Chademo");
  765. } else if (bd0_1_status == 1 && bd0_2_status == 0) {
  766. log_info("Connector 1 : CCS");
  767. } else if (bd0_1_status == 1 && bd0_2_status == 1) {
  768. log_info("Connector 1 : GB");
  769. }
  770. if (bd1_1_status == 0 && bd1_2_status == 1) {
  771. log_info("Connector 2 : Chademo");
  772. } else if (bd1_1_status == 1 && bd1_2_status == 0) {
  773. log_info("Connector 2 : CCS");
  774. } else if (bd1_1_status == 1 && bd1_2_status == 1) {
  775. log_info("Connector 2 : GB");
  776. }
  777. }
  778. void CheckHwSlotStatusLog(uint8_t index)
  779. {
  780. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  781. if (pDcChargingInfo->Type == _Type_Chademo) {
  782. log_info("Hw check : Connector %d, Type : Chademo, Evboard_id = %d ",
  783. index, pDcChargingInfo->Evboard_id);
  784. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  785. log_info("Hw check : Connector %d, Type : CCS, Evboard_id = %d ",
  786. index, pDcChargingInfo->Evboard_id);
  787. } else if (pDcChargingInfo->Type == _Type_GB) {
  788. log_info("Hw check : Connector %d, Type : GB, Evboard_id = %d ",
  789. index, pDcChargingInfo->Evboard_id);
  790. }
  791. }
  792. //=================================
  793. // LCM Page
  794. //=================================
  795. void ChangeLcmByIndex(uint8_t page_index)
  796. {
  797. if (pSysWarning->Level != WARN_LV_ER ||
  798. page_index == _LCM_COMPLETE ||
  799. page_index == _LCM_FIX
  800. ) {
  801. pSysInfo->PageIndex = page_index;
  802. }
  803. }
  804. //======================================================
  805. // Peripheral initial
  806. //======================================================
  807. void InitGPIO()
  808. {
  809. /*****************0~3, 4 bank, bank x 32+ num*********************/
  810. /***************************************************************/
  811. /*************** GPIO 0 ***************************************/
  812. /***************************************************************/
  813. /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/
  814. system("echo 22 > /sys/class/gpio/export");
  815. system("echo \"in\" > /sys/class/gpio/gpio22/direction");
  816. /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/
  817. system("echo 23 > /sys/class/gpio/export");
  818. system("echo \"in\" > /sys/class/gpio/gpio23/direction");
  819. /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/
  820. system("echo 26 > /sys/class/gpio/export");
  821. system("echo \"out\" > /sys/class/gpio/gpio26/direction");
  822. system("echo 1 > /sys/class/gpio/gpio26/value");
  823. /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/
  824. system("echo 27 > /sys/class/gpio/export");
  825. system("echo \"in\" > /sys/class/gpio/gpio27/direction");
  826. /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
  827. system("echo 29 > /sys/class/gpio/export");
  828. system("echo \"in\" > /sys/class/gpio/gpio29/direction");
  829. /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/
  830. system("echo 19 > /sys/class/gpio/export");
  831. system("echo \"out\" > /sys/class/gpio/gpio19/direction");
  832. system("echo 1 > /sys/class/gpio/gpio19/value");
  833. /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/
  834. system("echo 20 > /sys/class/gpio/export");
  835. system("echo \"in\" > /sys/class/gpio/gpio20/direction");
  836. /***************************************************************/
  837. /*************** GPIO 1 ***************************************/
  838. /***************************************************************/
  839. /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/
  840. system("echo 44 > /sys/class/gpio/export");
  841. system("echo \"in\" > /sys/class/gpio/gpio44/direction");
  842. /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/
  843. system("echo 45 > /sys/class/gpio/export");
  844. system("echo \"in\" > /sys/class/gpio/gpio45/direction");
  845. /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/
  846. system("echo 46 > /sys/class/gpio/export");
  847. system("echo \"out\" > /sys/class/gpio/gpio46/direction");
  848. system("echo 0 > /sys/class/gpio/gpio46/value");
  849. /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/
  850. system("echo 47 > /sys/class/gpio/export");
  851. system("echo \"in\" > /sys/class/gpio/gpio47/direction");
  852. /***************************************************************/
  853. /*************** GPIO 2 ***************************************/
  854. /***************************************************************/
  855. /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
  856. system("echo 89 > /sys/class/gpio/export");
  857. system("echo \"out\" > /sys/class/gpio/gpio89/direction");
  858. system("echo 1 > /sys/class/gpio/gpio89/value");
  859. /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
  860. system("echo 87 > /sys/class/gpio/export");
  861. system("echo \"out\" > /sys/class/gpio/gpio87/direction");
  862. system("echo 0 > /sys/class/gpio/gpio87/value");
  863. /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/
  864. system("echo 88 > /sys/class/gpio/export");
  865. system("echo \"in\" > /sys/class/gpio/gpio88/direction");
  866. /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/
  867. system("echo 86 > /sys/class/gpio/export");
  868. system("echo \"in\" > /sys/class/gpio/gpio86/direction");
  869. /***************************************************************/
  870. /*************** GPIO 3 ***************************************/
  871. /***************************************************************/
  872. /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
  873. system("echo 111 > /sys/class/gpio/export");
  874. system("echo \"in\" > /sys/class/gpio/gpio111/direction");
  875. /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
  876. system("echo 114 > /sys/class/gpio/export");
  877. system("echo \"in\" > /sys/class/gpio/gpio114/direction");
  878. /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
  879. system("echo 113 > /sys/class/gpio/export");
  880. system("echo \"in\" > /sys/class/gpio/gpio113/direction");
  881. /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
  882. system("echo 110 > /sys/class/gpio/export");
  883. system("echo \"out\" > /sys/class/gpio/gpio110/direction");
  884. system("echo 0 > /sys/class/gpio/gpio110/value");
  885. /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
  886. system("echo 115 > /sys/class/gpio/export");
  887. system("echo \"out\" > /sys/class/gpio/gpio115/direction");
  888. system("echo 0 > /sys/class/gpio/gpio115/value");
  889. /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
  890. system("echo 112 > /sys/class/gpio/export");
  891. system("echo \"out\" > /sys/class/gpio/gpio112/direction");
  892. system("echo 1 > /sys/class/gpio/gpio112/value");
  893. /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
  894. system("echo 116 > /sys/class/gpio/export");
  895. system("echo \"out\" > /sys/class/gpio/gpio116/direction");
  896. system("echo 0 > /sys/class/gpio/gpio116/value");
  897. /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
  898. system("echo 103 > /sys/class/gpio/export");
  899. system("echo \"out\" > /sys/class/gpio/gpio103/direction");
  900. system("echo 0 > /sys/class/gpio/gpio103/value");
  901. /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
  902. system("echo 104 > /sys/class/gpio/export");
  903. system("echo \"out\" > /sys/class/gpio/gpio104/direction");
  904. system("echo 0 > /sys/class/gpio/gpio104/value");
  905. log_info("Initial GPIO OK");
  906. }
  907. int LoadSysConfigAndInfo()
  908. {
  909. int fd, wrd;
  910. unsigned char *buf;
  911. unsigned int ChkSum, ChkSumOrg;
  912. if ((buf = malloc(MtdBlockSize)) == NULL) {
  913. log_error("malloc buffer NG,rebooting..");
  914. if (pAlarmCode != NULL) {
  915. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  916. }
  917. sleep(5);
  918. system("reboot -f");
  919. sleep(5);
  920. system("reboot -f");
  921. }
  922. memset(buf, 0, MtdBlockSize);
  923. //================================================
  924. // Load configuration from mtdblock10
  925. //================================================
  926. system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
  927. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  928. if (fd < 0) {
  929. free(buf);
  930. log_error("open mtdblock10 NG,rebooting..");
  931. if (pAlarmCode != NULL) {
  932. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  933. }
  934. sleep(5);
  935. system("reboot -f");
  936. sleep(5);
  937. system("reboot -f");
  938. }
  939. wrd = read(fd, buf, MtdBlockSize);
  940. close(fd);
  941. if (wrd < MtdBlockSize) {
  942. free(buf);
  943. log_error("read SysConfigData data NG,rebooting..");
  944. if (pAlarmCode != NULL) {
  945. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  946. }
  947. sleep(5);
  948. system("reboot -f");
  949. sleep(5);
  950. system("reboot -f");
  951. }
  952. ChkSum = 0;
  953. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  954. ChkSum += buf[wrd];
  955. }
  956. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  957. memcpy(&pSysConfig->ModelName, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), ARRAY_SIZE(pSysConfig->ModelName));
  958. memcpy(&pSysConfig->SerialNumber, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), ARRAY_SIZE(pSysConfig->SerialNumber));
  959. //================================================
  960. // Load configuration from mtdblock11
  961. //================================================
  962. if (ChkSum != ChkSumOrg) {
  963. log_error("Primary SysConfigData checksum NG, read backup");
  964. system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
  965. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  966. if (fd < 0) {
  967. free(buf);
  968. log_error("open mtdblock11 (backup) NG,rebooting..");
  969. if (pAlarmCode != NULL) {
  970. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  971. }
  972. sleep(5);
  973. system("reboot -f");
  974. sleep(5);
  975. system("reboot -f");
  976. }
  977. memset(buf, 0, MtdBlockSize);
  978. wrd = read(fd, buf, MtdBlockSize);
  979. close(fd);
  980. if (wrd < MtdBlockSize) {
  981. free(buf);
  982. log_error("read backup SysConfigData data NG,rebooting..");
  983. if (pAlarmCode != NULL) {
  984. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  985. }
  986. sleep(5);
  987. system("reboot -f");
  988. sleep(5);
  989. system("reboot -f");
  990. }
  991. ChkSum = 0;
  992. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  993. ChkSum += buf[wrd];
  994. }
  995. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  996. //================================================
  997. // Load configuration from mtdblock12 (Factory default)
  998. //================================================
  999. if (ChkSum != ChkSumOrg) {
  1000. log_warn("backup SysConfigData checksum NG, read Factory default");
  1001. system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
  1002. fd = open("/mnt/EvseConfig.bin", O_RDWR);
  1003. if (fd < 0) {
  1004. log_error("open mtdblock12 (Factory default) NG,rebooting..");
  1005. free(buf);
  1006. if (pAlarmCode != NULL) {
  1007. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  1008. }
  1009. sleep(5);
  1010. system("reboot -f");
  1011. sleep(5);
  1012. system("reboot -f");
  1013. }
  1014. memset(buf, 0, MtdBlockSize);
  1015. wrd = read(fd, buf, MtdBlockSize);
  1016. close(fd);
  1017. if (wrd < MtdBlockSize) {
  1018. log_error("read factory default SysConfigData data NG,rebooting..");
  1019. free(buf);
  1020. if (pAlarmCode != NULL) {
  1021. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  1022. }
  1023. sleep(5);
  1024. system("reboot -f");
  1025. sleep(5);
  1026. system("reboot -f");
  1027. }
  1028. ChkSum = 0;
  1029. for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
  1030. ChkSum += buf[wrd];
  1031. }
  1032. memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
  1033. memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), &pSysConfig->ModelName, ARRAY_SIZE(pSysConfig->ModelName));
  1034. memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), &pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
  1035. if (ChkSum != ChkSumOrg) {
  1036. log_warn("factory default SysConfigData checksum NG, restore factory default");
  1037. free(buf);
  1038. system("cd /root;./FactoryConfig -m");
  1039. system("rm -f /Storage/OCPP/OCPPConfiguration");
  1040. system("sync");
  1041. sleep(5);
  1042. system("reboot -f");
  1043. sleep(5);
  1044. system("reboot -f");
  1045. return FAIL;
  1046. }
  1047. }
  1048. }
  1049. //load OK
  1050. memcpy(pSysConfig, buf, sizeof(struct SysConfigData));
  1051. free(buf);
  1052. system("rm -f /mnt/EvseConfig.bin");
  1053. // SysConfig in flash is empty (0xffffffff)
  1054. if ((strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) ||
  1055. (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) ||
  1056. (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) ||
  1057. (pSysConfig->Eth0Interface.EthDhcpClient == 0xff)) {
  1058. if (strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) {
  1059. memset(pSysConfig->ModelName, 0x00, ARRAY_SIZE(pSysConfig->ModelName));
  1060. }
  1061. if (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) {
  1062. memset(pSysConfig->SerialNumber, 0x00, ARRAY_SIZE(pSysConfig->SerialNumber));
  1063. }
  1064. if (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) {
  1065. memset(pSysConfig->SystemId, 0x00, ARRAY_SIZE(pSysConfig->SystemId));
  1066. }
  1067. if (pSysConfig->Eth0Interface.EthDhcpClient == 0xff) {
  1068. log_info("Ethernet dhcp config is null.");
  1069. }
  1070. if (strlen((char *)pSysConfig->ModelName) == 0x00) {
  1071. log_info("Model name over length.");
  1072. }
  1073. if (strlen((char *)pSysConfig->SerialNumber) == 0x00) {
  1074. log_info("Model serial number over length.");
  1075. }
  1076. if (strlen((char *)pSysConfig->SystemId) == 0x00) {
  1077. log_info("SystemId over length.");
  1078. }
  1079. system("cd /root;./FactoryConfig -m");
  1080. sleep(3);
  1081. system("/usr/bin/run_evse_restart.sh");
  1082. }
  1083. //log_info("Load SysConfigData OK");
  1084. return PASS;
  1085. }
  1086. int Initialization(void)
  1087. {
  1088. uint8_t count = 0;
  1089. uint8_t pinOut[2] = {116, 115};
  1090. // 初始化卡號驗證的 Flag
  1091. ClearAuthorizedFlag();
  1092. for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  1093. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  1094. // 初始化插槍驗證的 Flag
  1095. ClearDetectPluginFlag(count);
  1096. pDcChargingInfo->RemoteStartFlag = NO;
  1097. if (pDcChargingInfo->Type == _Type_Chademo) {
  1098. gpio_set_value(pinOut[count], 0x00);
  1099. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1100. } else if (pDcChargingInfo->Type == _Type_GB) {
  1101. gpio_set_value(pinOut[count], 0x00);
  1102. ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1103. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1104. //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
  1105. if (pSysConfig->TotalConnectorCount == 1) {
  1106. gpio_set_value(pinOut[1], 0x01);
  1107. } else {
  1108. gpio_set_value(pinOut[count], 0x01);
  1109. }
  1110. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = NO;
  1111. //}
  1112. }
  1113. strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
  1114. }
  1115. for (count = 0; count < pSysConfig->AcConnectorCount; count++) {
  1116. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
  1117. pAcChargingInfo->RemoteStartFlag = NO;
  1118. if (pAcChargingInfo->Type == _Type_AC) {
  1119. pAcChargingInfo->SelfTest_Comp = NO;
  1120. strcpy((char *)ShmOCPP16Data->StatusNotification[count + pSysConfig->TotalConnectorCount].ErrorCode, "NoError");
  1121. }
  1122. }
  1123. return PASS;
  1124. }
  1125. bool InitialSystemDefaultConfig()
  1126. {
  1127. bool result = true;
  1128. LoadSysConfigAndInfo();
  1129. InitGPIO();
  1130. InitEthernet();
  1131. GetMacAddress();
  1132. // system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
  1133. // sleep(3);
  1134. // system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
  1135. // sleep(1);
  1136. // system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
  1137. return result;
  1138. }
  1139. //顯示自檢錯誤原因,觸發對應的flag
  1140. bool DisplaySelfTestFailReason()
  1141. {
  1142. bool result = false;
  1143. uint8_t index = 0;
  1144. // RB、FB、407、EV 小板中有些板子無回應
  1145. if (ShmRelayModuleData->SelfTest_Comp == NO) {
  1146. pAlarmCode->AlarmEvents.bits.RelayboardStestFail = true;
  1147. }
  1148. if (ShmFanModuleData->SelfTest_Comp == NO) {
  1149. pAlarmCode->AlarmEvents.bits.FanboardStestFail = true;
  1150. }
  1151. if (ShmPrimaryMcuData->SelfTest_Comp == NO) {
  1152. pAlarmCode->AlarmEvents.bits.PrimaryStestFail = true;
  1153. }
  1154. if (ShmLedModuleData->SelfTest_Comp == NO) {
  1155. pAlarmCode->AlarmEvents.bits.LedboardStestFail = true;
  1156. }
  1157. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  1158. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1159. if (pDcChargingInfo->Type == _Type_Chademo) {
  1160. if (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1161. pAlarmCode->AlarmEvents.bits.ChademoboardStestFail = true;
  1162. }
  1163. } else if (pDcChargingInfo->Type == _Type_GB) {
  1164. if (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1165. pAlarmCode->AlarmEvents.bits.GbtboardStestFail = true;
  1166. }
  1167. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1168. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  1169. if (ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
  1170. pAlarmCode->AlarmEvents.bits.CCSboardStestFail = true;
  1171. }
  1172. }
  1173. }
  1174. }
  1175. for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
  1176. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
  1177. // 先借 GBT 顯示
  1178. if (pAcChargingInfo->SelfTest_Comp == NO) {
  1179. pAlarmCode->AlarmEvents.bits.AcConnectorStestFail = true;
  1180. }
  1181. }
  1182. if (pSysInfo->AcContactorStatus == NO) {
  1183. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1184. // AC Contact 未搭上
  1185. pAlarmCode->AlarmEvents.bits.AcContactStestFail = true;
  1186. result = true;
  1187. #endif // !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1188. } else if (ShmPsuData->SystemAvailablePower <= 0 &&
  1189. ShmPsuData->SystemAvailableCurrent <= 0) {
  1190. // PSU 通訊問題
  1191. pAlarmCode->AlarmEvents.bits.PsuModuleStestFail = true;
  1192. result = true;
  1193. }
  1194. return result;
  1195. }
  1196. #if 0 //not use
  1197. int StoreUsrConfigData(struct SysConfigData *UsrData)
  1198. {
  1199. int result = PASS;
  1200. int fd, wrd;
  1201. unsigned int i, Chk;
  1202. uint8_t *ptr, *BufTmp;
  1203. Chk = 0;
  1204. ptr = (uint8_t *)UsrData;
  1205. if ((BufTmp = malloc(MtdBlockSize)) != NULL) {
  1206. memset(BufTmp, 0, MtdBlockSize);
  1207. memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
  1208. for (i = 0; i < MtdBlockSize - 4; i++) {
  1209. Chk += *(ptr + i);
  1210. }
  1211. memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
  1212. fd = open("/dev/mtdblock10", O_RDWR);
  1213. if (fd > 0) {
  1214. wrd = write(fd, BufTmp, MtdBlockSize);
  1215. close(fd);
  1216. if (wrd >= MtdBlockSize) {
  1217. fd = open("/dev/mtdblock11", O_RDWR);
  1218. if (fd > 0) {
  1219. wrd = write(fd, BufTmp, MtdBlockSize);
  1220. close(fd);
  1221. if (wrd < MtdBlockSize) {
  1222. log_error("write /dev/mtdblock11(backup) NG");
  1223. result = FAIL;
  1224. }
  1225. } else {
  1226. log_error("open /dev/mtdblock11(backup) NG");
  1227. result = FAIL;
  1228. }
  1229. } else {
  1230. log_error("write /dev/mtdblock10 NG");
  1231. result = FAIL;
  1232. }
  1233. } else {
  1234. log_error("open /dev/mtdblock10 NG");
  1235. result = FAIL;
  1236. }
  1237. } else {
  1238. log_error("alloc BlockSize NG");
  1239. result = FAIL;
  1240. }
  1241. if (BufTmp != NULL) {
  1242. free(BufTmp);
  1243. }
  1244. return result;
  1245. }
  1246. #endif //0
  1247. //===============================================
  1248. // Common Detect Chk - Stop Charging ?
  1249. //===============================================
  1250. int isEvBoardStopChargeFlag(uint8_t gunIndex)
  1251. {
  1252. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1253. //printf("StopChargeFlag = %d", chargingInfo[gunIndex]->StopChargeFlag);
  1254. return pDcChargingInfo->StopChargeFlag;
  1255. }
  1256. bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
  1257. {
  1258. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1259. return pDcChargingInfo->NormalStopChargeFlag;
  1260. }
  1261. //===============================================
  1262. // 掃描插槍狀況
  1263. //===============================================
  1264. void ClearDetectPluginFlag(int gunIndex)
  1265. {
  1266. if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
  1267. return;
  1268. ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
  1269. //DS60-120 add
  1270. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1271. if (pDcChargingInfo->RemoteStartFlag == YES) {
  1272. pDcChargingInfo->RemoteStartFlag = NO;
  1273. }
  1274. if (pSysInfo->OrderCharging != NO_DEFINE) {
  1275. pSysInfo->OrderCharging = NO_DEFINE;
  1276. }
  1277. }
  1278. void DetectPluginStart(int gunIndex)
  1279. {
  1280. //pSysInfo->WaitForPlugit = YES;
  1281. if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
  1282. return;
  1283. ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
  1284. log_info("Gun%d start detect plug in",gunIndex);
  1285. }
  1286. bool isDetectPlugin(int gunIndex)
  1287. {
  1288. if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
  1289. return false;
  1290. if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
  1291. return true;
  1292. }
  1293. /*
  1294. if (pSysInfo->WaitForPlugit == YES) {
  1295. return true;
  1296. }
  1297. */
  1298. return false;
  1299. }
  1300. //===============================================
  1301. // Common Detect Chk - Chademo
  1302. //===============================================
  1303. bool isEvGunLocked_chademo(uint8_t gunIndex)
  1304. {
  1305. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1306. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1307. }
  1308. bool isEvContactorWelding_chademo(uint8_t gunIndex)
  1309. {
  1310. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1311. return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 3);
  1312. }
  1313. bool isEvStopReq_chademo(uint8_t gunIndex)
  1314. {
  1315. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1316. return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 4);
  1317. }
  1318. bool isEvStopCharging_chademo(uint8_t gunIndex)
  1319. {
  1320. if (isEvGunLocked_chademo(gunIndex) == NO) {
  1321. // 無鎖槍 = 停止
  1322. //log_info("gun locked none (%d) ", gunIndex);
  1323. return YES;
  1324. }
  1325. return NO;
  1326. }
  1327. uint8_t isPrechargeStatus_chademo(uint8_t gunIndex)
  1328. {
  1329. uint8_t result = 0x00;
  1330. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1331. result = ShmCHAdeMOData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
  1332. return result;
  1333. }
  1334. //===============================================
  1335. // Common Detect Chk - GB
  1336. //===============================================
  1337. bool isEvGunLocked_gb(uint8_t gunIndex)
  1338. {
  1339. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1340. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1341. }
  1342. bool isEvStopCharging_gb(uint8_t gunIndex)
  1343. {
  1344. if (isEvGunLocked_gb(gunIndex) == NO) {
  1345. // 無鎖槍 = 停止
  1346. //log_info("gun locked none. ");
  1347. return YES;
  1348. }
  1349. return NO;
  1350. }
  1351. uint8_t isPrechargeStatus_gb(uint8_t gunIndex)
  1352. {
  1353. uint8_t result = 0x00;
  1354. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1355. result = ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
  1356. return result;
  1357. }
  1358. //===============================================
  1359. // Common Detect Chk - CCS
  1360. //===============================================
  1361. bool isEvGunLocked_ccs(uint8_t gunIndex)
  1362. {
  1363. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1364. return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
  1365. }
  1366. uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
  1367. {
  1368. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1369. return ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;;
  1370. }
  1371. bool isEvStopCharging_ccs(uint8_t gunIndex)
  1372. {
  1373. if (isEvGunLocked_ccs(gunIndex) == NO) {
  1374. // 無鎖槍 = 停止
  1375. //log_info("gun locked none. ");
  1376. return YES;
  1377. }
  1378. return NO;
  1379. }
  1380. //===============================================
  1381. // Callback
  1382. //===============================================
  1383. void DisplayChargingInfo()
  1384. {
  1385. uint8_t i = 0;
  1386. log_info("*********** DisplayChargingInfo *********** ");
  1387. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1388. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1389. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  1390. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  1391. ChangeGunSelectByIndex(i);
  1392. if (CheckDispenserGeneration() < _DISPENSER_GENERATION_3_5) {
  1393. systemPageRestoreInit();
  1394. }
  1395. return;
  1396. }
  1397. }
  1398. if (pSysConfig->AcConnectorCount > 0 &&
  1399. pSysInfo->CurGunSelectedByAc == NO_DEFINE)
  1400. {
  1401. pAcChargingInfo = (struct ChargingInfoData*)GetAcChargingInfoData(0);
  1402. if (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
  1403. pAcChargingInfo->SystemStatus <= S_COMPLETE)
  1404. {
  1405. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  1406. }
  1407. }
  1408. usleep(50000);
  1409. systemPageRestoreInit();
  1410. }
  1411. void _AutoReturnTimeout(int gunIndex)
  1412. {
  1413. log_info("*********** _AutoReturnTimeout(%d) *********** ", pSysInfo->SystemPage);
  1414. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  1415. if (pSysInfo->SystemPage == _LCM_WAIT_FOR_PLUG) {
  1416. if (pDcChargingInfo->RemoteStartFlag) {
  1417. ClearDetectPluginFlag(gunIndex);
  1418. } else {
  1419. ClearDetectPluginFlag(0);
  1420. ClearDetectPluginFlag(1);
  1421. }
  1422. } else if (pSysInfo->SystemPage == _LCM_AUTHORIZ_COMP) {
  1423. if (pDcChargingInfo->RemoteStartFlag) {
  1424. DetectPluginStart(gunIndex);
  1425. } else {
  1426. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  1427. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  1428. if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
  1429. DetectPluginStart(gunIndex);
  1430. } else {
  1431. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
  1432. if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
  1433. DetectPluginStart(LEFT_GUN_NUM);
  1434. if (pSysConfig->TotalConnectorCount > 1) {
  1435. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
  1436. if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
  1437. DetectPluginStart(RIGHT_GUN_NUM);
  1438. }
  1439. pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
  1440. }
  1441. }
  1442. } else if (pSysInfo->SystemPage == _LCM_AUTHORIZ_FAIL) {
  1443. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  1444. ClearDetectPluginFlag(gunIndex);
  1445. } else {
  1446. ClearDetectPluginFlag(LEFT_GUN_NUM);
  1447. ClearDetectPluginFlag(RIGHT_GUN_NUM);
  1448. }
  1449. systemPageRestoreInit();
  1450. ClearAuthorizedFlag();
  1451. }
  1452. usleep(50000);
  1453. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  1454. systemPageRestoreInit();
  1455. }
  1456. }
  1457. void _SelfTestTimeout(void)
  1458. {
  1459. if (pSysInfo->BootingStatus != BOOT_COMPLETE) {
  1460. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  1461. setChargerMode(gunIndex, MODE_MAINTAIN);
  1462. }
  1463. }
  1464. ShmPsuData->Work_Step = _NO_WORKING;
  1465. pSysInfo->SelfTestSeq = _STEST_FAIL;
  1466. log_info("Self test timeout. ");
  1467. //sleep(3);
  1468. //system("/usr/bin/run_evse_restart.sh");
  1469. }
  1470. void _AuthorizedTimeout(void)
  1471. {
  1472. if (IsAuthorizingMode()) {
  1473. log_info("*********** _AuthorizedTimeout *********** ");
  1474. //isCardScan = false;
  1475. SetIsCardScan(false);
  1476. pSysInfo->SystemPage = _LCM_AUTHORIZ_FAIL;
  1477. //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
  1478. strcpy((char *)pSysConfig->UserId, "");
  1479. ClearAuthorizedFlag();
  1480. }
  1481. }
  1482. void _DetectPlugInTimeout(int gunIndex)
  1483. {
  1484. if (gunIndex == pSysInfo->CurGunSelected) {
  1485. ShmDcCommonData->LcmPage = _PAGE_PLUGIN_TIMEOUT;
  1486. }
  1487. strcpy((char *)pSysConfig->UserId, "");
  1488. uint8_t is_remote = NO;
  1489. int i;
  1490. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1491. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  1492. if (pDcChargingInfo->RemoteStartFlag) {
  1493. //此停止為remote start停止
  1494. is_remote = YES;
  1495. break;
  1496. }
  1497. }
  1498. if (is_remote) {
  1499. // Remote start進入充電
  1500. log_info("Clear Gun%d Remote start detect plugin flag",gunIndex);
  1501. StopGunInfoTimeoutDet(gunIndex);
  1502. ClearDetectPluginFlag(gunIndex);
  1503. } else {
  1504. // 刷卡進入充電
  1505. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  1506. log_info("Clear Gun%d RFID detect plugin flag", gunIndex);
  1507. ClearDetectPluginFlag(gunIndex);
  1508. StopGunInfoTimeoutDet(gunIndex);
  1509. } else {
  1510. log_info("Clear All Gun RFID detect plugin flag");
  1511. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1512. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  1513. if (!pDcChargingInfo->RemoteStartFlag) {
  1514. ClearDetectPluginFlag(i);
  1515. StopGunInfoTimeoutDet(i);
  1516. }
  1517. }
  1518. }
  1519. }
  1520. sleep(1); //等待DoComm回報插槍訊號給主櫃
  1521. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  1522. if (pSysInfo->SystemPage == _LCM_WAIT_FOR_PLUG)
  1523. changeLcmPage(_LCM_IDLE);
  1524. } else {
  1525. systemPageRestoreInit();
  1526. }
  1527. #if defined DD360Audi
  1528. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1529. setChargerMode(gunIndex, S_TERMINATING);
  1530. #elif DD360 || DD360Combox
  1531. setChargerMode(gunIndex, S_IDLE);
  1532. #endif
  1533. }
  1534. void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
  1535. {
  1536. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1537. if (pDcChargingInfo->Type == _Type_Chademo) {
  1538. if (!isEvGunLocked_chademo(gunIndex)) {
  1539. log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********");
  1540. }
  1541. } else if (pDcChargingInfo->Type == _Type_GB) {
  1542. if (!isEvGunLocked_ccs(gunIndex)) {
  1543. log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********");
  1544. }
  1545. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  1546. if (!isEvGunLocked_ccs(gunIndex)) {
  1547. log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********");
  1548. }
  1549. }
  1550. ChargingTerminalProcess(gunIndex);
  1551. _AutoReturnTimeout(gunIndex);
  1552. }
  1553. void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
  1554. {
  1555. log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********");
  1556. //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
  1557. {
  1558. #if defined DD360Audi
  1559. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1560. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1561. #elif DD360 || DD360Combox
  1562. setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
  1563. #endif
  1564. _AutoReturnTimeout(gunIndex);
  1565. }
  1566. }
  1567. void _PrepareTimeout(uint8_t gunIndex)
  1568. {
  1569. log_info("*********** _PrepareTimeout ***********");
  1570. #if defined DD360Audi
  1571. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1572. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1573. #elif DD360 || DD360Combox
  1574. setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
  1575. #endif
  1576. pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
  1577. _AutoReturnTimeout(gunIndex);
  1578. }
  1579. void _CcsPrechargeTimeout(uint8_t gunIndex)
  1580. {
  1581. log_info("*********** _CcsPrechargeTimeout ***********");
  1582. #if defined DD360Audi
  1583. //pSysInfo->SystemPage = _LCM_COMPLETE;
  1584. setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
  1585. #elif DD360 || DD360Combox
  1586. setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
  1587. pSysInfo->SystemPage = _LCM_COMPLETE;
  1588. return;
  1589. #endif
  1590. }
  1591. //===============================================
  1592. // 取得卡號與卡號驗證
  1593. //===============================================
  1594. void AuthorizingStart(void)
  1595. {
  1596. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
  1597. pSysInfo->AuthorizeFlag = YES;
  1598. }
  1599. void ClearAuthorizedFlag(void)
  1600. {
  1601. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
  1602. pSysInfo->AuthorizeFlag = NO;
  1603. }
  1604. bool isAuthorizedComplete(void)
  1605. {
  1606. if (pSysInfo->AuthorizeFlag == YES) {
  1607. return false;
  1608. }
  1609. return true;
  1610. }
  1611. bool IsAuthorizingMode()
  1612. {
  1613. if (pSysInfo->AuthorizeFlag == NO) {
  1614. return false;
  1615. }
  1616. return true;
  1617. }
  1618. //===============================================
  1619. // 紀錄 Alarm Code
  1620. //===============================================
  1621. void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
  1622. {
  1623. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1624. if (strcmp(code, "012234") == EQUAL) {
  1625. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  1626. } else if (strcmp(code, "012235") == EQUAL) {
  1627. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  1628. } else if (strcmp(code, "012236") == EQUAL) {
  1629. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  1630. } else if (strcmp(code, "012288") == EQUAL) {
  1631. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
  1632. } else if (strcmp(code, "012289") == EQUAL) {
  1633. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
  1634. } else if (strcmp(code, "012290") == EQUAL) {
  1635. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
  1636. } else if (strcmp(code, "012229") == EQUAL) {
  1637. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
  1638. } else if (strcmp(code, "012230") == EQUAL) {
  1639. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
  1640. } else if (strcmp(code, "012231") == EQUAL) {
  1641. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
  1642. } else if (strcmp(code, "011011") == EQUAL) {
  1643. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  1644. } else if (strcmp(code, "011013") == EQUAL) {
  1645. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  1646. } else if (strcmp(code, "011015") == EQUAL) {
  1647. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  1648. } else if (strcmp(code, "011012") == EQUAL) {
  1649. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  1650. } else if (strcmp(code, "011014") == EQUAL) {
  1651. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  1652. } else if (strcmp(code, "011016") == EQUAL) {
  1653. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  1654. } else if (strcmp(code, "011018") == EQUAL) {
  1655. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
  1656. } else if (strcmp(code, "011019") == EQUAL) {
  1657. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
  1658. } else if (strcmp(code, "011020") == EQUAL) {
  1659. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
  1660. } else if (strcmp(code, "012323") == EQUAL) {
  1661. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
  1662. } else if (strcmp(code, "011038") == EQUAL) {
  1663. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
  1664. }
  1665. //if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) != EQUAL) {
  1666. // if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip == NO &&
  1667. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip == NO &&
  1668. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip == NO &&
  1669. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail == NO &&
  1670. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail == NO &&
  1671. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail == NO &&
  1672. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP == NO &&
  1673. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO &&
  1674. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP == NO &&
  1675. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault == NO &&
  1676. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault == NO &&
  1677. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault == NO &&
  1678. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault == NO &&
  1679. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault == NO &&
  1680. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault == NO &&
  1681. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail == NO &&
  1682. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail == NO &&
  1683. // ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail == NO &&
  1684. // ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP == NO &&
  1685. // ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail == NO
  1686. // ) {
  1687. // strncpy((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1688. // }
  1689. //}
  1690. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012229", 6) == EQUAL ||
  1691. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012230", 6) == EQUAL ||
  1692. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012231", 6) == EQUAL ||
  1693. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011011", 6) == EQUAL ||
  1694. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011013", 6) == EQUAL ||
  1695. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011015", 6) == EQUAL ||
  1696. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011012", 6) == EQUAL ||
  1697. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011014", 6) == EQUAL ||
  1698. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011016", 6) == EQUAL ||
  1699. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011018", 6) == EQUAL ||
  1700. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011019", 6) == EQUAL ||
  1701. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011020", 6) == EQUAL ||
  1702. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012323", 6) == EQUAL ||
  1703. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL) {
  1704. strncpy((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1705. }
  1706. }
  1707. void RecordAlarmCode(uint8_t gunIndex, char *code)
  1708. {
  1709. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1710. if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1711. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
  1712. {
  1713. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1714. memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
  1715. }
  1716. if (pDcChargingInfo->StopChargeFlag == NO)
  1717. {
  1718. pDcChargingInfo->StopChargeFlag = YES;
  1719. }
  1720. }
  1721. #if 0
  1722. if (strcmp(code, "012234") == EQUAL) {
  1723. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
  1724. } else if (strcmp(code, "012235") == EQUAL) {
  1725. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  1726. } else if (strcmp(code, "012236") == EQUAL) {
  1727. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
  1728. } else if (strcmp(code, "012288") == EQUAL) {
  1729. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES;
  1730. } else if (strcmp(code, "012289") == EQUAL) {
  1731. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES;
  1732. } else if (strcmp(code, "012290") == EQUAL) {
  1733. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES;
  1734. } else if (strcmp(code, "012229") == EQUAL) {
  1735. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
  1736. } else if (strcmp(code, "012230") == EQUAL) {
  1737. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
  1738. } else if (strcmp(code, "012231") == EQUAL) {
  1739. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
  1740. } else if (strcmp(code, "012296") == EQUAL) {
  1741. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
  1742. } else if (strcmp(code, "012297") == EQUAL) {
  1743. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
  1744. } else if (strcmp(code, "012298") == EQUAL) {
  1745. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
  1746. } else if (strcmp(code, "011011") == EQUAL) {
  1747. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
  1748. } else if (strcmp(code, "011013") == EQUAL) {
  1749. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
  1750. } else if (strcmp(code, "011015") == EQUAL) {
  1751. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
  1752. } else if (strcmp(code, "011012") == EQUAL) {
  1753. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
  1754. } else if (strcmp(code, "011014") == EQUAL) {
  1755. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
  1756. } else if (strcmp(code, "011016") == EQUAL) {
  1757. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
  1758. } else if (strcmp(code, "011018") == EQUAL) {
  1759. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
  1760. } else if (strcmp(code, "011019") == EQUAL) {
  1761. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
  1762. } else if (strcmp(code, "011020") == EQUAL) {
  1763. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
  1764. } else if (strcmp(code, "012323") == EQUAL) {
  1765. if ((gunIndex == 0) &&
  1766. ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
  1767. (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
  1768. ) {
  1769. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  1770. } else if ((gunIndex == 1) &&
  1771. ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
  1772. (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
  1773. ) {
  1774. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
  1775. }
  1776. } else if (strcmp(code, "011038") == EQUAL) {
  1777. if ((gunIndex == 0) &&
  1778. ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
  1779. (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
  1780. ) {
  1781. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  1782. } else if ((gunIndex == 1) &&
  1783. ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
  1784. (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
  1785. ) {
  1786. ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
  1787. }
  1788. }
  1789. #endif
  1790. }
  1791. void ReleaseAlarmCode(uint8_t gunIndex)
  1792. {
  1793. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  1794. //if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1795. // return;
  1796. //}
  1797. #if 0
  1798. // 回 idle 後主要清除 GFD Trip、UVP、OVP、GFD Warning
  1799. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012251", 6) == EQUAL ||
  1800. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012252", 6) == EQUAL) {
  1801. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1802. }
  1803. #endif
  1804. switch (pDcChargingInfo->Type) {
  1805. case _Type_Chademo:
  1806. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  1807. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
  1808. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
  1809. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  1810. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  1811. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  1812. #if 0
  1813. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012234", 6) == EQUAL ||
  1814. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012289", 6) == EQUAL ||
  1815. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012217", 6) == EQUAL ||
  1816. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012296", 6) == EQUAL) {
  1817. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1818. }
  1819. #endif
  1820. break;
  1821. case _Type_CCS_2:
  1822. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  1823. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
  1824. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
  1825. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  1826. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  1827. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  1828. #if 0
  1829. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012235", 6) == EQUAL ||
  1830. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012288", 6) == EQUAL ||
  1831. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012219", 6) == EQUAL ||
  1832. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012297", 6) == EQUAL) {
  1833. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1834. }
  1835. #endif
  1836. break;
  1837. case _Type_GB:
  1838. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  1839. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
  1840. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
  1841. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  1842. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  1843. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  1844. #if 0
  1845. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012236", 6) == EQUAL ||
  1846. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012290", 6) == EQUAL ||
  1847. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012221", 6) == EQUAL ||
  1848. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012298", 6) == EQUAL) {
  1849. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1850. }
  1851. #endif
  1852. break;
  1853. }
  1854. #if 0
  1855. //system alarm
  1856. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012251", 6) == EQUAL ||
  1857. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012252", 6) == EQUAL ||
  1858. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012238", 6) == EQUAL ||
  1859. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012304", 6) == EQUAL ||
  1860. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012323", 6) == EQUAL ||
  1861. strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL
  1862. ) {
  1863. memset(pDcChargingInfo->ConnectorAlarmCode, 0, sizeof(pDcChargingInfo->ConnectorAlarmCode));
  1864. }
  1865. #endif
  1866. memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
  1867. }
  1868. //===============================================
  1869. // EmergencyStop and Charging Stop
  1870. //===============================================
  1871. void ChargingTerminalProcess(uint8_t gunIndex)
  1872. {
  1873. setChargerMode(gunIndex, MODE_TERMINATING);
  1874. }
  1875. void ChargingAlarmProcess(uint8_t gunIndex)
  1876. {
  1877. UpdateErrorCodeToOcpp(gunIndex);
  1878. setChargerMode(gunIndex, MODE_ALARM);
  1879. }
  1880. void AcChargingTerminalProcess(void)
  1881. {
  1882. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  1883. pAcChargingInfo->SystemStatus = MODE_TERMINATING;
  1884. }
  1885. void StopChargingProcessByString(uint8_t level)
  1886. {
  1887. if (level > pSysWarning->Level) {
  1888. pSysWarning->Level = level;
  1889. }
  1890. }
  1891. void ReleaseChargingProcessByString(uint8_t level)
  1892. {
  1893. if (level >= pSysWarning->Level) {
  1894. pSysWarning->Level = WARN_LV_NL;
  1895. }
  1896. }
  1897. // 一般錯誤停止充電處理函式
  1898. void BoardErrOccurByString(uint8_t index, char *code)
  1899. {
  1900. uint8_t level = 1;
  1901. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  1902. if ((pDcChargingInfo->SystemStatus > S_IDLE &&
  1903. pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1904. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1905. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1906. if (strncmp(code, "023730", 6) == EQUAL &&
  1907. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == NO
  1908. ) {
  1909. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
  1910. }
  1911. ChargingTerminalProcess(index);
  1912. }
  1913. StopChargingProcessByString(level);
  1914. }
  1915. void ReleaseBoardErrOccurByString(uint8_t index, char *code)
  1916. {
  1917. bool isTrigger = false;
  1918. uint8_t level = 1;
  1919. if (strncmp(code, "023730", 6) == 0 &&
  1920. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
  1921. isTrigger = true;
  1922. pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
  1923. }
  1924. if (isTrigger) {
  1925. ReleaseChargingProcessByString(level);
  1926. }
  1927. }
  1928. // 急停狀況的停止充電處理函式
  1929. void EmcOccureByString(char *code)
  1930. {
  1931. uint8_t level = 2;
  1932. // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
  1933. // 其錯誤等級為 2
  1934. //DS60-120 remove
  1935. if (strncmp(code, "012251", 6) == EQUAL ||
  1936. strncmp(code, "012252", 6) == EQUAL ||
  1937. strncmp(code, "012304", 6) == EQUAL ||
  1938. strncmp(code, "012238", 6) == EQUAL/* ||
  1939. strncmp(code, "042251", 6) == EQUAL ||
  1940. strncmp(code, "042252", 6) == EQUAL ||
  1941. strncmp(code, "042200", 6) == EQUAL ||
  1942. strncmp(code, "042201", 6) == EQUAL ||
  1943. strncmp(code, "042202", 6) == EQUAL ||
  1944. strncmp(code, "042267", 6) == EQUAL*/)
  1945. {
  1946. for (uint8_t gun = 0; gun < pSysConfig->TotalConnectorCount; gun++) {
  1947. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  1948. //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
  1949. if ((pDcChargingInfo->SystemStatus > S_IDLE &&
  1950. pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  1951. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1952. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  1953. //ChargingTerminalProcess(gun);
  1954. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1955. memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
  1956. }
  1957. pDcChargingInfo->StopChargeFlag = DISPENSER_STOP_CHARGING;
  1958. ChargingAlarmProcess(gun);
  1959. } else if (pDcChargingInfo->SystemStatus == S_IDLE) {
  1960. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  1961. memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
  1962. }
  1963. }
  1964. }
  1965. StopChargingProcessByString(level);
  1966. InformOcppErrOccur(4);
  1967. }
  1968. }
  1969. void ReleaseEmsOccureByString(uint8_t index, char *code)
  1970. {
  1971. bool isTrigger = false;
  1972. uint8_t level = 2;
  1973. if (strncmp(code, "042251", 6) == 0 ) {
  1974. isTrigger = true;
  1975. } else if (strncmp(code, "012251", 6) == 0 &&
  1976. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
  1977. isTrigger = true;
  1978. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
  1979. } else if (strncmp(code, "012252", 6) == 0 &&
  1980. pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
  1981. isTrigger = true;
  1982. pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
  1983. } else if (strncmp(code, "012237", 6) == 0 &&
  1984. pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
  1985. isTrigger = true;
  1986. pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
  1987. } else if (strncmp(code, "012238", 6) == 0 &&
  1988. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  1989. isTrigger = true;
  1990. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
  1991. } else if (strncmp(code, "012348", 6) == 0 &&
  1992. pAlarmCode->AlarmEvents.bits.ChillerAlarmFail == YES) {
  1993. isTrigger = true;
  1994. pAlarmCode->AlarmEvents.bits.ChillerAlarmFail = NO;
  1995. }
  1996. if (isTrigger) {
  1997. ReleaseChargingProcessByString(level);
  1998. InformOcppErrOccur(6);
  1999. }
  2000. }
  2001. static void checkOvpState(uint8_t gunIndex, uint8_t gunType)
  2002. {
  2003. switch(gunType)
  2004. {
  2005. case _Type_Chademo:
  2006. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP == YES)
  2007. {
  2008. RecordAlarmCode(gunIndex, "012217");
  2009. }
  2010. break;
  2011. case _Type_CCS_2:
  2012. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP == YES)
  2013. {
  2014. RecordAlarmCode(gunIndex, "012219");
  2015. }
  2016. break;
  2017. case _Type_GB:
  2018. if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP == YES)
  2019. {
  2020. RecordAlarmCode(gunIndex, "012221");
  2021. }
  2022. break;
  2023. }
  2024. }
  2025. //===============================================
  2026. // 確認各小板偵測的錯誤狀況
  2027. //===============================================
  2028. void CheckErrorOccurStatus(uint8_t index)
  2029. {
  2030. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  2031. // RB
  2032. if (pSysConfig->PhaseLossPolicy == YES) {
  2033. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES ||
  2034. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES ||
  2035. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  2036. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  2037. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
  2038. StopChargingProcessByString(2);
  2039. InformOcppErrOccur(13);
  2040. }
  2041. //DS60-120 add -----
  2042. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  2043. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES) {
  2044. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012203", 6);
  2045. } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES) {
  2046. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012204", 6);
  2047. } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  2048. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012205", 6);
  2049. }
  2050. }
  2051. //log_info("1 CheckErrorOccurStatus");
  2052. pDcChargingInfo->StopChargeFlag = YES;
  2053. //------------------------------------------------------------------
  2054. } else {
  2055. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  2056. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2057. ReleaseChargingProcessByString(2);
  2058. InformOcppErrOccur(6);
  2059. }
  2060. }
  2061. } else {
  2062. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  2063. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2064. ReleaseChargingProcessByString(2);
  2065. InformOcppErrOccur(6);
  2066. }
  2067. }
  2068. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
  2069. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
  2070. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  2071. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  2072. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
  2073. StopChargingProcessByString(2);
  2074. InformOcppErrOccur(14);
  2075. }
  2076. //DS60-120 -----
  2077. if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
  2078. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES) {
  2079. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012200", 6);
  2080. } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES) {
  2081. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012201", 6);
  2082. } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  2083. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012202", 6);
  2084. }
  2085. }
  2086. //log_info("2 CheckErrorOccurStatus");
  2087. pDcChargingInfo->StopChargeFlag = YES;
  2088. //----------------------------------------------------------------------
  2089. } else {
  2090. if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
  2091. pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2092. ReleaseChargingProcessByString(2);
  2093. InformOcppErrOccur(6);
  2094. }
  2095. }
  2096. checkOvpState(index, pDcChargingInfo->Type);
  2097. //--------------------------------------------------------------------------
  2098. if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == 0) {
  2099. //Primary
  2100. if (pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
  2101. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012251", 6);
  2102. } else if (pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
  2103. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012252", 6);
  2104. } else if (pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  2105. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012238", 6);
  2106. } else if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
  2107. memcpy(pDcChargingInfo->ConnectorAlarmCode, "012304", 6);
  2108. }/* else if (ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectTempSensorFail) {
  2109. memcpy(pDcChargingInfo->ConnectorAlarmCode, "011018", 6);
  2110. UpdateErrorCodeToOcpp(index);
  2111. } else if (ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectTempSensorFail) {
  2112. memcpy(pDcChargingInfo->ConnectorAlarmCode, "011019", 6);
  2113. UpdateErrorCodeToOcpp(index);
  2114. } else if (ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectTempSensorFail) {
  2115. memcpy(pDcChargingInfo->ConnectorAlarmCode, "011020", 6);
  2116. UpdateErrorCodeToOcpp(index);
  2117. }*/
  2118. //Chiller temperature
  2119. //else if (pAlarmCode->AlarmEvents.bits.SystemChillerOTP == YES) {
  2120. // memcpy(pDcChargingInfo->ConnectorAlarmCode, "012323", 6);
  2121. //} else if (pFaultCode->FaultEvents.bits.ChillerTempSensorBroken == YES) {
  2122. // memcpy(pDcChargingInfo->ConnectorAlarmCode, "011038", 6);
  2123. //}
  2124. }
  2125. }
  2126. //===============================================
  2127. // 確認 GPIO 狀態
  2128. //===============================================
  2129. void gpio_set_value(unsigned int gpio, unsigned int value)
  2130. {
  2131. int fd;
  2132. char buf[MAX_BUF];
  2133. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  2134. fd = open(buf, O_WRONLY);
  2135. if (fd < 0) {
  2136. perror("gpio/set-value");
  2137. return;
  2138. }
  2139. if (value) {
  2140. write(fd, "1", 2);
  2141. } else {
  2142. write(fd, "0", 2);
  2143. }
  2144. close(fd);
  2145. }
  2146. int gpio_get_value(unsigned int gpio, unsigned int *value)
  2147. {
  2148. int fd;
  2149. char buf[MAX_BUF];
  2150. char ch;
  2151. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  2152. fd = open(buf, O_RDONLY);
  2153. if (fd < 0) {
  2154. perror("gpio/get-value");
  2155. return fd;
  2156. }
  2157. read(fd, &ch, 1);
  2158. if (ch != '0') {
  2159. *value = 1;
  2160. } else {
  2161. *value = 0;
  2162. }
  2163. close(fd);
  2164. return 0;
  2165. }
  2166. void CheckGunTypeFromHw()
  2167. {
  2168. uint8_t i = 0;
  2169. int pinIn[4] = {22, 23, 44, 45};
  2170. unsigned int gpioValue = 0;
  2171. uint8_t tmp[2] = {0};
  2172. log_info("ModelName = %s", pSysConfig->ModelName);
  2173. for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
  2174. gpio_get_value(pinIn[i], &gpioValue);
  2175. switch (pinIn[i]) {
  2176. //right slot
  2177. case 22:
  2178. bd1_1_status = gpioValue;
  2179. break;
  2180. case 23:
  2181. bd1_2_status = gpioValue;
  2182. break;
  2183. //left slot
  2184. case 44:
  2185. bd0_1_status = gpioValue;
  2186. break;
  2187. case 45:
  2188. bd0_2_status = gpioValue;
  2189. break;
  2190. }
  2191. }
  2192. //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
  2193. //CcsChargingData [0至1] 分別為 Right至Left
  2194. //model name 槍順序左至右分別為Right至Left
  2195. tmp[1] = (bd0_1_status << 4 | bd0_2_status);
  2196. tmp[0] = (bd1_1_status << 4 | bd1_2_status);
  2197. for (i = 0; i < 2; i++) {
  2198. switch (tmp[i]) {
  2199. case 0x01:
  2200. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
  2201. break;
  2202. case 0x10:
  2203. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
  2204. break;
  2205. case 0x11:
  2206. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
  2207. break;
  2208. case 0x00:
  2209. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
  2210. break;
  2211. }
  2212. }
  2213. }
  2214. void CheckGpioInStatus()
  2215. {
  2216. int i = 0;
  2217. int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
  2218. unsigned int gpioValue = 0;
  2219. for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
  2220. gpio_get_value(pinIn[i], &gpioValue);
  2221. if (gpioValue == 0x01) {
  2222. switch (pinIn[i]) {
  2223. // 小板緊急停止
  2224. case 47:
  2225. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2226. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2227. if (pDcChargingInfo->slotsIndex == 1) {
  2228. //if (pDcChargingInfo->Type == _Type_Chademo) {
  2229. // BoardErrOccurByString(i, "023730");
  2230. //} else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2231. // BoardErrOccurByString(i, "013627");
  2232. //}
  2233. break;
  2234. }
  2235. }
  2236. break;
  2237. case 27:
  2238. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2239. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2240. if (pDcChargingInfo->slotsIndex == 3) {
  2241. // if (pDcChargingInfo->Type == _Type_Chademo) {
  2242. // BoardErrOccurByString(i, "023730");
  2243. // } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2244. // BoardErrOccurByString(i, "013627");
  2245. // }
  2246. break;
  2247. }
  2248. }
  2249. break;
  2250. }
  2251. } else {
  2252. switch (pinIn[i]) {
  2253. // 小板解除緊急停止
  2254. case 47:
  2255. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2256. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2257. if (pDcChargingInfo->slotsIndex == 1) {
  2258. if (pDcChargingInfo->Type == _Type_Chademo) {
  2259. ReleaseBoardErrOccurByString(i, "023730");
  2260. // } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2261. // ReleaseBoardErrOccurByString(i, "013627");
  2262. }
  2263. break;
  2264. }
  2265. }
  2266. break;
  2267. case 27:
  2268. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2269. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2270. if (pDcChargingInfo->slotsIndex == 3) {
  2271. if (pDcChargingInfo->Type == _Type_Chademo) {
  2272. ReleaseBoardErrOccurByString(i, "023730");
  2273. //} else if (pDcChargingInfo->Type == _Type_CCS_2) {
  2274. // ReleaseBoardErrOccurByString(i, "013627");
  2275. }
  2276. break;
  2277. }
  2278. }
  2279. break;
  2280. }
  2281. }
  2282. }
  2283. }
  2284. //===============================================
  2285. // Main process
  2286. //===============================================
  2287. // 檢查 uint8_t 中某個 Bit 的值
  2288. // _byte : 欲改變的 byte
  2289. // _bit : 該 byte 的第幾個 bit
  2290. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit)
  2291. {
  2292. uint8_t mask_table[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
  2293. return ( _byte & mask_table[_bit] ) != 0x00;
  2294. }
  2295. // 設定 Byte 中某個 Bit的值
  2296. // _byte : 欲改變的 byte
  2297. // _bit : 該 byte 的第幾個 bit
  2298. // value : 修改的值為 0 or 1
  2299. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value)
  2300. {
  2301. if (value == 1) {
  2302. *_byte |= (1 << _bit);
  2303. } else if (value == 0) {
  2304. *_byte ^= (1 << _bit);
  2305. }
  2306. }
  2307. uint8_t isModeChange(uint8_t gunIndex)
  2308. {
  2309. uint8_t result = NO;
  2310. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2311. if (pDcChargingInfo->SystemStatus == pDcChargingInfo->PreviousSystemStatus) {
  2312. return result;
  2313. }
  2314. pDcChargingInfo->PreviousSystemStatus = pDcChargingInfo->SystemStatus;
  2315. ShmDcCommonData->SystemModeChange[gunIndex] = YES; //for Module_EvRxComm print temperature message
  2316. return YES;
  2317. }
  2318. static int checkSlotGpioMappingGunType(uint8_t gunIndex, uint8_t gunType)
  2319. {
  2320. uint8_t slot1 = 0, slot2 = 0;
  2321. if (gunIndex == 0) {
  2322. slot1 = bd0_1_status;
  2323. slot2 = bd0_2_status;
  2324. } else if (gunIndex == 1) {
  2325. slot1 = bd1_1_status;
  2326. slot2 = bd1_2_status;
  2327. }
  2328. log_info("slot %d gpio1 = %d, gpio2 = %d, type = %d",
  2329. gunIndex,
  2330. slot1,
  2331. slot2,
  2332. gunType);
  2333. switch (gunType) {
  2334. case _Type_Chademo:
  2335. if (slot1 != NO && slot2 != YES) {
  2336. return FAIL;
  2337. }
  2338. break;
  2339. case _Type_CCS_2:
  2340. if (slot1 != YES && slot2 != NO) {
  2341. return FAIL;
  2342. }
  2343. break;
  2344. case _Type_GB:
  2345. if (slot1 != YES && slot2 != YES) {
  2346. return FAIL;
  2347. }
  2348. break;
  2349. }
  2350. return PASS;
  2351. }
  2352. bool CheckConnectorTypeStatus(void)
  2353. {
  2354. bool result = true;
  2355. uint8_t gunIndex = 0;
  2356. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  2357. struct ChargingInfoData *pDcChargingInfo = NULL;
  2358. if (!MappingGunChargingInfo("CSU Task")) {
  2359. log_error("CheckConnectorTypeStatus MappingGunChargingInfo failed");
  2360. return false;
  2361. }
  2362. // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
  2363. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  2364. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2365. if (checkSlotGpioMappingGunType(gunIndex, pDcChargingInfo->Type) == FAIL) {
  2366. return false;
  2367. }
  2368. pDcChargingInfo->SystemStatus = S_BOOTING;
  2369. switch (gunIndex) {
  2370. case 0:
  2371. if (pSysConfig->TotalConnectorCount == 1) {
  2372. if ((bd0_1_status == YES || bd0_2_status == YES) &&
  2373. (bd1_1_status == NO && bd1_2_status == NO)) {
  2374. pDcChargingInfo->Evboard_id = 0x01;
  2375. }
  2376. if ((bd0_1_status == NO && bd0_2_status == NO) &&
  2377. (bd1_1_status == YES || bd1_2_status == YES)
  2378. ) {
  2379. pDcChargingInfo->Evboard_id = 0x02;
  2380. }
  2381. break;
  2382. }
  2383. pDcChargingInfo->Evboard_id = 0x01;
  2384. break;
  2385. case 1:
  2386. pDcChargingInfo->Evboard_id = 0x02;
  2387. break;
  2388. }
  2389. CheckHwSlotStatusLog(gunIndex);
  2390. if (pDcChargingInfo->Evboard_id == 0x00) {
  2391. return false;
  2392. }
  2393. }
  2394. //AdjustChargerCurrent();
  2395. return result;
  2396. }
  2397. int SpawnTask(void)
  2398. {
  2399. if(SIMULATION)
  2400. system("/root/simulation &");
  2401. sleep(2);
  2402. system("/root/Module_EventLogging &");
  2403. system("/root/Module_PrimaryComm &");
  2404. system("/root/Module_EvComm &");
  2405. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  2406. system("/root/Module_LcmControl &");
  2407. } else {
  2408. system("/root/Module_LcmWistronControl &");
  2409. }
  2410. system("/root/Module_InternalComm &");
  2411. system("/root/Module_ProduceUtils &");
  2412. system("/root/Module_UpdateFW &");
  2413. if (pSysConfig->ModelName[3] == 'P')
  2414. system("/root/Module_DcMeter &");
  2415. system("/root/Module_DoComm &");
  2416. return PASS;
  2417. }
  2418. void KillTask(void)
  2419. {
  2420. ChangeLcmByIndex(_LCM_FIX);
  2421. system("killall Module_EventLogging");
  2422. system("killall Module_PrimaryComm");
  2423. system("killall Module_EvComm");
  2424. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  2425. system("killall Module_LcmControl");
  2426. } else {
  2427. system("killall Module_LcmWistronControl");
  2428. }
  2429. system("killall Module_InternalComm");
  2430. system("killall Module_UpdateFW");
  2431. system("killall Module_ChkSysTask");
  2432. if (pSysConfig->ModelName[3] == 'P')
  2433. system("killall Module_DcMeter");
  2434. //system("killall Module_DoComm");
  2435. return ;
  2436. }
  2437. void KillTaskExceptPrimary(void)
  2438. {
  2439. ChangeLcmByIndex(_LCM_FIX);
  2440. system("killall Module_EvComm");
  2441. system("killall Module_InternalComm");
  2442. if (pSysConfig->ModelName[3] == 'P')
  2443. system("killall Module_DcMeter");
  2444. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2445. return;
  2446. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2447. system("killall Module_PsuComm");
  2448. system("killall Module_4g &");
  2449. system("killall Module_Wifi &");
  2450. }
  2451. void KillAllTask(void)
  2452. {
  2453. ChangeLcmByIndex(_LCM_FIX);
  2454. system("killall Module_EventLogging");
  2455. system("killall Module_PrimaryComm");
  2456. system("killall Module_EvComm");
  2457. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  2458. system("killall Module_LcmControl");
  2459. } else {
  2460. system("killall Module_LcmWistronControl");
  2461. }
  2462. system("killall Module_InternalComm");
  2463. system("killall Module_UpdateFW");
  2464. system("killall Module_ChkSysTask");
  2465. if (pSysConfig->ModelName[3] == 'P')
  2466. system("killall Module_DcMeter");
  2467. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2468. system("killall Module_DoComm");
  2469. return ;
  2470. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2471. system("killall Module_PsuComm");
  2472. system("killall OcppBackend &");
  2473. system("killall Module_4g &");
  2474. system("killall Module_Wifi &");
  2475. }
  2476. void StartSystemTimeoutDet(uint8_t flag)
  2477. {
  2478. if (pSysInfo->SystemTimeoutFlag != flag) {
  2479. GetClockTime(&pSysInfo->SystemTimeoutTimer);
  2480. //log_info("Start System Timeout: %d",flag);
  2481. }
  2482. pSysInfo->SystemTimeoutFlag = flag;
  2483. }
  2484. void StopSystemTimeoutDet(void)
  2485. {
  2486. GetClockTime(&pSysInfo->SystemTimeoutTimer);
  2487. pSysInfo->SystemTimeoutFlag = Timeout_None;
  2488. }
  2489. void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
  2490. {
  2491. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2492. if (gunIndex < pSysConfig->TotalConnectorCount) {
  2493. if (pDcChargingInfo->TimeoutFlag != flag) {
  2494. GetClockTime(&pDcChargingInfo->ConnectorTimeout);
  2495. //log_info("Start Gun%d Info timeout: %d",gunIndex,flag);
  2496. }
  2497. pDcChargingInfo->TimeoutFlag = flag;
  2498. }
  2499. }
  2500. void checkLanguagePageTimeout(void)
  2501. {
  2502. int is_idle = TRUE;
  2503. for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  2504. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  2505. if (pDcChargingInfo->SystemStatus != S_IDLE)
  2506. is_idle = FALSE;
  2507. }
  2508. if (is_idle)
  2509. pSysInfo->SystemPage = _PAGE_SELECTGUN;
  2510. else
  2511. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  2512. }
  2513. void StopGunInfoTimeoutDet(uint8_t gunIndex)
  2514. {
  2515. if (gunIndex < pSysConfig->TotalConnectorCount) {
  2516. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2517. pDcChargingInfo->TimeoutFlag = Timeout_None;
  2518. }
  2519. }
  2520. void CheckConnectionTimeout(void)
  2521. {
  2522. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2523. if (ShmSelectGunInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
  2524. _connectionTimeout = ShmSelectGunInfo->RemoteSetup.ConnectionTimeout;
  2525. } else {
  2526. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2527. }
  2528. return;
  2529. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2530. if (system("pidof -s OcppBackend > /dev/null") != 0) {
  2531. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2532. } else {
  2533. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
  2534. _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  2535. if (_connectionTimeout <= 0) {
  2536. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2537. }
  2538. } else {
  2539. _connectionTimeout = CONN_PLUG_TIME_OUT;
  2540. }
  2541. }
  2542. }
  2543. void _evccidlinktimeout(uint8_t gunIndex)
  2544. {
  2545. log_info("Getting EVCCID Timeout");
  2546. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2547. pDcChargingInfo->isEVCCIDVerify = true;
  2548. StopGunInfoTimeoutDet(gunIndex);
  2549. destroySelGun(pSysInfo->CurGunSelected);
  2550. connectorPageRestoreIdle();
  2551. }
  2552. void CreateTimeoutFork(void)
  2553. {
  2554. pid_t timeoutPid;
  2555. timeoutPid = fork();
  2556. if (timeoutPid == 0) {
  2557. GetClockTime(&_cmdSubPriority_time);
  2558. CheckConnectionTimeout();
  2559. log_info("Timeout Fork Child's PID is %d", getpid());
  2560. while (1) {
  2561. if ((GetClockTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
  2562. CheckConnectionTimeout();
  2563. GetClockTime(&_cmdSubPriority_time);
  2564. }
  2565. if ((GetClockTimeoutValue(ShmDcCommonData->_touch_time) / 1000) > 200) {
  2566. ShmDcCommonData->isTouch = FALSE;
  2567. }
  2568. //log_info("Timeout ***********SystemTimeoutFlag = %d(%d) ********",pSysInfo->SystemTimeoutFlag,
  2569. // GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL);
  2570. // 系統
  2571. switch (pSysInfo->SystemTimeoutFlag) {
  2572. case Timeout_SelftestChk:
  2573. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
  2574. _SelfTestTimeout();
  2575. StopSystemTimeoutDet();
  2576. destroySelGun(DESTROY_ALL_SEL); //jerry add
  2577. }
  2578. break;
  2579. case Timeout_ShowStopPage:
  2580. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SHOW_STOP_TIMEOUT) {
  2581. log_error("Timeout_ShowStopPage");
  2582. StopSystemTimeoutDet();
  2583. pSysInfo->SystemPage = _PAGE_SELECTGUN;
  2584. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  2585. if (pDcChargingInfo->SystemStatus == S_AUTHORIZING || pDcChargingInfo->SystemStatus == S_COMPLETE ||
  2586. pDcChargingInfo->SystemStatus == S_ALARM) {
  2587. setChargerMode(pSysInfo->CurGunSelected, MODE_IDLE);
  2588. }
  2589. }
  2590. break;
  2591. case Timeout_helpPage:
  2592. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= HELP_PAGE_TIMEOUT) {
  2593. StopSystemTimeoutDet();
  2594. pSysInfo->SystemPage = ShmDcCommonData->previousPage;
  2595. }
  2596. break;
  2597. case Timeout_SettingPage:
  2598. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SETTING_PAGE_TIMEOUT) {
  2599. StopSystemTimeoutDet();
  2600. //checkLanguagePageTimeout();
  2601. ShmDcCommonData->LcmPage = ShmDcCommonData->previousPage;
  2602. }
  2603. break;
  2604. case Timeout_Authorizing:
  2605. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
  2606. log_error("Authorizing Timeout");
  2607. _AuthorizedTimeout();
  2608. StopSystemTimeoutDet();
  2609. destroySelGun(pSysInfo->CurGunSelected);
  2610. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2611. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2612. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2613. log_error("Author timeout restart DoComm");
  2614. system("killall Module_DoComm");
  2615. //sleep(1);
  2616. //system("/root/Module_DoComm &");
  2617. }
  2618. }
  2619. break;
  2620. case Timeout_WaitBalance:
  2621. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= BALANCE_TIMEOUT) {
  2622. log_error("Wait Balance timeout");
  2623. _AuthorizedTimeout();
  2624. StopSystemTimeoutDet();
  2625. destroySelGun(pSysInfo->CurGunSelected);
  2626. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2627. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2628. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2629. log_error("Author timeout restart DoComm");
  2630. system("killall Module_DoComm");
  2631. }
  2632. }
  2633. break;
  2634. case Timeout_VerifyFail:
  2635. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
  2636. _AutoReturnTimeout(pSysInfo->CurGunSelected);
  2637. StopSystemTimeoutDet();
  2638. destroySelGun(pSysInfo->CurGunSelected);
  2639. if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
  2640. ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
  2641. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  2642. log_error("Author timeout restart DoComm");
  2643. system("killall Module_DoComm");
  2644. //sleep(1);
  2645. //system("/root/Module_DoComm &");
  2646. }
  2647. }
  2648. break;
  2649. case Timeout_VerifyComp:
  2650. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
  2651. _AutoReturnTimeout(pSysInfo->CurGunSelected);
  2652. StopSystemTimeoutDet();
  2653. }
  2654. break;
  2655. case Timeout_ReturnToChargingGunDet:
  2656. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
  2657. #if defined DD360Audi
  2658. if (getCurLcmPage() != _LCM_PRE_CHARGE &&
  2659. getCurLcmPage() != _LCM_CHARGING &&
  2660. getCurLcmPage() != _LCM_COMPLETE) {
  2661. destroySelGun(pSysInfo->CurGunSelected); //jerry add
  2662. }
  2663. #endif //defined DD360Audi
  2664. DisplayChargingInfo();
  2665. StopSystemTimeoutDet();
  2666. }
  2667. break;
  2668. case Timeout_AuthorizingForStop:
  2669. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
  2670. strcpy((char *)pSysConfig->UserId, "");
  2671. ClearAuthorizedFlag();
  2672. StopSystemTimeoutDet();
  2673. }
  2674. break;
  2675. case Timeout_SelectGun: //Jerry add
  2676. if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
  2677. log_info("Timeout_SelectGun");
  2678. ShmDcCommonData->LcmPage = _PAGE_SELECTGUN;
  2679. StopSystemTimeoutDet();
  2680. }
  2681. break;
  2682. }
  2683. // 各槍
  2684. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  2685. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2686. //log_info("Timeout ***********Gun %d TimeoutFlag = %d(%d) ********",gunIndex,pDcChargingInfo->TimeoutFlag,
  2687. // GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL);
  2688. switch (pDcChargingInfo->TimeoutFlag) {
  2689. case Timeout_EVCCID_Link:
  2690. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= EVCCID_LINK_TIMEOUT) {
  2691. _evccidlinktimeout(gunIndex);
  2692. }
  2693. break;
  2694. case Timeout_WaitPlug:
  2695. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= _connectionTimeout) {
  2696. log_info("*********** Gun%d _DetectPlugInTimeout *********** ", gunIndex);
  2697. _DetectPlugInTimeout(gunIndex);
  2698. StopGunInfoTimeoutDet(gunIndex);
  2699. }
  2700. break;
  2701. case Timeout_Preparing:
  2702. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
  2703. _PrepareTimeout(gunIndex);
  2704. StopGunInfoTimeoutDet(gunIndex);
  2705. destroySelGun(gunIndex);
  2706. }
  2707. break;
  2708. case Timeout_EvChargingDet:
  2709. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
  2710. _DetectEvChargingEnableTimeout(gunIndex);
  2711. StopGunInfoTimeoutDet(gunIndex);
  2712. destroySelGun(gunIndex);
  2713. }
  2714. break;
  2715. case Timeout_EvseChargingDet:
  2716. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
  2717. _DetectEvseChargingEnableTimeout(gunIndex);
  2718. StopGunInfoTimeoutDet(gunIndex);
  2719. destroySelGun(gunIndex);
  2720. }
  2721. break;
  2722. case Timeout_EvseCompleteDet:
  2723. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
  2724. StopGunInfoTimeoutDet(gunIndex);
  2725. destroySelGun(gunIndex);
  2726. }
  2727. break;
  2728. case Timeout_ForCcsPrechargeDet:
  2729. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
  2730. _CcsPrechargeTimeout(gunIndex);
  2731. StopGunInfoTimeoutDet(gunIndex);
  2732. destroySelGun(gunIndex);
  2733. }
  2734. break;
  2735. case Timeout_ShowPlugFail:
  2736. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= SHOW_PLUG_FAIL_TIMEOUT) {
  2737. log_info("Timeout_ShowPlugFail");
  2738. if (gunIndex == pSysInfo->CurGunSelected)
  2739. ShmDcCommonData->LcmPage = _PAGE_SELECTGUN;
  2740. StopGunInfoTimeoutDet(gunIndex);
  2741. destroySelGun(gunIndex);
  2742. }
  2743. break;
  2744. case Timeout_ExitComplete:
  2745. if (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= EXIT_COMPLETE_TIMEOUT) {
  2746. log_info("Timeout_ExitComplete");
  2747. if (ShmDcCommonData->pGunInfo[gunIndex].ReservationStatus) {
  2748. setChargerMode(gunIndex, MODE_RESERVATION);
  2749. } else {
  2750. setChargerMode(gunIndex, MODE_IDLE);
  2751. }
  2752. StopGunInfoTimeoutDet(gunIndex);
  2753. destroySelGun(gunIndex);
  2754. #if defined DD360 || defined DD3660ComBox
  2755. if (gunIndex == pSysInfo->CurGunSelected)
  2756. connectorPageRestoreIdle();
  2757. #endif
  2758. }
  2759. break;
  2760. }
  2761. }
  2762. sleep(1);
  2763. }
  2764. }
  2765. }
  2766. void CheckFactoryConfigFunction(void)
  2767. {
  2768. char Buf[256] = {0};
  2769. if (pSysInfo->FactoryConfiguration) {
  2770. sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
  2771. pSysConfig->ModelName,
  2772. pSysConfig->SerialNumber);
  2773. system(Buf);
  2774. system("rm -f /Storage/OCPP/OCPPConfiguration");
  2775. system("sync");
  2776. sleep(5);
  2777. system("reboot -f");
  2778. sleep(5);
  2779. system("reboot -f");
  2780. }
  2781. }
  2782. //===============================================
  2783. // Check reservation date is expired
  2784. //===============================================
  2785. int isReservationExpired(uint8_t gunIndex)
  2786. {
  2787. int result = NO;
  2788. struct tm expiredDate;
  2789. struct timeb expiredTime;
  2790. if (sscanf((char *) ShmOCPP16Data->ReserveNow[gunIndex].ExpiryDate,
  2791. "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
  2792. &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
  2793. &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
  2794. expiredDate.tm_year -= 1900;
  2795. expiredDate.tm_mon -= 1;
  2796. expiredTime.time = mktime(&expiredDate);
  2797. if (!CheckTimeOut(expiredTime)) {
  2798. result = YES;
  2799. }
  2800. }
  2801. return result;
  2802. }
  2803. //===============================================
  2804. // OCPP
  2805. //===============================================
  2806. void CheckOcppStatus(void)
  2807. {
  2808. bool canReset = true;
  2809. //bool canHardReset = true; //DS60-120 add
  2810. if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
  2811. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
  2812. }
  2813. if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
  2814. if (pSysWarning->Level != WARN_LV_ER) {
  2815. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  2816. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  2817. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  2818. pDcChargingInfo->SystemStatus != S_RESERVATION &&
  2819. pDcChargingInfo->SystemStatus != S_MAINTAIN) {
  2820. canReset = false;
  2821. if (pDcChargingInfo->SystemStatus >= S_REASSIGN &&
  2822. pDcChargingInfo->SystemStatus < S_TERMINATING) {
  2823. //canHardReset = false;
  2824. ChargingTerminalProcess(_index);
  2825. //restartFlag = 1;
  2826. }
  2827. }
  2828. }
  2829. }
  2830. if (canReset) {
  2831. ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
  2832. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
  2833. if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
  2834. log_error("****** Hard Reboot ****** ");
  2835. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  2836. sleep(3);
  2837. system("reboot -f");
  2838. } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
  2839. log_error("****** Soft Reboot ****** ");
  2840. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  2841. sleep(3);
  2842. system("killall OcppBackend &");
  2843. KillAllTask();
  2844. TryCloseWatchdog();
  2845. system("/usr/bin/run_evse_restart.sh");
  2846. }
  2847. }
  2848. }
  2849. }
  2850. void OcppStartTransation(uint8_t gunIndex)
  2851. {
  2852. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  2853. return;
  2854. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  2855. uint8_t _OcppGunIndex = gunIndex;
  2856. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2857. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  2858. if (pSysConfig->AcConnectorCount == 1 && gunIndex == 1) {
  2859. _OcppGunIndex = 2;
  2860. }
  2861. if (strcmp((char *)pDcChargingInfo->StartUserId, "") == EQUAL) {
  2862. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag,
  2863. (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  2864. } else {
  2865. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag,
  2866. (char *)pDcChargingInfo->StartUserId);
  2867. }
  2868. log_info("IdTag = %s ", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  2869. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
  2870. }
  2871. void OcppStopTransation(uint8_t gunIndex)
  2872. {
  2873. uint8_t _OcppGunIndex = gunIndex;
  2874. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2875. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  2876. if (pSysConfig->AcConnectorCount == 1 && gunIndex == 1) {
  2877. _OcppGunIndex = 2;
  2878. }
  2879. if (strcmp((char *)pDcChargingInfo->StartUserId, "") == EQUAL) {
  2880. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  2881. } else {
  2882. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)pDcChargingInfo->StartUserId);
  2883. }
  2884. log_info("IdTag = %s ", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  2885. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
  2886. }
  2887. bool OcppRemoteStop(uint8_t gunIndex)
  2888. {
  2889. uint8_t acDirIndex = pSysConfig->AcConnectorCount;
  2890. // 有 AC 槍的話
  2891. if (acDirIndex > 0 && gunIndex > 0) {
  2892. gunIndex += acDirIndex;
  2893. }
  2894. bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
  2895. if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
  2896. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
  2897. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
  2898. }
  2899. return result;
  2900. }
  2901. bool WifiScheduleStop(uint8_t gunIndex)
  2902. {
  2903. bool result = false;
  2904. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2905. result = pDcChargingInfo->schedule.isTriggerStop;
  2906. pDcChargingInfo->schedule.isTriggerStop = NO;
  2907. return result;
  2908. }
  2909. void OcppRemoteStartChk()
  2910. {
  2911. if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
  2912. } else{
  2913. // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
  2914. uint8_t acDirIndex = pSysConfig->AcConnectorCount;
  2915. for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
  2916. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(ac_index);
  2917. if (!isDetectPlugin(acDirIndex)) {
  2918. if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
  2919. if (pAcChargingInfo->SystemStatus == S_IDLE ||
  2920. pAcChargingInfo->SystemStatus == S_RESERVATION) {
  2921. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  2922. pAcChargingInfo->RemoteStartFlag = YES;
  2923. pSysInfo->OrderCharging = YES;
  2924. //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
  2925. ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
  2926. DetectPluginStart(acDirIndex);
  2927. return;
  2928. }
  2929. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  2930. }
  2931. }
  2932. }
  2933. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  2934. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
  2935. if (ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq == YES) {
  2936. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2937. pDcChargingInfo->SystemStatus == S_RESERVATION) {
  2938. pDcChargingInfo->RemoteStartFlag = YES;
  2939. pSysInfo->OrderCharging = YES;
  2940. //pSysInfo->OrderCharging = gunIndex;
  2941. ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
  2942. DetectPluginStart(_index);
  2943. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  2944. setSelGunWaitToAuthor(_index);
  2945. }
  2946. }
  2947. ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
  2948. }
  2949. }
  2950. }
  2951. }
  2952. void ChkOcppStatus(uint8_t gunIndex)
  2953. {
  2954. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  2955. if (pDcChargingInfo->SystemStatus == S_IDLE &&
  2956. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
  2957. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
  2958. if (isReservationExpired(gunIndex)) {
  2959. log_info("***************ChkOcppStatus : OcppReservedStatus******************** ");
  2960. //log_error("***************ChkOcppStatus : OcppReservedStatus******************** ");
  2961. pDcChargingInfo->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
  2962. pDcChargingInfo->SystemStatus = S_RESERVATION;
  2963. }
  2964. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  2965. }
  2966. if (pDcChargingInfo->SystemStatus == S_RESERVATION &&
  2967. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
  2968. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
  2969. if (isReservationExpired(gunIndex)) {
  2970. log_info("***************ChkOcppStatus : Cancel OcppReservedStatus******************** ");
  2971. //log_error("***************ChkOcppStatus : Cancel OcppReservedStatus******************** ");
  2972. pDcChargingInfo->ReservationId = 0;
  2973. pDcChargingInfo->SystemStatus = S_IDLE;
  2974. }
  2975. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
  2976. }
  2977. if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
  2978. log_info("***************ChkOcppStatus : OcppChangeAvailability******************** ");
  2979. //log_error("***************ChkOcppStatus : OcppChangeAvailability******************** ");
  2980. ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
  2981. if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
  2982. if (isDb_ready) {
  2983. DB_Update_Operactive(gunIndex, true);
  2984. }
  2985. pDcChargingInfo->IsAvailable = YES;
  2986. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2987. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2988. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  2989. setChargerMode(gunIndex, MODE_IDLE);
  2990. }
  2991. } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
  2992. if (isDb_ready) {
  2993. DB_Update_Operactive(gunIndex, false);
  2994. }
  2995. pDcChargingInfo->IsAvailable = NO;
  2996. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2997. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2998. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  2999. setChargerMode(gunIndex, MODE_MAINTAIN);
  3000. }
  3001. }
  3002. }
  3003. if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
  3004. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
  3005. if (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
  3006. pDcChargingInfo->SystemStatus <= S_CHARGING) {
  3007. // 充電中,需停止充電
  3008. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
  3009. ChargingTerminalProcess(gunIndex);
  3010. }
  3011. strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
  3012. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
  3013. }
  3014. }
  3015. bool CheckBackendChargingTimeout(uint8_t gunIndex)
  3016. {
  3017. bool result = false;
  3018. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3019. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  3020. if (pSysConfig->MaxChargingDuration > 0) {
  3021. if (pDcChargingInfo->PresentChargedDuration > (pSysConfig->MaxChargingDuration * 60)) {
  3022. result = true;
  3023. }
  3024. }
  3025. } /*else if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  3026. // 隨插即充電的要看 offline
  3027. if (pSysConfig->OfflineMaxChargeDuration > 0) {
  3028. if (pDcChargingInfo->PresentChargedDuration > (pSysConfig->OfflineMaxChargeDuration * 60)) {
  3029. result = true;
  3030. }
  3031. }
  3032. }*/
  3033. return result;
  3034. }
  3035. bool CheckBackendChargingEnergy(uint8_t gunIndex)
  3036. {
  3037. bool result = false;
  3038. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3039. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  3040. if (pSysConfig->MaxChargingEnergy > 0) {
  3041. if (pDcChargingInfo->PresentChargedEnergy > pSysConfig->MaxChargingEnergy) {
  3042. result = true;
  3043. }
  3044. }
  3045. }/* else if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  3046. // 隨插即充電的要看 offline
  3047. if (pSysConfig->OfflineMaxChargeEnergy > 0) {
  3048. if (pDcChargingInfo->PresentChargedEnergy > (pSysConfig->OfflineMaxChargeEnergy)) {
  3049. result = true;
  3050. }
  3051. }
  3052. }*/
  3053. return result;
  3054. }
  3055. void InformOcppErrOccur(uint8_t codeType)
  3056. {
  3057. char _error[25];
  3058. switch (codeType) {
  3059. case 4:
  3060. strcpy(_error, "InternalError");
  3061. break;
  3062. case 6:
  3063. strcpy(_error, "NoError");
  3064. break;
  3065. case 7:
  3066. strcpy(_error, "OtherError");
  3067. break;
  3068. case 13:
  3069. strcpy(_error, "UnderVoltage");
  3070. break;
  3071. case 14:
  3072. strcpy(_error, "OverVoltage");
  3073. break;
  3074. }
  3075. for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  3076. strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, _error);
  3077. }
  3078. }
  3079. //===============================================
  3080. // Config process
  3081. //===============================================
  3082. void AddPlugInTimes(uint8_t gunIndex)
  3083. {
  3084. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3085. if (pDcChargingInfo->Type == _Type_Chademo) {
  3086. pSysConfig->ChademoPlugInTimes += 1;
  3087. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3088. pSysConfig->Ccs2PlugInTimes += 1;
  3089. } else if (pDcChargingInfo->Type == _Type_GB) {
  3090. pSysConfig->GbPlugInTimes += 1;
  3091. }
  3092. }
  3093. void ChangeStartOrStopDateTime(uint8_t isStart, uint8_t gunIndex)
  3094. {
  3095. char cmdBuf[32];
  3096. struct timeb csuTime;
  3097. struct tm *tmCSU;
  3098. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3099. ftime(&csuTime);
  3100. tmCSU = localtime(&csuTime.time);
  3101. sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
  3102. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  3103. tmCSU->tm_sec);
  3104. if (isStart) {
  3105. strcpy((char *)pDcChargingInfo->StartDateTime, cmdBuf);
  3106. } else {
  3107. strcpy((char *)pDcChargingInfo->StopDateTime, cmdBuf);
  3108. }
  3109. }
  3110. void ChangeGunSelectByIndex(uint8_t sel)
  3111. {
  3112. pSysInfo->CurGunSelected = sel;
  3113. pSysInfo->CurGunSelectedByAc = NO_DEFINE;
  3114. }
  3115. void CheckIsAlternatvieByModelName()
  3116. {
  3117. // 黑白機 ?
  3118. /*if (strcmp((char *)pSysConfig->ModelName, "DWWU301J0UT1PH") == EQUAL ||
  3119. strcmp((char *)pSysConfig->ModelName, "DWYE301J0ET1PH") == EQUAL ||
  3120. strcmp((char *)pSysConfig->ModelName, "DSYE301J3EW2PH") == EQUAL ||
  3121. strcmp((char *)pSysConfig->ModelName, "DWYC301J0UW1PH") == EQUAL) {
  3122. */
  3123. if (pSysConfig->ModelName[1] == 'W') { //DS60-120
  3124. // 壁掛
  3125. pSysInfo->IsAlternatvieConf = YES;
  3126. } else {
  3127. pSysInfo->IsAlternatvieConf = NO;
  3128. }
  3129. }
  3130. void StopProcessingLoop()
  3131. {
  3132. for (;;) {
  3133. CheckFactoryConfigFunction();
  3134. //CheckFwUpdateFunction();
  3135. if (pSysWarning->Level == WARN_LV_ER) {
  3136. ChkPrimaryStatus();
  3137. if (pSysWarning->Level == WARN_LV_NL) {
  3138. log_info("Soft reboot for retry self-tets (Primary). ");
  3139. KillAllTask();
  3140. sleep(3);
  3141. TryCloseWatchdog();
  3142. system("/usr/bin/run_evse_restart.sh");
  3143. return;
  3144. }
  3145. }
  3146. sleep(1);
  3147. TryFeedWatchdog();
  3148. }
  3149. }
  3150. bool IsConnectorWholeIdle()
  3151. {
  3152. bool result = true;
  3153. for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  3154. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  3155. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  3156. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  3157. result = false;
  3158. break;
  3159. }
  3160. }
  3161. for (uint8_t count = 0; count < pSysConfig->AcConnectorCount; count++) {
  3162. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
  3163. if (pAcChargingInfo->SystemStatus != S_IDLE &&
  3164. pAcChargingInfo->IsErrorOccur == NO) {
  3165. result = false;
  3166. break;
  3167. }
  3168. }
  3169. return result;
  3170. }
  3171. void ClearAlarmCodeWhenAcOff()
  3172. {
  3173. if (!pSysInfo->AcContactorStatus) {
  3174. pAlarmCode->AlarmEvents.bits.PsuNoResource = NO;
  3175. }
  3176. }
  3177. //==========================================
  3178. // Check task processing
  3179. //==========================================
  3180. void CheckTask()
  3181. {
  3182. /*+++ 20200908, vern, disable it for DD360 +++*/
  3183. #if 0
  3184. if (pSysConfig->ModelName[10] == 'T') {
  3185. if (system("pidof -s Module_4g > /dev/null") != 0) {
  3186. log_error("Module_4g not running, restart it.");
  3187. system("/root/Module_4g &");
  3188. }
  3189. } else if (pSysConfig->ModelName[10] == 'W') {
  3190. if (system("pidof -s Module_Wifi > /dev/null") != 0) {
  3191. log_error("Module_Wifi not running, restart it.");
  3192. system("/root/Module_Wifi &");
  3193. }
  3194. }
  3195. if (strcmp((char *)pSysConfig->OcppServerURL, "") != EQUAL &&
  3196. strcmp((char *)pSysConfig->ChargeBoxId, "") != EQUAL) {
  3197. if (system("pidof -s OcppBackend > /dev/null") != 0) {
  3198. log_error("OcppBackend not running, restart it.");
  3199. system("/root/OcppBackend &");
  3200. }
  3201. }
  3202. #endif //0
  3203. /*--- 20200908, vern, disable it for DD360 ---*/
  3204. /*
  3205. if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
  3206. log_error("Module_ProduceUtils not running, restart it.");
  3207. system ("/root/Module_ProduceUtils &");
  3208. }*/
  3209. }
  3210. //==========================================
  3211. // Check Smart Charging Profile
  3212. //==========================================
  3213. int GetStartScheduleTime(uint8_t *time)
  3214. {
  3215. int result = -1;
  3216. struct tm tmScheduleStart;
  3217. struct timeb tbScheduleStart;
  3218. 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)) {
  3219. tmScheduleStart.tm_year -= 1900;
  3220. tmScheduleStart.tm_mon -= 1;
  3221. tbScheduleStart.time = mktime(&tmScheduleStart);
  3222. tbScheduleStart.millitm = 0;
  3223. result = DiffTimebWithNow(tbScheduleStart) / 1000;
  3224. }
  3225. return result;
  3226. }
  3227. void CheckSmartChargeProfile(uint8_t _index)
  3228. {
  3229. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  3230. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  3231. // Get Charging Profile
  3232. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  3233. if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
  3234. ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
  3235. ) {
  3236. int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  3237. uint8_t _startCount = NO_DEFINE;
  3238. uint8_t _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
  3239. for (uint8_t _count = 0; _count < _maxCount; _count++) {
  3240. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  3241. if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
  3242. if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
  3243. ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
  3244. _startCount = _count;
  3245. }
  3246. }
  3247. }
  3248. log_info("_startCount = %d ", _startCount);
  3249. if (_startCount < _maxCount) {
  3250. //DS60-120 add
  3251. log_info("Profile Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  3252. pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
  3253. if (pDcChargingInfo->EvBatterytargetVoltage > 0 && pDcChargingInfo->PresentChargingVoltage > 0) {
  3254. pDcChargingInfo->ChargingProfileCurrent = (pDcChargingInfo->ChargingProfilePower / pDcChargingInfo->PresentChargingVoltage) * 10;
  3255. } else {
  3256. pDcChargingInfo->ChargingProfileCurrent = 0;
  3257. }
  3258. //DS60-120 remove
  3259. //log_info("*********Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  3260. //pDcChargingInfo->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
  3261. //pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * pDcChargingInfo->EvBatterytargetVoltage / 100;
  3262. //pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
  3263. // if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0)
  3264. // {
  3265. // pDcChargingInfo->ChargingProfileCurrent = pDcChargingInfo->ChargingProfilePower / (pDcChargingInfo->EvBatterytargetVoltage * 10);
  3266. // }
  3267. } else {
  3268. pDcChargingInfo->ChargingProfilePower = -1;
  3269. pDcChargingInfo->ChargingProfileCurrent = -1;
  3270. }
  3271. } else {
  3272. pDcChargingInfo->ChargingProfilePower = -1;
  3273. pDcChargingInfo->ChargingProfileCurrent = -1;
  3274. }
  3275. log_info("ChargingProfilePower = %f ", pDcChargingInfo->ChargingProfilePower);
  3276. log_info("ChargingProfileCurrent = %f ", pDcChargingInfo->ChargingProfileCurrent);
  3277. }
  3278. //
  3279. // printf("-------------Schedule------------");
  3280. // printf("index = %d ", _index);
  3281. // printf("StartSchedule = %s ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  3282. // printf("ChargingRateUnit = %s ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
  3283. // printf("----------SchedulePeriod---------");
  3284. // for (int v = 0; v < 10; v++)
  3285. // {
  3286. // printf("StartPeriod = %d ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
  3287. // printf("Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
  3288. // }
  3289. // printf("---------------------------------");
  3290. }
  3291. void ChargingProfileFlat(uint8_t _index)
  3292. {
  3293. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
  3294. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
  3295. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
  3296. }
  3297. }
  3298. }
  3299. void CheckReturnToChargingConn()
  3300. {
  3301. if ((pSysConfig->TotalConnectorCount + pSysConfig->AcConnectorCount) > 1 &&
  3302. pSysInfo->SystemPage != _LCM_AUTHORIZING &&
  3303. pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL &&
  3304. pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
  3305. pSysInfo->SystemPage != _LCM_WAIT_FOR_PLUG) {
  3306. bool isReturnTimeout = false;
  3307. for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  3308. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  3309. // 如果選的 DC 槍在充電~ 則 DC 槍不改變
  3310. if (count == pSysInfo->CurGunSelected) {
  3311. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  3312. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  3313. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  3314. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  3315. ) {
  3316. isReturnTimeout = false;
  3317. break;
  3318. }
  3319. } else if (count != pSysInfo->CurGunSelected) {
  3320. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  3321. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  3322. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  3323. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  3324. ) {
  3325. isReturnTimeout = true;
  3326. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  3327. }
  3328. }
  3329. }
  3330. if (CheckDispenserGeneration() >= _DISPENSER_GENERATION_3_5) {
  3331. if (!isReturnTimeout &&
  3332. (ShmDcCommonData->LcmPage != _PAGE_SELECT_PAY && ShmDcCommonData->LcmPage != _PAGE_LANGUAGE &&
  3333. ShmDcCommonData->LcmPage != _PAGE_SETTING && ShmDcCommonData->LcmPage != _PAGE_BACKLIGHT)) {
  3334. StopSystemTimeoutDet();
  3335. }
  3336. } else {
  3337. if (!isReturnTimeout) {
  3338. StopSystemTimeoutDet();
  3339. }
  3340. }
  3341. }
  3342. }
  3343. bool GetStartChargingByAlterMode(uint8_t _gun)
  3344. {
  3345. bool result = true;
  3346. if (pSysConfig->TotalConnectorCount == 2 &&
  3347. pSysInfo->IsAlternatvieConf == YES) {
  3348. for (uint8_t _select = 0; _select < pSysConfig->TotalConnectorCount; _select++) {
  3349. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_select);
  3350. if (_select != _gun) {
  3351. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  3352. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  3353. result = false;
  3354. break;
  3355. }
  3356. }
  3357. }
  3358. }
  3359. return result;
  3360. }
  3361. void TheEndCharging(uint8_t gunIndex)
  3362. {
  3363. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3364. ftime(&endChargingTime[gunIndex]);
  3365. if (pDcChargingInfo->PresentChargedDuration != 0) {
  3366. pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
  3367. }
  3368. pDcChargingInfo->isRemoteStart = NO;
  3369. StopGunInfoTimeoutDet(gunIndex);
  3370. StartGunInfoTimeoutDet(gunIndex, Timeout_EvseCompleteDet);
  3371. ChangeStartOrStopDateTime(NO, gunIndex);
  3372. DB_Insert_Record(gunIndex);
  3373. }
  3374. void UpdateErrorCodeToOcpp(uint8_t index)
  3375. {
  3376. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  3377. //log_info("%d = ConnectorAlarmCode = %s", index, pDcChargingInfo->ConnectorAlarmCode);
  3378. //log_info("%d = EvConnAlarmCode = %s", index, pDcChargingInfo->EvConnAlarmCode);
  3379. if (strcmp((char *)pDcChargingInfo->ConnectorAlarmCode, "") != EQUAL) {
  3380. //if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == EQUAL) {
  3381. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
  3382. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->ConnectorAlarmCode);
  3383. } else if (strcmp((char *)pDcChargingInfo->EvConnAlarmCode, "") != EQUAL) {
  3384. //} else if (strlen((char *)pDcChargingInfo->EvConnAlarmCode) == EQUAL) {
  3385. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
  3386. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->EvConnAlarmCode);
  3387. }
  3388. //log_info("Gun %d = VendorErrorCode = %s", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
  3389. }
  3390. void AdjustChargerCurrent()
  3391. {
  3392. pSysConfig->RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
  3393. // 設定的電流~ 如超過可輸出的電流,則 bypass
  3394. if (pSysConfig->RatingCurrent < pSysConfig->MaxChargingCurrent ||
  3395. pSysConfig->RatingCurrent == 0) {
  3396. pSysConfig->MaxChargingCurrent = 0;
  3397. }
  3398. log_info("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
  3399. ShmPsuData->SystemAvailablePower / 10,
  3400. ShmPsuData->SystemAvailableCurrent / 10
  3401. );
  3402. log_info("Config : ChargingPower = %d, ChargingCurrent = %d",
  3403. pSysConfig->MaxChargingPower,
  3404. pSysConfig->MaxChargingCurrent
  3405. );
  3406. }
  3407. void ResetDetAlarmStatus(uint8_t gun)
  3408. {
  3409. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  3410. if (pDcChargingInfo->Type == _Type_Chademo) {
  3411. if (pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  3412. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  3413. }
  3414. } else if (pDcChargingInfo->Type == _Type_GB) {
  3415. if (pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP == YES) {
  3416. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  3417. }
  3418. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3419. if (pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  3420. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  3421. }
  3422. }
  3423. }
  3424. char OldUseId[32] = {0};
  3425. static void autoStartCharging(uint8_t gunIndex)
  3426. {
  3427. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3428. if ( (pSysInfo->SystemPage >= _LCM_AUTHORIZING && pSysInfo->SystemPage <= _LCM_AUTHORIZ_FAIL) ||
  3429. pDcChargingInfo->isEVCCIDVerify || (strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL)) {
  3430. return;
  3431. }
  3432. if ((pDcChargingInfo->ConnectorPlugIn == YES) &&
  3433. (pDcChargingInfo->SystemStatus == S_IDLE )
  3434. ) {
  3435. if(!pSysConfig->AuthorisationMode) {
  3436. if (pSysConfig->isAuthrizeByEVCCID && !pDcChargingInfo->isEVCCIDVerify &&
  3437. pDcChargingInfo->Type == _Type_CCS_2) {
  3438. #ifdef DD360Audi
  3439. // LCM show linking pic. & timeout 2 min
  3440. if( pSysInfo->CurGunSelected == gunIndex ) {
  3441. systemPageRestoreInit();
  3442. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  3443. }
  3444. StartGunInfoTimeoutDet(gunIndex,Timeout_EVCCID_Link);
  3445. #endif
  3446. // Getting EVCCID
  3447. if( strcmp( (char *)pDcChargingInfo->EVCCID, "" ) != EQUAL ) {
  3448. log_info("Authorizing EVCCID");
  3449. StopSystemTimeoutDet();
  3450. ShmDcCommonData->LcmPage = _PAGE_SELECT_PAY;
  3451. strcpy((char *)pSysConfig->UserId, (char *)pDcChargingInfo->EVCCID);
  3452. pSysInfo->CurGunSelected = gunIndex;
  3453. ChangeGunSelectByIndex(gunIndex);
  3454. confirmSelGun(gunIndex);
  3455. pDcChargingInfo->isEVCCIDVerify = true;
  3456. ShmDcCommonData->AuthroizeType = IdTokenType_MacAddress;
  3457. //pSysInfo->SystemPage = _LCM_AUTHORIZING;
  3458. pDcChargingInfo->StartMethod = _CHARGING_START_EVCCID;
  3459. }
  3460. } else
  3461. return;
  3462. } else {
  3463. ShmDcCommonData->LcmPage = _PAGE_SELECT_PAY;
  3464. strcpy((char *)&pSysConfig->UserId, "AutoStartCharging");
  3465. pSysInfo->CurGunSelected = gunIndex;
  3466. ChangeGunSelectByIndex(gunIndex);
  3467. confirmSelGun(gunIndex);
  3468. //pSysInfo->SystemPage = _LCM_AUTHORIZING;
  3469. ShmDcCommonData->AuthroizeType = IdTokenType_NoAuthorization;
  3470. pDcChargingInfo->StartMethod = _CHARGING_START_AUTOSTART;
  3471. }
  3472. if (strcmp( (char *)pSysConfig->UserId , OldUseId ) != EQUAL) {
  3473. strcpy((char *)OldUseId, (char *)pSysConfig->UserId);
  3474. log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
  3475. }
  3476. }else if (pDcChargingInfo->ConnectorPlugIn == NO && pDcChargingInfo->Type == _Type_CCS_2) {
  3477. strcpy((char *)OldUseId, "");
  3478. }
  3479. }
  3480. static bool PrecheckIsPass(uint8_t gunIndex)
  3481. {
  3482. bool result = true;
  3483. // relay welding or driving 是反向
  3484. result = !ShmDcCommonData->GunRelayWeldingOccur[gunIndex];
  3485. return result;
  3486. }
  3487. static void ReviewCriticalAlarm(void)
  3488. {
  3489. if (//ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
  3490. //ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
  3491. //ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
  3492. //ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
  3493. pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES ||
  3494. pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES ||
  3495. pAlarmCode->AlarmEvents.bits.DoorOpen == YES ||
  3496. pSysWarning->ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
  3497. pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == YES ||
  3498. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES ||
  3499. //Power cabinet alarm status
  3500. ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop == YES ||
  3501. ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen == YES ||
  3502. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP == YES ||
  3503. ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP == YES ||
  3504. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP == YES ||
  3505. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP == YES ||
  3506. ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP == YES ||
  3507. ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure == YES
  3508. ) {
  3509. pSysWarning->Level = WARN_LV_ER;
  3510. } else {
  3511. pSysWarning->Level = WARN_LV_NL;
  3512. }
  3513. }
  3514. static void CheckRelayWeldingOrDrivingFault(uint8_t gunIndex)
  3515. {
  3516. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3517. // relay welding fault then stop the charging process.
  3518. uint8_t faultCode = RELAY_STATUS_ERROR_NONE;
  3519. //static uint8_t drivingCount = 0;
  3520. if (gunIndex == 0) {
  3521. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3522. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3523. faultCode = RELAY_STATUS_ERROR_WELDING;
  3524. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3525. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3526. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3527. }
  3528. } else if (gunIndex == 1) {
  3529. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  3530. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  3531. faultCode = RELAY_STATUS_ERROR_WELDING;
  3532. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  3533. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  3534. faultCode = RELAY_STATUS_ERROR_DRIVING;
  3535. }
  3536. }
  3537. if (faultCode == RELAY_STATUS_ERROR_WELDING) {
  3538. // welding
  3539. if (pDcChargingInfo->Type == _Type_Chademo) {
  3540. RecordAlarmCode(gunIndex, "011011");
  3541. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
  3542. } else if (pDcChargingInfo->Type == _Type_GB) {
  3543. RecordAlarmCode(gunIndex, "011015");
  3544. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
  3545. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3546. RecordAlarmCode(gunIndex, "011013");
  3547. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
  3548. }
  3549. if (ShmDcCommonData->GunRelayWeldingOccur[gunIndex] != YES) {
  3550. log_error("Gun%d Relay welding....",gunIndex);
  3551. }
  3552. ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = YES;
  3553. } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
  3554. // driving
  3555. if (pDcChargingInfo->Type == _Type_Chademo) {
  3556. RecordAlarmCode(gunIndex, "011012");
  3557. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
  3558. } else if (pDcChargingInfo->Type == _Type_GB) {
  3559. RecordAlarmCode(gunIndex, "011016");
  3560. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
  3561. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3562. RecordAlarmCode(gunIndex, "011014");
  3563. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
  3564. }
  3565. if (ShmDcCommonData->GunRelayDrivingOccur[gunIndex] != YES) {
  3566. log_error("Gun%d Relay driving fault....",gunIndex);
  3567. }
  3568. ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = YES;
  3569. } else {
  3570. ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = NO;
  3571. ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = NO;
  3572. /*
  3573. if (pDcChargingInfo->Type == _Type_Chademo) {
  3574. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
  3575. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
  3576. } else if (pDcChargingInfo->Type == _Type_GB) {
  3577. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
  3578. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
  3579. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3580. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
  3581. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
  3582. }
  3583. */
  3584. //drivingCount = 0;
  3585. }
  3586. }
  3587. static void isChargingAverageState(void)
  3588. {
  3589. if (pSysInfo->MainChargingMode != _MAIN_CHARGING_MODE_AVER) {
  3590. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3591. return;
  3592. }
  3593. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3594. if (pSysInfo->AcContactorStatus != YES) {
  3595. pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  3596. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3597. }
  3598. #endif //!defined DD360 && !defined DD360Audi
  3599. // 均充 -> 最大充
  3600. if (pSysInfo->BridgeRelayStatus == NO) {
  3601. if (pSysInfo->ReAssignedFlag == _REASSIGNED_NONE) {
  3602. log_info("=============Smart Charging============= Step 11 ");
  3603. pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
  3604. }
  3605. } else if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
  3606. pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
  3607. log_info("=============Smart Charging============= Step 14 ");
  3608. pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
  3609. } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
  3610. pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  3611. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  3612. }
  3613. }
  3614. bool Taskconutstring(char *src, char *taskname)
  3615. {
  3616. bool result = false;
  3617. if (src == NULL || strlen(src) == 0)
  3618. return result;
  3619. if (strstr(src, taskname) != NULL &&
  3620. strstr(src, "grep") == NULL &&
  3621. strstr(src, "[") == NULL)
  3622. {
  3623. result = true;
  3624. }
  3625. return result;
  3626. }
  3627. int GetProcessCount(char *procName)
  3628. {
  3629. int result = 0;
  3630. FILE *fp;
  3631. char cmd[256];
  3632. char buf[256];
  3633. sprintf(cmd, "ps -ef |grep %s", procName);
  3634. fp = popen(cmd, "r");
  3635. if(fp != NULL)
  3636. {
  3637. while(fgets(buf, sizeof(buf), fp) != NULL)
  3638. {
  3639. if (Taskconutstring(buf, procName))
  3640. result++;
  3641. }
  3642. }
  3643. pclose(fp);
  3644. return result;
  3645. }
  3646. void CheckTaskAlive()
  3647. {
  3648. pid_t Pid = fork();
  3649. if ( Pid == 0 ) {
  3650. while(1) {
  3651. sleep(3);
  3652. unsigned char count = GetProcessCount("Module_ChkSysTask");
  3653. if( count != 1 ) {
  3654. system("pkill Module_ChkSysTask");
  3655. sleep(10);
  3656. system("/root/Module_ChkSysTask &");
  3657. }
  3658. }
  3659. return;
  3660. }
  3661. log_info("Create Check Systam fork:%d",Pid);
  3662. return;
  3663. }
  3664. /**
  3665. * [checkPileEndGfdResult 確認充電樁GFD狀態]
  3666. * @Author Jerry
  3667. * @DateTime 2021-07-01
  3668. * @param gunIndex [當前的槍]
  3669. * @param gunType [槍的類型]
  3670. * @param sysStatus [槍的系統狀態]
  3671. */
  3672. static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sysStatus)
  3673. {
  3674. switch (gunType) {
  3675. case _Type_Chademo:
  3676. // 檢查樁端的 GFD 結果
  3677. if (sysStatus == S_PREPARING_FOR_EVSE &&
  3678. isPrechargeStatus_chademo(gunIndex) >= 6) {
  3679. // 當前操作的槍號,進入 Charging
  3680. setChargerMode(gunIndex, MODE_CHARGING);
  3681. }
  3682. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  3683. //if ((sysStatus == S_ALARM ||
  3684. // sysStatus == S_TERMINATING) &&
  3685. // isEvStopCharging_chademo(gunIndex) == YES) {
  3686. // /*+++ 20200908, vern, disable it for DD360 +++*/
  3687. // if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3688. // strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  3689. // /*--- 20200908, vern, disable it for DD360 ---*/
  3690. // }
  3691. //}
  3692. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3693. // GFD 錯誤停止
  3694. RecordAlarmCode(gunIndex, "012234");
  3695. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
  3696. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  3697. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3698. // GFD 警告
  3699. //RecordAlarmCode(gunIndex, "012296");
  3700. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  3701. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
  3702. }
  3703. else
  3704. {
  3705. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  3706. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  3707. }
  3708. //else if (sysStatus == S_CHARGING &&
  3709. // ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
  3710. // pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  3711. // (pDcChargingInfo->PresentChargedDuration >= 10 &&
  3712. // pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
  3713. // ) {
  3714. // // UVP
  3715. // RecordAlarmCode(gunIndex, "012289");
  3716. // ChargingTerminalProcess(gunIndex);
  3717. //}
  3718. break;
  3719. case _Type_GB:
  3720. // 檢查樁端的 GFD 結果
  3721. //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
  3722. if (sysStatus == S_PREPARING_FOR_EVSE && isPrechargeStatus_gb(gunIndex) >= 6) {
  3723. setChargerMode(gunIndex, MODE_CHARGING);
  3724. }
  3725. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  3726. //if (isEvStopCharging_chademo(gunIndex) == YES) {
  3727. // /*+++ 20200908, vern, disable it for DD360 +++*/
  3728. // if ((sysStatus == S_ALARM ||
  3729. // sysStatus == S_TERMINATING) &&
  3730. // strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL
  3731. // ) {
  3732. // strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  3733. // }
  3734. // /*--- 20200908, vern, disable it for DD360 ---*/
  3735. //}
  3736. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3737. // GFD 錯誤停止
  3738. RecordAlarmCode(gunIndex, "012236");
  3739. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
  3740. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  3741. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3742. // GFD 警告
  3743. //RecordAlarmCode(gunIndex, "012298");
  3744. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  3745. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
  3746. }
  3747. else
  3748. {
  3749. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  3750. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  3751. }
  3752. //else if (sysStatus == S_CHARGING &&
  3753. // isPrechargeStatus_gb(gunIndex) == 10 &&
  3754. // (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
  3755. // pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  3756. // (pDcChargingInfo->PresentChargedDuration >= 10 &&
  3757. // pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL))
  3758. // ) {
  3759. // // UVP
  3760. // RecordAlarmCode(gunIndex, "012290");
  3761. // ChargingTerminalProcess(gunIndex);
  3762. //}
  3763. break;
  3764. case _Type_CCS_2:
  3765. // 檢查樁端的 GFD 結果
  3766. if (sysStatus == S_PREPARING_FOR_EVSE &&
  3767. (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
  3768. pDcChargingInfo->GroundFaultStatus == GFD_WARNING)
  3769. ) {
  3770. setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP0);
  3771. }
  3772. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  3773. //if (isEvStopCharging_chademo(gunIndex) == YES) {
  3774. // /*+++ 20200908, vern, disable it for DD360 +++*/
  3775. // if ((sysStatus == S_ALARM ||
  3776. // sysStatus == S_TERMINATING) &&
  3777. // (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
  3778. // ) {
  3779. // strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  3780. // }
  3781. // /*--- 20200908, vern, disable it for DD360 ---*/
  3782. //}
  3783. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  3784. // GFD 錯誤停止
  3785. RecordAlarmCode(gunIndex, "012235");
  3786. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  3787. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  3788. } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  3789. // GFD 警告
  3790. //RecordAlarmCode(gunIndex, "012297");
  3791. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  3792. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
  3793. }
  3794. else
  3795. {
  3796. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  3797. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  3798. }
  3799. //else if (sysStatus == S_CHARGING &&
  3800. // ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
  3801. // pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  3802. // (pDcChargingInfo->PresentChargedDuration >= 10 &&
  3803. // pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
  3804. // ) {
  3805. // // UVP
  3806. // RecordAlarmCode(gunIndex, "012288");
  3807. // ChargingTerminalProcess(gunIndex);
  3808. //}
  3809. break;
  3810. }
  3811. }
  3812. static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
  3813. {
  3814. uint8_t evBoardStopState = 0;
  3815. if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
  3816. log_info("evBoardStopState :%d ",evBoardStopState);
  3817. // 板端要求停止 (錯誤)
  3818. if (sysStatus != S_CCS_PRECHARGE_ST0 &&
  3819. sysStatus != S_CCS_PRECHARGE_ST1) {
  3820. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3821. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  3822. }
  3823. }
  3824. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  3825. ChargingAlarmProcess(gunIndex);
  3826. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  3827. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  3828. log_info("Cabinet Stop Gun%d Charging permittion, Status Code [%s]",gunIndex,pDcChargingInfo->ConnectorAlarmCode);
  3829. if (strncmp((char*)pDcChargingInfo->ConnectorAlarmCode,"000000",6) != EQUAL &&
  3830. strncmp((char*)pDcChargingInfo->ConnectorAlarmCode,"",6) != EQUAL) {
  3831. ChargingAlarmProcess(gunIndex);
  3832. //log_info("Cabinet Stop Gun%d Charging permittion, Status Code [%s]",gunIndex,pDcChargingInfo->ConnectorAlarmCode);
  3833. } else {
  3834. ChargingTerminalProcess(gunIndex);
  3835. }
  3836. }
  3837. } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
  3838. // 板端要求停止 (正常)
  3839. if (sysStatus != S_CCS_PRECHARGE_ST0 &&
  3840. sysStatus != S_CCS_PRECHARGE_ST1) {
  3841. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  3842. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  3843. }
  3844. }
  3845. ChargingTerminalProcess(gunIndex);
  3846. } else if (OcppRemoteStop(gunIndex) == YES ||
  3847. WifiScheduleStop(gunIndex)) {
  3848. // 後臺要求停止
  3849. ChargingTerminalProcess(gunIndex);
  3850. }
  3851. }
  3852. void showversion()
  3853. {
  3854. uint8_t index = 0;
  3855. log_info("\t========= Charger info ========= ");
  3856. log_info("\tSW Version = %s", pSysInfo->CsuRootFsFwRev);
  3857. log_info("\tDebug Version = %s",ShmDcCommonData->DebugVersion);
  3858. log_info("\tModelName = %s", pSysConfig->ModelName);
  3859. log_info("\tRelay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
  3860. log_info("\tFan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
  3861. log_info("\tPrimary FW Rev = %s", pSysInfo->CsuPrimFwRev);
  3862. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  3863. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  3864. if (pDcChargingInfo->Type == _Type_Chademo) {
  3865. log_info("\tCHAdeMO[%d] FW Rev = %s",
  3866. pDcChargingInfo->type_index,
  3867. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
  3868. } else if (pDcChargingInfo->Type == _Type_GB) {
  3869. log_info("\tGBT[%d] FW Rev = %s",
  3870. pDcChargingInfo->type_index,
  3871. ShmGBTData->evse[pDcChargingInfo->type_index].version);
  3872. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  3873. log_info("\tCCS[%d] FW Rev = %s",
  3874. pDcChargingInfo->type_index,
  3875. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
  3876. }
  3877. }
  3878. log_info("\t================================ ");
  3879. }
  3880. void SetNatural300AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3881. {
  3882. deratingByConnOtp->isNeedDerating = YES;
  3883. deratingByConnOtp->deratingTargetCurrent[0] = 5000;
  3884. deratingByConnOtp->deratingTargetCurrent[1] = 3000;
  3885. deratingByConnOtp->deratingTargetCurrent[2] = 1000;
  3886. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3887. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3888. }
  3889. void SetLiquidCoolGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3890. {
  3891. deratingByConnOtp->isNeedDerating = YES;
  3892. deratingByConnOtp->deratingTargetCurrent[0] = 5000;
  3893. deratingByConnOtp->deratingTargetCurrent[1] = 4000;
  3894. deratingByConnOtp->deratingTargetCurrent[2] = 3000;
  3895. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3896. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3897. }
  3898. void SetCHAdeMoTypeKOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3899. {
  3900. deratingByConnOtp->isNeedDerating = YES;
  3901. deratingByConnOtp->deratingTargetRate[0] = 1;
  3902. deratingByConnOtp->deratingTargetRate[1] = 0.8;
  3903. deratingByConnOtp->deratingTargetRate[2] = 0.8;
  3904. deratingByConnOtp->deratingTargetRate[3] = 0;
  3905. deratingByConnOtp->deratingTargetRate[4] = 0;
  3906. memset(&deratingByConnOtp->deratingTargetCurrent[0], 0, sizeof(deratingByConnOtp->deratingTargetCurrent));
  3907. }
  3908. void SetCHAdeMoTypeSJOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3909. {
  3910. deratingByConnOtp->isNeedDerating = YES;
  3911. deratingByConnOtp->deratingTargetCurrent[0] = 2000;
  3912. deratingByConnOtp->deratingTargetCurrent[1] = 1250;
  3913. deratingByConnOtp->deratingTargetCurrent[2] = 1250;
  3914. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3915. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3916. }
  3917. void SetCHAdeMoTypeOOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
  3918. {
  3919. deratingByConnOtp->isNeedDerating = YES;
  3920. deratingByConnOtp->deratingTargetCurrent[0] = 3500;
  3921. deratingByConnOtp->deratingTargetCurrent[1] = 2000;
  3922. deratingByConnOtp->deratingTargetCurrent[2] = 2000;
  3923. deratingByConnOtp->deratingTargetCurrent[3] = 0;
  3924. deratingByConnOtp->deratingTargetCurrent[4] = 0;
  3925. }
  3926. static void SetGunTypeOTPValue(void)
  3927. {
  3928. //struct ChargingInfoData* chargingData_2 = NULL;
  3929. uint8_t Gun1Type = 0;
  3930. uint8_t Gun2Type = 0;
  3931. int i,cnt;
  3932. if (pSysConfig->TotalConnectorCount == 1) {
  3933. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(0);
  3934. Gun1Type = pSysConfig->ModelName[7];
  3935. Gun2Type = pSysConfig->ModelName[7];
  3936. switch (Gun1Type) {
  3937. case 'K':
  3938. SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3939. break;
  3940. case 'S':
  3941. SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3942. break;
  3943. case 'I':
  3944. case 'Q':
  3945. SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3946. break;
  3947. case 'O':
  3948. SetCHAdeMoTypeOOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3949. break;
  3950. // 水冷
  3951. case 'V':
  3952. case 'F':
  3953. SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3954. break;
  3955. default:
  3956. pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
  3957. }
  3958. if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
  3959. log_info("------------ Gun0 - Type:%c Derating info (OTP)-----------", Gun1Type);
  3960. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
  3961. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  3962. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
  3963. log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
  3964. }
  3965. }
  3966. } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
  3967. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  3968. if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
  3969. log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
  3970. }
  3971. }
  3972. }
  3973. }
  3974. } else if (pSysConfig->TotalConnectorCount == 2) {
  3975. Gun1Type = pSysConfig->ModelName[7];
  3976. Gun2Type = pSysConfig->ModelName[9];
  3977. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  3978. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  3979. switch (i == 0 ? Gun1Type : Gun2Type) {
  3980. case 'K':
  3981. SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3982. break;
  3983. case 'S':
  3984. SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3985. break;
  3986. // 風冷300A
  3987. case 'I':
  3988. case 'Q':
  3989. SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3990. break;
  3991. case 'O':
  3992. SetCHAdeMoTypeOOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3993. break;
  3994. // 水冷
  3995. case 'V':
  3996. case 'F':
  3997. SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
  3998. break;
  3999. default:
  4000. pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
  4001. }
  4002. if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
  4003. log_info("------------ Gun%d - Type:%c Derating info (OTP)-----------",i, i == 0 ? Gun1Type : Gun2Type);
  4004. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
  4005. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  4006. if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
  4007. log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
  4008. }
  4009. }
  4010. } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
  4011. for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
  4012. if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
  4013. log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
  4014. }
  4015. }
  4016. }
  4017. }
  4018. }
  4019. }
  4020. }
  4021. bool checkGunTempFail(uint8_t gunIndex)
  4022. {
  4023. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4024. switch (pDcChargingInfo->Type) {
  4025. case _Type_Chademo:
  4026. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail) {
  4027. RecordAlarmCode(gunIndex,"011018");
  4028. if (IntoChargeProcess(pDcChargingInfo->SystemStatus)) {
  4029. setChargerMode(gunIndex,S_ALARM);
  4030. }
  4031. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  4032. pDcChargingInfo->SystemStatus == S_RESERVATION ) {
  4033. memcpy(pDcChargingInfo->ConnectorAlarmCode, "011018", 6);
  4034. setChargerMode(gunIndex,S_FAULT);
  4035. }
  4036. return TRUE;
  4037. }
  4038. break;
  4039. case _Type_CCS_2:
  4040. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail) {
  4041. RecordAlarmCode(gunIndex,"011019");
  4042. if (IntoChargeProcess(pDcChargingInfo->SystemStatus)) {
  4043. setChargerMode(gunIndex,S_ALARM);
  4044. }
  4045. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  4046. pDcChargingInfo->SystemStatus == S_RESERVATION ) {
  4047. memcpy(pDcChargingInfo->ConnectorAlarmCode, "011019", 6);
  4048. setChargerMode(gunIndex,S_FAULT);
  4049. }
  4050. return TRUE;
  4051. }
  4052. break;
  4053. case _Type_GB:
  4054. if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail) {
  4055. RecordAlarmCode(gunIndex,"011020");
  4056. if (IntoChargeProcess(pDcChargingInfo->SystemStatus)) {
  4057. setChargerMode(gunIndex,S_ALARM);
  4058. }
  4059. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  4060. pDcChargingInfo->SystemStatus == S_RESERVATION ) {
  4061. memcpy(pDcChargingInfo->ConnectorAlarmCode, "011020", 6);
  4062. setChargerMode(gunIndex,S_FAULT);
  4063. }
  4064. return TRUE;
  4065. }
  4066. break;
  4067. }
  4068. return FALSE;
  4069. }
  4070. //==========================================
  4071. // Ocmf
  4072. //==========================================
  4073. void ConfigOcmfInfo(uint8_t gun_index)
  4074. {
  4075. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
  4076. strncpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.evseId,
  4077. (char *)pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
  4078. char trId[32];
  4079. sprintf(trId, "%d", ShmSelectGunInfo->PricesInfo[gun_index].TransactionId);
  4080. memcpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.transactionId, trId,
  4081. sizeof(trId));
  4082. char clientId[32] = "DC_Charger";
  4083. memcpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.clientId, clientId,
  4084. sizeof(clientId));
  4085. pSysInfo->DcMeterTransactionAction[gun_index].head.tariffId = 0;
  4086. pSysInfo->DcMeterTransactionAction[gun_index].head.cableId = 0;
  4087. memcpy((char *)pSysInfo->DcMeterTransactionAction[gun_index].head.userData,
  4088. (char *)pDcChargingInfo->StartUserId,
  4089. sizeof(pDcChargingInfo->StartUserId));
  4090. }
  4091. void ConfigOcmfInfo_Record(int _trID, uint8_t gun_index)
  4092. {
  4093. strncpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.evseId,
  4094. (char *)pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
  4095. char trId[32];
  4096. sprintf(trId, "%d", _trID);
  4097. strcpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.transactionId, trId);
  4098. strcpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.clientId, "DC_Charger");
  4099. pSysInfo->DcMeterReadTransactionRecord[gun_index].head.tariffId = 0;
  4100. pSysInfo->DcMeterReadTransactionRecord[gun_index].head.cableId = 0;
  4101. strcpy((char *)pSysInfo->DcMeterReadTransactionRecord[gun_index].head.userData, "Record");
  4102. }
  4103. void StoreOcmfFile(uint8_t gun_index,int trid,int isRecord)
  4104. {
  4105. if (ShmDcCommonData->pGunInfo[gun_index].ConnectorID <= 0 || ShmDcCommonData->pGunInfo[gun_index].ConnectorID > 4) {
  4106. log_info("Gun%d ConnectorID:%d",gun_index,ShmDcCommonData->pGunInfo[gun_index].ConnectorID);
  4107. return;
  4108. }
  4109. FILE *pfile;
  4110. char cmd[500];
  4111. sprintf((char*)ShmDcCommonData->pGunInfo[gun_index].OcmfFileName,"/mnt/Gun_%d_%d_OCMF",
  4112. ShmDcCommonData->pGunInfo[gun_index].ConnectorID,trid);
  4113. log_info("OCMF File:%s",ShmDcCommonData->pGunInfo[gun_index].OcmfFileName);
  4114. pfile = fopen(ShmDcCommonData->pGunInfo[gun_index].OcmfFileName,"w+");
  4115. if (isRecord)
  4116. fprintf(pfile,"%s",pSysInfo->DcMeterReadTransactionRecord[gun_index].transactionOCMF);
  4117. else
  4118. fprintf(pfile,"%s",pSysInfo->DcMeterTransactionAction[gun_index].transactionOCMF);
  4119. fclose(pfile);
  4120. sprintf(cmd,"ftpput -u root -p y42j/4cj84 192.168.100.1 %s",ShmDcCommonData->pGunInfo[gun_index].OcmfFileName);
  4121. if (system(cmd) != 0 ) {
  4122. log_info("Put OCMF File to Cabinet Fail");
  4123. sprintf(cmd,"rm -f %s",ShmDcCommonData->pGunInfo[gun_index].OcmfFileName);
  4124. system(cmd);
  4125. } else {
  4126. log_info("Put OCMF File to Cabinet OK");
  4127. ShmDcCommonData->pGunInfo[gun_index].SendOcmfDataReq = TRUE;
  4128. }
  4129. }
  4130. void ChkOcmfRecord(uint8_t gun_index)
  4131. {
  4132. if (pAlarmCode->AlarmEvents.bits.Meter1CommTimeout) {
  4133. return;
  4134. }
  4135. int trid = DB_Get_OcmfTrid(gun_index);
  4136. if (trid != 0 &&
  4137. trid != ShmDcCommonData->ocmfTridRecord[gun_index] &&
  4138. trid != ShmSelectGunInfo->PricesInfo[gun_index].TransactionId)
  4139. {
  4140. ShmDcCommonData->ocmfTridRecord[gun_index] = trid;
  4141. ConfigOcmfInfo_Record(ShmDcCommonData->ocmfTridRecord[gun_index], gun_index);
  4142. pSysInfo->DcMeterReadTransactionRecord[gun_index].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4143. }
  4144. if (pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady == _OCMF_INFO_READY_YES &&
  4145. ShmDcCommonData->pGunInfo[gun_index].SendOcmfDataReq == FALSE)
  4146. {
  4147. log_info("OCMF Record - Reture Pass \n");
  4148. pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady = _OCMF_INFO_READY_NO;
  4149. //ocpp_ocmf_information(gun_index);
  4150. DB_Update_ocmf_Record(gun_index, ShmDcCommonData->ocmfTridRecord[gun_index], true);
  4151. StoreOcmfFile(gun_index,trid,TRUE);
  4152. //ShmDcCommonData->ocmfTridRecord[gun_index] = 0;
  4153. }
  4154. else if (pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady == _OCMF_INFO_READY_FAIL)
  4155. {
  4156. log_info("OCMF Record - Reture Fail \n");
  4157. pSysInfo->DcMeterReadTransactionRecord[gun_index].OcmfInfoReady = _OCMF_INFO_READY_NO;
  4158. DB_Update_ocmf_Record(gun_index, ShmDcCommonData->ocmfTridRecord[gun_index], false);
  4159. //ShmDcCommonData->ocmfTridRecord[gun_index] = 0;
  4160. }
  4161. }
  4162. int main(void)
  4163. {
  4164. bool isModelNameMatch = true;
  4165. uint8_t evBoardStopState = 0;
  4166. uint8_t _ocppProfileChkFlag;
  4167. uint8_t gunIndex = 0;
  4168. uint8_t _isStop[2] = {0};
  4169. float powerconsumption;
  4170. uint8_t ConnectID[2];
  4171. uint8_t SendOcmfDataReq[2];
  4172. if (CreateAllCsuShareMemory() == FAIL) {
  4173. log_error("create share memory error");
  4174. return FAIL;
  4175. }
  4176. ClearAllShmMemParameter();
  4177. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  4178. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  4179. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  4180. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  4181. pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  4182. pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
  4183. ShmPsuData = (struct PsuData *)GetShmPsuData();
  4184. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  4185. ShmGBTData = (struct GBTData *)GetShmGBTData();
  4186. ShmCcsData = (struct CcsData *)GetShmCcsData();
  4187. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  4188. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  4189. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  4190. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  4191. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  4192. ShmOCPP20Data = (struct OCPP20Data*)GetShmOCPP20Data();
  4193. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  4194. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  4195. ShmSysConfigAndInfo = (struct SysConfigAndInfo *)GetShmSysConfigAndInfo();
  4196. ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();
  4197. log_info(" ********************************************************");
  4198. log_info(" ****************** FileSystem Boot up *****************");
  4199. log_info(" ********************************************************");
  4200. #if defined DD360
  4201. log_info(" ****************** Project:DD360 *********************");
  4202. #elif defined DD360Audi
  4203. log_info(" ****************** Project:DD360Audi *****************");
  4204. #elif defined DD360ComBox
  4205. log_info(" ****************** Project:DD360ComBox ***************");
  4206. #endif
  4207. log_info(" ********************************************************");
  4208. if (!InitialSystemDefaultConfig()) {
  4209. log_error("InitialSystemDefaultConfig NG ");
  4210. //StopProcessingLoop();
  4211. sleep(5);
  4212. system("reboot -f");
  4213. }
  4214. CheckGunTypeFromHw();
  4215. CheckIsAlternatvieByModelName();
  4216. InitialShareMemoryInfo();
  4217. GetFirmwareVersion();
  4218. ChangeLcmByIndex(_LCM_INIT);
  4219. if (!CheckConnectorTypeStatus()) {
  4220. isModelNameMatch = false;
  4221. }
  4222. Initialization();
  4223. SpawnTask();
  4224. log_info("Spawned all Task");
  4225. if (!isModelNameMatch) {
  4226. pAlarmCode->AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
  4227. ChangeLcmByIndex(_LCM_FIX);
  4228. // Module Name 與硬體對應不正確
  4229. log_error("Module Name & HW info none match. ");
  4230. sleep(3);
  4231. KillAllTask();
  4232. StopProcessingLoop();
  4233. }
  4234. CreateTimeoutFork();
  4235. PrimaryLedIndicatorCtrlFork();
  4236. ChangeLcmByIndex(_LCM_FIX);
  4237. SelfTestRun();
  4238. StopSystemTimeoutDet();
  4239. log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
  4240. pSysInfo->SelfTestSeq,
  4241. ShmPsuData->Work_Step);
  4242. if (pSysInfo->SelfTestSeq == _STEST_FAIL ||
  4243. ShmPsuData->Work_Step == _NO_WORKING ||
  4244. pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES //DS60-120 add
  4245. ) {
  4246. /*
  4247. if (pSysWarning->Level != WARN_LV_ER) {
  4248. if (!DisplaySelfTestFailReason()) { //DS60-120 add
  4249. log_info("Soft reboot for retry self-tets. ");
  4250. sleep(3);
  4251. system("killall OcppBackend &");
  4252. KillAllTask();
  4253. system("/usr/bin/run_evse_restart.sh");
  4254. }
  4255. }
  4256. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4257. setChargerMode(gunIndex, MODE_ALARM);
  4258. }
  4259. //ChangeLcmByIndex(_LCM_FIX);
  4260. sleep(3);
  4261. if (pSysWarning->Level == WARN_LV_ER) { //DS60-120 add
  4262. KillTaskExceptPrimary();
  4263. } else {
  4264. KillTask();
  4265. }
  4266. StopProcessingLoop();
  4267. */
  4268. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4269. setChargerMode(gunIndex, MODE_MAINTAIN);
  4270. }
  4271. ChangeLcmByIndex(_LCM_FIX);
  4272. } else {
  4273. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4274. setChargerMode(gunIndex, MODE_IDLE);
  4275. }
  4276. }
  4277. // Local DB
  4278. if (DB_Open() != PASS) {
  4279. log_info("DB_Open fail. ");
  4280. isDb_ready = false;
  4281. } else {
  4282. isDb_ready = true;
  4283. for (int _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  4284. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  4285. pDcChargingInfo->IsAvailable = DB_Get_Operactive(_index);
  4286. if (!DB_Get_PowerConsumption(_index)) {
  4287. DB_Insert_PowerConsumption(_index, 0);
  4288. }
  4289. }
  4290. DB_Reboot_Record();
  4291. }
  4292. log_info("===== Create DB End ===== ");
  4293. #if defined DD360Audi
  4294. ChangeLcmByIndex(_LCM_SELECT_GUN);
  4295. #else
  4296. ChangeLcmByIndex(_LCM_IDLE);
  4297. #endif //defined DD360Audi
  4298. sleep(1);
  4299. //***** 須新增的偵測 *****//
  4300. // 1. Thernal - 控制風扇轉速
  4301. // 2. ouput fuse - 控制風扇轉速
  4302. CreateRfidFork();
  4303. // Main loop
  4304. showversion();
  4305. CheckFwSlotStatusLog();
  4306. //AdjustChargerCurrent();
  4307. GetClockTime(&_cmdMainPriority_time);
  4308. GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
  4309. CheckTaskAlive();
  4310. CreateWatchdog();
  4311. pSysInfo->OTPTemp = GUN_OTP_VALUE;
  4312. pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
  4313. SetGunTypeOTPValue();
  4314. struct ChargingInfoData *pDcInfo = NULL;
  4315. for (;;) {
  4316. if (ShmDcCommonData->demo_flag) {
  4317. TryFeedWatchdog();
  4318. usleep(WHILE_LOOP_TIME);
  4319. continue;
  4320. }
  4321. CheckOcppStatus();
  4322. ChkPrimaryStatus();
  4323. if ((IsConnectorWholeIdle() ||
  4324. (pSysInfo->PageIndex == _LCM_FIX)) &&
  4325. (pSysInfo->SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
  4326. ) {
  4327. CheckFactoryConfigFunction();
  4328. //CheckFwUpdateFunction();
  4329. }
  4330. // OCPP 邏輯
  4331. OcppRemoteStartChk();
  4332. // 讀卡邏輯
  4333. ScannerCardProcess();
  4334. // 當 AC 沒有搭上時,清除一些錯誤碼
  4335. ClearAlarmCodeWhenAcOff();
  4336. // 確認是否要回到充電中的槍畫面邏輯判斷
  4337. CheckReturnToChargingConn();
  4338. //確認Power cabinet PSU Status
  4339. //powerCabinetPsuAlarmStatus();
  4340. if ((GetClockTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
  4341. //CheckTask();
  4342. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4343. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4344. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  4345. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  4346. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  4347. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  4348. if (pDcChargingInfo->SystemStatus == S_CHARGING &&
  4349. _ocppProfileChkFlag == 12) {
  4350. ChargingProfileFlat(gunIndex);
  4351. _ocppProfileChkFlag = 0;
  4352. } else if (pDcChargingInfo->SystemStatus != S_CHARGING) {
  4353. ChargingProfileFlat(gunIndex);
  4354. _ocppProfileChkFlag = 0;
  4355. } else {
  4356. _ocppProfileChkFlag++;
  4357. }
  4358. }
  4359. checkGunOTPState(gunIndex); //check gun OTP
  4360. // OCMF
  4361. ChkOcmfRecord(gunIndex);
  4362. }
  4363. GetClockTime(&_cmdMainPriority_time);
  4364. }
  4365. // 確認當前錯誤 Level = 2 ?
  4366. ReviewCriticalAlarm();
  4367. gEvBoardErr.GunErrMessage = 0; //清除系統執行中的錯誤訊息
  4368. gChillerTempErr.TempErrMsg = 0;//清除系統執行中的錯誤訊息
  4369. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4370. // 重新收集各槍的錯誤狀態
  4371. collectError(gunIndex);
  4372. }
  4373. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4374. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4375. // convert common status code to alarm event
  4376. checkEvBoardAlarmState(pDcChargingInfo->Type);
  4377. }
  4378. checkChillerAlarmState();
  4379. //log_info("MeterCommTimeout:%d",pAlarmCode->AlarmEvents.bits.MeterCommTimeout);
  4380. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  4381. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4382. autoStartCharging(gunIndex);
  4383. CheckGpioInStatus();
  4384. CheckErrorOccurStatus(gunIndex);
  4385. // 確認 Relay Welding or Driving Fault
  4386. CheckRelayWeldingOrDrivingFault(gunIndex);
  4387. ChkOcppStatus(gunIndex);
  4388. if (IntoChargeProcess(pDcChargingInfo->SystemStatus)) {
  4389. CheckSmartChargeProfile(gunIndex);
  4390. }
  4391. //checkGunTempFail(gunIndex);
  4392. if (pSysInfo->SelfTestSeq == _STEST_FAIL ) {
  4393. setChargerMode(gunIndex, MODE_MAINTAIN);
  4394. ChangeLcmByIndex(_LCM_FIX);
  4395. }
  4396. switch (pDcChargingInfo->SystemStatus) {
  4397. case S_IDLE:
  4398. case S_RESERVATION:
  4399. if (isModeChange(gunIndex)) {
  4400. if (pDcChargingInfo->SystemStatus == S_IDLE)
  4401. log_info("============================= S_IDLE(%x) ============================= ", gunIndex);
  4402. else if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
  4403. log_info("============================= S_RESERVATION(%x) ============================= ", gunIndex);
  4404. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  4405. }
  4406. pDcChargingInfo->PresentChargedDuration = 0;
  4407. pDcChargingInfo->RemainChargingDuration = 0;
  4408. pDcChargingInfo->StartMethod = 0;
  4409. pDcChargingInfo->PresentChargingVoltage = 0;//DS60-120 add
  4410. pDcChargingInfo->PresentChargingCurrent = 0;//DS60-120 add
  4411. strcpy((char *)pDcChargingInfo->StartDateTime, "");
  4412. strcpy((char *)pDcChargingInfo->StopDateTime, "");
  4413. strcpy((char *)pDcChargingInfo->StartUserId, "");
  4414. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "");
  4415. if (pDcChargingInfo->deratingByConnOtp.deratingIndex != 0) {
  4416. pDcChargingInfo->deratingByConnOtp.deratingIndex = 0;
  4417. }
  4418. ShmDcCommonData->ocmfTridRecord[gunIndex] = 0 ;
  4419. _isStop[gunIndex] = 0;
  4420. //Jerry add
  4421. memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
  4422. powerconsumption = ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption;
  4423. ConnectID[gunIndex] = ShmDcCommonData->pGunInfo[gunIndex].ConnectorID;
  4424. SendOcmfDataReq[gunIndex] = ShmDcCommonData->pGunInfo[gunIndex].SendOcmfDataReq;
  4425. memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
  4426. ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = powerconsumption;
  4427. ShmDcCommonData->pGunInfo[gunIndex].ConnectorID = ConnectID[gunIndex];
  4428. ShmDcCommonData->pGunInfo[gunIndex].SendOcmfDataReq = SendOcmfDataReq[gunIndex];
  4429. ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
  4430. destroySelGun(gunIndex);
  4431. ResetDetAlarmStatus(gunIndex); //recovery OVP status code
  4432. if (ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] == YES) {
  4433. ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] = NO;
  4434. }
  4435. //strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
  4436. ReleaseAlarmCode(gunIndex);
  4437. sleep(1);
  4438. }
  4439. if (pDcChargingInfo->IsAvailable == NO) {
  4440. setChargerMode(gunIndex, MODE_MAINTAIN);
  4441. }
  4442. case S_FAULT:
  4443. if (isModeChange(gunIndex)) {
  4444. if(pDcChargingInfo->SystemStatus == S_FAULT)
  4445. {
  4446. log_info("============================= S_FAULT(%x) ============================= ", gunIndex);
  4447. }
  4448. }
  4449. if (pSysWarning->Level == WARN_LV_ER) {
  4450. struct ChargingInfoData *pSelectedDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  4451. if (gunIndex == pSysInfo->CurGunSelected) {
  4452. pSysInfo->SystemPage = _LCM_FIX;
  4453. } else if (pSelectedDcChargingInfo->SystemStatus != S_IDLE &&
  4454. pSelectedDcChargingInfo->SystemStatus != S_RESERVATION &&
  4455. pSelectedDcChargingInfo->SystemStatus != S_MAINTAIN &&
  4456. pSelectedDcChargingInfo->SystemStatus != S_FAULT) {
  4457. if (pSelectedDcChargingInfo->SystemStatus == S_CHARGING) {
  4458. pSysInfo->SystemPage = _LCM_COMPLETE;
  4459. } else {
  4460. systemPageRestoreInit();
  4461. }
  4462. }
  4463. ClearDetectPluginFlag(gunIndex);
  4464. if (pDcChargingInfo->SystemStatus != S_FAULT)
  4465. {
  4466. ChkPrimaryStatus();
  4467. UpdateErrorCodeToOcpp(gunIndex);
  4468. setChargerMode(gunIndex, MODE_FAULT);
  4469. }
  4470. continue;
  4471. }
  4472. if (checkGunTempFail(gunIndex)) {
  4473. break;
  4474. }
  4475. if (pDcChargingInfo->SystemStatus == S_FAULT) {
  4476. systemPageRestoreInit();
  4477. setChargerMode(gunIndex, MODE_IDLE);
  4478. }
  4479. isChargingAverageState();
  4480. if (PrecheckIsPass(gunIndex) == false) {
  4481. //log_error("Relay welding");
  4482. setChargerMode(gunIndex, MODE_FAULT);
  4483. if (gunIndex == pSysInfo->CurGunSelected) {
  4484. pSysInfo->SystemPage = _LCM_FIX;
  4485. }
  4486. break;
  4487. }
  4488. if (pDcChargingInfo->SystemStatus == S_FAULT) {
  4489. pSysInfo->SystemPage = _LCM_NONE;
  4490. setChargerMode(gunIndex, MODE_IDLE);
  4491. }
  4492. if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
  4493. if (pSysInfo->CurGunSelected == gunIndex) {
  4494. connectorPageRestoreIdle();
  4495. }
  4496. continue;
  4497. }
  4498. // Idle 正常程序起點
  4499. // 判斷是否有啟用檢查插槍
  4500. if (isDetectPlugin(gunIndex)) {
  4501. StartGunInfoTimeoutDet(gunIndex, Timeout_WaitPlug);
  4502. // 卡號驗證成功後,等待充電槍插入充電車
  4503. if (pDcChargingInfo->RemoteStartFlag == YES) {
  4504. if (pDcChargingInfo->ConnectorPlugIn == YES &&
  4505. pDcChargingInfo->IsAvailable) {
  4506. log_info("-----------------1----------------- %d ", gunIndex);
  4507. pDcChargingInfo->RemoteStartFlag = NO;
  4508. pDcChargingInfo->isRemoteStart = YES; //DS60-120
  4509. ChangeGunSelectByIndex(gunIndex);
  4510. AddPlugInTimes(gunIndex);
  4511. setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
  4512. strcpy((char *)pDcChargingInfo->StartUserId, "");
  4513. ClearDetectPluginFlag(gunIndex);
  4514. StopGunInfoTimeoutDet(gunIndex);
  4515. pDcChargingInfo->StartMethod = _CHARGING_START_REMOTESTART;
  4516. continue;
  4517. }
  4518. } else if (pSysInfo->OrderCharging == NO_DEFINE) {
  4519. if (pDcChargingInfo->ConnectorPlugIn == YES &&
  4520. pDcChargingInfo->IsAvailable &&
  4521. (pDcChargingInfo->SystemStatus == S_IDLE ||
  4522. pDcChargingInfo->SystemStatus == S_RESERVATION) &&
  4523. //waitSelectGunPlugIt(gunIndex)
  4524. (waitRightGunPlugIt(gunIndex) == PASS ||
  4525. waitLeftGunPlugIt(gunIndex) == PASS) ) {
  4526. if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
  4527. if (strcmp((char*)pSysConfig->UserId, (char*)ShmDcCommonData->pGunInfo[gunIndex].ReservationID) != EQUAL) {
  4528. //log_info("Not Resercation ID");
  4529. continue;
  4530. }
  4531. }
  4532. log_info("-----------------2----------------- ");
  4533. ChangeGunSelectByIndex(gunIndex);
  4534. AddPlugInTimes(gunIndex);
  4535. strcpy((char *)pDcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
  4536. if (CheckDispenserGeneration() >= _DISPENSER_GENERATION_3_5) {
  4537. log_info("index = %d, CardNumber = %s ",
  4538. gunIndex,
  4539. ShmDcCommonData->pGunInfo[gunIndex].StartUserId);
  4540. } else {
  4541. log_info("index = %d, CardNumber = %s ",
  4542. gunIndex,
  4543. pSysConfig->UserId);
  4544. }
  4545. strcpy((char *)pSysConfig->UserId, "");
  4546. ShmDcCommonData->AuthroizeType = IdTokenType_Central;
  4547. if (pDcChargingInfo->StartMethod != _CHARGING_START_AUTOSTART &&
  4548. pDcChargingInfo->StartMethod != _CHARGING_START_EVCCID)
  4549. pDcChargingInfo->StartMethod = _CHARGING_START_RFID;
  4550. // 當前操作的槍號,進入 Preparing
  4551. setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
  4552. systemPageRestoreInit();
  4553. if (pSysInfo->CurGunSelected == gunIndex) {
  4554. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4555. }
  4556. if (CheckDispenserGeneration() == _DISPENSER_GENERATION_3_5) {
  4557. ClearDetectPluginFlag(gunIndex);
  4558. StopGunInfoTimeoutDet(gunIndex);
  4559. } else {
  4560. ClearDetectPluginFlag(LEFT_GUN_NUM);
  4561. ClearDetectPluginFlag(RIGHT_GUN_NUM);
  4562. StopGunInfoTimeoutDet(LEFT_GUN_NUM);
  4563. StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
  4564. }
  4565. continue;
  4566. }
  4567. }
  4568. if (isDetectPlugin(gunIndex) && pSysInfo->CurGunSelected == gunIndex) {
  4569. // LCM => Waiting for plugging
  4570. // AUDI_LCM_CHANGE
  4571. pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
  4572. }
  4573. } else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn &&
  4574. pSysInfo->CurGunSelected == gunIndex && !pDcChargingInfo->isEVCCIDVerify) {
  4575. systemPageRestoreInit();
  4576. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4577. continue;
  4578. } else {
  4579. if (pSysInfo->CurGunSelected == gunIndex) {
  4580. connectorPageRestoreIdle();
  4581. }
  4582. }
  4583. break;
  4584. case S_REASSIGN_CHECK: {
  4585. if (isModeChange(gunIndex)) {
  4586. log_info("============================= S_REASSIGN_CHECK(%x) ============================= ", gunIndex);
  4587. log_info("Start Method:%d",pDcChargingInfo->StartMethod);
  4588. systemPageRestoreInit();
  4589. if (pSysInfo->OrderCharging != NO_DEFINE) {
  4590. pSysInfo->OrderCharging = NO_DEFINE;
  4591. }
  4592. StopSystemTimeoutDet();
  4593. //GetClockTime(&pDcChargingInfo->PreChargeTimer);
  4594. }
  4595. pDcChargingInfo->Replug_flag = true;
  4596. setChargerMode(gunIndex, S_PREPARNING);
  4597. if (pSysInfo->CurGunSelected == gunIndex) {
  4598. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4599. }
  4600. }
  4601. break;
  4602. case S_PREPARNING:
  4603. if (isModeChange(gunIndex)) {
  4604. log_info("============================= S_PREPARNING(%x) ============================= ", gunIndex);
  4605. StopGunInfoTimeoutDet(gunIndex);
  4606. StartGunInfoTimeoutDet(gunIndex, Timeout_Preparing);
  4607. }
  4608. if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
  4609. ShmPsuData->SystemAvailablePower > 10 &&
  4610. GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) >= 3000000) {
  4611. setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
  4612. }
  4613. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4614. if (pSysInfo->CurGunSelected == gunIndex) {
  4615. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4616. }
  4617. break;
  4618. case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
  4619. if (isModeChange(gunIndex)) {
  4620. log_info("============================= S_PREPARING_FOR_EV(%x) ============================= ", gunIndex);
  4621. //strcpy((char *)pSysConfig->UserId, "");
  4622. StopGunInfoTimeoutDet(gunIndex);
  4623. StartGunInfoTimeoutDet(gunIndex, Timeout_EvChargingDet);
  4624. }
  4625. if (pDcChargingInfo->Type == _Type_Chademo) {
  4626. // 檢查車端的槍鎖是否為鎖上
  4627. if (isEvGunLocked_chademo(gunIndex) == YES) {
  4628. if (pSysConfig->ModelName[3] == 'P')
  4629. {
  4630. ConfigOcmfInfo(gunIndex);
  4631. DB_Insert_ocmf(gunIndex);
  4632. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4633. }
  4634. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  4635. }
  4636. } else if (pDcChargingInfo->Type == _Type_GB) {
  4637. // 檢查車端的 charging enable 是否為 1
  4638. if (isEvGunLocked_gb(gunIndex) == YES) {
  4639. if (pSysConfig->ModelName[3] == 'P')
  4640. {
  4641. ConfigOcmfInfo(gunIndex);
  4642. DB_Insert_ocmf(gunIndex);
  4643. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4644. }
  4645. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  4646. }
  4647. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  4648. // 檢查車端的 charging enable 是否為 1
  4649. if (isEvGunLocked_ccs(gunIndex) == YES) {
  4650. if (pSysConfig->ModelName[3] == 'P')
  4651. {
  4652. ConfigOcmfInfo(gunIndex);
  4653. DB_Insert_ocmf(gunIndex);
  4654. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_START;
  4655. }
  4656. setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
  4657. }
  4658. }
  4659. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4660. // LCM => Pre-charging
  4661. if (pSysInfo->CurGunSelected == gunIndex) {
  4662. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4663. }
  4664. break;
  4665. case S_PREPARING_FOR_EVSE: // Ground fault test, 等待 Relay Board 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
  4666. if (isModeChange(gunIndex)) {
  4667. log_info("============================= S_PREPARING_FOR_EVSE(%x) ============================= ", gunIndex);
  4668. StopGunInfoTimeoutDet(gunIndex);
  4669. StartGunInfoTimeoutDet(gunIndex, Timeout_EvseChargingDet);
  4670. if (pSysConfig->ModelName[3] == 'P') {
  4671. ShmDcCommonData->pGunInfo[gunIndex].isMeterStart = TRUE;
  4672. ShmDcCommonData->ocmfTridRecord[gunIndex] = ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId;
  4673. }
  4674. }
  4675. checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  4676. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4677. // LCM => Pre-charging
  4678. if (pSysInfo->CurGunSelected == gunIndex) {
  4679. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4680. }
  4681. break;
  4682. case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
  4683. if (isModeChange(gunIndex)) {
  4684. log_info("============================= S_CHARGING(%x) ============================= ", gunIndex);
  4685. StopGunInfoTimeoutDet(gunIndex);
  4686. ftime(&startChargingTime[gunIndex]);
  4687. strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
  4688. ChangeStartOrStopDateTime(YES, gunIndex);
  4689. OcppStartTransation(gunIndex);
  4690. }
  4691. pDcChargingInfo->Replug_flag = false;
  4692. if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
  4693. ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf = NO;
  4694. }
  4695. ftime(&endChargingTime[gunIndex]);
  4696. pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
  4697. checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  4698. if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime) >= 5) {
  4699. ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
  4700. if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
  4701. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4702. }
  4703. if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
  4704. // 板端要求停止 (錯誤)
  4705. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  4706. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  4707. }
  4708. //printf("%d evBoardStopState = %d", gunIndex, evBoardStopState);
  4709. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  4710. ChargingAlarmProcess(gunIndex);
  4711. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  4712. log_info("Cabinet Stop Gun%d Charging permittion, Status Code [%s]",gunIndex,pDcChargingInfo->ConnectorAlarmCode);
  4713. if (strncmp((char*)pDcChargingInfo->ConnectorAlarmCode,"000000",6) != EQUAL &&
  4714. strncmp((char*)pDcChargingInfo->ConnectorAlarmCode,"",6) != EQUAL) {
  4715. ChargingAlarmProcess(gunIndex);
  4716. //log_info("Cabinet Stop Gun%d Charging permittion, Status Code [%s]",gunIndex,pDcChargingInfo->ConnectorAlarmCode);
  4717. } else {
  4718. ChargingTerminalProcess(gunIndex);
  4719. }
  4720. }
  4721. } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
  4722. // 板端要求停止 (正常)
  4723. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  4724. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
  4725. }
  4726. ChargingTerminalProcess(gunIndex);
  4727. } else if (OcppRemoteStop(gunIndex) == YES ||
  4728. WifiScheduleStop(gunIndex) ||
  4729. CheckBackendChargingTimeout(gunIndex) ||
  4730. CheckBackendChargingEnergy(gunIndex) ||
  4731. strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
  4732. // 後臺要求停止
  4733. ChargingTerminalProcess(gunIndex);
  4734. }
  4735. // LCM => Charging
  4736. if (pSysInfo->CurGunSelected == gunIndex) {
  4737. pSysInfo->ConnectorPage = _LCM_CHARGING;
  4738. }
  4739. break;
  4740. case S_ALARM:
  4741. case S_TERMINATING:
  4742. if (isModeChange(gunIndex)) {
  4743. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
  4744. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
  4745. }
  4746. if (pDcChargingInfo->SystemStatus == S_ALARM) {
  4747. log_info("============================= S_ALARM(%x) ============================= ", gunIndex);
  4748. UpdateErrorCodeToOcpp(gunIndex);
  4749. if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
  4750. OcppStopTransation(gunIndex);
  4751. }
  4752. TheEndCharging(gunIndex);
  4753. } else {
  4754. log_info("============================= S_TERMINATING(%x) ============================= ", gunIndex);
  4755. }
  4756. //log_info ("terminating......................... %x ", gunIndex);
  4757. StopGunInfoTimeoutDet(gunIndex);
  4758. ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
  4759. if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
  4760. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4761. }
  4762. //checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
  4763. if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P' && ShmDcCommonData->pGunInfo[gunIndex].isMeterStart &&
  4764. pDcChargingInfo->RelayK1K2Status == NO && !_isStop[gunIndex]) {
  4765. pSysInfo->DcMeterTransactionAction[gunIndex].ActionCmd = _DC_METER_TRANSACTION_ACTION_STOP;
  4766. log_info("Gun%d Stop Dc Meter Transcation",gunIndex);
  4767. _isStop[gunIndex] = TRUE;
  4768. }
  4769. if (pDcChargingInfo->SystemStatus == S_ALARM) {
  4770. if (pDcChargingInfo->ConnectorPlugIn == NO ) {
  4771. StartGunInfoTimeoutDet(gunIndex,Timeout_ExitComplete);
  4772. }
  4773. /*
  4774. if (pDcChargingInfo->ConnectorPlugIn == NO &&
  4775. GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) >= 10000000) {
  4776. if (ShmDcCommonData->pGunInfo[gunIndex].ReservationStatus) {
  4777. setChargerMode(gunIndex, MODE_RESERVATION);
  4778. } else {
  4779. setChargerMode(gunIndex, MODE_IDLE);
  4780. }
  4781. }
  4782. */
  4783. } else {
  4784. if (pDcChargingInfo->Type == _Type_Chademo) {
  4785. if (isEvStopCharging_chademo(gunIndex) == YES ||
  4786. isPrechargeStatus_chademo(gunIndex) <= 0) {
  4787. setChargerMode(gunIndex, MODE_COMPLETE);
  4788. }
  4789. } else if (pDcChargingInfo->Type == _Type_GB) {
  4790. if (isEvStopCharging_gb(gunIndex) == YES ||
  4791. isPrechargeStatus_gb(gunIndex) <= 0) {
  4792. setChargerMode(gunIndex, MODE_COMPLETE);
  4793. }
  4794. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  4795. if (isEvStopCharging_ccs(gunIndex) == YES &&
  4796. (isPrechargeStatus_ccs(gunIndex) >= 53 ||
  4797. isPrechargeStatus_ccs(gunIndex) == 0 ||
  4798. isPrechargeStatus_ccs(gunIndex) == 13 ||
  4799. isPrechargeStatus_ccs(gunIndex) == 14)
  4800. ) {
  4801. setChargerMode(gunIndex, MODE_COMPLETE);
  4802. }
  4803. }
  4804. }
  4805. if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P') {
  4806. if (pDcChargingInfo->SystemStatus == S_ALARM && ShmDcCommonData->pGunInfo[gunIndex].isMeterStop &&
  4807. pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady)
  4808. {
  4809. pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady = NO;
  4810. DB_Update_ocmf(gunIndex);
  4811. StoreOcmfFile(gunIndex,ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId,FALSE);
  4812. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4813. }
  4814. }
  4815. if (pSysInfo->CurGunSelected == gunIndex) {
  4816. pSysInfo->ConnectorPage = _LCM_COMPLETE;
  4817. }
  4818. break;
  4819. case S_COMPLETE:
  4820. if (isModeChange(gunIndex)) {
  4821. log_info ("============================= S_COMPLETE(%x) ============================= ", gunIndex);
  4822. if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
  4823. OcppStopTransation(gunIndex);
  4824. }
  4825. TheEndCharging(gunIndex);
  4826. }
  4827. if (pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady && ShmDcCommonData->pGunInfo[gunIndex].isMeterStop) {
  4828. pSysInfo->DcMeterTransactionAction[gunIndex].OcmfInfoReady = NO;
  4829. DB_Update_ocmf(gunIndex);
  4830. StoreOcmfFile(gunIndex,ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId,FALSE);
  4831. DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
  4832. }
  4833. if (pDcChargingInfo->ConnectorPlugIn == NO ) {
  4834. StartGunInfoTimeoutDet(gunIndex,Timeout_ExitComplete);
  4835. }
  4836. /*
  4837. if (pDcChargingInfo->ConnectorPlugIn == NO &&
  4838. GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) >= 10000000) {
  4839. if (ShmDcCommonData->pGunInfo[gunIndex].ReservationStatus) {
  4840. setChargerMode(gunIndex, MODE_RESERVATION);
  4841. } else {
  4842. setChargerMode(gunIndex, MODE_IDLE);
  4843. }
  4844. destroySelGun(gunIndex); //Jerry add
  4845. #if defined DD360 || defined DD3660ComBox
  4846. connectorPageRestoreIdle();
  4847. #endif
  4848. }
  4849. */
  4850. if (pSysInfo->CurGunSelected == gunIndex) {
  4851. pSysInfo->ConnectorPage = _LCM_COMPLETE;
  4852. }
  4853. break;
  4854. case S_CCS_PRECHARGE_ST0:
  4855. if (isModeChange(gunIndex)) {
  4856. log_info("============================= CCS Precharge Processing 1(%x) ============================= ", gunIndex);
  4857. StopGunInfoTimeoutDet(gunIndex);
  4858. StartGunInfoTimeoutDet(gunIndex, Timeout_ForCcsPrechargeDet);
  4859. }
  4860. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  4861. // GFD 錯誤停止
  4862. RecordAlarmCode(gunIndex, "012235");
  4863. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  4864. }
  4865. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4866. // 等待 EV 小板 (CCS) 通知可以開始 Precharge
  4867. // 切換 D+ Relay to Precharge Relay
  4868. if (isPrechargeStatus_ccs(gunIndex) == 39 ||
  4869. isPrechargeStatus_ccs(gunIndex) == 40) {
  4870. if ((pDcChargingInfo->RelayKPK2Status == YES || pDcChargingInfo->PantographFlag == YES) &&
  4871. pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
  4872. //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
  4873. {
  4874. //log_info("Send precharge ready 1..........%x, status = %d ",
  4875. // gunIndex,
  4876. // isPrechargeStatus_ccs(gunIndex));
  4877. if (isPrechargeStatus_ccs(gunIndex) == 39) {
  4878. log_info("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) ",
  4879. gunIndex,
  4880. isPrechargeStatus_ccs(gunIndex));
  4881. } else if (isPrechargeStatus_ccs(gunIndex) == 40) {
  4882. log_info("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) ",
  4883. gunIndex,
  4884. isPrechargeStatus_ccs(gunIndex));
  4885. }
  4886. pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
  4887. }
  4888. } else if (isPrechargeStatus_ccs(gunIndex) == 45 ||
  4889. isPrechargeStatus_ccs(gunIndex) == 46
  4890. ) {
  4891. setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP1);
  4892. }
  4893. if (pSysInfo->CurGunSelected == gunIndex) {
  4894. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4895. }
  4896. break;
  4897. case S_CCS_PRECHARGE_ST1:
  4898. if (isModeChange(gunIndex)) {
  4899. log_info("============================= CCS Precharge Processing 2(%x) ============================= ", gunIndex);
  4900. }
  4901. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  4902. // GFD 錯誤停止
  4903. RecordAlarmCode(gunIndex, "012235");
  4904. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
  4905. }
  4906. checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
  4907. // 等待小板通知進入充電
  4908. // 切換 D+ Relay to Precharge Relay
  4909. if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
  4910. pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
  4911. setChargerMode(gunIndex, MODE_CHARGING);
  4912. }
  4913. if (pSysInfo->CurGunSelected == gunIndex) {
  4914. pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
  4915. }
  4916. break;
  4917. case S_MAINTAIN:
  4918. if (isModeChange(gunIndex)) {
  4919. log_info("============================= S_MAINTAIN(%x) ============================= ", gunIndex);
  4920. //pSysInfo->SystemPage = _PAGE_MAINTAIN;
  4921. StopSystemTimeoutDet();
  4922. if (pSysInfo->FirmwareUpdate == YES) {
  4923. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  4924. pSysInfo->SystemPage = _LCM_FIX;
  4925. }
  4926. continue;
  4927. }
  4928. if (pDcChargingInfo->IsAvailable == NO) {
  4929. log_info("Gun%d is not availbale");
  4930. break;
  4931. }
  4932. /*
  4933. if (pSysWarning->Level != WARN_LV_ER) {
  4934. if (!DisplaySelfTestFailReason()) { //DS60-120 add
  4935. log_info("Soft reboot for retry self-tets. ");
  4936. sleep(3);
  4937. KillAllTask();
  4938. system("/usr/bin/run_evse_restart.sh");
  4939. }
  4940. }
  4941. */
  4942. if (pSysWarning->Level == WARN_LV_ER) { //DS60-120 add
  4943. KillTaskExceptPrimary();
  4944. } else {
  4945. KillTask();
  4946. }
  4947. /*
  4948. if (pSysInfo->SelfTestSeq == _STEST_FAIL)
  4949. StopProcessingLoop();
  4950. */
  4951. }
  4952. if (pSysInfo->SelfTestSeq == _STEST_FAIL) {
  4953. SelfTestRun();
  4954. StopSystemTimeoutDet();
  4955. sleep(3);
  4956. break;
  4957. }
  4958. if (pDcChargingInfo->IsAvailable && pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
  4959. if (pSysWarning->Level == WARN_LV_ER)
  4960. setChargerMode(gunIndex, MODE_FAULT);
  4961. else
  4962. setChargerMode(gunIndex, MODE_IDLE);
  4963. }
  4964. #ifndef DD360Audi
  4965. if (pSysInfo->CurGunSelected == gunIndex) {
  4966. if (CheckDispenserGeneration() != _DISPENSER_GENERATION_3_5) {
  4967. pSysInfo->SystemPage = _LCM_FIX;
  4968. }
  4969. }
  4970. #endif
  4971. break;
  4972. case S_UPDATE:
  4973. if (isModeChange(gunIndex)) {
  4974. log_info("============================= S_UPDATE(%x) ============================= ", gunIndex);
  4975. }
  4976. if (!pSysInfo->FirmwareUpdate) {
  4977. setChargerMode(gunIndex, MODE_IDLE);
  4978. }
  4979. break;
  4980. default:
  4981. if (isModeChange(gunIndex)) {
  4982. log_info("============================= UNKONWN (%x) ============================= ", gunIndex);
  4983. }
  4984. if (pSysConfig->TotalConnectorCount >= 2) {
  4985. pDcInfo = (struct ChargingInfoData *)GetDcChargingInfoData((gunIndex ? LEFT_GUN_NUM : RIGHT_GUN_NUM));
  4986. } else {
  4987. pDcInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  4988. }
  4989. if (pSysInfo->SelfTestSeq != _STEST_FAIL && !IntoOperateProcess(pDcInfo->SystemStatus)) {
  4990. log_info("Gun%d into UNKOWN status, Dispenser will soft reset",gunIndex);
  4991. TryCloseWatchdog();
  4992. system("/usr/bin/run_evse_restart.sh");
  4993. }
  4994. }//switch
  4995. TryFeedWatchdog();
  4996. }//for
  4997. #if defined DD360Audi
  4998. if (pSysInfo->SystemPage != _LCM_SELECT_GUN) {
  4999. #else
  5000. if (pSysInfo->SystemPage != _LCM_NONE) {
  5001. #endif //defined DD360Audi
  5002. ChangeLcmByIndex(pSysInfo->SystemPage);
  5003. } else {
  5004. bool dcPageRun = false;
  5005. if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  5006. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  5007. if (pAcChargingInfo->SystemStatus == S_IDLE) {
  5008. ChangeLcmByIndex(_LCM_IDLE);
  5009. } else if (pAcChargingInfo->SystemStatus == S_PREPARNING) {
  5010. ChangeLcmByIndex(_LCM_PRE_CHARGE);
  5011. } else if (pAcChargingInfo->SystemStatus == S_CHARGING) {
  5012. ChangeLcmByIndex(_LCM_CHARGING);
  5013. } else if (pAcChargingInfo->SystemStatus == S_TERMINATING ||
  5014. pAcChargingInfo->SystemStatus == S_COMPLETE) {
  5015. ChangeLcmByIndex(_LCM_COMPLETE);
  5016. } else {
  5017. dcPageRun = true;
  5018. }
  5019. } else {
  5020. dcPageRun = true;
  5021. }
  5022. if (dcPageRun) {
  5023. ChangeLcmByIndex(pSysInfo->ConnectorPage);
  5024. }
  5025. }
  5026. //for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  5027. // pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  5028. // checkEvBoardAlarmState(pDcChargingInfo->Type);
  5029. // checkChillerAlarmState();
  5030. // //if (checkChillerAlarmState(gunIndex) == ABNORMAL) {
  5031. // // break;
  5032. // //}
  5033. //}
  5034. TryFeedWatchdog();
  5035. usleep(WHILE_LOOP_TIME);
  5036. }
  5037. return FAIL;
  5038. }