main.c 228 KB

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