MessageHandler.c 892 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  96. struct ClientTime
  97. {
  98. struct timespec Heartbeat;
  99. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  100. struct timespec StartTransaction;
  101. struct timespec StopTransaction;
  102. struct timespec MeterValues[CONNECTOR_QUANTITY];
  103. struct timespec RemoteStartWait;
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4,
  117. unsigned char :3; //bit5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // TTIA routine
  357. //=========================================
  358. int sendTTIAInfo(uint8_t gun_index)
  359. {
  360. static int sn = 0;
  361. int result = FAIL;
  362. struct hostent *server;
  363. int udp_socket_fd;
  364. struct sockaddr_in dest_addr = {0};
  365. uint8_t tx_buf[80] = {0};
  366. uint8_t logBuf[256]= {0};
  367. uint8_t tx_len, tempIndex, socStart, socEnd;
  368. uint16_t PresentChargedEnergy;
  369. struct tm tmStart, tmEnd;
  370. DEBUG_INFO("sendTTIAInfo...\n");
  371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  372. {
  373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  374. {
  375. tempIndex = ((gun_index==2) ? 1: 0);
  376. }
  377. else
  378. {
  379. tempIndex = gun_index;
  380. }
  381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  382. {
  383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  384. {
  385. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  386. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  387. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  388. }
  389. }
  390. }
  391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  392. {
  393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  394. {
  395. tempIndex = ((gun_index==2) ? 1: 0);
  396. }
  397. else
  398. {
  399. tempIndex = gun_index;
  400. }
  401. for (int index = 0; index < CCS_QUANTITY; index++)
  402. {
  403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  404. {
  405. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  406. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  407. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  408. }
  409. }
  410. }
  411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  412. {
  413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  414. {
  415. tempIndex = ((gun_index==2) ? 1: 0);
  416. }
  417. else
  418. {
  419. tempIndex = gun_index;
  420. }
  421. for (int index = 0; index < GB_QUANTITY; index++)
  422. {
  423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  424. {
  425. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  426. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  427. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  428. }
  429. }
  430. }
  431. else if(gunType[gun_index] == GUN_TYPE_DO)
  432. {
  433. tempIndex = gun_index;
  434. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  435. {
  436. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  437. {
  438. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  439. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  440. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  441. }
  442. }
  443. }
  444. else
  445. {
  446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  447. {
  448. tempIndex = 2;
  449. }
  450. else
  451. {
  452. tempIndex = gun_index;
  453. }
  454. for (int index = 0; index < AC_QUANTITY; index++)
  455. {
  456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  457. {
  458. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  459. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  460. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  461. }
  462. }// END
  463. }
  464. // Message assembly
  465. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  466. tx_buf[4] = 0x02; // Protocol Version
  467. tx_buf[5] = 0xb0; // Message ID
  468. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  469. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  470. tx_buf[8] = 0x00; // CarID low byte
  471. tx_buf[9] = 0x00; // CarID high byte
  472. tx_buf[10] = 0x00; // ID Storage
  473. tx_buf[11] = 0x00; // Driver lowest byte
  474. tx_buf[12] = 0x00; // Driver 2nd byte
  475. tx_buf[13] = 0x00; // Driver 3rd byte
  476. tx_buf[14] = 0x00; // Driver highest byte
  477. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  478. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  479. tx_buf[17] = 0x00; // Reserve
  480. tx_buf[18] = 60 & 0xff; // Payload length low byte
  481. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  482. // EVSE provider
  483. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  484. // EVSE provider
  485. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  486. // EVSE id
  487. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  488. // Connector id
  489. tx_buf[37] = gun_index;
  490. // EVSE station
  491. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  492. // Vehicle SN
  493. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  494. // Mileage
  495. tx_buf[61] = 0x00; // lowest byte
  496. tx_buf[62] = 0x00; // 2nd byte
  497. tx_buf[63] = 0x00; // highest byte
  498. // Start date time 6 bytes
  499. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  500. {
  501. struct tm *tmTarget;
  502. struct timeb tbTarget;
  503. tmStart.tm_year -= 1900;
  504. tmStart.tm_mon -= 1;
  505. tmStart.tm_gmtoff = 0;
  506. tbTarget.time = mktime(&tmStart);
  507. tbTarget.timezone = 0;
  508. tbTarget.time += (8*3600);
  509. tmTarget = gmtime(&tbTarget.time);
  510. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  511. tx_buf[65] = (tmTarget->tm_mon+1);
  512. tx_buf[66] = tmTarget->tm_mday;
  513. tx_buf[67] = tmTarget->tm_hour;
  514. tx_buf[68] = tmTarget->tm_min;
  515. tx_buf[69] = tmTarget->tm_sec;
  516. }
  517. // Stop date time 6 bytes
  518. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  519. {
  520. struct tm *tmTarget;
  521. struct timeb tbTarget;
  522. tmEnd.tm_year -= 1900;
  523. tmEnd.tm_mon -= 1;
  524. tmEnd.tm_gmtoff = 0;
  525. tbTarget.time = mktime(&tmEnd);
  526. tbTarget.timezone = 0;
  527. tbTarget.time += (8*3600);
  528. tmTarget = gmtime(&tbTarget.time);
  529. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  530. tx_buf[71] = (tmTarget->tm_mon+1);
  531. tx_buf[72] = tmTarget->tm_mday;
  532. tx_buf[73] = tmTarget->tm_hour;
  533. tx_buf[74] = tmTarget->tm_min;
  534. tx_buf[75] = tmTarget->tm_sec;
  535. }
  536. // Session energy 2 bytes
  537. tx_buf[76] = PresentChargedEnergy & 0xff;
  538. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  539. // Start SOC 1 byte
  540. tx_buf[78] = socStart;
  541. // Stop SOC 1 byte
  542. tx_buf[79] = socEnd;
  543. // Open socket
  544. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  545. if(udp_socket_fd == -1)
  546. {
  547. DEBUG_ERROR("UDP socket create failed!\n");
  548. }
  549. else
  550. {
  551. // Get server DNS entry
  552. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  553. if (server == NULL)
  554. {
  555. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  556. }
  557. else
  558. {
  559. // Build the server's Internet address
  560. bzero((char *) &dest_addr, sizeof(dest_addr));
  561. dest_addr.sin_family = AF_INET;
  562. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  563. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  564. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  565. {
  566. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  567. {
  568. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  569. }
  570. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  571. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  572. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  573. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  574. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  575. DEBUG_TTIA_INFO("---------- Header ----------\n");
  576. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  577. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  578. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  579. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  580. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  581. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  582. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  583. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  584. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  585. DEBUG_TTIA_INFO("Len: 0x3C\n");
  586. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  587. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  588. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  589. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  590. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  591. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  592. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  593. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  594. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  596. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  597. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  598. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  599. DEBUG_TTIA_INFO("=========================================\n");
  600. sn++;
  601. result = PASS;
  602. }
  603. else
  604. {
  605. DEBUG_ERROR("UDP sent out fail.\n");
  606. }
  607. }
  608. }
  609. return result;
  610. }
  611. //=========================================
  612. // Save configuration
  613. //=========================================
  614. int runShellCmd(const char*cmd)
  615. {
  616. int result = FAIL;
  617. char buf[256];
  618. FILE *fp;
  619. fp = popen(cmd, "r");
  620. if(fp != NULL)
  621. {
  622. while(fgets(buf, sizeof(buf), fp) != NULL)
  623. {
  624. DEBUG_INFO("%s\n", buf);
  625. }
  626. result = PASS;
  627. }
  628. pclose(fp);
  629. return result;
  630. }
  631. int StoreUsrConfigData(struct SysConfigData *UsrData)
  632. {
  633. int result = PASS;
  634. int fd,wrd;
  635. unsigned int i,Chk;
  636. unsigned char *ptr, *BufTmp;
  637. int MtdBlockSize = 0x300000;
  638. Chk=0;
  639. ptr=(unsigned char *)UsrData;
  640. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  641. {
  642. memset(BufTmp,0,MtdBlockSize);
  643. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  644. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  645. Chk+=*(BufTmp+i);
  646. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  647. // Output configuration to file.
  648. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  649. if (fd < 0)
  650. {
  651. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  652. free(BufTmp);
  653. return 0;
  654. }
  655. wrd=write(fd, BufTmp, MtdBlockSize);
  656. close(fd);
  657. if(wrd<MtdBlockSize)
  658. {
  659. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  660. free(BufTmp);
  661. return 0;
  662. }
  663. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  664. DEBUG_INFO("Erase /dev/mtd10.\n");
  665. runShellCmd("flash_erase /dev/mtd10 0 0");
  666. DEBUG_INFO("Write /dev/mtd10.\n");
  667. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  668. DEBUG_INFO("Erase /dev/mtd11.\n");
  669. runShellCmd("flash_erase /dev/mtd11 0 0");
  670. DEBUG_INFO("Write /dev/mtd11.\n");
  671. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  672. system("rm -f /mnt/EvseConfig.bin");
  673. DEBUG_INFO("EvseConfig write to flash OK\n");
  674. }
  675. else
  676. {
  677. DEBUG_ERROR("alloc BlockSize NG\r\n");
  678. result = FAIL;
  679. }
  680. if(BufTmp!=NULL)
  681. free(BufTmp);
  682. return result;
  683. }
  684. //=========================================
  685. // Sqlite3 related function
  686. //=========================================
  687. static int selectSqlCount = 0;
  688. static int callback(void *data, int argc, char **argv, char **azColName){
  689. int i;
  690. //printf("%s: ", (const char*)data);
  691. selectSqlCount = argc;
  692. for(i = 0; i<argc; i++){
  693. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  694. }
  695. //printf("\n");
  696. return 0;
  697. }
  698. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  699. //int i;
  700. //printf("%s:\n", (const char*)data);
  701. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  702. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  703. return 0;
  704. }
  705. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  706. //printf("%s:\n", (const char*)data);
  707. //idTag
  708. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  710. //parentIdTag
  711. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  712. //expir_date
  713. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  714. //status
  715. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  716. //version
  717. if(columenCount > 5)
  718. idTagQuery.listVersionInt = atoi(columnValue[5]);
  719. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  720. return 0;
  721. }
  722. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  723. {
  724. // localversion = argv[5] ? atoi(argv[5]) : 0;
  725. // printf("localversion=%d\n", localversion);
  726. return 0;
  727. }
  728. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  729. {
  730. for (int i = 0; i < n_columns; i++)
  731. {
  732. DEBUG_INFO("%s\t", col_values[i]);
  733. }
  734. DEBUG_INFO("\n");
  735. return 0;
  736. }
  737. int OCPP_cleanLocalCache()
  738. {
  739. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  740. char *errMsg = 0;
  741. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  742. if (SQLITE_OK != rc)
  743. {
  744. DEBUG_INFO("SQL error: %s\n",errMsg);
  745. return FALSE;
  746. }
  747. return TRUE;
  748. }
  749. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  750. {
  751. int isSuccess = TRUE;
  752. int ret = 0;
  753. //const char* data = "Callback function called";
  754. char sql[300];
  755. char zErrMsg[200];
  756. memset(sql, 0, 300);
  757. memset(zErrMsg, 0, 200);
  758. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  759. //* Execute SQL statement */
  760. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  761. if( ret != SQLITE_OK )
  762. {
  763. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  764. isSuccess = FALSE;
  765. }
  766. return isSuccess;
  767. }
  768. void OCPP_getIdTagFromLocalCache(char idTag[])
  769. {
  770. int rc = 0;
  771. char sql[100];
  772. char zErrMsg[100];
  773. memset(sql, 0, 100);
  774. memset(zErrMsg, 0, 100);
  775. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  776. memset(&idTagQuery, 0, sizeof(idTagQuery));
  777. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  778. /* Execute SQL statement */
  779. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  780. if( rc != SQLITE_OK )
  781. {
  782. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  783. }
  784. }
  785. void OCPP_getListVerion()
  786. {
  787. int rc = 0;
  788. // const char* data = "Callback function called";
  789. char sql[100];
  790. char zErrMsg[100];
  791. memset(sql, 0, 100);
  792. memset(zErrMsg, 0, 100);
  793. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  794. /* Execute SQL statement */
  795. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  796. if( rc != SQLITE_OK )
  797. {
  798. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  799. }
  800. }
  801. void OCPP_get_TableAuthlocalAllData(void)
  802. {
  803. int rc = 0;
  804. char sql[100];
  805. char zErrMsg[100];
  806. memset(sql, 0, 100);
  807. memset(zErrMsg, 0, 100);
  808. sprintf(sql,"select * from ocpp_auth_local ");
  809. /* Execute SQL statement */
  810. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  811. if( rc != SQLITE_OK )
  812. {
  813. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  814. }
  815. //return ver;
  816. }
  817. int OCPP_cleanLocalList()
  818. {
  819. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  820. char *errMsg = 0;
  821. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  822. if (SQLITE_OK != rc)
  823. {
  824. DEBUG_INFO("%s\n",errMsg);
  825. return FALSE;
  826. }
  827. return TRUE;
  828. }
  829. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  830. {
  831. int isSuccess = FALSE;
  832. int ret = 0;
  833. //const char* data = "Callback function called";
  834. char sql[300];
  835. char zErrMsg[200];
  836. memset(sql, 0, 300);
  837. memset(zErrMsg, 0, 200);
  838. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  839. //* Execute SQL statement */
  840. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  841. if( ret != SQLITE_OK )
  842. {
  843. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  844. return isSuccess;
  845. }
  846. memset(sql, 0, 300);
  847. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  848. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  849. if( ret != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. return isSuccess;
  853. }
  854. isSuccess = TRUE;
  855. return isSuccess;
  856. }
  857. void OCPP_getIdTagFromLocalList(char idTag[])
  858. {
  859. int rc = 0;
  860. // const char* data = "Callback function called";
  861. char sql[100];
  862. char zErrMsg[100];
  863. memset(sql, 0, 100);
  864. memset(zErrMsg, 0, 100);
  865. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  866. memset(&idTagQuery, 0, sizeof(idTagQuery));
  867. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  868. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  869. /* Execute SQL statement */
  870. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  871. if( rc != SQLITE_OK )
  872. {
  873. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  874. }
  875. //return ver;
  876. }
  877. void OCPP_deleteIdTagFromLocalList(char idTag[])
  878. {
  879. //int ver = 0;
  880. //int isSuccess = FALSE;
  881. int rc = 0;
  882. char sql[100];
  883. char zErrMsg[100];
  884. memset(sql, 0, 100);
  885. memset(zErrMsg, 0, 100);
  886. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  887. //* Execute SQL statement */
  888. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  889. if( rc != SQLITE_OK )
  890. {
  891. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  892. }
  893. }
  894. int getCurrentYear()
  895. {
  896. int result = 0;
  897. time_t CurrentTime;
  898. struct tm *tm;
  899. CurrentTime = time(NULL);
  900. tm=localtime(&CurrentTime);
  901. result = (tm->tm_year + 1900);
  902. return result;
  903. }
  904. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  905. {
  906. int result = PASS;
  907. char* errMsg = NULL;
  908. char sqlStr[8192];
  909. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  910. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  911. {
  912. result = FAIL;
  913. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  914. }
  915. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  920. }
  921. return result;
  922. }
  923. //==========================================
  924. // Check time passed since today
  925. //==========================================
  926. long long DiffTimebWithNow(struct timeb ST)
  927. {
  928. //return milli-second
  929. struct timeb ET;
  930. long long StartTime,StopTime;
  931. ftime(&ET);
  932. StartTime=(long long)ST.time;
  933. StopTime=(long long)ET.time;
  934. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  935. }
  936. int getTimePassSinceToday(uint8_t gun_index)
  937. {
  938. int result = -1;
  939. static time_t lastTime[4];
  940. time_t t;
  941. struct tm *tmStartToday;
  942. struct timeb tbStartToday;
  943. t=time(NULL);
  944. if(difftime(t, lastTime[gun_index])>0)
  945. {
  946. tmStartToday=localtime(&t);
  947. tmStartToday->tm_hour = 0;
  948. tmStartToday->tm_min = 0;
  949. tmStartToday->tm_sec = 0;
  950. tbStartToday.time = mktime(tmStartToday);
  951. tbStartToday.millitm = 0;
  952. result = DiffTimebWithNow(tbStartToday)/1000;
  953. lastTime[gun_index] = t;
  954. }
  955. return result;
  956. }
  957. void getNowDatetime(uint8_t *data)
  958. {
  959. time_t t = time(NULL);
  960. struct tm tm = *localtime(&t);
  961. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  962. }
  963. int syncDateTimeRTC(uint8_t *data)
  964. {
  965. struct ParsingResult
  966. {
  967. int result;
  968. int scanedElement;
  969. int year;
  970. int month;
  971. int mday;
  972. int hour;
  973. int min;
  974. int sec;
  975. int tz_hour;
  976. int tz_min;
  977. float minSec;
  978. }result;
  979. struct tm tmOrg;
  980. struct tm *tmTarget;
  981. struct timeb tbTarget;
  982. char buf[128];
  983. memset(&result, 0x00, sizeof(struct ParsingResult));
  984. result.result = PASS;
  985. if(strstr((char*)data, ".") != NULL)
  986. {
  987. // Original data with mini second
  988. if(strstr((char*)data, "Z") != NULL)
  989. {
  990. // Original data with Z
  991. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  992. &result.year,
  993. &result.month,
  994. &result.mday,
  995. &result.hour,
  996. &result.min,
  997. &result.sec,
  998. &result.minSec);
  999. }
  1000. else
  1001. {
  1002. // Original data without Z
  1003. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1004. &result.year,
  1005. &result.month,
  1006. &result.mday,
  1007. &result.hour,
  1008. &result.min,
  1009. &result.sec,
  1010. &result.minSec,
  1011. &result.tz_hour,
  1012. &result.tz_min);
  1013. }
  1014. }
  1015. else
  1016. {
  1017. // Original data without mini second
  1018. if(strstr((char*)data, "Z") != NULL)
  1019. {
  1020. // Original data with Z
  1021. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1022. &result.year,
  1023. &result.month,
  1024. &result.mday,
  1025. &result.hour,
  1026. &result.min,
  1027. &result.sec);
  1028. }
  1029. else
  1030. {
  1031. // Original data without Z
  1032. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1033. &result.year,
  1034. &result.month,
  1035. &result.mday,
  1036. &result.hour,
  1037. &result.min,
  1038. &result.sec,
  1039. &result.tz_hour,
  1040. &result.tz_min);
  1041. }
  1042. }
  1043. tmOrg.tm_year = result.year - 1900;
  1044. tmOrg.tm_mon = result.month - 1;
  1045. tmOrg.tm_mday = result.mday;
  1046. tmOrg.tm_hour = result.hour;
  1047. tmOrg.tm_min = result.min;
  1048. tmOrg.tm_sec = result.sec;
  1049. tmOrg.tm_gmtoff = 0;
  1050. tbTarget.time = mktime(&tmOrg);
  1051. tbTarget.timezone = 0;
  1052. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1053. tmTarget = gmtime(&tbTarget.time);
  1054. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1055. //DEBUG_INFO(" org date time: %s\n", data);
  1056. //DEBUG_INFO("parse date time: %s\n", buf);
  1057. system(buf);
  1058. system("/sbin/hwclock -w --systohc");
  1059. if(result.scanedElement < 6)
  1060. result.result = FAIL;
  1061. return result.result;
  1062. }
  1063. //==========================================
  1064. // GetCompositeSchedule logic related function
  1065. //==========================================
  1066. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1067. {
  1068. //return milli-second
  1069. unsigned int StartTime,StopTime;
  1070. StartTime=(unsigned int)ST.time;
  1071. StopTime=(unsigned int)ET.time;
  1072. return (StopTime-StartTime);
  1073. }
  1074. int DiffTimebWithNowSec(struct timeb ST)
  1075. {
  1076. //return milli-second
  1077. struct timeb ET;
  1078. unsigned int StartTime,StopTime;
  1079. ftime(&ET);
  1080. StartTime=(unsigned int)ST.time;
  1081. StopTime=(unsigned int)ET.time;
  1082. return (StopTime-StartTime);
  1083. }
  1084. int getStartStop(uint8_t *start, uint8_t *stop)
  1085. {
  1086. int result = -1;
  1087. struct tm tmStart;
  1088. struct timeb tbStart;
  1089. struct tm tmStop;
  1090. struct timeb tbStop;
  1091. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1092. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1093. {
  1094. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1095. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1096. tmStart.tm_year -= 1900;
  1097. tmStart.tm_mon -= 1;
  1098. tbStart.time = mktime(&tmStart);
  1099. tbStart.millitm = 0;
  1100. tmStop.tm_year -= 1900;
  1101. tmStop.tm_mon -= 1;
  1102. tbStop.time = mktime(&tmStop);
  1103. tbStop.millitm = 0;
  1104. result = DiffTimebSec(tbStart, tbStop);
  1105. //DEBUG_INFO("getStartStop(): %d\n", result);
  1106. }
  1107. else
  1108. {
  1109. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1110. }
  1111. return result;
  1112. }
  1113. int isOvertNow(uint8_t *start)
  1114. {
  1115. int result = NO;
  1116. struct ParsingResult
  1117. {
  1118. int result;
  1119. int scanedElement;
  1120. int year;
  1121. int month;
  1122. int mday;
  1123. int hour;
  1124. int min;
  1125. int sec;
  1126. int tz_hour;
  1127. int tz_min;
  1128. float minSec;
  1129. }parsingResult;
  1130. struct tm tmStart;
  1131. struct timeb tbStart;
  1132. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1133. if(strstr((char*)start, ".") != NULL)
  1134. {
  1135. // Original data with mini second
  1136. if(strstr((char*)start, "Z") != NULL)
  1137. {
  1138. // Original data with Z
  1139. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1140. &parsingResult.year,
  1141. &parsingResult.month,
  1142. &parsingResult.mday,
  1143. &parsingResult.hour,
  1144. &parsingResult.min,
  1145. &parsingResult.sec,
  1146. &parsingResult.minSec);
  1147. }
  1148. else
  1149. {
  1150. // Original data without Z
  1151. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1152. &parsingResult.year,
  1153. &parsingResult.month,
  1154. &parsingResult.mday,
  1155. &parsingResult.hour,
  1156. &parsingResult.min,
  1157. &parsingResult.sec,
  1158. &parsingResult.minSec,
  1159. &parsingResult.tz_hour,
  1160. &parsingResult.tz_min);
  1161. }
  1162. }
  1163. else
  1164. {
  1165. // Original data without mini second
  1166. if(strstr((char*)start, "Z") != NULL)
  1167. {
  1168. // Original data with Z
  1169. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1170. &parsingResult.year,
  1171. &parsingResult.month,
  1172. &parsingResult.mday,
  1173. &parsingResult.hour,
  1174. &parsingResult.min,
  1175. &parsingResult.sec);
  1176. }
  1177. else
  1178. {
  1179. // Original data without Z
  1180. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1181. &parsingResult.year,
  1182. &parsingResult.month,
  1183. &parsingResult.mday,
  1184. &parsingResult.hour,
  1185. &parsingResult.min,
  1186. &parsingResult.sec,
  1187. &parsingResult.tz_hour,
  1188. &parsingResult.tz_min);
  1189. }
  1190. }
  1191. if(parsingResult.scanedElement >= 6)
  1192. {
  1193. tmStart.tm_year = parsingResult.year - 1900;
  1194. tmStart.tm_mon = parsingResult.month - 1;
  1195. tmStart.tm_mday = parsingResult.mday;
  1196. tmStart.tm_hour = parsingResult.hour;
  1197. tmStart.tm_min = parsingResult.min;
  1198. tmStart.tm_sec = parsingResult.sec;
  1199. tmStart.tm_gmtoff = 0;
  1200. tbStart.time = mktime(&tmStart);
  1201. tbStart.timezone = 0;
  1202. tbStart.millitm = 0;
  1203. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1204. if(DiffTimebWithNowSec(tbStart) <= 0)
  1205. result = NO;
  1206. else
  1207. result = YES;
  1208. }
  1209. else
  1210. {
  1211. DEBUG_WARN("Start date parsing error.\n");
  1212. }
  1213. return result;
  1214. }
  1215. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1216. {
  1217. int result = -1;
  1218. struct tm tmStart;
  1219. struct timeb tbStart;
  1220. struct tm tmStop;
  1221. struct timeb tbStop;
  1222. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1223. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1224. {
  1225. tmStart.tm_year -= 1900;
  1226. tmStart.tm_mon -= 1;
  1227. tbStart.time = mktime(&tmStart);
  1228. tbStart.millitm = 0;
  1229. tmStop.tm_year -= 1900;
  1230. tmStop.tm_mon -= 1;
  1231. tbStop.time = mktime(&tmStop);
  1232. tbStop.millitm = 0;
  1233. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1234. }
  1235. return result;
  1236. }
  1237. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1238. {
  1239. FILE *fp;
  1240. char profileFileName[128];
  1241. char *line = NULL;
  1242. size_t len = 0;
  1243. time_t CurrentTime;
  1244. struct tm *tmComposite;
  1245. struct StructChargingProfile maxProfile;
  1246. uint8_t limitMax=0;
  1247. int compositePeriodIdx = 0;
  1248. CurrentTime = time(NULL);
  1249. tmComposite=localtime(&CurrentTime);
  1250. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1251. if(isUnitA)
  1252. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1253. else
  1254. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1255. compositeProfile->ChargingSchedule.Duration = durationReq;
  1256. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1257. {
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1260. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1261. }
  1262. compositeProfile->ChargingProfileId = 0;
  1263. compositeProfile->StackLevel = 99 ;
  1264. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1265. maxProfile.ChargingProfileId = -1;
  1266. maxProfile.ChargingSchedule.Duration = -1;
  1267. system("rm -f /tmp/*.json");
  1268. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1269. // Search max profile
  1270. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1271. if((access(profileFileName, F_OK))!=-1)
  1272. {
  1273. fp = fopen(profileFileName, "r");
  1274. while(getline(&line, &len, fp) != -1)
  1275. {
  1276. json_object *obj = NULL;
  1277. obj = json_tokener_parse(line);
  1278. if(is_error(obj))
  1279. {
  1280. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1281. }
  1282. else
  1283. {
  1284. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1285. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1286. )
  1287. {
  1288. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1289. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1290. )
  1291. {
  1292. struct tm tmFrom, tmTo;
  1293. struct timeb tbFrom, tbTo;
  1294. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1295. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1296. {
  1297. tmFrom.tm_year -= 1900;
  1298. tmFrom.tm_mon -= 1;
  1299. tbFrom.time = mktime(&tmFrom);
  1300. tmTo.tm_year -= 1900;
  1301. tmTo.tm_mon -= 1;
  1302. tbTo.time = mktime(&tmTo);
  1303. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1304. {
  1305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1306. {
  1307. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1309. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1310. }
  1311. maxProfile.ChargingProfileId = -1;
  1312. maxProfile.StackLevel = -1;
  1313. if(maxProfile.ChargingProfileId == -1)
  1314. DEBUG_INFO("MaxProfile found.\n");
  1315. else
  1316. DEBUG_INFO("MaxProfile updated.\n");
  1317. // Required item
  1318. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1319. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1320. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1321. if(isUnitA)
  1322. {
  1323. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1324. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1325. {
  1326. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1327. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1328. 3:
  1329. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1330. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1331. }
  1332. }
  1333. else
  1334. {
  1335. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1336. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1337. {
  1338. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1339. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1340. 3:
  1341. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1342. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1343. }
  1344. }
  1345. // Optional item
  1346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1347. {
  1348. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1349. }
  1350. else
  1351. {
  1352. sprintf((char*)maxProfile.ValidFrom, " ");
  1353. }
  1354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1355. {
  1356. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1357. }
  1358. else
  1359. {
  1360. sprintf((char*)maxProfile.ValidTo, " ");
  1361. }
  1362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1363. {
  1364. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1365. }
  1366. else
  1367. {
  1368. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1369. }
  1370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1371. {
  1372. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1373. }
  1374. else
  1375. {
  1376. maxProfile.TransactionId = -1;
  1377. }
  1378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1379. {
  1380. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1381. }
  1382. else
  1383. {
  1384. maxProfile.ChargingSchedule.Duration = 86400;
  1385. }
  1386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1387. {
  1388. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1389. }
  1390. else
  1391. {
  1392. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1393. }
  1394. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1395. {
  1396. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1397. }
  1398. else
  1399. {
  1400. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. else
  1406. {
  1407. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1408. {
  1409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1411. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1412. }
  1413. maxProfile.ChargingProfileId = -1;
  1414. maxProfile.StackLevel = -1;
  1415. if(maxProfile.ChargingProfileId == -1)
  1416. DEBUG_INFO("MaxProfile found.\n");
  1417. else
  1418. DEBUG_INFO("MaxProfile updated.\n");
  1419. // Required item
  1420. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1421. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1422. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1423. if(isUnitA)
  1424. {
  1425. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1426. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1427. {
  1428. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1429. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1430. 3:
  1431. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1432. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1433. }
  1434. }
  1435. else
  1436. {
  1437. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1438. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1439. {
  1440. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1441. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1442. 3:
  1443. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1444. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1445. }
  1446. }
  1447. // Optional item
  1448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1449. {
  1450. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1451. }
  1452. else
  1453. {
  1454. sprintf((char*)maxProfile.ValidFrom, " ");
  1455. }
  1456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1457. {
  1458. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1459. }
  1460. else
  1461. {
  1462. sprintf((char*)maxProfile.ValidTo, " ");
  1463. }
  1464. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1465. {
  1466. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1467. }
  1468. else
  1469. {
  1470. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1471. }
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1473. {
  1474. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1475. }
  1476. else
  1477. {
  1478. maxProfile.TransactionId = -1;
  1479. }
  1480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1481. {
  1482. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1483. }
  1484. else
  1485. {
  1486. maxProfile.ChargingSchedule.Duration = 86400;
  1487. }
  1488. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1495. }
  1496. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1497. {
  1498. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1503. }
  1504. }
  1505. }
  1506. }
  1507. json_object_put(obj);
  1508. }
  1509. fclose(fp);
  1510. /*
  1511. if(maxProfile.ChargingProfileId !=-1)
  1512. {
  1513. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1514. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1515. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1516. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1517. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1518. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1519. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1520. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1521. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1522. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1523. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1524. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1525. {
  1526. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1527. {
  1528. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1529. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1530. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1531. }
  1532. }
  1533. }
  1534. else
  1535. DEBUG_INFO("MaxProfile not found.\n");
  1536. DEBUG_INFO("------------------------------------\n");*/
  1537. }
  1538. if(maxProfile.ChargingProfileId != -1)
  1539. {
  1540. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1541. {
  1542. if(maxProfile.ChargingSchedule.Duration != -1)
  1543. {
  1544. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. }
  1548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1549. {
  1550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1551. {
  1552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1553. 0:
  1554. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1555. if(idxPeriod > 0)
  1556. {
  1557. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1558. {
  1559. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1560. }
  1561. }
  1562. }
  1563. }
  1564. }
  1565. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1566. {
  1567. if(maxProfile.ChargingSchedule.Duration != -1)
  1568. {
  1569. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1570. }
  1571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1572. {
  1573. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1574. {
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1576. if(idxPeriod > 0)
  1577. {
  1578. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1579. {
  1580. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. else
  1587. {
  1588. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1589. {
  1590. if(maxProfile.ChargingSchedule.Duration != -1)
  1591. {
  1592. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1593. 0:
  1594. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1595. }
  1596. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1597. {
  1598. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1599. {
  1600. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1601. 0:
  1602. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1603. if(idxPeriod > 0)
  1604. {
  1605. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1606. {
  1607. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1608. }
  1609. }
  1610. }
  1611. }
  1612. }
  1613. else
  1614. {
  1615. if(maxProfile.ChargingSchedule.Duration != -1)
  1616. {
  1617. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1618. 0:
  1619. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1620. }
  1621. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1622. {
  1623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1624. {
  1625. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1626. 0:
  1627. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1628. if(idxPeriod > 0)
  1629. {
  1630. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1631. {
  1632. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1633. }
  1634. }
  1635. }
  1636. }
  1637. }
  1638. }
  1639. /*
  1640. DEBUG_INFO("MaxProfile after align.\n");
  1641. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1642. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1643. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1644. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1645. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1646. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1647. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1648. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1649. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1650. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1651. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1653. {
  1654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1655. {
  1656. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1657. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1658. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1659. }
  1660. }
  1661. DEBUG_INFO("------------------------------------\n");*/
  1662. }
  1663. // Find each profile period quantity
  1664. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1665. {
  1666. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1667. limitMax = idx+1;
  1668. }
  1669. if(maxProfile.ChargingProfileId != -1)
  1670. {
  1671. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1672. {
  1673. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1674. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1675. (maxProfile.ChargingSchedule.Duration > 0))
  1676. {
  1677. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1678. {
  1679. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1680. compositePeriodIdx++;
  1681. }
  1682. else
  1683. {
  1684. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1685. }
  1686. }
  1687. }
  1688. }
  1689. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1690. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1691. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1692. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1694. {
  1695. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1696. {
  1697. compositeProfile->ChargingProfileId = 1;
  1698. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1699. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1700. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1701. }
  1702. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1703. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1704. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1705. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1706. }
  1707. if(line)
  1708. free(line);
  1709. }
  1710. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1711. {
  1712. FILE *fp;
  1713. char profileFileName[128];
  1714. char *line = NULL;
  1715. size_t len = 0;
  1716. time_t CurrentTime;
  1717. struct tm *tmComposite;
  1718. struct StructChargingProfile maxProfile;
  1719. struct StructChargingProfile defaultTxProfile;
  1720. struct StructChargingProfile txProfile;
  1721. struct StructChargingSchedulePeriod tmpPeriod;
  1722. uint8_t limitMax=0;
  1723. uint8_t limitDef=0;
  1724. uint8_t limitTx=0;
  1725. int compositePeriodIdx = 0;
  1726. CurrentTime = time(NULL);
  1727. tmComposite=localtime(&CurrentTime);
  1728. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1729. if(isUnitA)
  1730. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1731. else
  1732. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1733. compositeProfile->ChargingSchedule.Duration = durationReq;
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1737. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1738. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1739. }
  1740. compositeProfile->ChargingProfileId = 0;
  1741. compositeProfile->StackLevel = 99 ;
  1742. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1743. maxProfile.ChargingProfileId = -1;
  1744. defaultTxProfile.ChargingProfileId = -1;
  1745. txProfile.ChargingProfileId = -1;
  1746. maxProfile.ChargingSchedule.Duration = -1;
  1747. defaultTxProfile.ChargingSchedule.Duration = -1;
  1748. txProfile.ChargingSchedule.Duration = -1;
  1749. system("rm -f /tmp/*.json");
  1750. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1751. /*
  1752. * Search valid charging profile
  1753. */
  1754. //DEBUG_INFO("====================================\n");
  1755. // Search tx profile
  1756. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1757. if((access(profileFileName, F_OK))!=-1)
  1758. {
  1759. fp = fopen(profileFileName, "r");
  1760. while(getline(&line, &len, fp) != -1)
  1761. {
  1762. json_object *obj = NULL;
  1763. obj = json_tokener_parse(line);
  1764. if(is_error(obj))
  1765. {
  1766. DEBUG_ERROR("Parse txProfile from file error.\n");
  1767. }
  1768. else
  1769. {
  1770. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1771. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1772. )
  1773. {
  1774. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1775. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1776. )
  1777. {
  1778. struct tm tmFrom, tmTo;
  1779. struct timeb tbFrom, tbTo;
  1780. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1781. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1782. {
  1783. tmFrom.tm_year -= 1900;
  1784. tmFrom.tm_mon -= 1;
  1785. tbFrom.time = mktime(&tmFrom);
  1786. tmTo.tm_year -= 1900;
  1787. tmTo.tm_mon -= 1;
  1788. tbTo.time = mktime(&tmTo);
  1789. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1790. {
  1791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1792. {
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1795. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1796. }
  1797. txProfile.ChargingProfileId = -1;
  1798. txProfile.StackLevel = -1;
  1799. if(txProfile.ChargingProfileId == -1)
  1800. DEBUG_INFO("TxProfile found.\n");
  1801. else
  1802. DEBUG_INFO("TxProfile updated.\n");
  1803. // Required item
  1804. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1805. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1806. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1807. if(isUnitA)
  1808. {
  1809. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1810. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1811. {
  1812. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1814. 3:
  1815. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1816. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1817. }
  1818. }
  1819. else
  1820. {
  1821. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1822. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1823. {
  1824. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1825. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1826. 3:
  1827. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1828. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1829. }
  1830. }
  1831. // Optional item
  1832. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1833. {
  1834. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1835. }
  1836. else
  1837. {
  1838. sprintf((char*)txProfile.ValidFrom, " ");
  1839. }
  1840. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1841. {
  1842. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1843. }
  1844. else
  1845. {
  1846. sprintf((char*)txProfile.ValidTo, " ");
  1847. }
  1848. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1849. {
  1850. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1851. }
  1852. else
  1853. {
  1854. sprintf((char*)txProfile.RecurrencyKind, " ");
  1855. }
  1856. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1857. {
  1858. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1859. }
  1860. else
  1861. {
  1862. txProfile.TransactionId = -1;
  1863. }
  1864. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1865. {
  1866. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1867. }
  1868. else
  1869. {
  1870. txProfile.ChargingSchedule.Duration = 86400;
  1871. }
  1872. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1873. {
  1874. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1875. }
  1876. else
  1877. {
  1878. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1879. }
  1880. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1881. {
  1882. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1883. }
  1884. else
  1885. {
  1886. txProfile.ChargingSchedule.MinChargingRate = -1;
  1887. }
  1888. }
  1889. }
  1890. }
  1891. else
  1892. {
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1896. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1897. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1898. }
  1899. txProfile.ChargingProfileId = -1;
  1900. txProfile.StackLevel = -1;
  1901. if(txProfile.ChargingProfileId == -1)
  1902. DEBUG_INFO("TxProfile found.\n");
  1903. else
  1904. DEBUG_INFO("TxProfile updated.\n");
  1905. // Required item
  1906. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1907. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1908. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1909. if(isUnitA)
  1910. {
  1911. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1912. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1913. {
  1914. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1915. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1916. 3:
  1917. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1918. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1919. }
  1920. }
  1921. else
  1922. {
  1923. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1924. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1925. {
  1926. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1927. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1928. 3:
  1929. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1930. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1931. }
  1932. }
  1933. // Optional item
  1934. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1935. {
  1936. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1937. }
  1938. else
  1939. {
  1940. sprintf((char*)txProfile.ValidFrom, " ");
  1941. }
  1942. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1943. {
  1944. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1945. }
  1946. else
  1947. {
  1948. sprintf((char*)txProfile.ValidTo, " ");
  1949. }
  1950. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1951. {
  1952. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1953. }
  1954. else
  1955. {
  1956. sprintf((char*)txProfile.RecurrencyKind, " ");
  1957. }
  1958. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1959. {
  1960. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1961. }
  1962. else
  1963. {
  1964. txProfile.TransactionId = -1;
  1965. }
  1966. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1967. {
  1968. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1969. }
  1970. else
  1971. {
  1972. txProfile.ChargingSchedule.Duration = 86400;
  1973. }
  1974. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1975. {
  1976. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1977. }
  1978. else
  1979. {
  1980. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1981. }
  1982. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1983. {
  1984. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1985. }
  1986. else
  1987. {
  1988. txProfile.ChargingSchedule.MinChargingRate = -1;
  1989. }
  1990. }
  1991. }
  1992. }
  1993. json_object_put(obj);
  1994. }
  1995. fclose(fp);
  1996. /*
  1997. if(txProfile.ChargingProfileId != -1)
  1998. {
  1999. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2000. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2001. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2002. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2003. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2004. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2005. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2006. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2007. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2008. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2009. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2010. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2011. {
  2012. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2013. {
  2014. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2015. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2016. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2017. }
  2018. }
  2019. }
  2020. else
  2021. DEBUG_INFO("TxProfile not found.\n");*/
  2022. }
  2023. // Search default tx profile
  2024. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2025. if((access(profileFileName, F_OK))==-1)
  2026. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2027. if((access(profileFileName, F_OK))!=-1)
  2028. {
  2029. fp = fopen(profileFileName, "r");
  2030. while(getline(&line, &len, fp) != -1)
  2031. {
  2032. json_object *obj = NULL;
  2033. obj = json_tokener_parse(line);
  2034. if(is_error(obj))
  2035. {
  2036. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2037. }
  2038. else
  2039. {
  2040. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2041. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2042. )
  2043. {
  2044. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2045. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2046. )
  2047. {
  2048. struct tm tmFrom, tmTo;
  2049. struct timeb tbFrom, tbTo;
  2050. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2051. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2052. {
  2053. tmFrom.tm_year -= 1900;
  2054. tmFrom.tm_mon -= 1;
  2055. tbFrom.time = mktime(&tmFrom);
  2056. tmTo.tm_year -= 1900;
  2057. tmTo.tm_mon -= 1;
  2058. tbTo.time = mktime(&tmTo);
  2059. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2060. {
  2061. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2062. {
  2063. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2064. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2065. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2066. }
  2067. defaultTxProfile.ChargingProfileId = -1;
  2068. defaultTxProfile.StackLevel = -1;
  2069. if(defaultTxProfile.ChargingProfileId == -1)
  2070. DEBUG_INFO("TxDefaultProfile found.\n");
  2071. else
  2072. DEBUG_INFO("TxDefaultProfile updated.\n");
  2073. // Required item
  2074. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2075. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2076. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2077. if(isUnitA)
  2078. {
  2079. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2080. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2081. {
  2082. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2083. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2084. 3:
  2085. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2086. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2087. }
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2092. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2093. {
  2094. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2095. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2096. 3:
  2097. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2098. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2099. }
  2100. }
  2101. // Optional item
  2102. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2103. {
  2104. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2105. }
  2106. else
  2107. {
  2108. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2109. }
  2110. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2111. {
  2112. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2113. }
  2114. else
  2115. {
  2116. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2117. }
  2118. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2119. {
  2120. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2121. }
  2122. else
  2123. {
  2124. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2125. }
  2126. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2127. {
  2128. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2129. }
  2130. else
  2131. {
  2132. defaultTxProfile.TransactionId = -1;
  2133. }
  2134. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2135. {
  2136. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2137. }
  2138. else
  2139. {
  2140. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2141. }
  2142. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2143. {
  2144. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2145. }
  2146. else
  2147. {
  2148. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2149. }
  2150. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2151. {
  2152. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2153. }
  2154. else
  2155. {
  2156. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2157. }
  2158. }
  2159. }
  2160. }
  2161. else
  2162. {
  2163. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2164. {
  2165. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2166. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2167. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2168. }
  2169. defaultTxProfile.ChargingProfileId = -1;
  2170. defaultTxProfile.StackLevel = -1;
  2171. if(defaultTxProfile.ChargingProfileId == -1)
  2172. DEBUG_INFO("TxDefaultProfile found.\n");
  2173. else
  2174. DEBUG_INFO("TxDefaultProfile updated.\n");
  2175. // Required item
  2176. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2177. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2178. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2179. if(isUnitA)
  2180. {
  2181. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2182. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2183. {
  2184. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2185. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2186. 3:
  2187. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2188. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2189. }
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2194. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2195. {
  2196. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2197. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2198. 3:
  2199. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2200. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2201. }
  2202. }
  2203. // Optional item
  2204. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2205. {
  2206. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2207. }
  2208. else
  2209. {
  2210. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2211. }
  2212. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2213. {
  2214. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2215. }
  2216. else
  2217. {
  2218. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2219. }
  2220. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2221. {
  2222. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2223. }
  2224. else
  2225. {
  2226. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2227. }
  2228. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2229. {
  2230. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2231. }
  2232. else
  2233. {
  2234. defaultTxProfile.TransactionId = -1;
  2235. }
  2236. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2237. {
  2238. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2239. }
  2240. else
  2241. {
  2242. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2243. }
  2244. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2251. }
  2252. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2253. {
  2254. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2255. }
  2256. else
  2257. {
  2258. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2259. }
  2260. }
  2261. }
  2262. }
  2263. json_object_put(obj);
  2264. }
  2265. fclose(fp);
  2266. /*
  2267. if(defaultTxProfile.ChargingProfileId != -1)
  2268. {
  2269. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2270. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2271. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2272. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2273. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2274. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2275. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2276. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2277. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2278. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2279. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2280. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2281. {
  2282. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2283. {
  2284. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2285. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2286. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2287. }
  2288. }
  2289. }
  2290. else
  2291. DEBUG_INFO("TxDefaultProfile not found.\n");
  2292. DEBUG_INFO("------------------------------------\n");*/
  2293. }
  2294. // Search max profile
  2295. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2296. if((access(profileFileName, F_OK))!=-1)
  2297. {
  2298. fp = fopen(profileFileName, "r");
  2299. while(getline(&line, &len, fp) != -1)
  2300. {
  2301. json_object *obj = NULL;
  2302. obj = json_tokener_parse(line);
  2303. if(is_error(obj))
  2304. {
  2305. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2306. }
  2307. else
  2308. {
  2309. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2310. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2311. )
  2312. {
  2313. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2314. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2315. )
  2316. {
  2317. struct tm tmFrom, tmTo;
  2318. struct timeb tbFrom, tbTo;
  2319. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2320. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2321. {
  2322. tmFrom.tm_year -= 1900;
  2323. tmFrom.tm_mon -= 1;
  2324. tbFrom.time = mktime(&tmFrom);
  2325. tmTo.tm_year -= 1900;
  2326. tmTo.tm_mon -= 1;
  2327. tbTo.time = mktime(&tmTo);
  2328. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2329. {
  2330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2331. {
  2332. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2333. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2334. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2335. }
  2336. maxProfile.ChargingProfileId = -1;
  2337. maxProfile.StackLevel = -1;
  2338. if(maxProfile.ChargingProfileId == -1)
  2339. DEBUG_INFO("MaxProfile found.\n");
  2340. else
  2341. DEBUG_INFO("MaxProfile updated.\n");
  2342. // Required item
  2343. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2344. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2345. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2346. if(isUnitA)
  2347. {
  2348. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2349. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2350. {
  2351. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2352. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2353. 3:
  2354. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2355. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2356. }
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2361. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2362. {
  2363. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2364. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2365. 3:
  2366. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2368. }
  2369. }
  2370. // Optional item
  2371. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2372. {
  2373. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2374. }
  2375. else
  2376. {
  2377. sprintf((char*)maxProfile.ValidFrom, " ");
  2378. }
  2379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2380. {
  2381. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2382. }
  2383. else
  2384. {
  2385. sprintf((char*)maxProfile.ValidTo, " ");
  2386. }
  2387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2388. {
  2389. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2394. }
  2395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2396. {
  2397. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2398. }
  2399. else
  2400. {
  2401. maxProfile.TransactionId = -1;
  2402. }
  2403. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2404. {
  2405. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2406. }
  2407. else
  2408. {
  2409. maxProfile.ChargingSchedule.Duration = 86400;
  2410. }
  2411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2412. {
  2413. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2414. }
  2415. else
  2416. {
  2417. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2418. }
  2419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2420. {
  2421. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2422. }
  2423. else
  2424. {
  2425. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2426. }
  2427. }
  2428. }
  2429. }
  2430. else
  2431. {
  2432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2433. {
  2434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2436. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2437. }
  2438. maxProfile.ChargingProfileId = -1;
  2439. maxProfile.StackLevel = -1;
  2440. if(maxProfile.ChargingProfileId == -1)
  2441. DEBUG_INFO("MaxProfile found.\n");
  2442. else
  2443. DEBUG_INFO("MaxProfile updated.\n");
  2444. // Required item
  2445. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2446. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2447. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2448. if(isUnitA)
  2449. {
  2450. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2451. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2452. {
  2453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2454. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2455. 3:
  2456. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2457. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2458. }
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2463. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2464. {
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2467. 3:
  2468. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2469. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2470. }
  2471. }
  2472. // Optional item
  2473. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2474. {
  2475. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2476. }
  2477. else
  2478. {
  2479. sprintf((char*)maxProfile.ValidFrom, " ");
  2480. }
  2481. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2482. {
  2483. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)maxProfile.ValidTo, " ");
  2488. }
  2489. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2490. {
  2491. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2492. }
  2493. else
  2494. {
  2495. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2496. }
  2497. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2498. {
  2499. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2500. }
  2501. else
  2502. {
  2503. maxProfile.TransactionId = -1;
  2504. }
  2505. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2506. {
  2507. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2508. }
  2509. else
  2510. {
  2511. maxProfile.ChargingSchedule.Duration = 86400;
  2512. }
  2513. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2514. {
  2515. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2516. }
  2517. else
  2518. {
  2519. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2520. }
  2521. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2522. {
  2523. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2524. }
  2525. else
  2526. {
  2527. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2528. }
  2529. }
  2530. }
  2531. }
  2532. json_object_put(obj);
  2533. }
  2534. fclose(fp);
  2535. /*
  2536. if(maxProfile.ChargingProfileId !=-1)
  2537. {
  2538. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2539. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2540. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2541. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2542. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2543. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2544. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2545. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2546. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2547. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2548. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2552. {
  2553. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2555. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2556. }
  2557. }
  2558. }
  2559. else
  2560. DEBUG_INFO("MaxProfile not found.\n");
  2561. DEBUG_INFO("------------------------------------\n");*/
  2562. }
  2563. /*
  2564. * Align found profile start schedule & periods
  2565. */
  2566. //DEBUG_INFO("====================================\n");
  2567. /*
  2568. // For local test usage, force modify found profile start schedule info
  2569. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  2570. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  2571. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  2572. */
  2573. if(txProfile.ChargingProfileId != -1)
  2574. {
  2575. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2576. {
  2577. if(txProfile.ChargingSchedule.Duration != -1)
  2578. {
  2579. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2580. 0:
  2581. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2582. }
  2583. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2584. {
  2585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2586. {
  2587. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2588. 0:
  2589. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2590. if(idxPeriod > 0)
  2591. {
  2592. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2593. {
  2594. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2601. {
  2602. if(txProfile.ChargingSchedule.Duration != -1)
  2603. {
  2604. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2605. 0:
  2606. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2607. }
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2611. {
  2612. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2613. 0:
  2614. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2615. if(idxPeriod > 0)
  2616. {
  2617. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2618. {
  2619. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. else
  2626. {
  2627. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2628. {
  2629. if(txProfile.ChargingSchedule.Duration != -1)
  2630. {
  2631. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2632. 0:
  2633. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2634. }
  2635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2636. {
  2637. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2638. {
  2639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2640. 0:
  2641. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2642. if(idxPeriod > 0)
  2643. {
  2644. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2645. {
  2646. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2647. }
  2648. }
  2649. }
  2650. }
  2651. }
  2652. else
  2653. {
  2654. if(txProfile.ChargingSchedule.Duration != -1)
  2655. {
  2656. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2657. 0:
  2658. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2659. }
  2660. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2661. {
  2662. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2663. {
  2664. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2665. 0:
  2666. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2667. if(idxPeriod > 0)
  2668. {
  2669. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2670. {
  2671. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. /*
  2679. DEBUG_INFO("txProfile after align.\n");
  2680. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2681. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2682. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2683. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2684. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2685. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2686. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2687. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2688. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2689. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2690. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2691. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2692. {
  2693. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2694. {
  2695. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2696. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2697. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2698. }
  2699. }*/
  2700. }
  2701. if(defaultTxProfile.ChargingProfileId != -1)
  2702. {
  2703. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2704. {
  2705. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2706. {
  2707. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2708. 0:
  2709. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2710. }
  2711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2712. {
  2713. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2714. {
  2715. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2718. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2719. {
  2720. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2721. }
  2722. if(idxPeriod > 0)
  2723. {
  2724. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2725. {
  2726. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2727. }
  2728. }
  2729. }
  2730. }
  2731. }
  2732. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2733. {
  2734. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2735. {
  2736. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2737. 0:
  2738. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2739. }
  2740. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2741. {
  2742. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2743. {
  2744. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2745. 0:
  2746. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2747. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2748. {
  2749. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2750. }
  2751. if(idxPeriod > 0)
  2752. {
  2753. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2754. {
  2755. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2756. }
  2757. }
  2758. }
  2759. }
  2760. }
  2761. else
  2762. {
  2763. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2764. {
  2765. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2766. {
  2767. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2770. }
  2771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2772. {
  2773. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2774. {
  2775. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2776. 0:
  2777. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2778. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2779. {
  2780. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2781. }
  2782. if(idxPeriod > 0)
  2783. {
  2784. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2785. {
  2786. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2787. }
  2788. }
  2789. }
  2790. }
  2791. }
  2792. else
  2793. {
  2794. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2795. {
  2796. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2797. 0:
  2798. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2799. }
  2800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2801. {
  2802. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2803. {
  2804. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2805. 0:
  2806. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2807. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2808. {
  2809. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2810. }
  2811. if(idxPeriod > 0)
  2812. {
  2813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2814. {
  2815. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. }
  2822. /*
  2823. DEBUG_INFO("defaultTxProfile after align.\n");
  2824. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2825. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2826. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2827. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2828. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2829. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2830. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2831. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2832. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2833. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2834. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2835. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2836. {
  2837. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2838. {
  2839. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2840. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2841. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2842. }
  2843. }
  2844. DEBUG_INFO("------------------------------------\n");*/
  2845. }
  2846. if(maxProfile.ChargingProfileId != -1)
  2847. {
  2848. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2849. {
  2850. if(maxProfile.ChargingSchedule.Duration != -1)
  2851. {
  2852. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2853. 0:
  2854. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2855. }
  2856. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2857. {
  2858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2859. {
  2860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2861. 0:
  2862. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2863. if(idxPeriod > 0)
  2864. {
  2865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2866. {
  2867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2868. }
  2869. }
  2870. }
  2871. }
  2872. }
  2873. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2874. {
  2875. if(maxProfile.ChargingSchedule.Duration != -1)
  2876. {
  2877. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2878. 0:
  2879. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2880. }
  2881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2882. {
  2883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2884. {
  2885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2886. 0:
  2887. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2888. if(idxPeriod > 0)
  2889. {
  2890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2891. {
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2893. }
  2894. }
  2895. }
  2896. }
  2897. }
  2898. else
  2899. {
  2900. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2901. {
  2902. if(maxProfile.ChargingSchedule.Duration != -1)
  2903. {
  2904. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2905. 0:
  2906. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2907. }
  2908. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2909. {
  2910. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2911. {
  2912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2913. 0:
  2914. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2915. if(idxPeriod > 0)
  2916. {
  2917. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2918. {
  2919. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2920. }
  2921. }
  2922. }
  2923. }
  2924. }
  2925. else
  2926. {
  2927. if(maxProfile.ChargingSchedule.Duration != -1)
  2928. {
  2929. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2930. 0:
  2931. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2932. }
  2933. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2934. {
  2935. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2936. {
  2937. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2938. 0:
  2939. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2940. if(idxPeriod > 0)
  2941. {
  2942. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2943. {
  2944. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. }
  2951. /*
  2952. DEBUG_INFO("MaxProfile after align.\n");
  2953. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2954. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2955. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2956. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2957. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2958. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2959. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2960. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2961. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2962. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2963. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2964. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2965. {
  2966. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2967. {
  2968. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2969. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2970. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2971. }
  2972. }
  2973. DEBUG_INFO("------------------------------------\n");*/
  2974. }
  2975. /*
  2976. * Merge to conposite schedule
  2977. */
  2978. //DEBUG_INFO("====================================\n");
  2979. // Find each profile period quantity
  2980. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2981. {
  2982. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2983. limitMax = idx+1;
  2984. }
  2985. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2986. {
  2987. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2988. limitDef = idx+1;
  2989. }
  2990. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2991. {
  2992. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2993. limitTx = idx+1;
  2994. }
  2995. // TxProfile found, composite schedule based on it
  2996. if(txProfile.ChargingProfileId != -1)
  2997. {
  2998. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2999. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3000. {
  3001. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3002. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3003. (txProfile.ChargingSchedule.Duration > 0))
  3004. {
  3005. if(maxProfile.ChargingProfileId != -1)
  3006. {
  3007. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3008. {
  3009. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3010. {
  3011. if((maxProfile.ChargingSchedule.Duration > 0))
  3012. {
  3013. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3014. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3015. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3016. }
  3017. else
  3018. {
  3019. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3020. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3021. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3022. }
  3023. }
  3024. if(idxMaxPeriod == (limitMax-1))
  3025. {
  3026. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3027. {
  3028. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3029. {
  3030. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3031. compositePeriodIdx++;
  3032. }
  3033. else
  3034. {
  3035. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3036. }
  3037. }
  3038. }
  3039. }
  3040. }
  3041. else
  3042. {
  3043. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3044. {
  3045. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3046. compositePeriodIdx++;
  3047. }
  3048. else
  3049. {
  3050. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3051. }
  3052. }
  3053. }
  3054. if(idxTxPeriod == (limitTx-1))
  3055. {
  3056. if(defaultTxProfile.ChargingProfileId != -1)
  3057. {
  3058. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3059. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3060. {
  3061. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3062. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3063. (defaultTxProfile.ChargingSchedule.Duration>0))
  3064. {
  3065. if(maxProfile.ChargingProfileId != -1)
  3066. {
  3067. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3068. {
  3069. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3070. {
  3071. if((maxProfile.ChargingSchedule.Duration > 0))
  3072. {
  3073. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3074. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3075. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3076. }
  3077. else
  3078. {
  3079. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3080. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3081. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3082. }
  3083. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3084. {
  3085. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3086. {
  3087. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3088. compositePeriodIdx++;
  3089. }
  3090. else
  3091. {
  3092. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3093. }
  3094. }
  3095. // Delete duplicate period
  3096. if(compositePeriodIdx > 1)
  3097. {
  3098. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3099. {
  3100. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3101. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3102. compositePeriodIdx -= 1;
  3103. }
  3104. }
  3105. }
  3106. else
  3107. {
  3108. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3109. {
  3110. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3111. compositePeriodIdx++;
  3112. }
  3113. else
  3114. {
  3115. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3116. }
  3117. break;
  3118. }
  3119. }
  3120. }
  3121. else
  3122. {
  3123. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3124. {
  3125. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3126. compositePeriodIdx++;
  3127. }
  3128. else
  3129. {
  3130. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. }
  3139. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3140. else if(defaultTxProfile.ChargingProfileId != -1)
  3141. {
  3142. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3143. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3144. {
  3145. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3146. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3147. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3148. {
  3149. if(maxProfile.ChargingProfileId != -1)
  3150. {
  3151. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3152. {
  3153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3154. {
  3155. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3156. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3157. if((maxProfile.ChargingSchedule.Duration > 0))
  3158. {
  3159. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3160. }
  3161. else
  3162. {
  3163. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3164. }
  3165. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3166. {
  3167. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3168. {
  3169. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3170. compositePeriodIdx++;
  3171. }
  3172. else
  3173. {
  3174. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3175. }
  3176. }
  3177. // Delete duplicate period
  3178. if(compositePeriodIdx > 1)
  3179. {
  3180. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3181. {
  3182. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3183. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3184. compositePeriodIdx -= 1;
  3185. }
  3186. }
  3187. }
  3188. else
  3189. {
  3190. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3191. {
  3192. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3193. compositePeriodIdx++;
  3194. }
  3195. else
  3196. {
  3197. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3198. }
  3199. break;
  3200. }
  3201. }
  3202. }
  3203. else
  3204. {
  3205. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3206. {
  3207. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3208. compositePeriodIdx++;
  3209. }
  3210. else
  3211. {
  3212. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3213. }
  3214. }
  3215. }
  3216. }
  3217. }
  3218. // Fill other period by MaxProfile
  3219. if(maxProfile.ChargingProfileId != -1)
  3220. {
  3221. if(compositePeriodIdx==0)
  3222. {
  3223. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3224. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3225. {
  3226. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3227. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3228. (maxProfile.ChargingSchedule.Duration > 0))
  3229. {
  3230. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3231. {
  3232. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3233. compositePeriodIdx++;
  3234. }
  3235. else
  3236. {
  3237. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3238. }
  3239. }
  3240. }
  3241. }
  3242. else
  3243. {
  3244. int lastCompositePeriodIdx = compositePeriodIdx;
  3245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3246. {
  3247. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3249. (maxProfile.ChargingSchedule.Duration > 0))
  3250. {
  3251. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3252. {
  3253. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3254. {
  3255. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3256. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3257. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3258. }
  3259. else
  3260. {
  3261. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3262. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3263. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3264. }
  3265. }
  3266. if(tmpPeriod.Limit != -1)
  3267. {
  3268. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3269. {
  3270. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3271. {
  3272. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3273. compositePeriodIdx++;
  3274. }
  3275. else
  3276. {
  3277. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3278. }
  3279. }
  3280. // Delete duplicate period
  3281. if(compositePeriodIdx > 1)
  3282. {
  3283. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3284. {
  3285. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3286. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3287. compositePeriodIdx -= 1;
  3288. }
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. }
  3295. compositeProfile->ChargingSchedule.Duration = durationReq;
  3296. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3297. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3298. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3299. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3301. {
  3302. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3303. {
  3304. compositeProfile->ChargingProfileId = 1;
  3305. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3306. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3307. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3308. }
  3309. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3310. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3311. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3312. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3313. }
  3314. if(line)
  3315. free(line);
  3316. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3317. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3318. }
  3319. //==========================================
  3320. // Init all share memory
  3321. //==========================================
  3322. int InitShareMemory()
  3323. {
  3324. int result = PASS;
  3325. int MeterSMId;
  3326. //creat ShmSysConfigAndInfo
  3327. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3328. {
  3329. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3330. result = FAIL;
  3331. }
  3332. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3333. {
  3334. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3335. result = FAIL;
  3336. }
  3337. else
  3338. {}
  3339. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3340. {
  3341. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3342. result = FAIL;
  3343. }
  3344. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3345. {
  3346. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3347. result = FAIL;
  3348. }
  3349. else
  3350. {}
  3351. //creat ShmPsuData
  3352. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3353. {
  3354. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3355. result = FAIL;
  3356. }
  3357. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3358. {
  3359. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3360. result = FAIL;
  3361. }
  3362. else
  3363. {}
  3364. //creat ShmOCPP16Data
  3365. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3366. {
  3367. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3368. result = FAIL;
  3369. }
  3370. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3371. {
  3372. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3373. result = FAIL;
  3374. }
  3375. else
  3376. {}
  3377. /****************************** For Initial Settings************************************************/
  3378. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3379. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3380. // allocate Configuration memory address
  3381. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3382. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3383. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3384. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3385. //offline MeterValue Interval
  3386. TempMeterValueInterval = 0;
  3387. return result;
  3388. }
  3389. int ProcessShareMemory()
  3390. {
  3391. int result = PASS;
  3392. ParsingRatedCur modelnameInfo={0};
  3393. if(InitShareMemory() == FAIL)
  3394. {
  3395. DEBUG_ERROR("InitShareMemory NG\n");
  3396. if(ShmStatusCodeData!=NULL)
  3397. {
  3398. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3399. }
  3400. result = FAIL;
  3401. }
  3402. // Model name parsing
  3403. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3404. {
  3405. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3406. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3407. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3408. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3409. ) // 'D' means DC
  3410. {
  3411. // DO series
  3412. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3413. {
  3414. SystemInitial += 1;
  3415. gunTotalNumber += 1;
  3416. gunType[gun_index] = GUN_TYPE_DO;
  3417. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3418. {
  3419. case Gun_Type_Chademo:
  3420. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3421. break;
  3422. case Gun_Type_CCS_2:
  3423. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3424. break;
  3425. case Gun_Type_GB:
  3426. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3427. break;
  3428. case Gun_Type_AC:
  3429. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3430. break;
  3431. default:
  3432. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3433. break;
  3434. }
  3435. }
  3436. }
  3437. else
  3438. {
  3439. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3440. {
  3441. SystemInitial += 1;
  3442. gunTotalNumber += 1;
  3443. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3444. {
  3445. case Gun_Type_Chademo:
  3446. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3447. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3448. break;
  3449. case Gun_Type_CCS_2:
  3450. gunType[gun_index] = GUN_TYPE_CCS;
  3451. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3452. break;
  3453. case Gun_Type_GB:
  3454. gunType[gun_index] = GUN_TYPE_GBT;
  3455. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3456. break;
  3457. case Gun_Type_AC:
  3458. gunType[gun_index] = GUN_TYPE_AC;
  3459. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3460. break;
  3461. default:
  3462. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3463. break;
  3464. }
  3465. }
  3466. }
  3467. }
  3468. else
  3469. {
  3470. DEBUG_ERROR("Model name parsing fail.\n");
  3471. result = FAIL;
  3472. }
  3473. if(result != PASS)sleep(5);
  3474. return result;
  3475. }
  3476. void checkRemoteStart(uint8_t connectorIdInt)
  3477. {
  3478. uint8_t tempIndex;
  3479. int result = PASS;
  3480. char cmdBuf[512];
  3481. //check Transaction active
  3482. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3483. {
  3484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3485. {
  3486. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3487. }
  3488. else
  3489. {
  3490. tempIndex = connectorIdInt -1;
  3491. }
  3492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3493. {
  3494. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3495. {
  3496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3497. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3498. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3499. {
  3500. //Reserved
  3501. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3502. }
  3503. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3504. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3505. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3506. {
  3507. //Reserved
  3508. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3509. result = FAIL;
  3510. goto end;
  3511. }
  3512. else
  3513. {
  3514. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3515. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3516. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3517. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3518. {
  3519. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3520. result = FAIL;
  3521. goto end;
  3522. }
  3523. }//END FOR ELSE
  3524. }
  3525. }// END FOR CHAdeMO_QUANTITY
  3526. }
  3527. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3528. {
  3529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3530. {
  3531. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3532. }
  3533. else
  3534. {
  3535. tempIndex = connectorIdInt -1;
  3536. }
  3537. for (int index = 0; index < CCS_QUANTITY; index++)
  3538. {
  3539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3540. {
  3541. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3543. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3544. {
  3545. //Reserved
  3546. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3547. }
  3548. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3549. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3550. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3551. {
  3552. //Reserved
  3553. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3554. result = FAIL;
  3555. goto end;
  3556. }
  3557. else
  3558. {
  3559. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3560. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3561. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3562. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3563. {
  3564. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3565. result = FAIL;
  3566. goto end;
  3567. }
  3568. }// END FOR ELSE
  3569. }
  3570. }// END FOR CCS_QUANTITY
  3571. }
  3572. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3573. {
  3574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3575. {
  3576. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3577. }
  3578. else
  3579. {
  3580. tempIndex = connectorIdInt -1;
  3581. }
  3582. for (int index = 0; index < GB_QUANTITY; index++)
  3583. {
  3584. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3585. {
  3586. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3588. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3589. {
  3590. //Reserved
  3591. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3592. }
  3593. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3594. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3595. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3596. {
  3597. //Reserved
  3598. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3599. result = FAIL;
  3600. goto end;
  3601. }
  3602. else
  3603. {
  3604. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3605. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3606. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3607. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3608. {
  3609. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3610. result = FAIL;
  3611. goto end;
  3612. }
  3613. }// END FOR ELSE
  3614. }
  3615. } // END FOR GB_QUANTITY
  3616. }
  3617. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3618. {
  3619. tempIndex = connectorIdInt -1;
  3620. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3621. {
  3622. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3623. {
  3624. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3625. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3626. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3627. {
  3628. //Reserved
  3629. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3630. }
  3631. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3632. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3633. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3634. {
  3635. //Reserved
  3636. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3637. result = FAIL;
  3638. goto end;
  3639. }
  3640. else
  3641. {
  3642. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3643. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3644. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3645. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3646. {
  3647. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3648. result = FAIL;
  3649. goto end;
  3650. }
  3651. }// END FOR ELSE
  3652. }
  3653. } // END FOR GB_QUANTITY
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = connectorIdInt -1;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3668. {
  3669. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3670. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3671. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3672. {
  3673. //Reserved
  3674. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3675. }
  3676. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3677. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3678. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3679. {
  3680. //Reserved
  3681. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3682. result = FAIL;
  3683. goto end;
  3684. }
  3685. else
  3686. {
  3687. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3688. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3689. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3690. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3691. {
  3692. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3693. result = FAIL;
  3694. goto end;
  3695. }
  3696. }//END FOR ELSE
  3697. }
  3698. }// END FOR AC_QUANTITY
  3699. }
  3700. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3701. {
  3702. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3703. {
  3704. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3705. {
  3706. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3707. system(cmdBuf);
  3708. }
  3709. }
  3710. else
  3711. {
  3712. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3713. result = FAIL;
  3714. }
  3715. }
  3716. end:
  3717. if(result == PASS)
  3718. {
  3719. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3720. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3721. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3722. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3723. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3724. }
  3725. }
  3726. void CheckSystemValue(void)
  3727. {
  3728. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3729. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3730. char filenmae[100]={0};
  3731. char str[100]={0};
  3732. int tempIndex = 0;
  3733. //===============================
  3734. // send Heartbeat
  3735. //===============================
  3736. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3737. {
  3738. //parameter for test
  3739. sendHeartbeatRequest(0);
  3740. //==============================================
  3741. // Reset Waiting Time
  3742. //==============================================
  3743. HeartBeatWithNOResponse += 1;
  3744. }
  3745. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3746. {
  3747. //==========================================
  3748. // Check remote start without connector id
  3749. //==========================================
  3750. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  3751. {
  3752. int connectorIdInt = -1;
  3753. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3754. {
  3755. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3756. {
  3757. connectorIdInt = (gun_index+1);
  3758. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3759. checkRemoteStart(connectorIdInt);
  3760. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3761. break;
  3762. }
  3763. }
  3764. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3765. {
  3766. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3767. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3768. }
  3769. }
  3770. //==========================================
  3771. // csu trigger DataTransferReq
  3772. //==========================================
  3773. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3774. {
  3775. sendDataTransferRequest(gun_index);
  3776. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3777. }
  3778. //==========================================
  3779. // CSU Trigger Authorize Request
  3780. //==========================================
  3781. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3782. {
  3783. sendAuthorizeRequest(0);
  3784. authorizeRetryTimes = authorizeRetryTimes + 1;
  3785. if(authorizeRetryTimes < 3)
  3786. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3787. }
  3788. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3789. {
  3790. authorizeRetryTimes = 0;
  3791. SetOcppConnStatus(FALSE);
  3792. server_sign = FALSE;
  3793. }
  3794. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  3795. {
  3796. sendAuthorizeRequest(0);
  3797. }
  3798. //==========================================
  3799. // Charger start transaction
  3800. //==========================================
  3801. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3802. {
  3803. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3804. sendStartTransactionRequest(gun_index);
  3805. refreshStartTimer(&clientTime.StartTransaction);
  3806. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3807. storeTempStopTransaction(gun_index);
  3808. }
  3809. //==========================================
  3810. // Charger stop transaction
  3811. //==========================================
  3812. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3813. {
  3814. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3815. sendStopTransactionRequest(gun_index);
  3816. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3817. refreshStartTimer(&clientTime.StopTransaction);
  3818. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3819. }
  3820. //==========================================
  3821. // Charger status report
  3822. //==========================================
  3823. //--- Check Mode Change ---//
  3824. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3825. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3826. {
  3827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3828. {
  3829. tempIndex = ((gun_index==2) ? 1: 0);
  3830. }
  3831. else
  3832. {
  3833. tempIndex = gun_index;
  3834. }
  3835. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3836. {
  3837. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3838. {
  3839. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3840. {
  3841. // Sent unplug message for California pricing logic
  3842. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3843. {
  3844. uint8_t ts[20];
  3845. getNowDatetime(ts);
  3846. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3847. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3848. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3849. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3850. }
  3851. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3852. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3853. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3854. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3855. {
  3856. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3857. if((access(filenmae,F_OK))!=-1)
  3858. {
  3859. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3860. sprintf(str,"rm -f %s",filenmae);
  3861. system(str);
  3862. }
  3863. }
  3864. }
  3865. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3866. #if 1 // for TempStopTransaction
  3867. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3868. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3869. {
  3870. checkTempStopTransaction(gun_index);
  3871. }
  3872. #endif
  3873. }
  3874. }
  3875. }
  3876. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3877. {
  3878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3879. {
  3880. tempIndex = ((gun_index==2) ? 1: 0);
  3881. }
  3882. else
  3883. {
  3884. tempIndex = gun_index;
  3885. }
  3886. for (int index = 0; index < CCS_QUANTITY; index++)
  3887. {
  3888. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3889. {
  3890. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  3891. {
  3892. // Sent unplug message for California pricing logic
  3893. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3894. {
  3895. uint8_t ts[20];
  3896. getNowDatetime(ts);
  3897. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3898. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3899. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3900. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3901. }
  3902. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3903. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3904. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3905. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3906. {
  3907. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3908. if((access(filenmae,F_OK))!=-1)
  3909. {
  3910. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3911. sprintf(str,"rm -f %s",filenmae);
  3912. system(str);
  3913. }
  3914. }
  3915. }
  3916. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3917. #if 1 // for TempStopTransaction
  3918. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3919. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3920. {
  3921. checkTempStopTransaction(gun_index);
  3922. }
  3923. #endif
  3924. }
  3925. }
  3926. }
  3927. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3928. {
  3929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3930. {
  3931. tempIndex = ((gun_index==2) ? 1: 0);
  3932. }
  3933. else
  3934. {
  3935. tempIndex = gun_index;
  3936. }
  3937. for (int index = 0; index < GB_QUANTITY; index++)
  3938. {
  3939. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3940. {
  3941. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3942. {
  3943. // Sent unplug message for California pricing logic
  3944. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3945. {
  3946. uint8_t ts[20];
  3947. getNowDatetime(ts);
  3948. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3949. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3950. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3951. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3952. }
  3953. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3954. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3955. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3956. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3957. {
  3958. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3959. if((access(filenmae,F_OK))!=-1)
  3960. {
  3961. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3962. sprintf(str,"rm -f %s",filenmae);
  3963. system(str);
  3964. }
  3965. }
  3966. }
  3967. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3968. #if 1 // for TempStopTransaction
  3969. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3970. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3971. {
  3972. checkTempStopTransaction(gun_index);
  3973. }
  3974. #endif
  3975. }
  3976. }
  3977. }
  3978. else if(gunType[gun_index] == GUN_TYPE_DO)
  3979. {
  3980. tempIndex = gun_index;
  3981. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3982. {
  3983. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3984. {
  3985. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3986. {
  3987. // Sent unplug message for California pricing logic
  3988. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3989. {
  3990. uint8_t ts[20];
  3991. getNowDatetime(ts);
  3992. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3993. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3994. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3995. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3996. }
  3997. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3998. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3999. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4000. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4001. {
  4002. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4003. if((access(filenmae,F_OK))!=-1)
  4004. {
  4005. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4006. sprintf(str,"rm -f %s",filenmae);
  4007. system(str);
  4008. }
  4009. }
  4010. }
  4011. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4012. #if 1 // for TempStopTransaction
  4013. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4014. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4015. {
  4016. checkTempStopTransaction(gun_index);
  4017. }
  4018. #endif
  4019. }
  4020. }
  4021. }
  4022. else
  4023. {
  4024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4025. {
  4026. tempIndex = 2;
  4027. }
  4028. else
  4029. {
  4030. tempIndex = gun_index;
  4031. }
  4032. for (int index = 0; index < AC_QUANTITY; index++)
  4033. {
  4034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4035. {
  4036. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4037. {
  4038. // Sent unplug message for California pricing logic
  4039. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4040. {
  4041. uint8_t ts[20];
  4042. getNowDatetime(ts);
  4043. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4044. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4045. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4046. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4047. }
  4048. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4049. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4050. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4051. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4052. {
  4053. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4054. if((access(filenmae,F_OK))!=-1)
  4055. {
  4056. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4057. sprintf(str,"rm -f %s",filenmae);
  4058. system(str);
  4059. }
  4060. }
  4061. }
  4062. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4063. #if 1 // for TempStopTransaction
  4064. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4065. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4066. {
  4067. checkTempStopTransaction(gun_index);
  4068. }
  4069. #endif
  4070. }
  4071. }// END
  4072. }
  4073. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4074. (
  4075. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  4076. )
  4077. )
  4078. {
  4079. if(SystemInitial > 0)
  4080. SystemInitial -= 1;
  4081. sendStatusNotificationRequest(gun_index);
  4082. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4083. }
  4084. //==============================================
  4085. // CSU Trigger Smart Charging Profilw
  4086. //==============================================
  4087. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4088. {
  4089. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4090. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4091. }
  4092. //==============================================
  4093. // Meter report
  4094. //==============================================
  4095. // Trigger MeterValue
  4096. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4097. {
  4098. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4099. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4100. }
  4101. // ClockAlign MeterValue
  4102. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4103. {
  4104. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4107. {
  4108. tempIndex = ((gun_index==2) ? 1: 0);
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4115. {
  4116. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4117. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4118. {
  4119. reqClockAlignMeter[gun_index] = 1;
  4120. }
  4121. }// End for CHAdeMO
  4122. }
  4123. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < CCS_QUANTITY; index++)
  4134. {
  4135. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4136. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4137. {
  4138. reqClockAlignMeter[gun_index] = 1;
  4139. }
  4140. } // End for CCS
  4141. }
  4142. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4145. {
  4146. tempIndex = ((gun_index==2) ? 1: 0);
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < GB_QUANTITY; index++)
  4153. {
  4154. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4155. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4156. {
  4157. reqClockAlignMeter[gun_index] = 1;
  4158. }
  4159. }// End for GB
  4160. }
  4161. else if(gunType[gun_index] == GUN_TYPE_DO)
  4162. {
  4163. tempIndex = gun_index;
  4164. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4165. {
  4166. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4167. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4168. {
  4169. reqClockAlignMeter[gun_index] = 1;
  4170. }
  4171. }
  4172. }
  4173. else
  4174. {
  4175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4176. {
  4177. tempIndex = 2;
  4178. }
  4179. else
  4180. {
  4181. tempIndex = gun_index;
  4182. }
  4183. for (int index = 0; index < AC_QUANTITY; index++)
  4184. {
  4185. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4186. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4187. {
  4188. reqClockAlignMeter[gun_index] = 1;
  4189. }
  4190. }//End for AC
  4191. }
  4192. if(reqClockAlignMeter[gun_index] == 1)
  4193. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4194. }
  4195. // Sample period MeterValue
  4196. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
  4197. {
  4198. //check Transaction active
  4199. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4200. {
  4201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4202. {
  4203. tempIndex = ((gun_index==2) ? 1: 0);
  4204. }
  4205. else
  4206. {
  4207. tempIndex = gun_index;
  4208. }
  4209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4210. {
  4211. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4212. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4213. {
  4214. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4215. {
  4216. reqSampleMeter[gun_index] = 1;
  4217. }
  4218. }
  4219. }// End for CHAdeMO
  4220. }
  4221. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4224. {
  4225. tempIndex = ((gun_index==2) ? 1: 0);
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < CCS_QUANTITY; index++)
  4232. {
  4233. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4234. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4235. {
  4236. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4237. {
  4238. reqSampleMeter[gun_index] = 1;
  4239. }
  4240. }
  4241. } // End for CCS
  4242. }
  4243. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4244. {
  4245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4246. {
  4247. tempIndex = ((gun_index==2) ? 1: 0);
  4248. }
  4249. else
  4250. {
  4251. tempIndex = gun_index;
  4252. }
  4253. for (int index = 0; index < GB_QUANTITY; index++)
  4254. {
  4255. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4256. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4257. {
  4258. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4259. {
  4260. reqSampleMeter[gun_index] = 1;
  4261. }
  4262. }
  4263. }// End for GB
  4264. }
  4265. else if(gunType[gun_index] == GUN_TYPE_DO)
  4266. {
  4267. tempIndex = gun_index;
  4268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4269. {
  4270. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4271. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4272. {
  4273. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4274. {
  4275. reqSampleMeter[gun_index] = 1;
  4276. }
  4277. }
  4278. }
  4279. }
  4280. else
  4281. {
  4282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4283. {
  4284. tempIndex = 2;
  4285. }
  4286. else
  4287. {
  4288. tempIndex = gun_index;
  4289. }
  4290. for (int index = 0; index < AC_QUANTITY; index++)
  4291. {
  4292. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4293. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4294. {
  4295. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4296. {
  4297. reqSampleMeter[gun_index] = 1;
  4298. }
  4299. }
  4300. }//End for AC
  4301. }
  4302. if(reqSampleMeter[gun_index] == 1)
  4303. {
  4304. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4305. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4306. storeTempStopTransaction(gun_index);
  4307. }
  4308. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4309. }
  4310. //==============================================
  4311. // Check Connector reserved
  4312. //==============================================
  4313. //===============================
  4314. // Check if Reserve is expired
  4315. //===============================
  4316. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4317. {
  4318. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4319. {
  4320. DEBUG_INFO("reserve expired.\n");
  4321. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4322. }
  4323. }//END OF Check if Reserve is expired
  4324. //==========================================
  4325. // csu trigger FirmwareStatusNotificationReq
  4326. //==========================================
  4327. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4328. {
  4329. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4330. }
  4331. //==========================================
  4332. // csu trigger DiagnosticsStatusNotificationReq
  4333. //==========================================
  4334. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4335. {
  4336. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4337. }
  4338. //==========================================
  4339. // csu trigger CancelReservationConf
  4340. //==========================================
  4341. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4342. {
  4343. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4344. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4345. }
  4346. //==========================================
  4347. // csu trigger ChangeAvailabilityConf
  4348. //==========================================
  4349. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4350. {
  4351. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4352. }
  4353. //==========================================
  4354. // csu trigger UnlockConnectorConf
  4355. //==========================================
  4356. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4357. {
  4358. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4359. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4360. }
  4361. //==========================================
  4362. // csu trigger ReserveNowConf
  4363. //==========================================
  4364. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4365. {
  4366. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4367. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4368. }
  4369. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4370. {
  4371. sendSignCertificateRequest();
  4372. }
  4373. }
  4374. }
  4375. //==========================================
  4376. // send request routine
  4377. //==========================================
  4378. int sendAuthorizeRequest(int gun_index)
  4379. {
  4380. mtrace();
  4381. int result = FAIL;
  4382. char message[100]={0};
  4383. char guid[37];
  4384. char tempdata[65]={0};
  4385. DEBUG_INFO("sendAuthorizeRequest...\n");
  4386. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4387. //Local Authorize
  4388. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4389. {
  4390. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4391. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4394. result = PASS;
  4395. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4396. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4397. authorizeRetryTimes = 0;
  4398. return result;
  4399. }
  4400. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  4401. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4402. {
  4403. // Query from cache
  4404. DEBUG_INFO("Authorize from cache.\n");
  4405. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4406. // Query from list
  4407. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4408. {
  4409. DEBUG_INFO("Authorize from list.\n");
  4410. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4411. }
  4412. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4413. {
  4414. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4415. {
  4416. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4417. }
  4418. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4419. {
  4420. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4421. }
  4422. if(!GetOcppConnStatus())
  4423. {
  4424. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4425. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4426. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4427. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4428. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4429. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4430. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4431. authorizeRetryTimes = 0;
  4432. return result;
  4433. }
  4434. }
  4435. else
  4436. {
  4437. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4438. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4439. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4440. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4441. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4442. else
  4443. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4444. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4445. result = PASS;
  4446. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4447. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4448. authorizeRetryTimes = 0;
  4449. return result;
  4450. }
  4451. }
  4452. //initialize struct Authorize
  4453. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4454. //get data from shared memory
  4455. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4456. random_uuid(guid);
  4457. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4458. LWS_Send(message);
  4459. sprintf(tempdata, "Authorize,%d", gun_index);
  4460. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4461. {
  4462. result = PASS;
  4463. DEBUG_INFO("Authorize mapItem pass\n");
  4464. }
  4465. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4466. return result;
  4467. }
  4468. int sendBootNotificationRequest(void)
  4469. {
  4470. mtrace();
  4471. int result = FAIL;
  4472. char message[500]={0}, payload[700]={0};
  4473. char guid[37]={0};
  4474. char tempdata[65]={0};
  4475. // Fill BootNotification fields
  4476. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4477. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4478. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4479. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4480. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4481. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4482. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4483. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4484. ShmOCPP16Data->ChargeBoxId
  4485. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4486. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4487. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4488. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4489. ,ShmOCPP16Data->BootNotification.CpIccid
  4490. ,ShmOCPP16Data->BootNotification.CpImsi);
  4491. random_uuid(guid);
  4492. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4493. LWS_Send(message);
  4494. sprintf(tempdata, "BootNotification,0");
  4495. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4496. {
  4497. result = PASS;
  4498. }
  4499. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4500. strcpy(queuedata,message);
  4501. return result;
  4502. }
  4503. int sendDataTransferRequest(int gun_index)
  4504. {
  4505. mtrace();
  4506. char message[1000]={0};
  4507. char guid[37]={0};
  4508. char tempdata[65]={0};
  4509. int result = FAIL;
  4510. random_uuid(guid);
  4511. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4512. MESSAGE_TYPE_CALL,
  4513. guid,
  4514. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4515. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4516. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4517. LWS_Send(message);
  4518. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4519. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4520. {
  4521. result = PASS;
  4522. DEBUG_INFO("DataTransfer mapItem pass\n");
  4523. }
  4524. return result;
  4525. }
  4526. int sendDiagnosticsStatusNotificationRequest(char *status)
  4527. {
  4528. mtrace();
  4529. int result = FAIL;
  4530. char message[110]={0};
  4531. char guid[37]={0};
  4532. char tempdata[65]={0};
  4533. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4534. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4535. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4536. random_uuid(guid);
  4537. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4538. LWS_SendNow(message);
  4539. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4540. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4541. {
  4542. result = PASS;
  4543. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4544. }
  4545. //#ifdef SystemLogMessage
  4546. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4547. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4548. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4549. //#endif
  4550. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4551. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4552. //record status
  4553. if(strcmp(status,"Idle")==0)
  4554. {
  4555. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4556. }
  4557. else if(strcmp(status,"Uploaded")==0)
  4558. {
  4559. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4560. }
  4561. else if(strcmp(status,"UploadFailed")==0)
  4562. {
  4563. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4564. }
  4565. else if(strcmp(status,"Uploading")==0)
  4566. {
  4567. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4568. }
  4569. return result;
  4570. }
  4571. int sendFirmwareStatusNotificationRequest(char *status)
  4572. {
  4573. mtrace();
  4574. int result = FAIL;
  4575. char message[110]={0};
  4576. char guid[37]={0};
  4577. char tempdata[65]={0};
  4578. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4579. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4580. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4581. random_uuid(guid);
  4582. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4583. LWS_SendNow(message);
  4584. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4585. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4586. {
  4587. result = PASS;
  4588. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4589. }
  4590. //#ifdef SystemLogMessage
  4591. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4592. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4593. //#endif
  4594. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4595. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4596. //record status
  4597. if(strcmp(status,"Downloaded")==0)
  4598. {
  4599. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4600. }
  4601. else if(strcmp(status,"DownloadFailed")==0)
  4602. {
  4603. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4604. }
  4605. else if(strcmp(status,"Downloading")==0)
  4606. {
  4607. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4608. }
  4609. else if(strcmp(status,"Idle")==0)
  4610. {
  4611. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4612. }
  4613. else if(strcmp(status,"InstallationFailed")==0)
  4614. {
  4615. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4616. }
  4617. else if(strcmp(status,"Installing")==0)
  4618. {
  4619. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4620. }
  4621. else if(strcmp(status,"Installed")==0)
  4622. {
  4623. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4624. }
  4625. return result;
  4626. }
  4627. int sendHeartbeatRequest(int gun_index)
  4628. {
  4629. mtrace();
  4630. int result = FAIL;
  4631. char message[80]={0};
  4632. char guid[37]={0};
  4633. char tempdata[65]={0};
  4634. random_uuid(guid);
  4635. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4636. , MESSAGE_TYPE_CALL
  4637. , guid );
  4638. LWS_Send(message);
  4639. sprintf(tempdata, "Heartbeat,%d", 0);
  4640. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4641. {
  4642. result = PASS;
  4643. }
  4644. return result;
  4645. }
  4646. int sendStartTransactionRequest(int gun_index)
  4647. {
  4648. mtrace();
  4649. int result = FAIL;
  4650. char message[250]={0};
  4651. char guid[37]={0};
  4652. struct timeval tmnow;
  4653. struct tm *tm;
  4654. char buf[28];//, usec_buf[6];
  4655. char tempdata[65]={0};
  4656. int tempIndex = 0;
  4657. DEBUG_INFO("sendStartTransactionRequest...\n");
  4658. gettimeofday(&tmnow, NULL);
  4659. time_t t;
  4660. t = time(NULL);
  4661. /*UTC time and date*/
  4662. tm = gmtime(&t);
  4663. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4664. #if 0 // remove temporally
  4665. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4666. strcat(buf,".");
  4667. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4668. strcat(buf,usec_buf);
  4669. #endif
  4670. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4671. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4672. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4673. // clear StartTransaction Response
  4674. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4675. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4676. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4677. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4678. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4679. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4680. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4681. {
  4682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4683. {
  4684. tempIndex = ((gun_index==2) ? 1: 0);
  4685. }
  4686. else
  4687. {
  4688. tempIndex = gun_index;
  4689. }
  4690. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4691. {
  4692. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4693. {
  4694. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4695. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4696. }
  4697. }
  4698. }
  4699. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4700. {
  4701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4702. {
  4703. tempIndex = ((gun_index==2) ? 1: 0);
  4704. }
  4705. else
  4706. {
  4707. tempIndex = gun_index;
  4708. }
  4709. for (int index = 0; index < CCS_QUANTITY; index++)
  4710. {
  4711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4712. {
  4713. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4714. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4715. }
  4716. }
  4717. }
  4718. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4719. {
  4720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4721. {
  4722. tempIndex = ((gun_index==2) ? 1: 0);
  4723. }
  4724. else
  4725. {
  4726. tempIndex = gun_index;
  4727. }
  4728. for (int index = 0; index < GB_QUANTITY; index++)
  4729. {
  4730. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4731. {
  4732. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4733. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4734. }
  4735. }
  4736. }
  4737. else if(gunType[gun_index] == GUN_TYPE_DO)
  4738. {
  4739. tempIndex = gun_index;
  4740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4741. {
  4742. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4743. {
  4744. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4745. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4746. }
  4747. }
  4748. }
  4749. else
  4750. {
  4751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4752. {
  4753. tempIndex = 2;
  4754. }
  4755. else
  4756. {
  4757. tempIndex = gun_index;
  4758. }
  4759. for (int index = 0; index < AC_QUANTITY; index++)
  4760. {
  4761. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4762. {
  4763. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4764. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4765. }
  4766. }
  4767. }
  4768. random_uuid(guid);
  4769. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4770. {
  4771. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4772. , gun_index +1
  4773. , MESSAGE_TYPE_CALL
  4774. , guid
  4775. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4776. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4777. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4778. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4779. }
  4780. else
  4781. {
  4782. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4783. , gun_index +1
  4784. , MESSAGE_TYPE_CALL
  4785. , guid
  4786. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4787. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4788. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4789. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4790. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4791. }
  4792. #if 1
  4793. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4794. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4795. {
  4796. result = PASS;
  4797. }
  4798. #endif
  4799. strcpy(queuedata, message);
  4800. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4801. OCPP_insert_transaction_msg(YES, queuedata);
  4802. return result;
  4803. }
  4804. int sendStatusNotificationRequest(int gun_index)
  4805. {
  4806. mtrace();
  4807. int result = FAIL;
  4808. char message[600]={0};
  4809. char guid[37];
  4810. int currentStatus = 0;
  4811. struct timeval tmnow;
  4812. struct tm *tm;
  4813. char buf[28];//, usec_buf[6];
  4814. char tempdata[65]={0};
  4815. int tempIndex = 0;
  4816. uint8_t isStateChanged = TRUE;
  4817. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4818. gettimeofday(&tmnow, NULL);
  4819. time_t t;
  4820. t = time(NULL);
  4821. /*UTC time and date*/
  4822. tm = gmtime(&t);
  4823. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4824. #if 0 // remove temporally
  4825. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4826. strcat(buf,".");
  4827. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4828. strcat(buf,usec_buf);
  4829. #endif
  4830. //printf("%s",buf);
  4831. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4832. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4833. // it's option
  4834. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4835. /*
  4836. enum _SYSTEM_STATUS
  4837. {
  4838. S_BOOTING = 0,
  4839. S_IDLE, = 1
  4840. S_AUTHORIZING, =2
  4841. S_REASSIGN_CHECK, =3
  4842. S_REASSIGN, =4
  4843. S_PRECHARGE, =5
  4844. S_PREPARING_FOR_EV, =6
  4845. S_PREPARING_FOR_EVSE, =7
  4846. S_CHARGING, =8
  4847. S_TERMINATING, =9
  4848. S_COMPLETE, =10
  4849. S_ALARM, =11
  4850. S_FAULT =12
  4851. }
  4852. */
  4853. //check Transaction active
  4854. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4855. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4856. {
  4857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4858. {
  4859. tempIndex = ((gun_index==2) ? 1: 0);
  4860. }
  4861. else
  4862. {
  4863. tempIndex = gun_index;
  4864. }
  4865. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4866. {
  4867. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4868. {
  4869. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4870. {
  4871. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4872. {
  4873. currentStatus = Preparing; //OCPP Status: Preparing
  4874. }
  4875. else
  4876. {
  4877. currentStatus = Available; //OCPP Status: Available
  4878. }
  4879. }
  4880. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4881. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4882. ) //S_PRECHARGE
  4883. {
  4884. currentStatus = Preparing; //OCPP Status: Preparing
  4885. }
  4886. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4887. {
  4888. currentStatus = Charging; //OCPP Status: Charging
  4889. }
  4890. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4891. {
  4892. currentStatus = Finishing; //OCPP Status: Finishing
  4893. }
  4894. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4895. {
  4896. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4897. }
  4898. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  4899. {
  4900. currentStatus = Unavailable; //OCPP Status: Unavailable
  4901. }
  4902. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4903. {
  4904. currentStatus = Faulted; //OCPP Status: Faulted
  4905. }
  4906. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4907. {
  4908. currentStatus = Reserved; //OCPP Status: Reserved
  4909. }
  4910. } //end of the same index
  4911. }//end of for CHAdeMO_QUANTITY
  4912. }
  4913. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4914. {
  4915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4916. {
  4917. tempIndex = ((gun_index==2) ? 1: 0);
  4918. }
  4919. else
  4920. {
  4921. tempIndex = gun_index;
  4922. }
  4923. for (int index = 0; index < CCS_QUANTITY; index++)
  4924. {
  4925. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4926. {
  4927. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4928. {
  4929. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4930. {
  4931. currentStatus = Preparing; //OCPP Status: Preparing
  4932. }
  4933. else
  4934. {
  4935. currentStatus = Available; //OCPP Status: Available
  4936. }
  4937. }
  4938. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4939. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4940. ) //S_PRECHARGE
  4941. {
  4942. currentStatus = Preparing; //OCPP Status: Preparing
  4943. }
  4944. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4945. {
  4946. currentStatus = Charging; //OCPP Status: Charging
  4947. }
  4948. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4949. {
  4950. currentStatus = Finishing; //OCPP Status: Finishing
  4951. }
  4952. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4953. {
  4954. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4955. }
  4956. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  4957. {
  4958. currentStatus = Unavailable; //OCPP Status : Unavailable
  4959. }
  4960. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4961. {
  4962. currentStatus = Faulted; //OCPP Status: Faulted
  4963. }
  4964. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4965. {
  4966. currentStatus = Reserved; //OCPP Status: Reserved
  4967. }
  4968. } //end of the same index
  4969. } // end of for CCS_QUANTITY
  4970. }
  4971. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4972. {
  4973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4974. {
  4975. tempIndex = ((gun_index==2) ? 1: 0);
  4976. }
  4977. else
  4978. {
  4979. tempIndex = gun_index;
  4980. }
  4981. for (int index = 0; index < GB_QUANTITY; index++)
  4982. {
  4983. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4984. {
  4985. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4986. {
  4987. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4988. {
  4989. currentStatus = Preparing; //OCPP Status: Preparing
  4990. }
  4991. else
  4992. {
  4993. currentStatus = Available; //OCPP Status: Available
  4994. }
  4995. }
  4996. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4997. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4998. ) //S_PRECHARGE
  4999. {
  5000. currentStatus = Preparing; //OCPP Status: Preparing
  5001. }
  5002. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5003. {
  5004. currentStatus = Charging; //OCPP Status: Charging
  5005. }
  5006. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5007. {
  5008. currentStatus = Finishing; //OCPP Status: Finishing
  5009. }
  5010. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5011. {
  5012. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5013. }
  5014. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5015. {
  5016. currentStatus = Unavailable; //OCPP Status: Unavailable
  5017. }
  5018. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5019. {
  5020. currentStatus = Faulted; //OCPP Status: Faulted
  5021. }
  5022. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5023. {
  5024. currentStatus = Reserved; //OCPP Status: Reserved
  5025. }
  5026. } //end of the same index
  5027. } // end of for GB_QUANTITY
  5028. }
  5029. else if(gunType[gun_index] == GUN_TYPE_DO)
  5030. {
  5031. tempIndex = gun_index;
  5032. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5033. {
  5034. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5035. {
  5036. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5037. {
  5038. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5039. {
  5040. currentStatus = Preparing; //OCPP Status: Preparing
  5041. }
  5042. else
  5043. {
  5044. currentStatus = Available; //OCPP Status: Available
  5045. }
  5046. }
  5047. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5048. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5049. ) //S_PRECHARGE
  5050. {
  5051. currentStatus = Preparing; //OCPP Status: Preparing
  5052. }
  5053. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5054. {
  5055. currentStatus = Charging; //OCPP Status: Charging
  5056. }
  5057. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5058. {
  5059. currentStatus = Finishing; //OCPP Status: Finishing
  5060. }
  5061. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5062. {
  5063. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5064. }
  5065. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5066. {
  5067. currentStatus = Unavailable; //OCPP Status: Unavailable
  5068. }
  5069. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5070. {
  5071. currentStatus = Faulted; //OCPP Status: Faulted
  5072. }
  5073. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5074. {
  5075. currentStatus = Reserved; //OCPP Status: Reserved
  5076. }
  5077. } //end of the same index
  5078. }
  5079. }
  5080. else
  5081. {
  5082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5083. {
  5084. tempIndex = 2;
  5085. }
  5086. else
  5087. {
  5088. tempIndex = gun_index;
  5089. }
  5090. for (int index = 0; index < AC_QUANTITY; index++)
  5091. {
  5092. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5093. {
  5094. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5095. {
  5096. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  5097. {
  5098. currentStatus = Preparing; //OCPP Status: Preparing
  5099. }
  5100. else
  5101. {
  5102. currentStatus = Available; //OCPP Status: Available
  5103. }
  5104. }
  5105. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5106. {
  5107. currentStatus = Preparing; //OCPP Status: Preparing
  5108. }
  5109. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5110. {
  5111. currentStatus = Charging; //OCPP Status: Charging
  5112. }
  5113. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5114. {
  5115. currentStatus = Finishing; //OCPP Status: Finishing
  5116. }
  5117. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5118. {
  5119. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5120. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5121. else
  5122. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5123. }
  5124. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5125. {
  5126. currentStatus = Unavailable; //OCPP Status: Unavailable
  5127. }
  5128. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5129. {
  5130. currentStatus = Faulted; //OCPP Status: Faulted
  5131. }
  5132. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5133. {
  5134. currentStatus = Reserved; //OCPP Status: Reserved
  5135. }
  5136. }//end of the same index
  5137. }//end of for AC_QUANTITY
  5138. }
  5139. //it's option
  5140. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5141. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  5142. {
  5143. isStateChanged = FALSE;
  5144. }
  5145. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5146. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5147. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5148. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5149. random_uuid(guid);
  5150. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5151. , MESSAGE_TYPE_CALL
  5152. , guid
  5153. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5154. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5155. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5156. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5157. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5158. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5159. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5160. if((server_sign == TRUE) && isStateChanged)
  5161. {
  5162. LWS_Send(message);
  5163. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5164. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5165. {
  5166. //DEBUG_ERROR("statusNotification mapitem pass");
  5167. result = PASS;
  5168. }
  5169. }
  5170. else
  5171. {
  5172. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5173. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5174. result = PASS;
  5175. }
  5176. return result;
  5177. }
  5178. int sendStopTransactionRequest(int gun_index)
  5179. {
  5180. mtrace();
  5181. int result = FAIL;
  5182. //char message[1500]={0};
  5183. char guid[37]={0};
  5184. char tempdata[65]={0};
  5185. int tempIndex = 0;
  5186. char TempStopTransaction[256];
  5187. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5188. //int idx_sample=0;
  5189. DEBUG_INFO("sendStopTransactionRequest \n");
  5190. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5191. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5192. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5193. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5194. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5195. {
  5196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5197. {
  5198. tempIndex = ((gun_index==2) ? 1: 0);
  5199. }
  5200. else
  5201. {
  5202. tempIndex = gun_index;
  5203. }
  5204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5205. {
  5206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5207. {
  5208. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5209. }
  5210. }// END OF CHAdeMO_QUANTITY
  5211. }
  5212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5213. {
  5214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5215. {
  5216. tempIndex = ((gun_index==2) ? 1: 0);
  5217. }
  5218. else
  5219. {
  5220. tempIndex = gun_index;
  5221. }
  5222. for (int index = 0; index < CCS_QUANTITY; index++)
  5223. {
  5224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5225. {
  5226. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5227. }
  5228. }// END OF CCS_QUANTITY
  5229. }
  5230. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5231. {
  5232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5233. {
  5234. tempIndex = ((gun_index==2) ? 1: 0);
  5235. }
  5236. else
  5237. {
  5238. tempIndex = gun_index;
  5239. }
  5240. for (int index = 0; index < GB_QUANTITY; index++)
  5241. {
  5242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5243. {
  5244. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5245. }
  5246. }// END OF GB_QUANTITY
  5247. }
  5248. else if(gunType[gun_index] == GUN_TYPE_DO)
  5249. {
  5250. tempIndex = gun_index;
  5251. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5252. {
  5253. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5254. {
  5255. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5256. }
  5257. }// END OF GB_QUANTITY
  5258. }
  5259. else
  5260. {
  5261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5262. {
  5263. tempIndex = 2;
  5264. }
  5265. else
  5266. {
  5267. tempIndex = gun_index;
  5268. }
  5269. for (int index = 0; index < AC_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5272. {
  5273. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5274. }
  5275. }// END OF AC_QUANTITY
  5276. }
  5277. //====================================== Stop Transaction Time =====================================================
  5278. struct timeval tmnow;
  5279. struct tm *tm;
  5280. char buf[28];//, usec_buf[6];
  5281. gettimeofday(&tmnow, NULL);
  5282. time_t t;
  5283. t = time(NULL);
  5284. /*UTC time and date*/
  5285. tm = gmtime(&t);
  5286. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5288. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5289. random_uuid(guid);
  5290. /***********************************transactionData******************************************************/
  5291. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5293. //=================================
  5294. // Transaction_Begin
  5295. //=================================
  5296. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5297. {
  5298. //============================================ Energy.Active.Import.Interval ================================
  5299. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5303. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5304. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  5305. {
  5306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5307. }
  5308. else
  5309. {
  5310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5311. }
  5312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5314. }
  5315. //=================================
  5316. // Transaction_End
  5317. //=================================
  5318. // ================================= Current.Import L1 ===============================================
  5319. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5320. {
  5321. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5322. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5323. {
  5324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5325. {
  5326. tempIndex = ((gun_index==2) ? 1: 0);
  5327. }
  5328. else
  5329. {
  5330. tempIndex = gun_index;
  5331. }
  5332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5333. {
  5334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5335. {
  5336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5337. }
  5338. }// End of for CHAdeMO_QUANTITY
  5339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5340. }
  5341. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5342. {
  5343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5344. {
  5345. tempIndex = ((gun_index==2) ? 1: 0);
  5346. }
  5347. else
  5348. {
  5349. tempIndex = gun_index;
  5350. }
  5351. for (int index = 0; index < CCS_QUANTITY; index++)
  5352. {
  5353. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5354. {
  5355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5356. }
  5357. }// End of for CCS_QUANTITY
  5358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5359. }
  5360. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5361. {
  5362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5363. {
  5364. tempIndex = ((gun_index==2) ? 1: 0);
  5365. }
  5366. else
  5367. {
  5368. tempIndex = gun_index;
  5369. }
  5370. for (int index = 0; index < GB_QUANTITY; index++)
  5371. {
  5372. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5373. {
  5374. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5375. }
  5376. }// End of for GB_QUANTITY
  5377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5378. }
  5379. else if(gunType[gun_index] == GUN_TYPE_DO)
  5380. {
  5381. tempIndex = gun_index;
  5382. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5383. {
  5384. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5385. {
  5386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5387. }
  5388. }
  5389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5390. }
  5391. else
  5392. {
  5393. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5394. {
  5395. tempIndex = 2;
  5396. }
  5397. else
  5398. {
  5399. tempIndex = gun_index;
  5400. }
  5401. for (int index = 0; index < AC_QUANTITY; index++)
  5402. {
  5403. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5404. {
  5405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5406. }
  5407. }// End of for AC_QUANTITY
  5408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5409. }
  5410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5415. }
  5416. // ================================= Energy.Active.Import.Interval ==============================================
  5417. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5418. {
  5419. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5420. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5421. {
  5422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5423. {
  5424. tempIndex = ((gun_index==2) ? 1: 0);
  5425. }
  5426. else
  5427. {
  5428. tempIndex = gun_index;
  5429. }
  5430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5431. {
  5432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5433. {
  5434. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5435. }
  5436. }// END OF CHAdeMO_QUANTITY
  5437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5438. }
  5439. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5440. {
  5441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5442. {
  5443. tempIndex = ((gun_index==2) ? 1: 0);
  5444. }
  5445. else
  5446. {
  5447. tempIndex = gun_index;
  5448. }
  5449. for (int index = 0; index < CCS_QUANTITY; index++)
  5450. {
  5451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5452. {
  5453. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5454. }
  5455. }// END OF CCS_QUANTITY
  5456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5457. }
  5458. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5461. {
  5462. tempIndex = ((gun_index==2) ? 1: 0);
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < GB_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5471. {
  5472. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5473. }
  5474. }// END OF GB_QUANTITY
  5475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5476. }
  5477. else if(gunType[gun_index] == GUN_TYPE_DO)
  5478. {
  5479. tempIndex = gun_index;
  5480. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5481. {
  5482. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5483. {
  5484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5485. }
  5486. }
  5487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5488. }
  5489. else
  5490. {
  5491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5492. {
  5493. tempIndex = 2;
  5494. }
  5495. else
  5496. {
  5497. tempIndex = gun_index;
  5498. }
  5499. for (int index = 0; index < AC_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5502. {
  5503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5504. }
  5505. }// END OF AC_QUANTITY
  5506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5507. }
  5508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5513. }
  5514. //=================================== Power.Active.Import ==================================================
  5515. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5516. {
  5517. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5518. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5519. {
  5520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5521. {
  5522. tempIndex = ((gun_index==2) ? 1: 0);
  5523. }
  5524. else
  5525. {
  5526. tempIndex = gun_index;
  5527. }
  5528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5529. {
  5530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5531. {
  5532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5533. }
  5534. } // End for CHAdeMO_QUANTITY
  5535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5536. }
  5537. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5538. {
  5539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5540. {
  5541. tempIndex = ((gun_index==2) ? 1: 0);
  5542. }
  5543. else
  5544. {
  5545. tempIndex = gun_index;
  5546. }
  5547. for (int index = 0; index < CCS_QUANTITY; index++)
  5548. {
  5549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5550. {
  5551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5552. }
  5553. } // END for CCS_QUANTITY
  5554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5555. }
  5556. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5557. {
  5558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5559. {
  5560. tempIndex = ((gun_index==2) ? 1: 0);
  5561. }
  5562. else
  5563. {
  5564. tempIndex = gun_index;
  5565. }
  5566. for (int index = 0; index < GB_QUANTITY; index++)
  5567. {
  5568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5569. {
  5570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5571. }
  5572. }// END for GB_QUANTITY
  5573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5574. }
  5575. else if(gunType[gun_index] == GUN_TYPE_DO)
  5576. {
  5577. tempIndex = gun_index;
  5578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5579. {
  5580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5581. {
  5582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5583. }
  5584. }
  5585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5586. }
  5587. else
  5588. {
  5589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5590. {
  5591. tempIndex = 2;
  5592. }
  5593. else
  5594. {
  5595. tempIndex = gun_index;
  5596. }
  5597. for (int index = 0; index < AC_QUANTITY; index++)
  5598. {
  5599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5600. {
  5601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5602. }
  5603. } // END for AC_QUANTITY
  5604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5605. }
  5606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5611. }
  5612. //============================ Voltage L1 ====================================
  5613. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5614. {
  5615. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5616. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5617. {
  5618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5619. {
  5620. tempIndex = ((gun_index==2) ? 1: 0);
  5621. }
  5622. else
  5623. {
  5624. tempIndex = gun_index;
  5625. }
  5626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5629. {
  5630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5631. }
  5632. } // END OF FOR CHAdeMO_QUANTITY
  5633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5634. }
  5635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5636. {
  5637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5638. {
  5639. tempIndex = ((gun_index==2) ? 1: 0);
  5640. }
  5641. else
  5642. {
  5643. tempIndex = gun_index;
  5644. }
  5645. for (int index = 0; index < CCS_QUANTITY; index++)
  5646. {
  5647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5648. {
  5649. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5650. }
  5651. } // END OF FOR CCS_QUANTITY
  5652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5653. }
  5654. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5655. {
  5656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5657. {
  5658. tempIndex = ((gun_index==2) ? 1: 0);
  5659. }
  5660. else
  5661. {
  5662. tempIndex = gun_index;
  5663. }
  5664. for (int index = 0; index < GB_QUANTITY; index++)
  5665. {
  5666. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5667. {
  5668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5669. }
  5670. } // END OF FOR GB_QUANTITY
  5671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5672. }
  5673. else if(gunType[gun_index] == GUN_TYPE_DO)
  5674. {
  5675. tempIndex = gun_index;
  5676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5681. }
  5682. }
  5683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5684. }
  5685. else
  5686. {
  5687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5688. {
  5689. tempIndex = 2;
  5690. }
  5691. else
  5692. {
  5693. tempIndex = gun_index;
  5694. }
  5695. for (int index = 0; index < AC_QUANTITY; index++)
  5696. {
  5697. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5698. {
  5699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5700. }
  5701. } // END OF FOR AC_QUANTITY
  5702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5703. }
  5704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5709. }
  5710. //====================== End SoC ================================
  5711. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5712. {
  5713. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5714. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  5715. {
  5716. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5717. {
  5718. tempIndex = ((gun_index==2) ? 1: 0);
  5719. }
  5720. else
  5721. {
  5722. tempIndex = gun_index;
  5723. }
  5724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5725. {
  5726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5727. {
  5728. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5729. {
  5730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5731. }
  5732. }
  5733. }
  5734. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5735. {
  5736. for (int index = 0; index < CCS_QUANTITY; index++)
  5737. {
  5738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5739. {
  5740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5741. }
  5742. }
  5743. }
  5744. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5745. {
  5746. for (int index = 0; index < GB_QUANTITY; index++)
  5747. {
  5748. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5749. {
  5750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5751. }
  5752. }
  5753. }
  5754. else if(gunType[gun_index] == GUN_TYPE_DO)
  5755. {
  5756. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5757. {
  5758. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5759. {
  5760. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5761. }
  5762. }
  5763. }
  5764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5770. } // END FOR DC CASE
  5771. }
  5772. // ================================= Current.Import L2 ===============================================
  5773. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5774. {
  5775. // AC 3 phse L2 current
  5776. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5777. {
  5778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5779. {
  5780. tempIndex = 2;
  5781. }
  5782. else
  5783. {
  5784. tempIndex = gun_index;
  5785. }
  5786. for (int index = 0; index < AC_QUANTITY; index++)
  5787. {
  5788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5789. {
  5790. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5791. }
  5792. }// End of for AC_QUANTITY
  5793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5794. }
  5795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5800. }
  5801. // ================================= Current.Import L3 ===============================================
  5802. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5803. {
  5804. // AC 3 phse L3 current
  5805. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5806. {
  5807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5808. {
  5809. tempIndex = 2;
  5810. }
  5811. else
  5812. {
  5813. tempIndex = gun_index;
  5814. }
  5815. for (int index = 0; index < AC_QUANTITY; index++)
  5816. {
  5817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5818. {
  5819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5820. }
  5821. }// End of for AC_QUANTITY
  5822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5823. }
  5824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5829. }
  5830. //============================ Voltage L2 ====================================
  5831. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5832. {
  5833. // AC 3 phse L2 voltage
  5834. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5835. {
  5836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5837. {
  5838. tempIndex = 2;
  5839. }
  5840. else
  5841. {
  5842. tempIndex = gun_index;
  5843. }
  5844. for (int index = 0; index < AC_QUANTITY; index++)
  5845. {
  5846. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5847. {
  5848. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5849. }
  5850. } // END OF FOR AC_QUANTITY
  5851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5852. }
  5853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5858. }
  5859. //============================ Voltage L3 ====================================
  5860. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5861. {
  5862. // AC 3 phse L3 voltage
  5863. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5864. {
  5865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5866. {
  5867. tempIndex = 2;
  5868. }
  5869. else
  5870. {
  5871. tempIndex = gun_index;
  5872. }
  5873. for (int index = 0; index < AC_QUANTITY; index++)
  5874. {
  5875. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5876. {
  5877. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5878. }
  5879. } // END OF FOR AC_QUANTITY
  5880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5881. }
  5882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5887. }
  5888. //====================== Start SoC ================================
  5889. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5890. {
  5891. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5892. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  5893. {
  5894. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5895. {
  5896. tempIndex = ((gun_index==2) ? 1: 0);
  5897. }
  5898. else
  5899. {
  5900. tempIndex = gun_index;
  5901. }
  5902. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5903. {
  5904. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5905. {
  5906. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5907. {
  5908. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5909. }
  5910. }
  5911. }
  5912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5913. {
  5914. for (int index = 0; index < CCS_QUANTITY; index++)
  5915. {
  5916. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5917. {
  5918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5919. }
  5920. }
  5921. }
  5922. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5923. {
  5924. for (int index = 0; index < GB_QUANTITY; index++)
  5925. {
  5926. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5927. {
  5928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5929. }
  5930. }
  5931. }
  5932. else if(gunType[gun_index] == GUN_TYPE_DO)
  5933. {
  5934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5935. {
  5936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5937. {
  5938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5939. }
  5940. }
  5941. }
  5942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5948. } // END FOR DC CASE
  5949. }
  5950. //================================================ Message create ====================================================
  5951. json_object *StopTransaction = json_object_new_object();
  5952. json_object *transactionDatas = json_object_new_array();
  5953. json_object *sampledValues = json_object_new_array();
  5954. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5955. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5956. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5957. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5958. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5959. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5960. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5961. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5962. {
  5963. json_object *transactionData = json_object_new_object();
  5964. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5965. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5966. {
  5967. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5968. {
  5969. json_object *sampledValue = json_object_new_object();
  5970. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5971. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5972. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5973. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5974. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5975. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5976. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5977. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5978. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5979. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5980. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5981. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5982. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5983. json_object_array_add(sampledValues, sampledValue);
  5984. }
  5985. }
  5986. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5987. json_object_array_add(transactionDatas, transactionData);
  5988. }
  5989. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5990. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5991. ,MESSAGE_TYPE_CALL
  5992. ,guid
  5993. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5994. json_object_put(StopTransaction);
  5995. #if 1 // for TempStopTransaction
  5996. //Delete TempStopTransaction
  5997. if((access(TempStopTransaction,F_OK))!=-1)
  5998. {
  5999. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6000. }
  6001. #endif
  6002. #if 1
  6003. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6004. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6005. {
  6006. result = PASS;
  6007. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6008. }
  6009. #endif
  6010. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6011. OCPP_insert_transaction_msg(NO, queuedata);
  6012. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6013. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6014. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6015. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6016. {
  6017. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6018. }
  6019. //for test
  6020. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6021. return result;
  6022. }
  6023. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6024. {
  6025. mtrace();
  6026. int result = FAIL;
  6027. char guid[37]={0};
  6028. char tempdata[65]={0};
  6029. int tempIndex = 0;
  6030. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6031. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6032. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6033. //set value
  6034. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6035. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6036. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6037. -1);
  6038. random_uuid(guid);
  6039. //UTC Date time
  6040. struct timeval tmnow;
  6041. struct tm *tm;
  6042. char buf[28];//, usec_buf[6];
  6043. gettimeofday(&tmnow, NULL);
  6044. time_t t;
  6045. t = time(NULL);
  6046. /*UTC time and date*/
  6047. tm = gmtime(&t);
  6048. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6050. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6051. //********************************(1)Current.Import L1************************************************/
  6052. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6053. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6054. (dataType == ReadingContext_Trigger))
  6055. {
  6056. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6057. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6058. {
  6059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6060. {
  6061. tempIndex = ((gun_index==2) ? 1: 0);
  6062. }
  6063. else
  6064. {
  6065. tempIndex = gun_index;
  6066. }
  6067. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6068. {
  6069. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6070. {
  6071. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6072. }
  6073. }
  6074. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6075. }
  6076. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6077. {
  6078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6079. {
  6080. tempIndex = ((gun_index==2) ? 1: 0);
  6081. }
  6082. else
  6083. {
  6084. tempIndex = gun_index;
  6085. }
  6086. for (int index = 0; index < CCS_QUANTITY; index++)
  6087. {
  6088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6089. {
  6090. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6091. }
  6092. }
  6093. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6094. }
  6095. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6096. {
  6097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6098. {
  6099. tempIndex = ((gun_index==2) ? 1: 0);
  6100. }
  6101. else
  6102. {
  6103. tempIndex = gun_index;
  6104. }
  6105. for (int index = 0; index < GB_QUANTITY; index++)
  6106. {
  6107. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6108. {
  6109. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6110. }
  6111. }
  6112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6113. }
  6114. else if(gunType[gun_index] == GUN_TYPE_DO)
  6115. {
  6116. tempIndex = gun_index;
  6117. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6118. {
  6119. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6120. {
  6121. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6122. }
  6123. }
  6124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6125. }
  6126. else
  6127. {
  6128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6129. {
  6130. tempIndex = 2;
  6131. }
  6132. else
  6133. {
  6134. tempIndex = gun_index;
  6135. }
  6136. for (int index = 0; index < AC_QUANTITY; index++)
  6137. {
  6138. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6139. {
  6140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6141. }
  6142. }
  6143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6144. }
  6145. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6150. }
  6151. //********************************(2)Energy.Active.Import.Register ************************************************/
  6152. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6153. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6154. (dataType == ReadingContext_Trigger))
  6155. {
  6156. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6157. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6158. {
  6159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6160. {
  6161. tempIndex = ((gun_index==2) ? 1: 0);
  6162. }
  6163. else
  6164. {
  6165. tempIndex = gun_index;
  6166. }
  6167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6168. {
  6169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6170. {
  6171. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6172. }
  6173. }
  6174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6175. }
  6176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6177. {
  6178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6179. {
  6180. tempIndex = ((gun_index==2) ? 1: 0);
  6181. }
  6182. else
  6183. {
  6184. tempIndex = gun_index;
  6185. }
  6186. for (int index = 0; index < CCS_QUANTITY; index++)
  6187. {
  6188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6189. {
  6190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6191. }
  6192. }
  6193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6194. }
  6195. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6196. {
  6197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6198. {
  6199. tempIndex = ((gun_index==2) ? 1: 0);
  6200. }
  6201. else
  6202. {
  6203. tempIndex = gun_index;
  6204. }
  6205. for (int index = 0; index < GB_QUANTITY; index++)
  6206. {
  6207. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6208. {
  6209. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6210. }
  6211. }
  6212. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6213. }
  6214. else if(gunType[gun_index] == GUN_TYPE_DO)
  6215. {
  6216. tempIndex = gun_index;
  6217. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6218. {
  6219. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6220. {
  6221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6222. }
  6223. }
  6224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6225. }
  6226. else
  6227. {
  6228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6229. {
  6230. tempIndex = 2;
  6231. }
  6232. else
  6233. {
  6234. tempIndex = gun_index;
  6235. }
  6236. for (int index = 0; index < AC_QUANTITY; index++)
  6237. {
  6238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6239. {
  6240. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6241. }
  6242. }
  6243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6244. }
  6245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6250. }
  6251. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6252. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6253. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6254. (dataType == ReadingContext_Trigger))
  6255. {
  6256. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6257. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6258. {
  6259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6260. {
  6261. tempIndex = ((gun_index==2) ? 1: 0);
  6262. }
  6263. else
  6264. {
  6265. tempIndex = gun_index;
  6266. }
  6267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6268. {
  6269. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6270. {
  6271. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6272. }
  6273. } // END OF FOR CHAdeMO_QUANTITY
  6274. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6275. }
  6276. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6277. {
  6278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6279. {
  6280. tempIndex = ((gun_index==2) ? 1: 0);
  6281. }
  6282. else
  6283. {
  6284. tempIndex = gun_index;
  6285. }
  6286. for (int index = 0; index < CCS_QUANTITY; index++)
  6287. {
  6288. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6289. {
  6290. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6291. }
  6292. } // END OF CCS_QUANTITY
  6293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6294. }
  6295. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6296. {
  6297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6298. {
  6299. tempIndex = ((gun_index==2) ? 1: 0);
  6300. }
  6301. else
  6302. {
  6303. tempIndex = gun_index;
  6304. }
  6305. for (int index = 0; index < GB_QUANTITY; index++)
  6306. {
  6307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6308. {
  6309. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6310. }
  6311. } // END OF GB_QUANTITY
  6312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6313. }
  6314. else if(gunType[gun_index] == GUN_TYPE_DO)
  6315. {
  6316. tempIndex = gun_index;
  6317. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6320. {
  6321. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6322. }
  6323. }
  6324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6325. }
  6326. else
  6327. {
  6328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6329. {
  6330. tempIndex = 2;
  6331. }
  6332. else
  6333. {
  6334. tempIndex = gun_index;
  6335. }
  6336. for (int index = 0; index < AC_QUANTITY; index++)
  6337. {
  6338. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6339. {
  6340. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6341. }
  6342. }
  6343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6344. }
  6345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6350. }
  6351. //********************************(4)Power.Active.Import************************************************/
  6352. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6353. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6354. (dataType == ReadingContext_Trigger))
  6355. {
  6356. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6357. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6358. {
  6359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6360. {
  6361. tempIndex = ((gun_index==2) ? 1: 0);
  6362. }
  6363. else
  6364. {
  6365. tempIndex = gun_index;
  6366. }
  6367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6370. {
  6371. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6372. }
  6373. } // END OF FOR
  6374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6375. }
  6376. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6377. {
  6378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6379. {
  6380. tempIndex = ((gun_index==2) ? 1: 0);
  6381. }
  6382. else
  6383. {
  6384. tempIndex = gun_index;
  6385. }
  6386. for (int index = 0; index < CCS_QUANTITY; index++)
  6387. {
  6388. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6389. {
  6390. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6391. }
  6392. }
  6393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6394. }
  6395. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6396. {
  6397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6398. {
  6399. tempIndex = ((gun_index==2) ? 1: 0);
  6400. }
  6401. else
  6402. {
  6403. tempIndex = gun_index;
  6404. }
  6405. for (int index = 0; index < GB_QUANTITY; index++)
  6406. {
  6407. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6408. {
  6409. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6410. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6411. }
  6412. }
  6413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6414. }
  6415. else if(gunType[gun_index] == GUN_TYPE_DO)
  6416. {
  6417. tempIndex = gun_index;
  6418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6419. {
  6420. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6421. {
  6422. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6423. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6424. }
  6425. }
  6426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6427. }
  6428. else
  6429. {
  6430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6431. {
  6432. tempIndex = 2;
  6433. }
  6434. else
  6435. {
  6436. tempIndex = gun_index;
  6437. }
  6438. for (int index = 0; index < AC_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6441. {
  6442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6443. }
  6444. }
  6445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6446. }
  6447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6452. }
  6453. //***********************************************(5)VOLTAGE L1******************************************************/
  6454. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6455. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6456. (dataType == ReadingContext_Trigger))
  6457. {
  6458. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6459. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6460. {
  6461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6462. {
  6463. tempIndex = ((gun_index==2) ? 1: 0);
  6464. }
  6465. else
  6466. {
  6467. tempIndex = gun_index;
  6468. }
  6469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6470. {
  6471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6472. {
  6473. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6474. }
  6475. }
  6476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6477. }
  6478. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6479. {
  6480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6481. {
  6482. tempIndex = ((gun_index==2) ? 1: 0);
  6483. }
  6484. else
  6485. {
  6486. tempIndex = gun_index;
  6487. }
  6488. for (int index = 0; index < CCS_QUANTITY; index++)
  6489. {
  6490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6491. {
  6492. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6493. }
  6494. }
  6495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6496. }
  6497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6498. {
  6499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6500. {
  6501. tempIndex = ((gun_index==2) ? 1: 0);
  6502. }
  6503. else
  6504. {
  6505. tempIndex = gun_index;
  6506. }
  6507. for (int index = 0; index < GB_QUANTITY; index++)
  6508. {
  6509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6510. {
  6511. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6512. }
  6513. }
  6514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6515. }
  6516. else if(gunType[gun_index] == GUN_TYPE_DO)
  6517. {
  6518. tempIndex = gun_index;
  6519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6520. {
  6521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6522. {
  6523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6524. }
  6525. }
  6526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6527. }
  6528. else
  6529. {
  6530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6531. {
  6532. tempIndex = 2;
  6533. }
  6534. else
  6535. {
  6536. tempIndex = gun_index;
  6537. }
  6538. for (int index = 0; index < AC_QUANTITY; index++)
  6539. {
  6540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6541. {
  6542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6543. }
  6544. }
  6545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6546. }
  6547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6552. }
  6553. //***********************************************(6)SOC******************************************************/
  6554. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6555. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6556. (dataType == ReadingContext_Trigger))
  6557. {
  6558. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6559. {
  6560. //idx_sample=5;
  6561. //sampledValue = NULL;
  6562. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6563. {
  6564. tempIndex = ((gun_index==2) ? 1: 0);
  6565. }
  6566. else
  6567. {
  6568. tempIndex = gun_index;
  6569. }
  6570. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6571. {
  6572. //tempIndex = ((gun_index==2) ? 1: 0);
  6573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6574. {
  6575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6576. {
  6577. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6578. }
  6579. }
  6580. }
  6581. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6582. {
  6583. //tempIndex = ((gun_index==2) ? 1: 0);
  6584. for (int index = 0; index < CCS_QUANTITY; index++)
  6585. {
  6586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6587. {
  6588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6589. }
  6590. }
  6591. }
  6592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6593. {
  6594. //tempIndex = ((gun_index==2) ? 1: 0);
  6595. for (int index = 0; index < GB_QUANTITY; index++)
  6596. {
  6597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6598. {
  6599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6600. }
  6601. }
  6602. }
  6603. else if(gunType[gun_index] == GUN_TYPE_DO)
  6604. {
  6605. //tempIndex = ((gun_index==2) ? 1: 0);
  6606. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6607. {
  6608. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6609. {
  6610. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6611. }
  6612. }
  6613. }
  6614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6620. }
  6621. }
  6622. //********************************(7)Current.Import L2************************************************/
  6623. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6624. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6625. (dataType == ReadingContext_Trigger))
  6626. {
  6627. // Only for AC 3 phase
  6628. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6629. {
  6630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6631. {
  6632. tempIndex = 2;
  6633. }
  6634. else
  6635. {
  6636. tempIndex = gun_index;
  6637. }
  6638. for (int index = 0; index < AC_QUANTITY; index++)
  6639. {
  6640. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6641. {
  6642. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6643. }
  6644. }
  6645. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6646. }
  6647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6652. }
  6653. //********************************(8)Current.Import L3************************************************/
  6654. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6655. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6656. (dataType == ReadingContext_Trigger))
  6657. {
  6658. // Only for AC 3 phase
  6659. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6660. {
  6661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6662. {
  6663. tempIndex = 2;
  6664. }
  6665. else
  6666. {
  6667. tempIndex = gun_index;
  6668. }
  6669. for (int index = 0; index < AC_QUANTITY; index++)
  6670. {
  6671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6672. {
  6673. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6674. }
  6675. }
  6676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6677. }
  6678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6683. }
  6684. //***********************************************(9)VOLTAGE L2******************************************************/
  6685. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6686. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6687. (dataType == ReadingContext_Trigger))
  6688. {
  6689. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6690. {
  6691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6692. {
  6693. tempIndex = 2;
  6694. }
  6695. else
  6696. {
  6697. tempIndex = gun_index;
  6698. }
  6699. for (int index = 0; index < AC_QUANTITY; index++)
  6700. {
  6701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6702. {
  6703. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6704. }
  6705. }
  6706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6707. }
  6708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6712. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6713. }
  6714. //***********************************************(10)VOLTAGE L3******************************************************/
  6715. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6716. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6717. (dataType == ReadingContext_Trigger))
  6718. {
  6719. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6720. {
  6721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6722. {
  6723. tempIndex = 2;
  6724. }
  6725. else
  6726. {
  6727. tempIndex = gun_index;
  6728. }
  6729. for (int index = 0; index < AC_QUANTITY; index++)
  6730. {
  6731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6732. {
  6733. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6734. }
  6735. }
  6736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6737. }
  6738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6743. }
  6744. //***********************************************(11)Current.Offered******************************************************/
  6745. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6746. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6747. (dataType == ReadingContext_Trigger))
  6748. {
  6749. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6750. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6751. {
  6752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6753. {
  6754. tempIndex = ((gun_index==2) ? 1: 0);
  6755. }
  6756. else
  6757. {
  6758. tempIndex = gun_index;
  6759. }
  6760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6763. {
  6764. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6765. }
  6766. } // END OF FOR CHAdeMO_QUANTITY
  6767. }
  6768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6769. {
  6770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6771. {
  6772. tempIndex = ((gun_index==2) ? 1: 0);
  6773. }
  6774. else
  6775. {
  6776. tempIndex = gun_index;
  6777. }
  6778. for (int index = 0; index < CCS_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6781. {
  6782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6783. }
  6784. } // END OF CCS_QUANTITY
  6785. }
  6786. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6787. {
  6788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6789. {
  6790. tempIndex = ((gun_index==2) ? 1: 0);
  6791. }
  6792. else
  6793. {
  6794. tempIndex = gun_index;
  6795. }
  6796. for (int index = 0; index < GB_QUANTITY; index++)
  6797. {
  6798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6799. {
  6800. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6801. }
  6802. } // END OF GB_QUANTITY
  6803. }
  6804. else if(gunType[gun_index] == GUN_TYPE_DO)
  6805. {
  6806. tempIndex = gun_index;
  6807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6808. {
  6809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6810. {
  6811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6812. }
  6813. }
  6814. }
  6815. else
  6816. {
  6817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6818. {
  6819. tempIndex = 2;
  6820. }
  6821. else
  6822. {
  6823. tempIndex = gun_index;
  6824. }
  6825. for (int index = 0; index < AC_QUANTITY; index++)
  6826. {
  6827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6828. {
  6829. uint16_t currentOffer;
  6830. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6831. {
  6832. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6833. }
  6834. else
  6835. {
  6836. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6837. }
  6838. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6839. }
  6840. }
  6841. }
  6842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6843. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6847. }
  6848. //***********************************************(12)Power.Offered******************************************************/
  6849. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6850. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6851. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6852. {
  6853. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6854. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6855. {
  6856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6857. {
  6858. tempIndex = ((gun_index==2) ? 1: 0);
  6859. }
  6860. else
  6861. {
  6862. tempIndex = gun_index;
  6863. }
  6864. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6865. {
  6866. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6867. {
  6868. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6869. }
  6870. } // END OF FOR CHAdeMO_QUANTITY
  6871. }
  6872. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6873. {
  6874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6875. {
  6876. tempIndex = ((gun_index==2) ? 1: 0);
  6877. }
  6878. else
  6879. {
  6880. tempIndex = gun_index;
  6881. }
  6882. for (int index = 0; index < CCS_QUANTITY; index++)
  6883. {
  6884. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6885. {
  6886. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6887. }
  6888. } // END OF CCS_QUANTITY
  6889. }
  6890. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6891. {
  6892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6893. {
  6894. tempIndex = ((gun_index==2) ? 1: 0);
  6895. }
  6896. else
  6897. {
  6898. tempIndex = gun_index;
  6899. }
  6900. for (int index = 0; index < GB_QUANTITY; index++)
  6901. {
  6902. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6903. {
  6904. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6905. }
  6906. } // END OF GB_QUANTITY
  6907. }
  6908. else if(gunType[gun_index] == GUN_TYPE_DO)
  6909. {
  6910. tempIndex = gun_index;
  6911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6914. {
  6915. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6916. }
  6917. }
  6918. }
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6924. }
  6925. // Message create ====================================================================================================
  6926. if(TRUE)
  6927. {
  6928. json_object *MeterValueReq = json_object_new_object();
  6929. json_object *MeterValues = json_object_new_array();
  6930. json_object *sampledValues = json_object_new_array();
  6931. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6932. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6933. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6934. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6935. {
  6936. json_object *MeterValue = json_object_new_object();
  6937. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6938. {
  6939. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6940. {
  6941. json_object *sampledValue = json_object_new_object();
  6942. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6943. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6944. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6945. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6946. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6947. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6948. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6949. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6950. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6951. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6952. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6953. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6954. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6955. json_object_array_add(sampledValues, sampledValue);
  6956. }
  6957. }
  6958. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6959. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6960. json_object_array_add(MeterValues, MeterValue);
  6961. }
  6962. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6963. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6964. ,gun_index + 1
  6965. ,MESSAGE_TYPE_CALL
  6966. ,guid
  6967. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6968. json_object_put(MeterValueReq);
  6969. }
  6970. // Put request guid to hash map
  6971. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6972. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  6973. {
  6974. result = PASS;
  6975. //DEBUG_INFO("MeterValues mapitem pass\n");
  6976. }
  6977. if((dataType != ReadingContext_Trigger) &&
  6978. (dataType != ReadingContext_Sample_Clock) &&
  6979. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6980. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6981. else
  6982. {
  6983. if(FirstHeartBeat)
  6984. LWS_Send(queuedata +2);
  6985. }
  6986. return result;
  6987. }
  6988. int sendLogStatusNotificationRequest(char *status)
  6989. {
  6990. mtrace();
  6991. int result = PASS;
  6992. char message[4096]={0};
  6993. char guid[37]={0};
  6994. char tempdata[128]={0};
  6995. json_object *LogStatusNotification = json_object_new_object();
  6996. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6997. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6998. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6999. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7000. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7001. random_uuid(guid);
  7002. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7003. json_object_put(LogStatusNotification);
  7004. LWS_Send(message);
  7005. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7006. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7007. {
  7008. result = PASS;
  7009. }
  7010. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7011. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7012. return result;
  7013. }
  7014. int sendSecurityEventNotificationRequest()
  7015. {
  7016. mtrace();
  7017. int result = PASS;
  7018. char message[4096]={0};
  7019. char guid[37]={0};
  7020. char tempdata[128]={0};
  7021. json_object *SecurityEventNotification = json_object_new_object();
  7022. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7023. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7024. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7025. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7026. random_uuid(guid);
  7027. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7028. json_object_put(SecurityEventNotification);
  7029. LWS_Send(message);
  7030. sprintf(tempdata, "SecurityEventNotification,0");
  7031. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7032. {
  7033. result = PASS;
  7034. }
  7035. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7036. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7037. return result;
  7038. }
  7039. int sendSignCertificateRequest()
  7040. {
  7041. mtrace();
  7042. int result = PASS;
  7043. char message[4096]={0};
  7044. char guid[37]={0};
  7045. char tempdata[128]={0};
  7046. json_object *SignCertificate = json_object_new_object();
  7047. DEBUG_INFO("sendSignCertificateRequest...\n");
  7048. // Read csr file content
  7049. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7050. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7051. char *line = NULL;
  7052. size_t len = 0;
  7053. while(getline(&line, &len, fp) != -1)
  7054. {
  7055. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7056. {
  7057. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7058. }
  7059. }
  7060. fclose(fp);
  7061. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7062. random_uuid(guid);
  7063. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7064. json_object_put(SignCertificate);
  7065. LWS_Send(message);
  7066. sprintf(tempdata, "SignCertificate,0");
  7067. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7068. {
  7069. result = PASS;
  7070. }
  7071. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7072. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7073. return result;
  7074. }
  7075. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7076. {
  7077. mtrace();
  7078. int result = PASS;
  7079. char message[110]={0};
  7080. char guid[37]={0};
  7081. char tempdata[65]={0};
  7082. json_object *FirmwareStatusNotification = json_object_new_object();
  7083. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7084. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7085. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7086. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7087. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7088. random_uuid(guid);
  7089. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7090. json_object_put(FirmwareStatusNotification);
  7091. LWS_Send(message);
  7092. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7093. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7094. {
  7095. result = PASS;
  7096. }
  7097. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7098. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7099. return result;
  7100. }
  7101. //==========================================
  7102. // send confirm routine
  7103. //==========================================
  7104. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7105. {
  7106. mtrace();
  7107. int result = FAIL;
  7108. char message[100]={0};
  7109. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7110. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7111. LWS_Send(message);
  7112. result = TRUE;
  7113. return result;
  7114. }
  7115. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7116. {
  7117. mtrace();
  7118. int result = FAIL;
  7119. char message[100]={0};
  7120. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7121. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7122. LWS_Send(message);
  7123. result = TRUE;
  7124. return result;
  7125. }
  7126. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7127. {
  7128. mtrace();
  7129. int result = FAIL;
  7130. char message[100]={0};
  7131. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7132. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7133. LWS_Send(message);
  7134. result = TRUE;
  7135. return result;
  7136. }
  7137. int sendClearCacheConfirmation(char *uuid,char *payload)
  7138. {
  7139. mtrace();
  7140. int result = FAIL;
  7141. char message[500]={0};
  7142. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7143. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7144. LWS_Send(message);
  7145. return result;
  7146. }
  7147. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7148. {
  7149. mtrace();
  7150. int result = FAIL;
  7151. char message[500]={0};
  7152. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7153. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7154. LWS_Send(message);
  7155. return result;
  7156. }
  7157. int sendDataTransferConfirmation(char *uuid,char *payload)
  7158. {
  7159. mtrace();
  7160. char statusStr[20]={0};
  7161. char dataStr[10]={0};
  7162. char sstr[20]={0};
  7163. int c = 0;
  7164. char *loc;
  7165. int result = FAIL;
  7166. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7167. /**********************status**************************/
  7168. loc = strstr(payload, "status");
  7169. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7170. c = 0;
  7171. while (loc[3+strlen("status")+c] != '\"')
  7172. {
  7173. sstr[c] = loc[3+strlen("status")+c];
  7174. c++;
  7175. }
  7176. sstr[c] = '\0';
  7177. strcpy(statusStr, sstr);
  7178. /**********************data**************************/
  7179. loc = strstr(payload, "data");
  7180. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7181. c = 0;
  7182. while (loc[3+strlen("data")+c] != '\"')
  7183. {
  7184. sstr[c] = loc[3+strlen("data")+c];
  7185. c++;
  7186. }
  7187. sstr[c] = '\0';
  7188. strcpy(dataStr, sstr);
  7189. return result;
  7190. }
  7191. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7192. {
  7193. mtrace();
  7194. int result = FAIL;
  7195. char message[1000]={0};
  7196. int CompositeScheduleIndex = 0;
  7197. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7198. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7199. if(nPeriod == 0)
  7200. {
  7201. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7202. {
  7203. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7204. ,MESSAGE_TYPE_CALLRESULT
  7205. ,uuid
  7206. ,payload
  7207. ,connectorIdInt);
  7208. }
  7209. else
  7210. {
  7211. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7212. ,MESSAGE_TYPE_CALLRESULT
  7213. ,uuid
  7214. ,payload
  7215. ,connectorIdInt
  7216. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7217. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7218. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7219. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7220. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7221. }
  7222. }
  7223. else
  7224. {
  7225. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7226. ,MESSAGE_TYPE_CALLRESULT
  7227. ,uuid
  7228. ,payload
  7229. ,connectorIdInt
  7230. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7231. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7232. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7233. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7234. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7235. {
  7236. if (idx_sample == 0)
  7237. {
  7238. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7239. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7240. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7241. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7242. }
  7243. else
  7244. {
  7245. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7246. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7247. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7248. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7249. }
  7250. }
  7251. sprintf(message + strlen(message), "]}}]");
  7252. }
  7253. LWS_Send(message);
  7254. result = TRUE;
  7255. return result;
  7256. }
  7257. int sendGetConfigurationConfirmation(char *uuid)
  7258. {
  7259. mtrace();
  7260. int result = FAIL;
  7261. int MaxKeySupported = 0;
  7262. int sentConfigurationNumber= 0;
  7263. int sentunConfigurationNumber= 0;
  7264. char message[1024*10]={0};
  7265. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7266. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7267. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7268. ,MESSAGE_TYPE_CALLRESULT
  7269. ,uuid );
  7270. //configuration key
  7271. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7272. {
  7273. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7274. {
  7275. if (sentConfigurationNumber == 0)
  7276. {
  7277. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7278. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7279. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7280. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7281. }
  7282. else
  7283. {
  7284. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7285. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7286. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7287. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7288. }
  7289. sentConfigurationNumber = sentConfigurationNumber + 1;
  7290. }
  7291. }
  7292. sprintf(message + strlen(message), "]");
  7293. if(UnknownKeynum != 0)
  7294. {
  7295. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7296. //unkown key
  7297. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7298. {
  7299. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7300. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7301. if(sentunConfigurationNumber == 0)
  7302. {
  7303. sprintf(message + strlen(message), "\"%s\""
  7304. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7305. }
  7306. else
  7307. {
  7308. sprintf(message + strlen(message), ",\"%s\""
  7309. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7310. }
  7311. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7312. }
  7313. sprintf(message + strlen(message), "]");
  7314. }
  7315. sprintf(message + strlen(message), "}]");
  7316. LWS_Send(message);
  7317. return result;
  7318. }
  7319. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7320. {
  7321. mtrace();
  7322. int result = FAIL;
  7323. char message[400]={0};
  7324. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7325. if(strcmp(payload,"")==0)
  7326. {
  7327. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7328. }
  7329. else
  7330. {
  7331. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7332. }
  7333. LWS_Send(message);
  7334. result = TRUE;
  7335. return result;
  7336. }
  7337. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7338. {
  7339. mtrace();
  7340. int result = FAIL;
  7341. char message[80]={0};
  7342. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7343. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7344. LWS_Send(message);
  7345. result = TRUE;
  7346. return result;
  7347. }
  7348. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7349. {
  7350. mtrace();
  7351. int result = FAIL;
  7352. char message[80]={0};
  7353. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7354. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7355. LWS_Send(message);
  7356. result = TRUE;
  7357. return result;
  7358. }
  7359. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7360. {
  7361. mtrace();
  7362. int result = FAIL;
  7363. char message[80]={0};
  7364. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7365. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7366. LWS_Send(message);
  7367. result = TRUE;
  7368. return result;
  7369. }
  7370. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7371. {
  7372. mtrace();
  7373. int result = FAIL;
  7374. char message[80]={0};
  7375. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7376. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7377. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7378. LWS_Send(message);
  7379. result = TRUE;
  7380. return result;
  7381. }
  7382. int sendResetConfirmation(char *uuid,char *payload)
  7383. {
  7384. mtrace();
  7385. int result = FAIL;
  7386. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7387. char message[80]={0};
  7388. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7389. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7390. LWS_Send(message);
  7391. result = TRUE;
  7392. return result;
  7393. }
  7394. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7395. {
  7396. mtrace();
  7397. int result = FAIL;
  7398. char message[500]={0};
  7399. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7400. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7401. LWS_Send(message);
  7402. result = TRUE;
  7403. return result;
  7404. }
  7405. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7406. {
  7407. mtrace();
  7408. int result = FAIL;
  7409. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7410. char message[80]={0};
  7411. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7412. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7413. LWS_Send(message);
  7414. result = TRUE;
  7415. return result;
  7416. }
  7417. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7418. {
  7419. mtrace();
  7420. int result = FAIL;
  7421. char message[80]={0};
  7422. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7423. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7424. LWS_Send(message);
  7425. result = TRUE;
  7426. return result;
  7427. }
  7428. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7429. {
  7430. mtrace();
  7431. int result = FAIL;
  7432. char message[80]={0};
  7433. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7434. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7435. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7436. LWS_Send(message);
  7437. result = TRUE;
  7438. return result;
  7439. }
  7440. int sendUpdateFirmwareConfirmation(char *uuid)
  7441. {
  7442. mtrace();
  7443. int result = FAIL;
  7444. char message[60]={0};
  7445. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7446. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7447. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7448. LWS_Send(message);
  7449. result = TRUE;
  7450. return result;
  7451. }
  7452. int sendCertificateSignedConfirmation(char *uuid)
  7453. {
  7454. mtrace();
  7455. int result = PASS;
  7456. char message[4096]={0};
  7457. json_object *CertificateSigned = json_object_new_object();
  7458. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7459. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7460. sprintf(message,"[%d,\"%s\",%s]"
  7461. ,MESSAGE_TYPE_CALLRESULT
  7462. ,uuid
  7463. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7464. json_object_put(CertificateSigned);
  7465. LWS_Send(message);
  7466. return result;
  7467. }
  7468. int sendDeleteCertificateConfirmation(char *uuid)
  7469. {
  7470. mtrace();
  7471. int result = PASS;
  7472. char message[4096]={0};
  7473. json_object *DeleteCertificate = json_object_new_object();
  7474. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7475. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7476. sprintf(message,"[%d,\"%s\",%s]"
  7477. ,MESSAGE_TYPE_CALLRESULT
  7478. ,uuid
  7479. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7480. json_object_put(DeleteCertificate);
  7481. LWS_Send(message);
  7482. return result;
  7483. }
  7484. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7485. {
  7486. mtrace();
  7487. int result = PASS;
  7488. char message[4096]={0};
  7489. json_object *ExtendedTriggerMessage = json_object_new_object();
  7490. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7491. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7492. sprintf(message,"[%d,\"%s\",%s]"
  7493. ,MESSAGE_TYPE_CALLRESULT
  7494. ,uuid
  7495. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7496. json_object_put(ExtendedTriggerMessage);
  7497. LWS_Send(message);
  7498. return result;
  7499. }
  7500. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7501. {
  7502. mtrace();
  7503. int result = PASS;
  7504. char message[4096]={0};
  7505. json_object *GetInstalledCertificateIds = json_object_new_object();
  7506. json_object *certificateHashDataDatas = json_object_new_array();
  7507. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7508. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7509. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7510. {
  7511. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7512. {
  7513. json_object *certificateHashData = json_object_new_object();
  7514. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7515. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7516. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7517. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7518. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7519. }
  7520. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7521. }
  7522. else
  7523. {
  7524. json_object_put(certificateHashDataDatas);
  7525. }
  7526. sprintf(message,"[%d,\"%s\",%s]"
  7527. ,MESSAGE_TYPE_CALLRESULT
  7528. ,uuid
  7529. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7530. json_object_put(GetInstalledCertificateIds);
  7531. LWS_Send(message);
  7532. return result;
  7533. }
  7534. int sendGetLogConfirmation(char *uuid)
  7535. {
  7536. mtrace();
  7537. int result = PASS;
  7538. char message[4096]={0};
  7539. json_object *GetLog = json_object_new_object();
  7540. DEBUG_INFO("sendGetLogConfirmation...\n");
  7541. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7542. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7543. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7544. sprintf(message,"[%d,\"%s\",%s]"
  7545. ,MESSAGE_TYPE_CALLRESULT
  7546. ,uuid
  7547. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7548. json_object_put(GetLog);
  7549. LWS_Send(message);
  7550. return result;
  7551. }
  7552. int sendInstallCertificateConfirmation(char *uuid)
  7553. {
  7554. mtrace();
  7555. int result = PASS;
  7556. char message[4096]={0};
  7557. json_object *InstallCertificate = json_object_new_object();
  7558. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7559. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7560. sprintf(message,"[%d,\"%s\",%s]"
  7561. ,MESSAGE_TYPE_CALLRESULT
  7562. ,uuid
  7563. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7564. json_object_put(InstallCertificate);
  7565. LWS_Send(message);
  7566. return result;
  7567. }
  7568. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7569. {
  7570. mtrace();
  7571. int result = PASS;
  7572. char message[4096]={0};
  7573. json_object *SignedUpdateFirmware = json_object_new_object();
  7574. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7575. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7576. sprintf(message,"[%d,\"%s\",%s]"
  7577. ,MESSAGE_TYPE_CALLRESULT
  7578. ,uuid
  7579. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7580. json_object_put(SignedUpdateFirmware);
  7581. LWS_Send(message);
  7582. return result;
  7583. }
  7584. int sendUnknownConfirmation(char *uuid)
  7585. {
  7586. mtrace();
  7587. int result = PASS;
  7588. char message[256]={0};
  7589. DEBUG_INFO("sendUnknownConfirmation...\n");
  7590. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7591. LWS_Send(message);
  7592. return result;
  7593. }
  7594. //==========================================
  7595. // Handle server request routine Start
  7596. //==========================================
  7597. int handleCancelReservationRequest(char *uuid, char *payload)
  7598. {
  7599. mtrace();
  7600. int result = FAIL;
  7601. int gunNO = 0;
  7602. int reservationIdInt = -1;
  7603. char comfirmstr[20];
  7604. DEBUG_INFO("handleCancelReservationRequest...\n");
  7605. json_object *CancelReservation;
  7606. CancelReservation = json_tokener_parse(payload);
  7607. if(!is_error(CancelReservation))
  7608. {
  7609. // Required data
  7610. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7611. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7612. }
  7613. json_object_put(CancelReservation);
  7614. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7615. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7616. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7617. if(reservationIdInt != -1)
  7618. {
  7619. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7620. //check Transaction active
  7621. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7623. {
  7624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7625. {
  7626. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7627. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7628. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7629. {
  7630. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7631. }
  7632. else
  7633. {
  7634. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7635. }
  7636. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7637. goto end;
  7638. }
  7639. }
  7640. for (int index = 0; index < CCS_QUANTITY; index++)
  7641. {
  7642. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7643. {
  7644. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7645. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7646. if(gunType[2] == GUN_TYPE_CCS)
  7647. {
  7648. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7649. }
  7650. else
  7651. {
  7652. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7653. }
  7654. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7655. goto end;
  7656. }
  7657. }
  7658. for (int index = 0; index < GB_QUANTITY; index++)
  7659. {
  7660. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7661. {
  7662. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7663. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7664. if(gunType[2] == GUN_TYPE_GBT)
  7665. {
  7666. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7667. }
  7668. else
  7669. {
  7670. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7671. }
  7672. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7673. goto end;
  7674. }
  7675. }
  7676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7677. {
  7678. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7679. {
  7680. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7681. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7682. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7683. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7684. goto end;
  7685. }
  7686. }
  7687. for (int index = 0; index < AC_QUANTITY; index++)
  7688. {
  7689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7690. {
  7691. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7692. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7693. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7694. {
  7695. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7696. }
  7697. else
  7698. {
  7699. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7700. }
  7701. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7702. goto end;
  7703. }
  7704. }
  7705. }
  7706. //The reservationId does NOT match the reservationId
  7707. sendCancelReservationConfirmation(uuid, comfirmstr);
  7708. end:
  7709. // Fill in ocpp packet uuid
  7710. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7711. return result;
  7712. }
  7713. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7714. {
  7715. mtrace();
  7716. int result = FAIL;
  7717. int gunIndex = -1;
  7718. char typeStr[16]={0};
  7719. char comfirmstr[20];
  7720. int specificId = FALSE;
  7721. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7722. json_object *ChangeAvailability;
  7723. ChangeAvailability = json_tokener_parse(payload);
  7724. if(!is_error(ChangeAvailability))
  7725. {
  7726. // Required data
  7727. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7728. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7729. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7730. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7731. }
  7732. json_object_put(ChangeAvailability);
  7733. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7734. {
  7735. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7736. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7737. }
  7738. else if(gunIndex == 0)
  7739. {
  7740. for(int i=0; i < gunTotalNumber; i++)
  7741. {
  7742. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7743. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7744. }
  7745. }
  7746. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7748. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7749. {
  7750. specificId = TRUE;
  7751. }
  7752. if(specificId == FALSE)
  7753. goto end;
  7754. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7755. {
  7756. //----------------------gunIndex is 0 ------------------------------------------------//
  7757. if(gunIndex == 0)
  7758. {
  7759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7760. {
  7761. for(int i=0; i < gunTotalNumber; i++)
  7762. {
  7763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7764. {
  7765. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7766. {
  7767. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7768. {
  7769. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7770. goto end;
  7771. }
  7772. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7773. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7774. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7775. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7776. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7777. {
  7778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7779. goto end;
  7780. }
  7781. }
  7782. }//END FOR CHAdeMO_QUANTITY
  7783. for (int index = 0; index < CCS_QUANTITY; index++)
  7784. {
  7785. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7786. {
  7787. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7788. {
  7789. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7790. goto end;
  7791. }
  7792. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7793. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7794. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7795. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7796. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7797. {
  7798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7799. goto end;
  7800. }
  7801. }
  7802. }//END FOR CCS_QUANTITY
  7803. for (int index = 0; index < GB_QUANTITY; index++)
  7804. {
  7805. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7806. {
  7807. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7808. {
  7809. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7810. goto end;
  7811. }
  7812. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7813. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7814. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7815. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7816. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7817. {
  7818. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7819. goto end;
  7820. }
  7821. }
  7822. }// END FOR GB_QUANTITY
  7823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7824. {
  7825. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7826. {
  7827. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7828. {
  7829. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7830. goto end;
  7831. }
  7832. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7833. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7834. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7837. {
  7838. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7839. goto end;
  7840. }
  7841. }
  7842. }// END FOR GENERAL_GUN_QUANTITY
  7843. for (int index = 0; index < AC_QUANTITY; index++)
  7844. {
  7845. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7846. {
  7847. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7848. {
  7849. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7850. goto end;
  7851. }
  7852. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7853. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7854. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7855. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7856. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7857. {
  7858. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7859. goto end;
  7860. }
  7861. }
  7862. }//END FOR AC_QUANTITY
  7863. }// END FOR gunTotalNumber
  7864. }
  7865. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7866. {
  7867. for(int i=0; i < gunTotalNumber; i++)
  7868. {
  7869. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7870. {
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7872. goto end;
  7873. }
  7874. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7875. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7876. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7877. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7878. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7879. {
  7880. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7881. goto end;
  7882. }
  7883. }
  7884. }
  7885. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7886. goto end;
  7887. }
  7888. //----------------------gunIndex is not 0 ------------------------------------------------//
  7889. //check Transaction active
  7890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7891. {
  7892. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7893. {
  7894. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7895. {
  7896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7897. goto end;
  7898. }
  7899. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7900. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7901. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7902. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7903. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7904. {
  7905. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7906. goto end;
  7907. }
  7908. else
  7909. {
  7910. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7911. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7912. goto end;
  7913. }
  7914. }
  7915. }//END FOR CHAdeMO_QUANTITY
  7916. for (int index = 0; index < CCS_QUANTITY; index++)
  7917. {
  7918. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7919. {
  7920. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7921. {
  7922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7923. goto end;
  7924. }
  7925. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7926. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7927. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7928. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7929. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7930. {
  7931. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7932. goto end;
  7933. }
  7934. else
  7935. {
  7936. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7937. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7938. goto end;
  7939. }
  7940. }
  7941. }//END FOR CCS_QUANTITY
  7942. for (int index = 0; index < GB_QUANTITY; index++)
  7943. {
  7944. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7945. {
  7946. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7947. {
  7948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7949. goto end;
  7950. }
  7951. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7952. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7953. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7954. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7955. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7956. {
  7957. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7958. goto end;
  7959. }
  7960. else
  7961. {
  7962. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7963. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7964. goto end;
  7965. }
  7966. }
  7967. }// END FOR GB_QUANTITY
  7968. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7969. {
  7970. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7971. {
  7972. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7973. {
  7974. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7975. goto end;
  7976. }
  7977. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7978. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7979. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7980. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7981. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7982. {
  7983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7984. goto end;
  7985. }
  7986. else
  7987. {
  7988. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7989. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7990. goto end;
  7991. }
  7992. }
  7993. }// END FOR GENERAL_GUN_QUANTITY
  7994. for (int index = 0; index < AC_QUANTITY; index++)
  7995. {
  7996. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7997. {
  7998. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7999. {
  8000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8001. goto end;
  8002. }
  8003. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8004. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8005. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8006. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8007. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8008. {
  8009. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8010. goto end;
  8011. }
  8012. else
  8013. {
  8014. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8016. goto end;
  8017. }
  8018. }
  8019. }//END FOR AC_QUANTITY
  8020. }//END FOR AvailabilityTypeStr[Inoperative]
  8021. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8022. {
  8023. //----------------------gunIndex is 0 ------------------------------------------------//
  8024. if(gunIndex == 0)
  8025. {
  8026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8027. {
  8028. for(int i=0; i < gunTotalNumber; i++)
  8029. {
  8030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8031. {
  8032. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8033. {
  8034. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8035. goto end;
  8036. }
  8037. }//END FOR CHAdeMO_QUANTITY
  8038. for (int index = 0; index < CCS_QUANTITY; index++)
  8039. {
  8040. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8041. {
  8042. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8043. goto end;
  8044. }
  8045. }//END FOR CCS_QUANTITY
  8046. for (int index = 0; index < GB_QUANTITY; index++)
  8047. {
  8048. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8049. {
  8050. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8051. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8052. goto end;
  8053. }
  8054. }// END FOR GB_QUANTITY
  8055. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8056. {
  8057. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8058. {
  8059. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8060. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8061. goto end;
  8062. }
  8063. }// END FOR GENERAL_GUN_QUANTITY
  8064. for (int index = 0; index < AC_QUANTITY; index++)
  8065. {
  8066. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8067. {
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8069. goto end;
  8070. }
  8071. }//END FOR CHAdeMO_QUANTITY
  8072. }// END FOR gunTotalNumber
  8073. }
  8074. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8075. {
  8076. for(int i=0; i < gunTotalNumber; i++)
  8077. {
  8078. for (int index = 0; index < AC_QUANTITY; index++)
  8079. {
  8080. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8081. {
  8082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8083. goto end;
  8084. }
  8085. }//END FOR CHAdeMO_QUANTITY
  8086. } // END FOR gunTotalNumber
  8087. }
  8088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8089. goto end;
  8090. }
  8091. //----------------------gunIndex is not 0 ------------------------------------------------//
  8092. //check Transaction active
  8093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8094. {
  8095. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8096. {
  8097. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8098. goto end;
  8099. }
  8100. }//END FOR CHAdeMO_QUANTITY
  8101. for (int index = 0; index < CCS_QUANTITY; index++)
  8102. {
  8103. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8104. {
  8105. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8106. goto end;
  8107. }
  8108. }//END FOR CCS_QUANTITY
  8109. for (int index = 0; index < GB_QUANTITY; index++)
  8110. {
  8111. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8112. {
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8114. goto end;
  8115. }
  8116. }// END FOR GB_QUANTITY
  8117. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8118. {
  8119. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8120. {
  8121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8122. goto end;
  8123. }
  8124. }// END FOR GENERAL_GUN_QUANTITY
  8125. for (int index = 0; index < AC_QUANTITY; index++)
  8126. {
  8127. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8128. {
  8129. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8130. goto end;
  8131. }
  8132. }//END FOR AC_QUANTITY
  8133. }//END FOR AvailabilityTypeStr[Operative]
  8134. end:
  8135. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8136. {
  8137. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8138. }
  8139. else
  8140. {
  8141. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8142. }
  8143. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8144. {
  8145. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8146. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8147. }
  8148. else if(gunIndex == 0)
  8149. {
  8150. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8151. {
  8152. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8153. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8154. }
  8155. }
  8156. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8157. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8158. return result;
  8159. }
  8160. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8161. {
  8162. mtrace();
  8163. int result = FAIL;
  8164. char keystr[40]={0};
  8165. char valuestr[256]={0};
  8166. char comfirmstr[20]={0};
  8167. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8168. json_object *ChangeConfiguration;
  8169. ChangeConfiguration = json_tokener_parse(payload);
  8170. if(!is_error(ChangeConfiguration))
  8171. {
  8172. // Required data
  8173. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8174. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8175. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  8176. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8177. }
  8178. json_object_put(ChangeConfiguration);
  8179. if((uuid==NULL) || (payload ==NULL) )
  8180. {
  8181. DEBUG_ERROR("Payload is null\n");
  8182. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8183. }
  8184. else
  8185. {
  8186. int status = setKeyValue(keystr, valuestr);
  8187. switch(status)
  8188. {
  8189. case ConfigurationStatus_Accepted:
  8190. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8191. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8192. StoreConfigurationTable();
  8193. break;
  8194. case RebootRequired:
  8195. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8196. StoreConfigurationTable();
  8197. break;
  8198. case NotSupported:
  8199. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8200. break;
  8201. case ConfigurationStatus_Rejected:
  8202. default:
  8203. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8204. break;
  8205. }
  8206. }
  8207. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8208. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8209. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  8210. {
  8211. ChageWebSocketPingInterval(atoi(valuestr));
  8212. }
  8213. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8214. {
  8215. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8216. SetOcppConnStatus(FALSE);
  8217. }
  8218. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8219. {
  8220. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8221. }
  8222. return result;
  8223. }
  8224. int handleClearCacheRequest(char *uuid, char *payload)
  8225. {
  8226. mtrace();
  8227. int result = FAIL;
  8228. char comfirmstr[20];
  8229. char rmFileCmd[100]={0};
  8230. struct stat stats;
  8231. DEBUG_INFO("handleClearCacheRequest...\n");
  8232. stat("/Storage/OCPP", &stats);
  8233. // Check for directory existence
  8234. if (S_ISDIR(stats.st_mode) == 1)
  8235. {}
  8236. else
  8237. {
  8238. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8239. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8240. system(rmFileCmd);
  8241. }
  8242. if(OCPP_cleanLocalCache())
  8243. {
  8244. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8245. }
  8246. else
  8247. {
  8248. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8249. }
  8250. sendClearCacheConfirmation(uuid, comfirmstr);
  8251. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8252. return result;
  8253. }
  8254. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8255. {
  8256. mtrace();
  8257. int result = FAIL;
  8258. int resultRename;
  8259. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8260. char chargingProfilePurposeStr[26]={0};
  8261. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8262. char tempchargingProfilePurposeStr[26]={0};
  8263. char str[100]={0};
  8264. char fname[200]={0};
  8265. char comfirmstr[20]={0};
  8266. char word[1600]={0};
  8267. int clearflag = FALSE;
  8268. int chargingProfileIdIsNULL = FALSE;
  8269. int connectorIsNULL = FALSE;
  8270. int chargingProfilePurposeIsNULL = FALSE;
  8271. int stackLevelIsNULL = FALSE;
  8272. //int GotoEnd = FALSE;
  8273. FILE *fptr1, *fptr2;
  8274. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8275. int n_chargingProfile=0;
  8276. int isEmptyFile = FALSE;
  8277. char sLineWord[1600]={0};
  8278. char chargingProfiles[10][100]={0};
  8279. int ChargeProfileCount = 0;
  8280. int ch;
  8281. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8282. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8283. json_object *ClearChargingProfile;
  8284. ClearChargingProfile = json_tokener_parse(payload);
  8285. if(!is_error(ClearChargingProfile))
  8286. {
  8287. // Optional data
  8288. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8289. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8290. else
  8291. chargingProfileIdIsNULL = TRUE;
  8292. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8293. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8294. else
  8295. connectorIsNULL = TRUE;
  8296. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8297. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8298. else
  8299. chargingProfilePurposeIsNULL = TRUE;
  8300. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8301. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8302. else
  8303. stackLevelIsNULL = TRUE;
  8304. }
  8305. json_object_put(ClearChargingProfile);
  8306. if(connectorIsNULL == FALSE)
  8307. {
  8308. switch(connectorIdInt)
  8309. {
  8310. case 0:
  8311. if(chargingProfilePurposeIsNULL == TRUE)
  8312. {
  8313. int l = 0;
  8314. strcpy(fname, ChargePointMaxProfile_JSON);
  8315. if((access(fname,F_OK))!=-1)
  8316. {
  8317. strcpy(chargingProfiles[l], fname);
  8318. l = l + 1;
  8319. }
  8320. strcpy(fname, TxDefaultProfile_0_JSON);
  8321. if((access(fname,F_OK))!=-1)
  8322. {
  8323. strcpy(chargingProfiles[l], fname);
  8324. l = l + 1;
  8325. }
  8326. ChargeProfileCount = l;
  8327. }
  8328. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8329. {
  8330. strcpy(fname, ChargePointMaxProfile_JSON);
  8331. if((access(fname,F_OK))!=-1)
  8332. {
  8333. strcpy(chargingProfiles[0], fname);
  8334. ChargeProfileCount = 1;
  8335. }
  8336. }
  8337. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8338. {
  8339. strcpy(fname, TxDefaultProfile_0_JSON);
  8340. if((access(fname,F_OK))!=-1)
  8341. {
  8342. strcpy(chargingProfiles[0], fname);
  8343. ChargeProfileCount = 1;
  8344. }
  8345. }
  8346. break;
  8347. default:
  8348. if(chargingProfilePurposeIsNULL == TRUE)
  8349. {
  8350. int m = 0;
  8351. memset(fname, 0, ARRAY_SIZE(fname));
  8352. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8353. if((access(fname,F_OK))!=-1)
  8354. {
  8355. strcpy(chargingProfiles[m], fname);
  8356. m = m + 1;
  8357. }
  8358. memset(fname, 0, ARRAY_SIZE(fname));
  8359. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8360. if((access(fname,F_OK))!=-1)
  8361. {
  8362. strcpy(chargingProfiles[m], fname);
  8363. m = m + 1;
  8364. }
  8365. ChargeProfileCount = m;
  8366. }
  8367. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8368. {
  8369. //strcpy(fname, TxDefaultProfile_1_JSON);
  8370. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8371. if((access(fname,F_OK))!=-1)
  8372. {
  8373. strcpy(chargingProfiles[0], fname);
  8374. ChargeProfileCount = 1;
  8375. }
  8376. }
  8377. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8378. {
  8379. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8380. if((access(fname,F_OK))!=-1)
  8381. {
  8382. strcpy(chargingProfiles[0], fname);
  8383. ChargeProfileCount = 1;
  8384. }
  8385. //strcpy(fname, TxProfile_1_JSON);
  8386. }
  8387. //strcpy(fname, ChargePointMaxProfile_JSON );
  8388. break;
  8389. }
  8390. }
  8391. else // Check all Charging Profiles
  8392. {
  8393. int i = 0;
  8394. char fnametemp[200]={0};
  8395. ChargeProfileCount = 0;
  8396. //Check ChargePointMaxProfile.json exit
  8397. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8398. {
  8399. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8400. i = i + 1;
  8401. }
  8402. //Check TxDefaultProfile_0.json exit
  8403. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8404. {
  8405. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8406. i = i + 1;
  8407. }
  8408. //Check TxDefaultProfile_%d.json
  8409. for(int j=1; j <= gunTotalNumber; j++)
  8410. {
  8411. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8412. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8413. if((access(fnametemp,F_OK))!=-1)
  8414. {
  8415. strcpy(chargingProfiles[i], fnametemp);
  8416. i = i + 1;
  8417. }
  8418. }
  8419. //Check TxProfile_%d.json
  8420. for(int j=1; j <= gunTotalNumber; j++)
  8421. {
  8422. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8423. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8424. if((access(fnametemp,F_OK))!=-1)
  8425. {
  8426. strcpy(chargingProfiles[i], fnametemp);
  8427. i = i + 1;
  8428. }
  8429. }
  8430. ChargeProfileCount = i;
  8431. }// End connectorIsNULL is TRUE
  8432. if(ChargeProfileCount == 0)
  8433. {
  8434. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8435. goto end;
  8436. }
  8437. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8438. {
  8439. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8440. goto end;
  8441. }
  8442. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8443. {
  8444. memset(str, 0, ARRAY_SIZE(str));
  8445. // clear temp file
  8446. sprintf(str,"rm -f %s",temp);
  8447. system(str);
  8448. for(int k=0; k < ChargeProfileCount; k++)
  8449. {
  8450. memset(str, 0, ARRAY_SIZE(str));
  8451. //clear file in C
  8452. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8453. system(str);
  8454. }
  8455. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8456. goto end;
  8457. }
  8458. else if(connectorIsNULL == TRUE)
  8459. {
  8460. for(int k=0; k < ChargeProfileCount; k++)
  8461. {
  8462. fptr1 = fopen(chargingProfiles[k], "r");
  8463. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8464. //Check Charging Profile Count
  8465. while(fscanf(fptr1, "%s", word) != EOF)
  8466. {
  8467. //DEBUG_INFO("word=%s\n",word);
  8468. if(strstr(word, "chargingProfileId")!= NULL)
  8469. {
  8470. //DEBUG_INFO("test chargingProfileId \n");
  8471. n_chargingProfile = n_chargingProfile + 1;
  8472. //DEBUG_INFO("chargingProfileId Found\n");
  8473. }
  8474. }
  8475. rewind(fptr1);
  8476. //search Charging Profile Element
  8477. //int i= 0;
  8478. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8479. {
  8480. json_object *tmpProfilee;
  8481. tmpProfilee = json_tokener_parse(sLineWord);
  8482. if(!is_error(tmpProfilee))
  8483. {
  8484. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8485. {
  8486. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8487. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8488. }
  8489. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8490. {
  8491. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8492. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8493. }
  8494. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8495. {
  8496. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8497. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8498. }
  8499. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8500. {
  8501. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8502. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8503. }
  8504. }
  8505. json_object_put(tmpProfilee);
  8506. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8507. {
  8508. //------- not write to fptr2-------//
  8509. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8510. //clearflag = TRUE;
  8511. }
  8512. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8513. {
  8514. //------- not write to fptr2-------//
  8515. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8516. }
  8517. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8518. {
  8519. //------- not write to fptr2-------//
  8520. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8521. }
  8522. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8523. {
  8524. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8525. }
  8526. else
  8527. {
  8528. fprintf(fptr2, sLineWord);//writing data into file
  8529. }
  8530. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8531. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8532. if(clearflag == TRUE)
  8533. {
  8534. fclose(fptr1);
  8535. fclose(fptr2);
  8536. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8537. system(str);
  8538. // clear temp file
  8539. sprintf(str,"rm -f %s",temp);
  8540. system(str);
  8541. }
  8542. else
  8543. {
  8544. fclose(fptr1);
  8545. fclose(fptr2);
  8546. memset(str, 0, ARRAY_SIZE(str));
  8547. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8548. system(str);
  8549. resultRename = rename(temp, chargingProfiles[k]);
  8550. if(resultRename == 0)
  8551. {
  8552. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8553. }
  8554. else
  8555. {
  8556. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8557. }
  8558. if(comfirmstr[0]== 0)
  8559. {
  8560. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8561. }
  8562. //Check chargingProfile is empty file
  8563. /*------ Read the file ----------------*/
  8564. fptr1=fopen(chargingProfiles[k],"r");
  8565. ch=fgetc(fptr1);
  8566. rewind(fptr1);
  8567. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8568. if(ch!=EOF)
  8569. {
  8570. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8571. {
  8572. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8573. if(sLineWord[0]=='\0')
  8574. {
  8575. isEmptyFile = TRUE;
  8576. break;
  8577. }
  8578. else
  8579. {
  8580. isEmptyFile = FALSE;
  8581. break;
  8582. }
  8583. }
  8584. }
  8585. else
  8586. isEmptyFile = TRUE;
  8587. fclose(fptr1);
  8588. if(isEmptyFile == TRUE)
  8589. {
  8590. memset(str, 0, ARRAY_SIZE(str));
  8591. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8592. system(str);
  8593. }
  8594. }
  8595. }// End of while(int k=0; k < ChargePointCount; k++)
  8596. }
  8597. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8598. {
  8599. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8600. for(int k=0; k < ChargeProfileCount; k++)
  8601. {
  8602. fptr1 = fopen(chargingProfiles[k], "r");
  8603. fptr2 = fopen(temp, "w+");
  8604. //Check Charging Profile Count
  8605. while(fscanf(fptr1, "%s", word) != EOF)
  8606. {
  8607. //DEBUG_INFO("word=%s\n",word);
  8608. if(strstr(word, "chargingProfileId")!= NULL)
  8609. {
  8610. n_chargingProfile = n_chargingProfile + 1;
  8611. }
  8612. }
  8613. rewind(fptr1);
  8614. //search Charging Profile Element
  8615. //int i= 0;
  8616. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8617. {
  8618. json_object *tmpProfilee;
  8619. tmpProfilee = json_tokener_parse(sLineWord);
  8620. if(!is_error(tmpProfilee))
  8621. {
  8622. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8623. {
  8624. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8625. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8626. }
  8627. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8628. {
  8629. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8630. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8631. }
  8632. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8633. {
  8634. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8635. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8636. }
  8637. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8638. {
  8639. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8640. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8641. }
  8642. }
  8643. json_object_put(tmpProfilee);
  8644. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8645. {
  8646. //------- not write to fptr2-------//
  8647. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8648. //clearflag = TRUE;
  8649. }
  8650. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8651. {
  8652. //------- not write to fptr2-------//
  8653. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8654. }
  8655. else if(stackLevelIsNULL == TRUE)
  8656. {
  8657. //Clear Whole File
  8658. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8659. clearflag = TRUE;
  8660. break;
  8661. }
  8662. else
  8663. {
  8664. fprintf(fptr2, sLineWord);//writing data into file
  8665. }
  8666. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8667. }
  8668. if(clearflag == TRUE)
  8669. {
  8670. fclose(fptr1);
  8671. fclose(fptr2);
  8672. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8673. system(str);
  8674. // clear temp file
  8675. sprintf(str,"rm -f %s",temp);
  8676. system(str);
  8677. }
  8678. else
  8679. {
  8680. fclose(fptr1);
  8681. fclose(fptr2);
  8682. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8683. system(str);
  8684. resultRename = rename(temp, chargingProfiles[k]);
  8685. if(resultRename == 0)
  8686. {
  8687. DEBUG_INFO("File ChargingProfile renamed successfully");
  8688. }
  8689. else
  8690. {
  8691. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8692. }
  8693. if(comfirmstr[0]== 0)
  8694. {
  8695. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8696. }
  8697. //Check chargingProfile is empty file
  8698. /*------ Read the file ----------------*/
  8699. fptr1=fopen(chargingProfiles[k],"r");
  8700. ch=fgetc(fptr1);
  8701. rewind(fptr1);
  8702. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8703. if(ch!=EOF)
  8704. {
  8705. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8706. {
  8707. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8708. if(sLineWord[0]=='\0')
  8709. {
  8710. isEmptyFile = TRUE;
  8711. break;
  8712. }
  8713. else
  8714. {
  8715. isEmptyFile = FALSE;
  8716. break;
  8717. }
  8718. }
  8719. }
  8720. else
  8721. isEmptyFile = TRUE;
  8722. fclose(fptr1);
  8723. if(isEmptyFile == TRUE)
  8724. {
  8725. memset(str, 0, ARRAY_SIZE(str));
  8726. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8727. system(str);
  8728. }
  8729. /*------- End of reading ---------------*/
  8730. }
  8731. } // while(int k=0; k < ChargeProfileCount; k++)
  8732. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8733. end:
  8734. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8735. {
  8736. if(connectorIdInt == 0)
  8737. {
  8738. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8739. {
  8740. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8741. }
  8742. }
  8743. else
  8744. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8745. }
  8746. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8747. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8748. return result;
  8749. }
  8750. void createFirmwareVersionByDataTransfer(void)
  8751. {
  8752. json_object *FirmwareDataTransfer = json_object_new_object();
  8753. // AC & DC model
  8754. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8755. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8756. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8757. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8758. // DC model
  8759. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8760. {
  8761. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8762. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8763. (gunType[3] != GUN_TYPE_UNKNOWN))
  8764. {
  8765. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8766. }
  8767. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8768. {
  8769. // DS DM DW
  8770. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8771. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8772. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8773. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8774. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8775. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8776. }
  8777. else
  8778. {
  8779. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8780. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8781. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8782. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8783. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8784. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8785. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8786. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8787. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8788. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8789. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8790. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8791. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8792. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8793. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8794. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8795. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8796. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8797. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8798. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8799. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8800. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8801. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8802. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8803. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8804. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8805. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8806. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8807. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8808. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8809. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8810. }
  8811. }
  8812. // 4G model
  8813. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8814. {
  8815. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8816. }
  8817. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8818. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8819. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8820. json_object_put(FirmwareDataTransfer);
  8821. }
  8822. int handleDataTransferRequest(char *uuid, char *payload)
  8823. {
  8824. mtrace();
  8825. json_object *response = json_object_new_object();
  8826. int result = FAIL;
  8827. char tempvendorId[255]={0};
  8828. char tempmessageId[50]={0};
  8829. char tempdata[512]={0};
  8830. char message[2048]={0};
  8831. DEBUG_INFO("handleDataTransferRequest...\n");
  8832. if((uuid != NULL) && (payload != NULL))
  8833. {
  8834. json_object *DataTransfer;
  8835. DataTransfer = json_tokener_parse(payload);
  8836. if(!is_error(DataTransfer))
  8837. {
  8838. // Required data
  8839. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8840. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8841. // Optional data
  8842. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8843. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8844. if(json_object_object_get(DataTransfer, "data") != NULL)
  8845. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8846. result = PASS;
  8847. }
  8848. json_object_put(DataTransfer);
  8849. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8850. {
  8851. // Send all moudle firmware version on EVSE
  8852. createFirmwareVersionByDataTransfer();
  8853. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8854. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8855. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8856. json_object_put(response);
  8857. }
  8858. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8859. {
  8860. system("/usr/bin/run_tmate_restart.sh &");
  8861. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8862. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8863. json_object_put(response);
  8864. }
  8865. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8866. {
  8867. json_object *data;
  8868. data = json_tokener_parse(tempdata);
  8869. if(!is_error(data))
  8870. {
  8871. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  8872. {
  8873. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8874. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8875. if(json_object_object_get(data, "SOC") != NULL)
  8876. {
  8877. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8878. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8879. }
  8880. if(json_object_object_get(data, "Energy") != NULL)
  8881. {
  8882. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8883. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8884. }
  8885. if(json_object_object_get(data, "Duration") != NULL)
  8886. {
  8887. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8888. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8889. }
  8890. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8891. }
  8892. else
  8893. {
  8894. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8895. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8896. }
  8897. }
  8898. else
  8899. {
  8900. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8901. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8902. }
  8903. json_object_put(data);
  8904. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8905. json_object_put(response);
  8906. }
  8907. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8908. {
  8909. json_object *data;
  8910. data = json_tokener_parse(tempdata);
  8911. if(!is_error(data))
  8912. {
  8913. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8914. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8915. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8916. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8917. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8918. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8919. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8920. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8921. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8922. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8923. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8924. }
  8925. else
  8926. {
  8927. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8928. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8929. }
  8930. json_object_put(data);
  8931. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8932. json_object_put(response);
  8933. }
  8934. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8935. {
  8936. json_object *data;
  8937. data = json_tokener_parse(tempdata);
  8938. if(!is_error(data))
  8939. {
  8940. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8941. if(json_object_object_get(data, "idToken") != NULL)
  8942. {
  8943. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8944. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8945. }
  8946. if(json_object_object_get(data, "price") != NULL)
  8947. {
  8948. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8949. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8950. }
  8951. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8952. }
  8953. else
  8954. {
  8955. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8956. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8957. }
  8958. json_object_put(data);
  8959. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8960. json_object_put(response);
  8961. }
  8962. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8963. {
  8964. json_object *data;
  8965. data = json_tokener_parse(tempdata);
  8966. if(!is_error(data))
  8967. {
  8968. if(json_object_object_get(data, "txId") != NULL)
  8969. {
  8970. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8971. for(int idx = 0;idx<gunTotalNumber;idx++)
  8972. {
  8973. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8974. {
  8975. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8976. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8977. if(json_object_object_get(data, "description") != NULL)
  8978. {
  8979. // California pricing V1.0
  8980. DEBUG_INFO("California pricing V1.0\n");
  8981. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8982. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8983. }
  8984. else
  8985. {
  8986. // California pricing V1.1
  8987. DEBUG_INFO("California pricing V1.1\n");
  8988. if(json_object_object_get(data, "timestamp") != NULL)
  8989. {
  8990. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8991. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8992. }
  8993. if(json_object_object_get(data, "meterValue") != NULL)
  8994. {
  8995. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8996. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8997. }
  8998. if(json_object_object_get(data, "cost") != NULL)
  8999. {
  9000. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9001. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9002. }
  9003. if(json_object_object_get(data, "state") != NULL)
  9004. {
  9005. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9006. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9007. }
  9008. if(json_object_object_get(data, "chargingPrice") != NULL)
  9009. {
  9010. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9011. {
  9012. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9013. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9014. }
  9015. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9016. {
  9017. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9018. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9019. }
  9020. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9021. {
  9022. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9023. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9024. }
  9025. }
  9026. if(json_object_object_get(data, "idlePrice") != NULL)
  9027. {
  9028. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9029. {
  9030. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9031. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9032. }
  9033. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9034. {
  9035. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9036. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9037. }
  9038. }
  9039. if(json_object_object_get(data, "nextPeriod") != NULL)
  9040. {
  9041. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9042. {
  9043. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9044. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9045. }
  9046. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9047. {
  9048. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9049. {
  9050. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9051. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9052. }
  9053. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9054. {
  9055. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9056. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9057. }
  9058. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9059. {
  9060. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9061. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9062. }
  9063. }
  9064. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9065. {
  9066. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9067. {
  9068. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9069. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9070. }
  9071. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9072. {
  9073. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9074. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9075. }
  9076. }
  9077. }
  9078. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9079. {
  9080. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9081. {
  9082. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9083. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9084. }
  9085. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9086. {
  9087. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9088. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9089. }
  9090. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9091. {
  9092. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9093. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9094. }
  9095. }
  9096. }
  9097. }
  9098. }
  9099. }
  9100. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9101. }
  9102. else
  9103. {
  9104. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9105. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9106. }
  9107. json_object_put(data);
  9108. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9109. json_object_put(response);
  9110. }
  9111. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9112. {
  9113. json_object *data;
  9114. data = json_tokener_parse(tempdata);
  9115. if(!is_error(data))
  9116. {
  9117. if(json_object_object_get(data, "txId") != NULL)
  9118. {
  9119. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9120. for(int idx = 0;idx<gunTotalNumber;idx++)
  9121. {
  9122. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9123. {
  9124. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9125. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9126. if(json_object_object_get(data, "description") != NULL)
  9127. {
  9128. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9129. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9130. }
  9131. }
  9132. }
  9133. }
  9134. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9135. }
  9136. else
  9137. {
  9138. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9139. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9140. }
  9141. json_object_put(data);
  9142. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9143. json_object_put(response);
  9144. }
  9145. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9146. {
  9147. json_object *data;
  9148. data = json_tokener_parse(tempdata);
  9149. if(!is_error(data))
  9150. {
  9151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9152. if(json_object_object_get(data, "Content_Type") != NULL)
  9153. {
  9154. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  9155. {
  9156. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9157. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9158. {
  9159. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9160. }
  9161. }
  9162. else
  9163. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9164. }
  9165. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9166. }
  9167. else
  9168. {
  9169. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9170. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9171. }
  9172. json_object_put(data);
  9173. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9174. json_object_put(response);
  9175. }
  9176. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9177. {
  9178. json_object *data;
  9179. data = json_tokener_parse(tempdata);
  9180. if(!is_error(data))
  9181. {
  9182. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9183. if(json_object_object_get(data, "Page_Index") != NULL)
  9184. {
  9185. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9186. }
  9187. if(json_object_object_get(data, "Duration") != NULL)
  9188. {
  9189. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9190. }
  9191. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9192. }
  9193. else
  9194. {
  9195. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9196. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9197. }
  9198. json_object_put(data);
  9199. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9200. json_object_put(response);
  9201. }
  9202. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9203. {
  9204. json_object *data;
  9205. data = json_tokener_parse(tempdata);
  9206. if(!is_error(data))
  9207. {
  9208. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9209. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9210. {
  9211. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9212. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9213. else
  9214. {
  9215. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9216. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9217. }
  9218. }
  9219. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9220. {
  9221. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9222. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9223. else
  9224. {
  9225. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9226. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9227. }
  9228. }
  9229. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9230. {
  9231. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9232. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9233. else
  9234. {
  9235. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9236. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9237. }
  9238. }
  9239. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9240. {
  9241. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9242. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9243. else
  9244. {
  9245. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9246. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9247. }
  9248. }
  9249. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9250. {
  9251. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9252. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9253. else
  9254. {
  9255. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9256. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9257. }
  9258. }
  9259. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9260. {
  9261. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9262. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9263. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9264. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9265. else
  9266. {
  9267. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9268. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9269. }
  9270. }
  9271. if(json_object_object_get(data, "isAuthentication") != NULL)
  9272. {
  9273. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9274. {
  9275. case 0:
  9276. case 1:
  9277. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9278. break;
  9279. default:
  9280. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9281. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9282. break;
  9283. }
  9284. }
  9285. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9286. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9287. }
  9288. else
  9289. {
  9290. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9291. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9292. }
  9293. json_object_put(data);
  9294. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9295. json_object_put(response);
  9296. }
  9297. else
  9298. {
  9299. // Can not find valid message id
  9300. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9301. }
  9302. }
  9303. else
  9304. {
  9305. // Payload is null
  9306. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9307. }
  9308. LWS_Send(message);
  9309. return result;
  9310. }
  9311. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9312. {
  9313. mtrace();
  9314. int result = FAIL;
  9315. int connectorIdInt, durationInt;
  9316. char chargingRateUnitStr[4]={0};
  9317. char comfirmstr[20];
  9318. int confirmPeriods = 0;
  9319. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9320. json_object *GetCompositeSchedule;
  9321. GetCompositeSchedule = json_tokener_parse(payload);
  9322. if(!is_error(GetCompositeSchedule))
  9323. {
  9324. // Required data
  9325. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9326. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9327. else
  9328. connectorIdInt = -1;
  9329. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9330. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9331. else
  9332. durationInt = 86400;
  9333. // Optional data
  9334. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9335. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9336. }
  9337. json_object_put(GetCompositeSchedule);
  9338. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9339. if((connectorIdInt == 0) ||
  9340. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9341. {
  9342. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9343. struct StructChargingProfile tmpProfile[1];
  9344. if(strstr(chargingRateUnitStr, "W") != NULL)
  9345. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9346. else
  9347. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9348. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9349. {
  9350. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9351. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9352. }
  9353. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9354. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9355. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9356. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9357. {
  9358. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9359. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9360. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9361. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9362. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9363. {
  9364. confirmPeriods = idx;
  9365. break;
  9366. }
  9367. }
  9368. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9369. {
  9370. confirmPeriods += 1;
  9371. }
  9372. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9373. }
  9374. else
  9375. {
  9376. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9377. }
  9378. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9379. return result;
  9380. }
  9381. int handleGetConfigurationRequest(char *uuid, char *payload)
  9382. {
  9383. mtrace();
  9384. int result = FAIL;
  9385. int MaxKeySupported = 0;
  9386. int n_keys = 0;
  9387. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9388. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9389. json_object *GetConfiguration;
  9390. GetConfiguration = json_tokener_parse(payload);
  9391. if(!is_error(GetConfiguration))
  9392. {
  9393. // Optional data
  9394. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9395. {
  9396. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9397. {
  9398. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9399. n_keys = idx + 1;
  9400. }
  9401. }
  9402. }
  9403. json_object_put(GetConfiguration);
  9404. UnknownKeynum = 0;
  9405. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9406. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9407. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9408. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9409. if(n_keys != 0)
  9410. {
  9411. for(int i=0;i<n_keys;i++)
  9412. {
  9413. getKeyValue(requestKey[i]);
  9414. }
  9415. }
  9416. else
  9417. {
  9418. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9419. getKeyValue("");
  9420. }
  9421. processUnkownKey();
  9422. sendGetConfigurationConfirmation(uuid);
  9423. return result;
  9424. }
  9425. static char fnamePlusPath[100]={0};
  9426. static char fnamePWithNoPath[60]={0};
  9427. void checkUploadLog(void)
  9428. {
  9429. FILE *fp;
  9430. /* Open the command for reading. */
  9431. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9432. if (fp == NULL) {
  9433. DEBUG_WARN("Failed to run command\n" );
  9434. exit(1);
  9435. }
  9436. int ftppathlen = 0;
  9437. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9438. int i = 0;
  9439. /* Read the output a line at a time - output it. */
  9440. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9441. if(i==0)
  9442. {
  9443. ftppathlen = strlen(fnamePlusPath);
  9444. DEBUG_INFO("%s\n", fnamePlusPath);
  9445. fnamePlusPath[ftppathlen]='\0';
  9446. break;
  9447. }
  9448. i= i+1;
  9449. }
  9450. /* close */
  9451. pclose(fp);
  9452. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9453. {
  9454. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9455. {
  9456. fnamePlusPath[k]='\0';
  9457. }
  9458. }
  9459. i=1;
  9460. //char fname[60]={0};
  9461. while(i < ftppathlen)
  9462. {
  9463. int len=ftppathlen-i;
  9464. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9465. {
  9466. DEBUG_INFO("compare '/' all right\n");
  9467. break;
  9468. }
  9469. i=i+1;
  9470. }
  9471. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9472. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9473. fnamePWithNoPath[i+1] = '\0';
  9474. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9475. {
  9476. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9477. {
  9478. fnamePWithNoPath[j]='\0';
  9479. }
  9480. }
  9481. FILE* fp1 = fopen(fnamePlusPath, "r");
  9482. if (fp1)
  9483. {
  9484. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9485. // file exists
  9486. fclose(fp1);
  9487. }
  9488. else
  9489. {
  9490. // file doesn't exist
  9491. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9492. }
  9493. }
  9494. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9495. {
  9496. mtrace();
  9497. int result = FAIL;
  9498. time_t CurrentTime;
  9499. struct tm *tm;
  9500. pthread_t th_Status;
  9501. CurrentTime = time(NULL);
  9502. tm = localtime(&CurrentTime);
  9503. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9504. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  9505. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9506. if(!interLock.isGetDiagnosticGoing)
  9507. {
  9508. interLock.isGetDiagnosticGoing = 1;
  9509. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9510. sleep(1);
  9511. }
  9512. else
  9513. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9514. return result;
  9515. }
  9516. void* GetDiagnosticsProcess(void* data)
  9517. {
  9518. pthread_detach(pthread_self());
  9519. mtrace();
  9520. int retriesInt=0, retryIntervalInt=0;
  9521. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9522. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  9523. int port=0;
  9524. int isSuccess = FALSE;
  9525. char cmdBuf[2048];
  9526. struct tm *tmNow;
  9527. time_t CurrentTime;
  9528. struct tm tmStart;
  9529. struct tm tmStop;
  9530. CurrentTime = time(NULL);
  9531. tmNow=localtime(&CurrentTime);
  9532. uint16_t targetYear, targetMonth;
  9533. json_object *GetDiagnostics;
  9534. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9535. GetDiagnostics = json_tokener_parse(data);
  9536. if(!is_error(GetDiagnostics))
  9537. {
  9538. // Required data
  9539. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9540. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9541. // Optional data
  9542. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9543. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9544. else
  9545. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9546. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9547. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9548. else
  9549. retryIntervalInt = 30;
  9550. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9551. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9552. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9553. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9554. }
  9555. json_object_put(GetDiagnostics);
  9556. // Pack log to compress file
  9557. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  9558. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  9559. {
  9560. // Pack system log
  9561. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9562. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9563. targetYear = tmStart.tm_year;
  9564. targetMonth = tmStart.tm_mon;
  9565. do
  9566. {
  9567. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9568. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9569. if(targetMonth+1>=13)
  9570. {
  9571. targetYear += 1;
  9572. targetMonth = 1;
  9573. }
  9574. else
  9575. {
  9576. targetMonth += 1;
  9577. }
  9578. }while((targetYear < (tmNow->tm_year+1900)) ||
  9579. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9580. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9581. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9582. system(cmdBuf);
  9583. // Pack charging & event log
  9584. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9585. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9586. targetYear = tmStart.tm_year;
  9587. targetMonth = tmStart.tm_mon;
  9588. do
  9589. {
  9590. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9591. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9592. if(targetMonth+1>=13)
  9593. {
  9594. targetYear += 1;
  9595. targetMonth = 1;
  9596. }
  9597. else
  9598. {
  9599. targetMonth += 1;
  9600. }
  9601. }while((targetYear < (tmNow->tm_year+1900)) ||
  9602. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9603. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9604. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9605. system(cmdBuf);
  9606. // Combine log file
  9607. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9608. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9609. }
  9610. else
  9611. {
  9612. system("exec /root/logPackTools 'log' 6");
  9613. }
  9614. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9615. system(cmdBuf);
  9616. checkUploadLog();
  9617. //****************location*******************/
  9618. if(strcmp(locationstr,"")==0)
  9619. {
  9620. DEBUG_INFO("location is <Empty>!\n");
  9621. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9622. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9623. goto end;
  9624. }
  9625. memset(protocol, 0, ARRAY_SIZE(protocol));
  9626. memset(user, 0, ARRAY_SIZE(user) );
  9627. memset(password, 0, ARRAY_SIZE(password));
  9628. memset(host, 0, ARRAY_SIZE(host));
  9629. memset(path, 0, ARRAY_SIZE(path));
  9630. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9631. memset(host1, 0, ARRAY_SIZE(host1));
  9632. memset(path1, 0, ARRAY_SIZE(path1));
  9633. /*location: ftp://user:password@host:port/path*/
  9634. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9635. if((access(fnamePlusPath,F_OK))!=-1)
  9636. {
  9637. DEBUG_INFO("fnamePlusPath exist.\n");
  9638. }
  9639. else
  9640. {
  9641. DEBUG_INFO("fnamePlusPath not exist!\n");
  9642. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9643. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9644. goto end;
  9645. }
  9646. if(strchr(locationstr,'@')==NULL)
  9647. {
  9648. sscanf(locationstr,
  9649. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9650. protocol, host, &port, path);
  9651. strcpy(user,"anonymous");
  9652. strcpy(password,"");
  9653. }
  9654. else
  9655. {
  9656. //DEBUG_INFO("pch=%s\n", pch);
  9657. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9658. protocol, user, password, host, &port, path);
  9659. }
  9660. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9661. {
  9662. DEBUG_INFO("protocol is not ftp/http ! \n");
  9663. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9664. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9665. goto end;
  9666. }
  9667. if(strncmp(locationstr,"http", 4) == 0)
  9668. {
  9669. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9670. sprintf(ftppath,"/%s", path);
  9671. do
  9672. {
  9673. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9674. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9675. sleep(3);
  9676. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9677. if(!isSuccess)
  9678. {
  9679. DEBUG_INFO("Diagnostics fail.\n");
  9680. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9681. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9682. sleep(retryIntervalInt);
  9683. }
  9684. else
  9685. {
  9686. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9687. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9688. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9689. }
  9690. retriesInt--;
  9691. }while((isSuccess == 0)&&(retriesInt >= 0));
  9692. }
  9693. else
  9694. {
  9695. sscanf(host,"%[^/]%s",host1, path1);
  9696. if(strlen(path) > 0)
  9697. sprintf(ftppath,"/%s", path);
  9698. else
  9699. sprintf(ftppath,"/%s", path1);
  9700. int ftppathlen=strlen(ftppath);
  9701. int i=1;
  9702. char filenametemp[50];
  9703. while(i < ftppathlen)
  9704. {
  9705. int len=ftppathlen-i;
  9706. if(ftppath[len]== 47) // '/' ascll code: 47
  9707. {
  9708. DEBUG_INFO("find '/' all right\n");
  9709. break;
  9710. }
  9711. i=i+1;
  9712. }
  9713. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9714. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9715. filenametemp[i+1] = 0;
  9716. if(port == 0)
  9717. port = 21;
  9718. do
  9719. {
  9720. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9721. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9722. sleep(3);
  9723. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9724. if(!isSuccess)
  9725. {
  9726. DEBUG_INFO("Diagnostics fail.\n");
  9727. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9728. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9729. sleep(retryIntervalInt);
  9730. }
  9731. else
  9732. {
  9733. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9734. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9735. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9736. }
  9737. retriesInt--;
  9738. }while((!isSuccess)&&(retriesInt >= 0));
  9739. }
  9740. end:
  9741. system("rm -f /mnt/*");
  9742. sleep(5);
  9743. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9744. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9745. interLock.isGetDiagnosticGoing = 0;
  9746. pthread_exit(NULL);
  9747. }
  9748. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9749. {
  9750. mtrace();
  9751. int result = FAIL;
  9752. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9753. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9754. {
  9755. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9756. locallistVersion = -1;
  9757. }
  9758. else
  9759. {
  9760. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9761. OCPP_getListVerion();
  9762. }
  9763. //from db.OCPP_getListVerion
  9764. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9765. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9766. sendGetLocalListVersionConfirmation(uuid,"");
  9767. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9768. return result;
  9769. }
  9770. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9771. {
  9772. mtrace();
  9773. int result = FAIL;
  9774. int connectorIdInt=-1;
  9775. int tempIndex = 0;
  9776. int connectorIdIsNULL, chargingProfileIsNULL;
  9777. char comfirmstr[20]={0};
  9778. char cmdBuf[512];
  9779. json_object *RemoteStartTransaction;
  9780. FILE *fp;
  9781. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9782. if(server_pending == TRUE)
  9783. {
  9784. return 0;
  9785. }
  9786. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9787. RemoteStartTransaction = json_tokener_parse(payload);
  9788. if(!is_error(RemoteStartTransaction))
  9789. {
  9790. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9791. {
  9792. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9793. }
  9794. else
  9795. {
  9796. connectorIdIsNULL = TRUE;
  9797. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9798. {
  9799. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9800. {
  9801. connectorIdIsNULL = FALSE;
  9802. connectorIdInt = (gun_index+1);
  9803. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9804. break;
  9805. }
  9806. }
  9807. }
  9808. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9809. {
  9810. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9811. // Required data
  9812. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9813. // Optional data
  9814. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9815. {
  9816. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9817. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9818. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9819. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9820. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9821. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9822. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9823. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9824. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9825. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9826. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9827. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9828. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9829. {
  9830. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  9831. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9832. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  9833. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9834. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  9835. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9836. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  9837. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9838. {
  9839. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  9840. {
  9841. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  9842. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  9843. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  9844. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  9845. }
  9846. }
  9847. }
  9848. }
  9849. else
  9850. {
  9851. chargingProfileIsNULL = TRUE;
  9852. }
  9853. }
  9854. }
  9855. else
  9856. {
  9857. connectorIdIsNULL = TRUE;
  9858. }
  9859. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9860. {
  9861. DEBUG_WARN("Connector id is NULL\n.");
  9862. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9863. goto end;
  9864. }
  9865. /*
  9866. enum _SYSTEM_STATUS
  9867. {
  9868. S_BOOTING = 0,
  9869. S_IDLE, = 1
  9870. S_AUTHORIZING, = 2
  9871. S_REASSIGN_CHECK, = 3
  9872. S_REASSIGN, = 4
  9873. S_PRECHARGE, = 5
  9874. S_PREPARING_FOR_EV, = 6
  9875. S_PREPARING_FOR_EVSE, = 7
  9876. S_CHARGING, = 8
  9877. S_TERMINATING, = 9
  9878. S_COMPLETE, = 10
  9879. S_ALARM, = 11
  9880. S_FAULT = 12
  9881. }
  9882. */
  9883. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9884. {
  9885. //check Transaction active
  9886. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9887. {
  9888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9889. {
  9890. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9891. }
  9892. else
  9893. {
  9894. tempIndex = connectorIdInt -1;
  9895. }
  9896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9897. {
  9898. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9899. {
  9900. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9901. {
  9902. //Reserved
  9903. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9904. }
  9905. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9906. {
  9907. //Reserved
  9908. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9909. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9910. goto end;
  9911. }
  9912. else
  9913. {
  9914. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9915. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9916. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9917. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9918. {
  9919. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9920. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9921. goto end;
  9922. }
  9923. }//END FOR ELSE
  9924. }
  9925. }// END FOR CHAdeMO_QUANTITY
  9926. }
  9927. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9928. {
  9929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9930. {
  9931. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9932. }
  9933. else
  9934. {
  9935. tempIndex = connectorIdInt -1;
  9936. }
  9937. for (int index = 0; index < CCS_QUANTITY; index++)
  9938. {
  9939. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9940. {
  9941. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9942. {
  9943. //Reserved
  9944. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9945. }
  9946. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9947. {
  9948. //Reserved
  9949. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9950. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9951. goto end;
  9952. }
  9953. else
  9954. {
  9955. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9956. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9957. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9958. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9959. {
  9960. DEBUG_WARN("CCS connector not allow start\n.");
  9961. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9962. goto end;
  9963. }
  9964. }// END FOR ELSE
  9965. }
  9966. }// END FOR CCS_QUANTITY
  9967. }
  9968. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9969. {
  9970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9971. {
  9972. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9973. }
  9974. else
  9975. {
  9976. tempIndex = connectorIdInt -1;
  9977. }
  9978. for (int index = 0; index < GB_QUANTITY; index++)
  9979. {
  9980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9981. {
  9982. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9983. {
  9984. //Reserved
  9985. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9986. }
  9987. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9988. {
  9989. //Reserved
  9990. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9991. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9992. goto end;
  9993. }
  9994. else
  9995. {
  9996. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9997. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9998. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9999. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10000. {
  10001. DEBUG_WARN("GB connector not allow start\n.");
  10002. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10003. goto end;
  10004. }
  10005. }// END FOR ELSE
  10006. }
  10007. } // END FOR GB_QUANTITY
  10008. }
  10009. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10010. {
  10011. tempIndex = connectorIdInt -1;
  10012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10013. {
  10014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10015. {
  10016. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10017. {
  10018. //Reserved
  10019. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10020. }
  10021. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10022. {
  10023. //Reserved
  10024. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10025. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10026. goto end;
  10027. }
  10028. else
  10029. {
  10030. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10031. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10032. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10033. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10034. {
  10035. DEBUG_WARN("GB connector not allow start\n.");
  10036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10037. goto end;
  10038. }
  10039. }// END FOR ELSE
  10040. }
  10041. } // END FOR GB_QUANTITY
  10042. }
  10043. else
  10044. {
  10045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10046. {
  10047. tempIndex = 2;
  10048. }
  10049. else
  10050. {
  10051. tempIndex = connectorIdInt -1;
  10052. }
  10053. for (int index = 0; index < AC_QUANTITY; index++)
  10054. {
  10055. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10056. {
  10057. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10058. {
  10059. //Reserved
  10060. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10061. }
  10062. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10063. {
  10064. //Reserved
  10065. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10067. goto end;
  10068. }
  10069. else
  10070. {
  10071. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10072. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10073. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10074. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10075. {
  10076. DEBUG_WARN("AC connector not allow start\n.");
  10077. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10078. goto end;
  10079. }
  10080. }//END FOR ELSE
  10081. }
  10082. }// END FOR AC_QUANTITY
  10083. }
  10084. if(chargingProfileIsNULL == FALSE)
  10085. {
  10086. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10087. {
  10088. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10090. //memset idTag
  10091. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10092. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10093. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10094. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10095. // Save profile to file
  10096. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10097. system(cmdBuf);
  10098. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10099. fp = fopen(cmdBuf, "w");
  10100. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10101. fclose(fp);
  10102. }
  10103. else
  10104. {
  10105. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10106. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10107. }
  10108. }
  10109. else
  10110. {
  10111. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10113. //memset idTag
  10114. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10115. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10116. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10117. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10118. }
  10119. }
  10120. else
  10121. {
  10122. DEBUG_WARN("Connector id over\n.");
  10123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10124. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10125. }
  10126. end:
  10127. json_object_put(RemoteStartTransaction);
  10128. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10129. {
  10130. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10131. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10132. }
  10133. //OCPP send RemoteStartConfirmation by first.
  10134. sendRemoteStartConfirmation(uuid, comfirmstr);
  10135. return result;
  10136. }
  10137. int handleRemoteStartRequest(char *uuid, char *payload)
  10138. {
  10139. mtrace();
  10140. int result = PASS;
  10141. int connectorIdInt=-1;
  10142. int tempIndex = 0;
  10143. char comfirmstr[20]={0};
  10144. char cmdBuf[512];
  10145. json_object *RemoteStartTransaction;
  10146. FILE *fp;
  10147. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10148. if(server_pending == TRUE)
  10149. {
  10150. result = FAIL;
  10151. }
  10152. RemoteStartTransaction = json_tokener_parse(payload);
  10153. if(!is_error(RemoteStartTransaction))
  10154. {
  10155. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10156. {
  10157. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10158. }
  10159. else
  10160. {
  10161. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10162. {
  10163. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10164. {
  10165. connectorIdInt = (gun_index+1);
  10166. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10167. break;
  10168. }
  10169. }
  10170. }
  10171. if(connectorIdInt == 0)
  10172. {
  10173. DEBUG_WARN("Connector id shall not equal 0.\n");
  10174. result = FAIL;
  10175. }
  10176. else if(connectorIdInt == -1)
  10177. {
  10178. DEBUG_INFO("Connector id does not specific.\n");
  10179. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10180. {
  10181. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10182. // Required data
  10183. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10184. // Optional data
  10185. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10186. {
  10187. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10188. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10189. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10190. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10191. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10192. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10193. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10194. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10195. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10196. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10197. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10198. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10199. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10200. {
  10201. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10202. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10203. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10204. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10205. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10206. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10207. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10208. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10209. {
  10210. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10211. {
  10212. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10213. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10214. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10215. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10216. }
  10217. }
  10218. }
  10219. }
  10220. else
  10221. {
  10222. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10223. }
  10224. }
  10225. }
  10226. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10227. {
  10228. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10229. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10230. // Required data
  10231. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10232. // Optional data
  10233. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10234. {
  10235. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10236. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10237. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10238. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10239. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10240. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10241. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10242. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10243. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10244. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10245. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10246. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10247. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10248. {
  10249. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10250. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10251. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10252. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10253. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10254. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10255. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10256. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10257. {
  10258. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10259. {
  10260. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10261. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10262. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10263. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10264. }
  10265. }
  10266. }
  10267. }
  10268. else
  10269. {
  10270. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10271. }
  10272. }
  10273. else
  10274. {
  10275. DEBUG_WARN("Connector id is over maximun value.\n");
  10276. result = FAIL;
  10277. }
  10278. }
  10279. if(result == PASS)
  10280. {
  10281. if(connectorIdInt > 0)
  10282. {
  10283. //check Transaction active
  10284. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10285. {
  10286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10287. {
  10288. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10289. }
  10290. else
  10291. {
  10292. tempIndex = connectorIdInt -1;
  10293. }
  10294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10295. {
  10296. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10297. {
  10298. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10299. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10300. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10301. {
  10302. //Reserved
  10303. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10304. }
  10305. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10306. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10307. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10308. {
  10309. //Reserved
  10310. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10312. goto end;
  10313. }
  10314. else
  10315. {
  10316. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10317. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10318. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10319. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10320. {
  10321. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10323. goto end;
  10324. }
  10325. }//END FOR ELSE
  10326. }
  10327. }// END FOR CHAdeMO_QUANTITY
  10328. }
  10329. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10330. {
  10331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10332. {
  10333. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10334. }
  10335. else
  10336. {
  10337. tempIndex = connectorIdInt -1;
  10338. }
  10339. for (int index = 0; index < CCS_QUANTITY; index++)
  10340. {
  10341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10342. {
  10343. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10344. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10345. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10346. {
  10347. //Reserved
  10348. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10349. }
  10350. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10351. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10352. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10353. {
  10354. //Reserved
  10355. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10356. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10357. goto end;
  10358. }
  10359. else
  10360. {
  10361. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10362. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10363. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10364. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10365. {
  10366. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10367. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10368. goto end;
  10369. }
  10370. }// END FOR ELSE
  10371. }
  10372. }// END FOR CCS_QUANTITY
  10373. }
  10374. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10375. {
  10376. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10377. {
  10378. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10379. }
  10380. else
  10381. {
  10382. tempIndex = connectorIdInt -1;
  10383. }
  10384. for (int index = 0; index < GB_QUANTITY; index++)
  10385. {
  10386. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10387. {
  10388. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10389. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10390. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10391. {
  10392. //Reserved
  10393. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10394. }
  10395. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10396. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10397. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10398. {
  10399. //Reserved
  10400. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10402. goto end;
  10403. }
  10404. else
  10405. {
  10406. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10407. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10408. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10409. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10410. {
  10411. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10413. goto end;
  10414. }
  10415. }// END FOR ELSE
  10416. }
  10417. } // END FOR GB_QUANTITY
  10418. }
  10419. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10420. {
  10421. tempIndex = connectorIdInt -1;
  10422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10423. {
  10424. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10425. {
  10426. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10427. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10428. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10429. {
  10430. //Reserved
  10431. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10432. }
  10433. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10434. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10435. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10436. {
  10437. //Reserved
  10438. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10439. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10440. goto end;
  10441. }
  10442. else
  10443. {
  10444. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10445. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10446. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10447. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10448. {
  10449. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10450. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10451. goto end;
  10452. }
  10453. }// END FOR ELSE
  10454. }
  10455. } // END FOR GB_QUANTITY
  10456. }
  10457. else
  10458. {
  10459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10460. {
  10461. tempIndex = 2;
  10462. }
  10463. else
  10464. {
  10465. tempIndex = connectorIdInt -1;
  10466. }
  10467. for (int index = 0; index < AC_QUANTITY; index++)
  10468. {
  10469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10470. {
  10471. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10472. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10473. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10474. {
  10475. //Reserved
  10476. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10477. }
  10478. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10480. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10481. {
  10482. //Reserved
  10483. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10485. goto end;
  10486. }
  10487. else
  10488. {
  10489. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10490. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10491. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10492. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10493. {
  10494. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10495. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10496. goto end;
  10497. }
  10498. }//END FOR ELSE
  10499. }
  10500. }// END FOR AC_QUANTITY
  10501. }
  10502. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10503. {
  10504. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10505. {
  10506. // Save profile to file
  10507. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10508. system(cmdBuf);
  10509. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10510. fp = fopen(cmdBuf, "w");
  10511. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10512. fclose(fp);
  10513. }
  10514. else
  10515. {
  10516. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10518. goto end;
  10519. }
  10520. }
  10521. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10522. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10523. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10524. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10525. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10526. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10527. }
  10528. else
  10529. {
  10530. uint8_t isHasIdleConnector = FALSE;
  10531. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10532. {
  10533. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10534. {
  10535. isHasIdleConnector = TRUE;
  10536. break;
  10537. }
  10538. }
  10539. if(isHasIdleConnector == TRUE)
  10540. {
  10541. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10542. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10543. {
  10544. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10545. {
  10546. // Save profile to file
  10547. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10548. system(cmdBuf);
  10549. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10550. fp = fopen(cmdBuf, "w");
  10551. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10552. fclose(fp);
  10553. refreshStartTimer(&clientTime.RemoteStartWait);
  10554. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10555. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10556. }
  10557. else
  10558. {
  10559. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10560. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10561. }
  10562. }
  10563. }
  10564. else
  10565. {
  10566. DEBUG_INFO("There is not any connector is idle.\n");
  10567. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10568. }
  10569. }
  10570. }
  10571. else
  10572. {
  10573. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10574. }
  10575. end:
  10576. json_object_put(RemoteStartTransaction);
  10577. sendRemoteStartConfirmation(uuid, comfirmstr);
  10578. return result;
  10579. }
  10580. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10581. {
  10582. mtrace();
  10583. int result = FAIL;
  10584. int match = FALSE;
  10585. int GunNO = 0;
  10586. int tempIndex = 0;
  10587. int transactionIdInt=0;
  10588. int transactionIdIsNULL= TRUE;
  10589. char comfirmstr[20];
  10590. json_object *RemoteStopTransaction;
  10591. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10592. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10593. if(server_pending == TRUE)
  10594. {
  10595. return 0;
  10596. }
  10597. RemoteStopTransaction = json_tokener_parse(payload);
  10598. if(!is_error(RemoteStopTransaction))
  10599. {
  10600. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10601. {
  10602. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10603. transactionIdIsNULL = FALSE;
  10604. }
  10605. }
  10606. json_object_put(RemoteStopTransaction);
  10607. if(transactionIdIsNULL == FALSE)
  10608. {
  10609. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10610. {
  10611. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10612. {
  10613. //check Transaction active
  10614. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10615. {
  10616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10617. {
  10618. tempIndex = ((gun_index==2) ? 1: 0);
  10619. }
  10620. else
  10621. {
  10622. tempIndex = gun_index;
  10623. }
  10624. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10625. {
  10626. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10627. {
  10628. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10629. {
  10630. match = TRUE;
  10631. GunNO = gun_index;
  10632. }
  10633. }
  10634. }// END FOR CHAdeMO_QUANTITY
  10635. }
  10636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10637. {
  10638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10639. {
  10640. tempIndex = ((gun_index==2) ? 1: 0);
  10641. }
  10642. else
  10643. {
  10644. tempIndex = gun_index;
  10645. }
  10646. for (int index = 0; index < CCS_QUANTITY; index++)
  10647. {
  10648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10649. {
  10650. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10651. {
  10652. match = TRUE;
  10653. GunNO = gun_index;
  10654. }
  10655. }
  10656. }// END FOR CCS_QUANTITY
  10657. }
  10658. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10659. {
  10660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10661. {
  10662. tempIndex = ((gun_index==2) ? 1: 0);
  10663. }
  10664. else
  10665. {
  10666. tempIndex = gun_index;
  10667. }
  10668. for (int index = 0; index < GB_QUANTITY; index++)
  10669. {
  10670. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10671. {
  10672. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10673. {
  10674. match = TRUE;
  10675. GunNO = gun_index;
  10676. }
  10677. }
  10678. }// END FOR GB_QUANTITY
  10679. }
  10680. else if(gunType[gun_index] == GUN_TYPE_DO)
  10681. {
  10682. tempIndex = gun_index;
  10683. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10684. {
  10685. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10686. {
  10687. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10688. {
  10689. match = TRUE;
  10690. GunNO = gun_index;
  10691. }
  10692. }
  10693. }// END FOR GB_QUANTITY
  10694. }
  10695. else
  10696. {
  10697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10698. {
  10699. tempIndex = 2;
  10700. }
  10701. else
  10702. {
  10703. tempIndex = gun_index;
  10704. }
  10705. for (int index = 0; index < AC_QUANTITY; index++)
  10706. {
  10707. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10708. {
  10709. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10710. {
  10711. match = TRUE;
  10712. GunNO = gun_index;
  10713. }
  10714. }
  10715. }// END FOR CHAdeMO_QUANTITY
  10716. } // END FOR AC ELSE
  10717. }// CHECK IF ResponseTransactionId == transactionIdInt
  10718. }//END FOR
  10719. if( match == TRUE)
  10720. {
  10721. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10722. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10723. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10724. }
  10725. else
  10726. {
  10727. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10728. }
  10729. }
  10730. else
  10731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10732. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10733. return result;
  10734. }
  10735. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10736. {
  10737. mtrace();
  10738. int result = FAIL;
  10739. int connectorIdInt=0, reservationIdInt=0;
  10740. int tempIndex = 0;
  10741. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10742. char comfirmstr[20]={0};
  10743. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10744. int c = 0;
  10745. char *loc;
  10746. //char *ptr;
  10747. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10748. strcpy(sstrtemp, stringtrimspace(payload));
  10749. //***(1)connectorId ****/
  10750. c=0;
  10751. loc = strstr(sstrtemp, "connectorId");
  10752. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10753. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10754. {
  10755. sstr[c] = loc[strlen("connectorId")+2+c];
  10756. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10757. c++;
  10758. }
  10759. sstr[c] = '\0';
  10760. connectorIdInt = atoi(sstr);
  10761. //***(2)expiryDate ****/
  10762. loc = strstr(sstrtemp, "expiryDate");
  10763. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10764. c = 0;
  10765. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10766. {
  10767. sstr[c] = loc[3+strlen("expiryDate")+c];
  10768. c++;
  10769. }
  10770. sstr[c] = '\0';
  10771. strcpy(expiryDatestr, sstr);
  10772. //***(3)idTag ****/
  10773. loc = strstr(sstrtemp, "idTag");
  10774. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10775. c = 0;
  10776. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10777. {
  10778. sstr[c] = loc[3+strlen("idTag")+c];
  10779. c++;
  10780. }
  10781. sstr[c] = '\0';
  10782. strcpy(idTagstr, sstr);
  10783. //***(4)parentIdTag ****/
  10784. loc = strstr(sstrtemp, "parentIdTag");
  10785. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10786. c = 0;
  10787. if(loc == NULL)
  10788. {
  10789. strcpy(parentIdTagstr, "");
  10790. }
  10791. else
  10792. {
  10793. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10794. {
  10795. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10796. c++;
  10797. }
  10798. sstr[c] = '\0';
  10799. strcpy(parentIdTagstr, sstr);
  10800. }
  10801. //***(5)reservationId ****/
  10802. c=0;
  10803. loc = strstr(sstrtemp, "reservationId");
  10804. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10805. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10806. {
  10807. sstr[c] = loc[strlen("reservationId")+2+c];
  10808. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10809. c++;
  10810. }
  10811. sstr[c] = '\0';
  10812. reservationIdInt = atoi(sstr);
  10813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10814. /*
  10815. enum SYSTEM_STATUS
  10816. {
  10817. SYS_MODE_BOOTING = 0,
  10818. SYS_MODE_IDLE = 1,
  10819. SYS_MODE_AUTHORIZING = 2,
  10820. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10821. SYS_MODE_REASSIGN = 4,
  10822. SYS_MODE_PREPARING = 5,
  10823. SYS_MODE_PREPARE_FOR_EV = 6,
  10824. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10825. SYS_MODE_CHARGING = 8,
  10826. SYS_MODE_TERMINATING = 9,
  10827. SYS_MODE_COMPLETE = 10,
  10828. SYS_MODE_ALARM = 11,
  10829. SYS_MODE_FAULT = 12,
  10830. SYS_MODE_RESERVATION = 13,
  10831. SYS_MODE_BOOKING = 14,
  10832. SYS_MODE_MAINTAIN = 15,
  10833. SYS_MODE_DEBUG = 16,
  10834. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10835. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10836. SYS_MODE_UPDATE = 19
  10837. };
  10838. */
  10839. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10840. {
  10841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10842. goto end;
  10843. }
  10844. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10845. {
  10846. //check Transaction active
  10847. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10848. {
  10849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10850. {
  10851. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10852. }
  10853. else
  10854. {
  10855. tempIndex = connectorIdInt -1;
  10856. }
  10857. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10858. {
  10859. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10860. {
  10861. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10862. {
  10863. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10864. {
  10865. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10866. {
  10867. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10869. }
  10870. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  10871. {
  10872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10873. }
  10874. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10875. {
  10876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10877. }
  10878. else
  10879. {
  10880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10881. }
  10882. }
  10883. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  10884. {
  10885. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10886. }
  10887. }
  10888. else
  10889. {
  10890. //replace reservation
  10891. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10893. }
  10894. }
  10895. } // END FOR CHAdeMO_QUANTITY
  10896. }
  10897. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10898. {
  10899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10900. {
  10901. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10902. }
  10903. else
  10904. {
  10905. tempIndex = connectorIdInt -1;
  10906. }
  10907. for (int index = 0; index < CCS_QUANTITY; index++)
  10908. {
  10909. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10910. {
  10911. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10912. {
  10913. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10914. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10915. {
  10916. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10917. {
  10918. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10920. }
  10921. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  10922. {
  10923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10924. }
  10925. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10926. {
  10927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10928. }
  10929. else
  10930. {
  10931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10932. }
  10933. }
  10934. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  10935. {
  10936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10937. }
  10938. }
  10939. else
  10940. {
  10941. //replace reservation
  10942. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10944. }
  10945. }
  10946. } // END FOR CCS_QUANTITY
  10947. }
  10948. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10949. {
  10950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10951. {
  10952. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10953. }
  10954. else
  10955. {
  10956. tempIndex = connectorIdInt -1;
  10957. }
  10958. for (int index = 0; index < GB_QUANTITY; index++)
  10959. {
  10960. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10961. {
  10962. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10963. {
  10964. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10965. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10966. {
  10967. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10968. {
  10969. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10971. }
  10972. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  10973. {
  10974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10975. }
  10976. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10977. {
  10978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10979. }
  10980. else
  10981. {
  10982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10983. }
  10984. }
  10985. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  10986. {
  10987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10988. }
  10989. }
  10990. else
  10991. {
  10992. //replace reservation
  10993. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10995. }
  10996. }
  10997. }// END FOR GB_QUANTITY
  10998. }
  10999. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11000. {
  11001. tempIndex = connectorIdInt -1;
  11002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11003. {
  11004. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11005. {
  11006. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11007. {
  11008. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11009. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11010. {
  11011. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11012. {
  11013. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11015. }
  11016. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11017. {
  11018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11019. }
  11020. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11021. {
  11022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11023. }
  11024. else
  11025. {
  11026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11027. }
  11028. }
  11029. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  11030. {
  11031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11032. }
  11033. }
  11034. else
  11035. {
  11036. //replace reservation
  11037. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11039. }
  11040. }
  11041. }// END FOR GB_QUANTITY
  11042. }
  11043. else
  11044. {
  11045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11046. {
  11047. tempIndex = 2;
  11048. }
  11049. else
  11050. {
  11051. tempIndex = (connectorIdInt -1);
  11052. }
  11053. for (int index = 0; index < AC_QUANTITY; index++)
  11054. {
  11055. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11056. {
  11057. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11058. {
  11059. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11060. {
  11061. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11062. {
  11063. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11064. {
  11065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11066. }
  11067. else
  11068. {
  11069. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11071. }
  11072. }
  11073. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11074. {
  11075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11076. }
  11077. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11078. {
  11079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11080. }
  11081. else
  11082. {
  11083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11084. }
  11085. }
  11086. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  11087. {
  11088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11089. }
  11090. }
  11091. else
  11092. {
  11093. //replace reservation
  11094. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11096. }
  11097. }
  11098. } // END FOR AC_QUANTITY
  11099. }
  11100. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11101. }
  11102. else if(connectorIdInt == 0)
  11103. {
  11104. //check Transaction active
  11105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11106. {
  11107. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11108. {
  11109. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11110. {
  11111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11112. goto end;
  11113. }
  11114. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11115. {
  11116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11117. goto end;
  11118. }
  11119. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11120. {
  11121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11122. goto end;
  11123. }
  11124. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11125. {
  11126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11127. goto end;
  11128. }
  11129. }
  11130. }// END FOR CHAdeMO_QUANTITY
  11131. for (int index = 0; index < CCS_QUANTITY; index++)
  11132. {
  11133. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11134. {
  11135. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11136. {
  11137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11138. goto end;
  11139. }
  11140. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11141. {
  11142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11143. goto end;
  11144. }
  11145. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11146. {
  11147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11148. goto end;
  11149. }
  11150. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11151. {
  11152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11153. goto end;
  11154. }
  11155. }
  11156. } // END FOR CCS_QUANTITY
  11157. for (int index = 0; index < GB_QUANTITY; index++)
  11158. {
  11159. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11160. {
  11161. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11162. {
  11163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11164. goto end;
  11165. }
  11166. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11167. {
  11168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11169. goto end;
  11170. }
  11171. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11172. {
  11173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11174. goto end;
  11175. }
  11176. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11177. {
  11178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11179. goto end;
  11180. }
  11181. }
  11182. } // END FOR GB_QUANTITY
  11183. for (int index = 0; index < AC_QUANTITY; index++)
  11184. {
  11185. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11186. {
  11187. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11188. {
  11189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11190. goto end;
  11191. }
  11192. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11193. {
  11194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11195. goto end;
  11196. }
  11197. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11198. {
  11199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11200. goto end;
  11201. }
  11202. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11203. {
  11204. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11205. {
  11206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11207. goto end;
  11208. }
  11209. }
  11210. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11211. {
  11212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11213. goto end;
  11214. }
  11215. }
  11216. }// END FOR AC_QUANTITY
  11217. //The connectorId is 0
  11218. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11220. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11221. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11222. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11223. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11224. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11225. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11226. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11227. result = TRUE;
  11228. return result;
  11229. }
  11230. else
  11231. {
  11232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11233. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11234. }
  11235. if(strcmp(comfirmstr,"Accepted") == 0)
  11236. {
  11237. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11238. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11239. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11240. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11241. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11242. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11243. result = TRUE;
  11244. return result;
  11245. }
  11246. end:
  11247. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11248. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11249. return result;
  11250. }
  11251. int handleResetRequest(char *uuid, char *payload)
  11252. {
  11253. mtrace();
  11254. int result = FAIL;
  11255. char sstr[10]={0},sstrtemp[30]={ 0 };
  11256. char typestr[10]={0};
  11257. char comfirmstr[20]={0};
  11258. int c = 0;
  11259. char *loc;
  11260. DEBUG_INFO("handleResetRequest...\n");
  11261. strcpy(sstrtemp, stringtrimspace(payload));
  11262. loc = strstr(sstrtemp, "type");
  11263. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11264. c = 0;
  11265. while (loc[3+strlen("type")+c] != '\"')
  11266. {
  11267. sstr[c] = loc[3+strlen("type")+c];
  11268. c++;
  11269. }
  11270. sstr[c] = '\0';
  11271. strcpy(typestr,sstr);
  11272. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11273. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11274. {
  11275. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11276. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11277. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11278. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11279. }
  11280. else
  11281. {
  11282. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11283. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11284. result = PASS;
  11285. }
  11286. sendResetConfirmation(uuid, comfirmstr);
  11287. return result;
  11288. }
  11289. int handleSendLocalListRequest(char *uuid, char *payload)
  11290. {
  11291. mtrace();
  11292. int result = FAIL;
  11293. char comfirmstr[20];
  11294. int checkState_Faulted = FALSE;
  11295. json_object *SendLocalList;
  11296. DEBUG_INFO("handleSendLocalListRequest...\n");
  11297. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11298. {
  11299. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11300. goto end;
  11301. }
  11302. //check Charge Point state
  11303. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11304. {
  11305. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11306. {
  11307. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11308. }
  11309. }
  11310. for (int index = 0; index < CCS_QUANTITY; index++)
  11311. {
  11312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11313. {
  11314. checkState_Faulted = TRUE; //OCPP Status
  11315. }
  11316. }
  11317. for (int index = 0; index < GB_QUANTITY; index++)
  11318. {
  11319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11320. {
  11321. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11322. }
  11323. }
  11324. //check Charge Point state
  11325. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11326. {
  11327. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11328. {
  11329. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11330. }
  11331. }
  11332. //check Charge Point state
  11333. for (int index = 0; index < AC_QUANTITY; index++)
  11334. {
  11335. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11336. {
  11337. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11338. }
  11339. }
  11340. if(checkState_Faulted == TRUE)
  11341. {
  11342. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11343. goto end;
  11344. }
  11345. // Parsing payload
  11346. SendLocalList = json_tokener_parse(payload);
  11347. if(!is_error(SendLocalList))
  11348. {
  11349. // Required data
  11350. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11351. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11352. // Optional data
  11353. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11354. {
  11355. //Check UpdateType
  11356. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11357. {
  11358. //Local list full update
  11359. DEBUG_INFO("Local list full update.\n");
  11360. OCPP_getListVerion();
  11361. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11362. {
  11363. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11364. goto end;
  11365. }
  11366. OCPP_cleanLocalList();
  11367. }
  11368. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11369. {
  11370. //Local list different update
  11371. DEBUG_INFO("Local list different update.\n");
  11372. OCPP_getListVerion();
  11373. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11374. {
  11375. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11376. goto end;
  11377. }
  11378. }
  11379. else
  11380. {
  11381. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11382. goto end;
  11383. }
  11384. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11385. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11386. {
  11387. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  11388. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11389. {
  11390. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  11391. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11392. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  11393. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11394. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  11395. }
  11396. // Add to db
  11397. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11398. {
  11399. //Local list full update
  11400. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11401. idx,
  11402. ShmOCPP16Data->SendLocalList.ListVersion,
  11403. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11404. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11405. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11406. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11407. // update list
  11408. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11409. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11410. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11411. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11412. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11413. }
  11414. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11415. {
  11416. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11417. idx,
  11418. ShmOCPP16Data->SendLocalList.ListVersion,
  11419. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11420. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11421. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11422. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11423. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11424. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11425. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11426. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11427. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11428. }
  11429. }
  11430. }
  11431. else
  11432. {
  11433. //Check UpdateType
  11434. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11435. {
  11436. //Local list full update
  11437. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11438. OCPP_cleanLocalList();
  11439. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11440. goto end;
  11441. }
  11442. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11443. {
  11444. //Local list different update
  11445. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11446. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11447. goto end;
  11448. }
  11449. }
  11450. result = PASS;
  11451. }
  11452. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11453. end:
  11454. json_object_put(SendLocalList);
  11455. sendSendLocalListConfirmation(uuid, comfirmstr);
  11456. return result;
  11457. }
  11458. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11459. {
  11460. mtrace();
  11461. int result = FAIL;
  11462. struct StructSetChargingProfile SetProfileReq = {0};
  11463. int tempchargingProfileIdInt;
  11464. int chargingSchedulePeriodCount = 0;
  11465. char comfirmstr[20]={0};
  11466. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11467. char rmFileCmd[128]={0};
  11468. int profileQuantity = 0;
  11469. json_object *SetChargingProfile;
  11470. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11471. SetChargingProfile = json_tokener_parse(payload);
  11472. if(!is_error(SetChargingProfile))
  11473. {
  11474. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11475. {
  11476. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11477. }
  11478. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11479. {
  11480. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11481. {
  11482. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11483. }
  11484. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11485. {
  11486. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11487. }
  11488. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11489. {
  11490. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11491. }
  11492. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11493. {
  11494. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11495. }
  11496. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11497. {
  11498. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11499. }
  11500. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11501. {
  11502. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11503. }
  11504. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11505. {
  11506. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11507. }
  11508. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11509. {
  11510. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11511. }
  11512. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11513. {
  11514. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11515. {
  11516. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  11517. }
  11518. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11519. {
  11520. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11521. }
  11522. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11523. {
  11524. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11525. }
  11526. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11527. {
  11528. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  11529. }
  11530. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11531. {
  11532. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11533. if(chargingSchedulePeriodCount <= 10)
  11534. {
  11535. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  11536. {
  11537. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  11538. {
  11539. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11540. }
  11541. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  11542. {
  11543. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11544. }
  11545. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11546. {
  11547. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11548. }
  11549. }
  11550. }
  11551. }
  11552. }
  11553. }
  11554. }
  11555. // Profile periods quantity check
  11556. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11557. {
  11558. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11559. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11560. goto end;
  11561. }
  11562. // Profile purpose info check
  11563. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11564. {
  11565. FILE *fp;
  11566. char dataLine[4096]={0};
  11567. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11568. if(SetProfileReq.ConnectorId != 0)
  11569. {
  11570. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11571. DEBUG_WARN("Profile connector id is not 0.\n");
  11572. goto end;
  11573. }
  11574. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11575. if (!fp)
  11576. {
  11577. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11578. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11579. }
  11580. else
  11581. {
  11582. while(fscanf(fp, "%s", dataLine) != EOF)
  11583. {
  11584. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11585. {
  11586. profileQuantity += 1;
  11587. }
  11588. }
  11589. }
  11590. fclose(fp);
  11591. }
  11592. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11593. {
  11594. FILE *fp;
  11595. char dataLine[4096]={0};
  11596. char filename[128]={0};
  11597. int tmpProfileQuantity;
  11598. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11599. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11600. {
  11601. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11602. DEBUG_WARN("Profile connector id is over max gun number.\n");
  11603. goto end;
  11604. }
  11605. if(SetProfileReq.ConnectorId == 0)
  11606. {
  11607. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11608. {
  11609. tmpProfileQuantity = 0;
  11610. memset(filename, 0, ARRAY_SIZE(filename));
  11611. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11612. fp = fopen(filename, "r");
  11613. if (!fp)
  11614. {
  11615. DEBUG_INFO("%s does not create.\n", filename);
  11616. fp = fopen(filename, "w+");
  11617. }
  11618. else
  11619. {
  11620. while(fscanf(fp, "%s", dataLine) != EOF)
  11621. {
  11622. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11623. {
  11624. tmpProfileQuantity += 1;
  11625. }
  11626. }
  11627. }
  11628. fclose(fp);
  11629. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11630. }
  11631. }
  11632. else
  11633. {
  11634. memset(filename, 0, ARRAY_SIZE(filename));
  11635. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11636. fp = fopen(filename, "r");
  11637. if (!fp)
  11638. {
  11639. DEBUG_INFO("%s does not create.\n", filename);
  11640. fp = fopen(filename, "w+");
  11641. }
  11642. else
  11643. {
  11644. while(fscanf(fp, "%s", dataLine) != EOF)
  11645. {
  11646. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11647. {
  11648. profileQuantity += 1;
  11649. }
  11650. }
  11651. }
  11652. fclose(fp);
  11653. }
  11654. }
  11655. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11656. {
  11657. int isMatchTransactiodId= FALSE;
  11658. FILE *fp;
  11659. char dataLine[4096]={0};
  11660. char filename[128]={0};
  11661. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11662. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11663. if(SetProfileReq.ConnectorId == 0)
  11664. {
  11665. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11666. DEBUG_WARN("Profile connector id is 0.\n");
  11667. goto end;
  11668. }
  11669. int tempIndex = 0;
  11670. //check Transaction active
  11671. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11672. {
  11673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11674. {
  11675. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11676. }
  11677. else
  11678. {
  11679. tempIndex = SetProfileReq.ConnectorId -1;
  11680. }
  11681. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11682. {
  11683. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11684. {
  11685. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11686. {
  11687. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11688. {
  11689. isMatchTransactiodId = TRUE;
  11690. break;
  11691. }
  11692. }
  11693. }
  11694. }
  11695. }
  11696. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11697. {
  11698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11699. {
  11700. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11701. }
  11702. else
  11703. {
  11704. tempIndex = SetProfileReq.ConnectorId -1;
  11705. }
  11706. for (int index = 0; index < CCS_QUANTITY; index++)
  11707. {
  11708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11709. {
  11710. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11711. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11712. {
  11713. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11714. {
  11715. isMatchTransactiodId = TRUE;
  11716. break;
  11717. }
  11718. }
  11719. }
  11720. }
  11721. }
  11722. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11723. {
  11724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11725. {
  11726. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11727. }
  11728. else
  11729. {
  11730. tempIndex = SetProfileReq.ConnectorId -1;
  11731. }
  11732. for (int index = 0; index < GB_QUANTITY; index++)
  11733. {
  11734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11735. {
  11736. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11737. {
  11738. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11739. {
  11740. isMatchTransactiodId = TRUE;
  11741. break;
  11742. }
  11743. }
  11744. }
  11745. }
  11746. }
  11747. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11748. {
  11749. tempIndex = SetProfileReq.ConnectorId -1;
  11750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11751. {
  11752. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11753. {
  11754. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11755. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11756. {
  11757. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11758. {
  11759. isMatchTransactiodId = TRUE;
  11760. break;
  11761. }
  11762. }
  11763. }
  11764. }
  11765. }
  11766. else
  11767. {
  11768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11769. {
  11770. tempIndex = 2;
  11771. }
  11772. else
  11773. {
  11774. tempIndex = (SetProfileReq.ConnectorId -1);
  11775. }
  11776. for (int index = 0; index < AC_QUANTITY; index++)
  11777. {
  11778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11779. {
  11780. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11781. {
  11782. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11783. {
  11784. isMatchTransactiodId = TRUE;
  11785. break;
  11786. }
  11787. }
  11788. }
  11789. }
  11790. }
  11791. //check Transaction active
  11792. if(isMatchTransactiodId == FALSE)
  11793. {
  11794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11795. DEBUG_WARN("Tx profile transaction id is not match.\n");
  11796. goto end;
  11797. }
  11798. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11799. {
  11800. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11801. DEBUG_WARN("Connector id is over max gun number.\n");
  11802. goto end;
  11803. }
  11804. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11805. fp = fopen(filename, "r");
  11806. if (!fp)
  11807. {
  11808. DEBUG_INFO("%s does not create.\n", filename);
  11809. fp = fopen(filename, "w+");
  11810. }
  11811. else
  11812. {
  11813. //Check Charging Profile Count
  11814. while(fscanf(fp, "%s", dataLine) != EOF)
  11815. {
  11816. //DEBUG_INFO("word=%s\n",word);
  11817. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11818. {
  11819. profileQuantity += 1;
  11820. }
  11821. }
  11822. }
  11823. fclose(fp);
  11824. }
  11825. // Check ChargeProfileMaxStackLevel
  11826. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11827. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11828. {
  11829. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11830. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11831. goto end;
  11832. }
  11833. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11834. {
  11835. FILE *fp;
  11836. char dataLine[4096]={0};
  11837. char fnametemp[128]={0};
  11838. int tmpProfileQuantity;
  11839. //Check ChargePointMaxProfile.json exit
  11840. profileQuantity = 0;
  11841. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11842. {
  11843. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11844. //Check Charging Profile Count
  11845. tmpProfileQuantity = 0;
  11846. while(fscanf(fp, "%s", dataLine) != EOF)
  11847. {
  11848. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11849. {
  11850. profileQuantity += 1;
  11851. tmpProfileQuantity += 1;
  11852. }
  11853. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11854. }
  11855. fclose(fp);
  11856. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11857. }
  11858. //Check TxDefaultProfile_%d.json
  11859. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11860. {
  11861. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11862. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11863. if((access(fnametemp,F_OK))!=-1)
  11864. {
  11865. fp = fopen(fnametemp, "r");
  11866. //Check Charging Profile Count
  11867. tmpProfileQuantity = 0;
  11868. while(fscanf(fp, "%s", dataLine) != EOF)
  11869. {
  11870. //DEBUG_INFO("word=%s\n",word);
  11871. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11872. {
  11873. profileQuantity += 1;
  11874. tmpProfileQuantity += 1;
  11875. }
  11876. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11877. }
  11878. fclose(fp);
  11879. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11880. }
  11881. }
  11882. //Check TxProfile_%d.json
  11883. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11884. {
  11885. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11886. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  11887. if((access(fnametemp,F_OK))!=-1)
  11888. {
  11889. fp = fopen(fnametemp, "r");
  11890. //Check Charging Profile Count
  11891. tmpProfileQuantity = 0;
  11892. while(fscanf(fp, "%s", dataLine) != EOF)
  11893. {
  11894. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11895. {
  11896. profileQuantity += 1;
  11897. tmpProfileQuantity += 1;
  11898. }
  11899. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11900. }
  11901. fclose(fp);
  11902. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11903. }
  11904. }
  11905. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11906. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11907. {
  11908. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11909. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11910. goto end;
  11911. }
  11912. }
  11913. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11914. //**********************************Write to File********************************************************/
  11915. {
  11916. FILE *infile;
  11917. FILE *outfile;
  11918. char dataLine[4096]={0};
  11919. char filename[128]={0};
  11920. int chkChar=0;
  11921. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11922. {
  11923. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11924. {
  11925. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11926. }
  11927. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11928. {
  11929. if(SetProfileReq.ConnectorId==0)
  11930. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11931. else
  11932. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11933. }
  11934. else
  11935. {
  11936. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11937. }
  11938. infile = fopen (filename, "r");
  11939. outfile = fopen (tempfile, "w");
  11940. chkChar = fgetc(infile);
  11941. rewind(infile);
  11942. if(chkChar == EOF)
  11943. {
  11944. // Profile is empty
  11945. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11946. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11947. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11948. fclose(infile);
  11949. fclose(outfile);
  11950. sprintf(rmFileCmd,"rm -f %s",filename);
  11951. system(rmFileCmd);
  11952. rename(tempfile, filename);
  11953. }
  11954. else
  11955. {
  11956. // Profile is not empty
  11957. int ChargingProfileAdded = FALSE;
  11958. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11959. {
  11960. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11961. json_object *tmpChargingProfile;
  11962. tmpChargingProfile = json_tokener_parse(dataLine);
  11963. if(!is_error(SetChargingProfile))
  11964. {
  11965. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11966. {
  11967. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11968. {
  11969. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11970. }
  11971. }
  11972. }
  11973. json_object_put(tmpChargingProfile);
  11974. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11975. {
  11976. if(ChargingProfileAdded == FALSE)
  11977. {
  11978. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11979. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11980. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11981. ChargingProfileAdded = TRUE;
  11982. }
  11983. }
  11984. else
  11985. {
  11986. fprintf(outfile,"%s\n",dataLine);
  11987. if(ChargingProfileAdded == FALSE)
  11988. {
  11989. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11990. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11991. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11992. ChargingProfileAdded = TRUE;
  11993. }
  11994. }
  11995. } // end of while loop
  11996. fclose(infile);
  11997. fclose(outfile);
  11998. sprintf(rmFileCmd,"rm -f %s",filename);
  11999. system(rmFileCmd);
  12000. rename(tempfile, filename);
  12001. }
  12002. }
  12003. sleep(1);
  12004. result = TRUE;
  12005. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12006. }
  12007. end:
  12008. json_object_put(SetChargingProfile);
  12009. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12010. {
  12011. if(SetProfileReq.ConnectorId == 0)
  12012. {
  12013. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12014. {
  12015. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12016. }
  12017. }
  12018. else
  12019. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12020. }
  12021. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12022. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12023. return result;
  12024. }
  12025. int handleTriggerMessageRequest(char *uuid, char *payload)
  12026. {
  12027. mtrace();
  12028. int result = FAIL;
  12029. int connectorIdIsNULL = FALSE;
  12030. int connectorIdInt =0;
  12031. char sstr[40]={0},sstrtemp[100]={ 0 };
  12032. char requestedMessagestr[40]={0};
  12033. char comfirmstr[20]={0};
  12034. int c = 0;
  12035. char *loc;
  12036. DEBUG_INFO("handleTriggerMessageRequest\n");
  12037. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12038. strcpy(sstrtemp, stringtrimspace(payload));
  12039. c = 0;
  12040. loc = strstr(sstrtemp, "requestedMessage");
  12041. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12042. {
  12043. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12044. c++;
  12045. }
  12046. sstr[c] = '\0';
  12047. strcpy(requestedMessagestr, sstr);
  12048. c = 0;
  12049. loc = strstr(sstrtemp, "connectorId");
  12050. if(loc == NULL)
  12051. {
  12052. connectorIdIsNULL = TRUE;
  12053. }
  12054. else
  12055. {
  12056. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12057. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12058. {
  12059. sstr[c] = loc[strlen("connectorId")+2+c];
  12060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12061. c++;
  12062. }
  12063. sstr[c] = '\0';
  12064. connectorIdInt = atoi(sstr);
  12065. }
  12066. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12067. {
  12068. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12069. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12070. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12071. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12072. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12073. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12074. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12075. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12076. {
  12077. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12078. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12079. return TRUE;
  12080. }
  12081. else
  12082. {
  12083. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12084. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12085. }
  12086. }
  12087. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12088. {
  12089. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12090. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12091. return TRUE;
  12092. }
  12093. //==========================
  12094. // Trigger message
  12095. //==========================
  12096. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12097. {
  12098. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12099. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12100. {
  12101. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12102. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12103. }
  12104. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12105. }
  12106. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12107. {
  12108. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12109. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12110. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12111. }
  12112. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12113. {
  12114. //sendBootNotificationRequest();
  12115. server_sign = FALSE;
  12116. }
  12117. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12118. {
  12119. refreshStartTimer(&clientTime.Heartbeat);
  12120. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12121. }
  12122. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12123. {
  12124. if(connectorIdIsNULL == FALSE)
  12125. {
  12126. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12127. {
  12128. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12129. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12130. }
  12131. }
  12132. else
  12133. {
  12134. for(int idx=0;idx< gunTotalNumber;idx++)
  12135. {
  12136. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12137. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12138. }
  12139. }
  12140. }
  12141. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12142. {
  12143. if(connectorIdIsNULL == FALSE)
  12144. {
  12145. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12146. {
  12147. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12148. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12149. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12150. }
  12151. }
  12152. else
  12153. {
  12154. for(int idx=0;idx< gunTotalNumber;idx++)
  12155. {
  12156. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12157. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12158. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12159. }
  12160. }
  12161. }
  12162. return result;
  12163. }
  12164. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12165. {
  12166. mtrace();
  12167. int result = FAIL;
  12168. int connectorIdInt =0;
  12169. char comfirmstr[20]={0};
  12170. int tempIndex = 0;
  12171. json_object *UnlockConnector;
  12172. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12173. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12174. UnlockConnector = json_tokener_parse(payload);
  12175. if(!is_error(UnlockConnector))
  12176. {
  12177. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12178. {
  12179. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12180. }
  12181. }
  12182. json_object_put(UnlockConnector);
  12183. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12184. if(gunTotalNumber == 0)
  12185. {
  12186. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12187. goto end;
  12188. }
  12189. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12190. {
  12191. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12192. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12193. goto end;
  12194. }
  12195. else
  12196. {
  12197. //check Transaction active
  12198. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12199. {
  12200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12201. {
  12202. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12203. }
  12204. else
  12205. {
  12206. tempIndex = connectorIdInt -1;
  12207. }
  12208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12209. {
  12210. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12211. {
  12212. //stop Transaction
  12213. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12214. }
  12215. }
  12216. }
  12217. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12218. {
  12219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12220. {
  12221. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12222. }
  12223. else
  12224. {
  12225. tempIndex = connectorIdInt -1;
  12226. }
  12227. for (int index = 0; index < CCS_QUANTITY; index++)
  12228. {
  12229. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12230. {
  12231. //stop Transaction
  12232. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12233. }
  12234. }
  12235. }
  12236. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12237. {
  12238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12239. {
  12240. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12241. }
  12242. else
  12243. {
  12244. tempIndex = connectorIdInt -1;
  12245. }
  12246. for (int index = 0; index < GB_QUANTITY; index++)
  12247. {
  12248. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12249. {
  12250. //stop Transaction
  12251. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12252. }
  12253. }
  12254. }
  12255. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12256. {
  12257. tempIndex = connectorIdInt -1;
  12258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12259. {
  12260. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12261. {
  12262. //stop Transaction
  12263. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12264. }
  12265. }
  12266. }
  12267. else
  12268. {
  12269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12270. {
  12271. tempIndex = 2;
  12272. }
  12273. else
  12274. {
  12275. tempIndex = connectorIdInt-1;
  12276. }
  12277. for (int index = 0; index < AC_QUANTITY; index++)
  12278. {
  12279. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12280. {
  12281. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12282. }
  12283. }
  12284. }
  12285. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12286. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12287. result = TRUE;
  12288. return result;
  12289. }
  12290. end:
  12291. //json_object_put(obj); --- remove temporally
  12292. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12293. return result;
  12294. }
  12295. static char UpdateFirmwarepayloadData[300]={0};
  12296. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12297. {
  12298. mtrace();
  12299. int result = FAIL;
  12300. pthread_t t;
  12301. sendUpdateFirmwareConfirmation(uuid);
  12302. memset(UpdateFirmwarepayloadData, 0, 300);
  12303. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12304. if(!interLock.isUpdateFirmwareGoing)
  12305. {
  12306. interLock.isUpdateFirmwareGoing = 1;
  12307. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12308. sleep(1);
  12309. }
  12310. else
  12311. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12312. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12313. return result;
  12314. }
  12315. void *UpdateFirmwareProcess(void *data)
  12316. {
  12317. pthread_detach(pthread_self());
  12318. mtrace();
  12319. int retriesInt =0, retryIntervalInt=0;
  12320. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12321. int port=0;
  12322. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12323. int isSuccess = 0;
  12324. char ftpbuf[1024];
  12325. char temp[1024];
  12326. char * pch;
  12327. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12328. json_object *UpdateFirmware;
  12329. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12330. if(!is_error(UpdateFirmware))
  12331. {
  12332. // Required data
  12333. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12334. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12335. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12336. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12337. // Optional data
  12338. if(json_object_object_get(UpdateFirmware, "retries"))
  12339. {
  12340. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12341. }
  12342. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12343. {
  12344. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12345. }
  12346. }
  12347. json_object_put(UpdateFirmware);
  12348. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12349. memset(path, 0, ARRAY_SIZE(path));
  12350. // Wait retrieveData
  12351. if(strlen(retrieveDatestr) > 10)
  12352. {
  12353. do
  12354. {
  12355. sleep(1);
  12356. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12357. }
  12358. // Ready to download
  12359. system("rm -f /mnt/*");
  12360. if(strncmp(locationstr,"http", 4) == 0)
  12361. {
  12362. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12363. sprintf(ftppath,"/%s", path);
  12364. DEBUG_INFO("locationstr: %s\n", locationstr);
  12365. DEBUG_INFO("protocol: %s\n",protocol);
  12366. DEBUG_INFO("host: %s\n",host);
  12367. DEBUG_INFO("path: %s\n",path);
  12368. DEBUG_INFO("ftppath: %s\n",ftppath);
  12369. int ftppathlen=strlen(ftppath);
  12370. int i=1;
  12371. char filenametemp[50];
  12372. while(i < ftppathlen)
  12373. {
  12374. int len=ftppathlen-i;
  12375. if(ftppath[len]== 47) // '/' ascll code: 47
  12376. {
  12377. DEBUG_INFO("compare '/' all right\n");
  12378. break;
  12379. }
  12380. i=i+1;
  12381. }
  12382. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12383. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12384. filenametemp[i+1] = 0;
  12385. do
  12386. {
  12387. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12388. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12389. sleep(1);
  12390. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12391. if(!isSuccess)
  12392. {
  12393. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12394. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12395. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12396. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12397. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12398. }
  12399. else
  12400. {
  12401. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12402. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12403. }
  12404. retriesInt--;
  12405. }while((isSuccess == 0)&&(retriesInt >= 0));
  12406. }
  12407. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12408. {
  12409. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12410. memset(temp, 0, ARRAY_SIZE(temp));
  12411. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12412. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12413. int ftppathlen=strlen(ftpbuf);
  12414. int i=1;
  12415. char filenametemp[50];
  12416. while(i < ftppathlen)
  12417. {
  12418. int len=ftppathlen-i;
  12419. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12420. {
  12421. DEBUG_INFO(" compare '/' all right\n");
  12422. break;
  12423. }
  12424. i=i+1;
  12425. }
  12426. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12427. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12428. filenametemp[i+1] = 0;
  12429. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12430. pch=strchr(temp,'@');
  12431. if(pch==NULL)
  12432. {
  12433. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12434. protocol, host, &port, path);
  12435. strcpy(user,"anonymous");
  12436. strcpy(password,"");
  12437. }
  12438. else
  12439. {
  12440. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12441. protocol, user, password, host, &port, path);
  12442. }
  12443. sscanf(host,"%[^/]%s",host1, path1);
  12444. sprintf(ftppath,"%s", path1);
  12445. //DEBUG_INFO("protocol =%s\n",protocol);
  12446. //DEBUG_INFO("user =%s\n",user);
  12447. //DEBUG_INFO("password =%s\n",password);
  12448. //DEBUG_INFO("host1 =%s\n",host1);
  12449. //DEBUG_INFO("port =%d\n",port);
  12450. //DEBUG_INFO("path1 =%s\n",path1);
  12451. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12452. //ftpFile(host, user, password, port, ftppath, fname);
  12453. //download firmware pthred
  12454. if(port == 0)
  12455. {
  12456. port = 21;
  12457. }
  12458. do
  12459. {
  12460. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12461. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12462. sleep(1);
  12463. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12464. if(!isSuccess)
  12465. {
  12466. //BulldogUtil.sleepMs(interval*1000);
  12467. DEBUG_INFO("Update firmware request and download file fail.\n");
  12468. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12469. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12470. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12471. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12472. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12473. }
  12474. else
  12475. {
  12476. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12477. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12478. }
  12479. retriesInt--;
  12480. }while((!isSuccess)&&(retriesInt >= 0));
  12481. }
  12482. else
  12483. {
  12484. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12485. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12486. sleep(1);
  12487. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12488. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12489. }
  12490. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12491. interLock.isUpdateFirmwareGoing = 0;
  12492. pthread_exit(NULL);
  12493. }
  12494. int handleCertificateSignedRequest(char *uuid, char *payload)
  12495. {
  12496. mtrace();
  12497. int result = PASS;
  12498. json_object *CertificateSigned;
  12499. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12500. CertificateSigned = json_tokener_parse(payload);
  12501. if(!is_error(CertificateSigned))
  12502. {
  12503. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12504. }
  12505. json_object_put(CertificateSigned);
  12506. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12507. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12508. fclose(fp);
  12509. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12510. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12511. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12512. sendCertificateSignedConfirmation(uuid);
  12513. return result;
  12514. }
  12515. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12516. {
  12517. mtrace();
  12518. int result = PASS;
  12519. json_object *DeleteCertificate;
  12520. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12521. DeleteCertificate = json_tokener_parse(payload);
  12522. if(!is_error(DeleteCertificate))
  12523. {
  12524. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12525. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12526. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12527. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12528. }
  12529. json_object_put(DeleteCertificate);
  12530. /*
  12531. * TODO: Delete certificateSigned process
  12532. */
  12533. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12534. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12535. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12536. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12537. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12538. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12539. sendDeleteCertificateConfirmation(uuid);
  12540. return result;
  12541. }
  12542. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12543. {
  12544. mtrace();
  12545. int result = PASS;
  12546. json_object *ExtendedTriggerMessage;
  12547. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12548. ExtendedTriggerMessage = json_tokener_parse(payload);
  12549. if(!is_error(ExtendedTriggerMessage))
  12550. {
  12551. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12552. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12553. {
  12554. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12555. }
  12556. else
  12557. {
  12558. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12559. }
  12560. }
  12561. json_object_put(ExtendedTriggerMessage);
  12562. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12563. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12564. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12565. {
  12566. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12567. }
  12568. else
  12569. {
  12570. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12571. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12572. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12573. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12574. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12575. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12576. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12577. {
  12578. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12579. }
  12580. else
  12581. {
  12582. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12583. }
  12584. }
  12585. sendExtendedTriggerMessageConfirmation(uuid);
  12586. //==========================
  12587. // Trigger message
  12588. //==========================
  12589. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12590. {
  12591. //sendBootNotificationRequest();
  12592. server_sign = FALSE;
  12593. }
  12594. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12595. {
  12596. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  12597. }
  12598. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12599. {
  12600. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12601. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12602. {
  12603. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12604. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12605. }
  12606. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12607. }
  12608. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12609. {
  12610. refreshStartTimer(&clientTime.Heartbeat);
  12611. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12612. }
  12613. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12614. {
  12615. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12616. {
  12617. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12618. }
  12619. else
  12620. {
  12621. for(int idx=0;idx< gunTotalNumber;idx++)
  12622. {
  12623. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12624. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12625. }
  12626. }
  12627. }
  12628. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12629. {
  12630. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  12631. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  12632. {
  12633. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  12634. }
  12635. }
  12636. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12637. {
  12638. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12639. {
  12640. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12641. }
  12642. else
  12643. {
  12644. for(int idx=0;idx< gunTotalNumber;idx++)
  12645. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12646. }
  12647. }
  12648. return result;
  12649. }
  12650. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12651. {
  12652. mtrace();
  12653. int result = PASS;
  12654. json_object *GetInstalledCertificateIds;
  12655. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12656. GetInstalledCertificateIds = json_tokener_parse(payload);
  12657. if(!is_error(GetInstalledCertificateIds))
  12658. {
  12659. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12660. }
  12661. json_object_put(GetInstalledCertificateIds);
  12662. /*
  12663. * TODO: Return installed certificate process
  12664. */
  12665. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12666. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  12667. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12668. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  12669. sendGetInstalledCertificateIdsConfirmation(uuid);
  12670. return result;
  12671. }
  12672. int handleGetLogRequest(char *uuid, char *payload)
  12673. {
  12674. mtrace();
  12675. int result = PASS;
  12676. json_object *GetLog;
  12677. DEBUG_INFO("handleGetLogRequest...\n");
  12678. GetLog = json_tokener_parse(payload);
  12679. if(!is_error(GetLog))
  12680. {
  12681. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12682. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12683. if(json_object_object_get(GetLog, "retries") != NULL)
  12684. {
  12685. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12686. }
  12687. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12688. {
  12689. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12690. }
  12691. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12692. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12693. {
  12694. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12695. }
  12696. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12697. {
  12698. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12699. }
  12700. }
  12701. json_object_put(GetLog);
  12702. /*
  12703. * TODO: Upload log process
  12704. */
  12705. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12706. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12707. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12708. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12709. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12710. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12711. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12712. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12713. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12714. sendGetLogConfirmation(uuid);
  12715. return result;
  12716. }
  12717. int handleInstallCertificateRequest(char *uuid, char *payload)
  12718. {
  12719. mtrace();
  12720. int result = PASS;
  12721. json_object *InstallCertificate;
  12722. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12723. InstallCertificate = json_tokener_parse(payload);
  12724. if(!is_error(InstallCertificate))
  12725. {
  12726. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12727. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12728. /*
  12729. * TODO: Install certificate process
  12730. */
  12731. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12732. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12733. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12734. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12735. sendInstallCertificateConfirmation(uuid);
  12736. }
  12737. json_object_put(InstallCertificate);
  12738. return result;
  12739. }
  12740. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12741. {
  12742. mtrace();
  12743. int result = PASS;
  12744. json_object *SignedUpdateFirmware;
  12745. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12746. SignedUpdateFirmware = json_tokener_parse(payload);
  12747. if(!is_error(SignedUpdateFirmware))
  12748. {
  12749. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12750. {
  12751. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12752. }
  12753. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12754. {
  12755. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12756. }
  12757. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12758. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12759. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12760. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12761. {
  12762. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12763. }
  12764. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12765. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12766. }
  12767. json_object_put(SignedUpdateFirmware);
  12768. /*
  12769. * TODO: Upgrade firmware process
  12770. */
  12771. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12772. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12773. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12774. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12775. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12776. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12777. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12778. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12779. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12780. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12781. sendInstallCertificateConfirmation(uuid);
  12782. return result;
  12783. }
  12784. int handleUnknownRequest(char *uuid, char *payload)
  12785. {
  12786. mtrace();
  12787. int result = PASS;
  12788. DEBUG_INFO("handleUnknownRequest...\n");
  12789. sendUnknownConfirmation(uuid);
  12790. result = PASS;
  12791. return result;
  12792. }
  12793. //==========================================
  12794. // Handle server response routine
  12795. //==========================================
  12796. void handleAuthorizeResponse(char *payload, int gun_index)
  12797. {
  12798. mtrace();
  12799. char expiryDatestr[30]={0};
  12800. char parentIdTagstr[20]={0};
  12801. char statusstr[20]={0};
  12802. int expiryDateISNULL=FALSE;
  12803. int parentIdTagISNULL=FALSE;
  12804. DEBUG_INFO("handleAuthorizeResponse...\n");
  12805. json_object *Authorize;
  12806. Authorize = json_tokener_parse(payload);
  12807. if(!is_error(Authorize))
  12808. {
  12809. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12810. {
  12811. // Required data
  12812. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12813. // Optional data
  12814. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12815. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12816. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12817. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12818. }
  12819. }
  12820. json_object_put(Authorize);
  12821. if(expiryDateISNULL == FALSE)
  12822. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12823. if(parentIdTagISNULL == FALSE)
  12824. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12825. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12826. //Update idTag information to authorization cache if supproted
  12827. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12828. {
  12829. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12830. }
  12831. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12832. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12833. authorizeRetryTimes = 0;
  12834. }
  12835. void handleBootNotificationResponse(char *payload, int gun_index)
  12836. {
  12837. mtrace();
  12838. char statusStr[12]={0};
  12839. char currentTimeStr[30]={0};
  12840. int intervalInt = 0;
  12841. DEBUG_INFO("handleBootNotificationResponse...\n");
  12842. json_object *BootNotification;
  12843. BootNotification = json_tokener_parse(payload);
  12844. if(!is_error(BootNotification))
  12845. {
  12846. // Required data
  12847. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12848. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12849. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12850. }
  12851. json_object_put(BootNotification);
  12852. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12853. BootNotificationInterval = intervalInt;
  12854. HeartBeatWaitTime = intervalInt;
  12855. //write back to ShmOCPP16Data->BootNotification
  12856. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12857. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12858. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12859. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12860. {
  12861. server_sign = TRUE;
  12862. server_pending =FALSE;
  12863. }
  12864. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12865. {
  12866. server_pending = TRUE;
  12867. }
  12868. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12869. srand(time(NULL));
  12870. refreshStartTimer(&clientTime.Heartbeat);
  12871. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12872. SetOcppConnStatus(TRUE);
  12873. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12874. }
  12875. void handleDataTransferResponse(char *payload, int gun_index)
  12876. {
  12877. char sstr[160]={0};//sstr[200]={ 0 };
  12878. int c = 0;
  12879. char *loc;
  12880. DEBUG_INFO("handleDataTransferResponse ...\n");
  12881. loc = strstr(payload, "status");
  12882. c = 0;
  12883. while (loc[3+strlen("status")+c] != '\"')
  12884. {
  12885. sstr[c] = loc[3+strlen("status")+c];
  12886. c++;
  12887. }
  12888. sstr[c] = '\0';
  12889. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12890. }
  12891. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12892. {
  12893. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12894. //struct json_object *obj;
  12895. // obj = json_tokener_parse(payload);
  12896. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12897. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12898. //No fields are defined.
  12899. }
  12900. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12901. {
  12902. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12903. //struct json_object *obj;
  12904. // obj = json_tokener_parse(payload);
  12905. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12906. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12907. //No fields are defined.
  12908. }
  12909. void handleHeartbeatResponse(char *payload, int gun_index)
  12910. {
  12911. mtrace();
  12912. DEBUG_INFO("handleHeartbeatResponse...\n");
  12913. json_object *Heartbeat;
  12914. Heartbeat = json_tokener_parse(payload);
  12915. if(!is_error(Heartbeat))
  12916. {
  12917. // Required data
  12918. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12919. }
  12920. json_object_put(Heartbeat);
  12921. if(FirstHeartBeat == 0)
  12922. {
  12923. FirstHeartBeat = 1;
  12924. DEBUG_INFO("FirstHeartBeat \n");
  12925. }
  12926. HeartBeatWithNOResponse = 0;
  12927. refreshStartTimer(&clientTime.Heartbeat);
  12928. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12929. }
  12930. void handleMeterValuesResponse(char *payload, int gun_index)
  12931. {
  12932. mtrace();
  12933. DEBUG_INFO("handleMeterValuesResponse...\n");
  12934. isQueueSendable = 1;
  12935. }
  12936. void handleStartTransactionResponse(char *payload, int gun_index)
  12937. {
  12938. mtrace();
  12939. //int transactionIdInt = 0;
  12940. FILE *outfile;
  12941. char data[100]={0};
  12942. DEBUG_INFO("handleStartTransactionResponse...\n");
  12943. json_object *StartTransaction;
  12944. StartTransaction = json_tokener_parse(payload);
  12945. if(!is_error(StartTransaction))
  12946. {
  12947. // Required data
  12948. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12949. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12950. // Optional data
  12951. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12952. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12953. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12954. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12955. }
  12956. json_object_put(StartTransaction);
  12957. isQueueSendable = 1;
  12958. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12959. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12960. //-----------Start : write to the Queue TransactionId file -----------------//
  12961. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12962. {}
  12963. else
  12964. {
  12965. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12966. if(log == NULL)
  12967. {
  12968. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12969. return ;
  12970. }
  12971. else
  12972. {
  12973. fclose(log);
  12974. }
  12975. }
  12976. // open file for writing
  12977. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12978. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12979. {
  12980. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12981. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12982. fputs(data, outfile);
  12983. fclose (outfile);
  12984. }
  12985. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12986. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12987. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12988. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12989. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12990. }
  12991. void handleStatusNotificationResponse(char *payload, int gun_index)
  12992. {
  12993. mtrace();
  12994. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12995. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12996. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12997. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12998. }
  12999. void handleStopTransactionnResponse(char *payload, int gun_index)
  13000. {
  13001. mtrace();
  13002. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13003. json_object *StopTransaction;
  13004. StopTransaction = json_tokener_parse(payload);
  13005. if(!is_error(StopTransaction))
  13006. {
  13007. // Optional data
  13008. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13009. {
  13010. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13011. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13012. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13013. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13014. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13015. }
  13016. }
  13017. json_object_put(StopTransaction);
  13018. isQueueSendable = 1;
  13019. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13020. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13021. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13022. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13023. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13024. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13025. }
  13026. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13027. {
  13028. mtrace();
  13029. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13030. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13031. }
  13032. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13033. {
  13034. mtrace();
  13035. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13036. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13037. }
  13038. void handleSignCertificateResponse(char *payload, int gun_index)
  13039. {
  13040. mtrace();
  13041. DEBUG_INFO("handleSignCertificateResponse...\n");
  13042. json_object *SignCertificate;
  13043. SignCertificate = json_tokener_parse(payload);
  13044. if(!is_error(SignCertificate))
  13045. {
  13046. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13047. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13048. }
  13049. json_object_put(SignCertificate);
  13050. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13051. }
  13052. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13053. {
  13054. mtrace();
  13055. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13056. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13057. }
  13058. //==========================================
  13059. // Handle Error routine
  13060. //==========================================
  13061. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13062. {
  13063. mtrace();
  13064. #ifdef SystemLogMessage
  13065. DEBUG_INFO("errorCode: %s\n", errorCode);
  13066. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13067. DEBUG_INFO("errorDetails: %s\n", payload);
  13068. #endif
  13069. }
  13070. //===============================================
  13071. // Common routine
  13072. //===============================================
  13073. int initialConfigurationTable(void)
  13074. {
  13075. //clock_t start_t, end_t, total_t;
  13076. FILE *fp;
  13077. FILE *outfile;
  13078. char str[512]={0};
  13079. char sstr[256]={0};
  13080. int c = 0;
  13081. char *loc;
  13082. int confVersion = 10;
  13083. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13084. //start_t = clock();
  13085. //printf("Starting of the program, start_t = %ld\n", start_t);
  13086. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13087. // Check configuration file size is correct
  13088. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13089. {
  13090. struct stat st;
  13091. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13092. if(st.st_size < 3100)
  13093. {
  13094. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13095. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13096. }
  13097. }
  13098. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13099. {
  13100. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13101. if(outfile == NULL)
  13102. {
  13103. DEBUG_INFO("Error opening file\n");
  13104. return FALSE;
  13105. }
  13106. /*Core Profile*/
  13107. //AllowOfflineTxForUnknownId
  13108. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13112. //AuthorizationCacheEnabled
  13113. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13117. //AuthorizeRemoteTxRequests
  13118. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13122. //BlinkRepeat
  13123. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13127. //ClockAlignedDataInterval
  13128. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13132. //ConnectionTimeOut
  13133. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13137. //GetConfigurationMaxKeys
  13138. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13142. // HeartbeatInterval
  13143. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13147. // LightIntensity
  13148. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13152. // LocalAuthorizeOffline
  13153. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13157. // LocalPreAuthorize
  13158. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13162. // MaxEnergyOnInvalidId
  13163. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13167. // MeterValuesAlignedData
  13168. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13170. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13172. else
  13173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13175. // MeterValuesAlignedDataMaxLength
  13176. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13180. else
  13181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13183. // MeterValuesSampledData
  13184. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13188. else
  13189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13191. // MeterValuesSampledDataMaxLength
  13192. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13196. else
  13197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13199. // MeterValueSampleInterval
  13200. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13204. // MinimumStatusDuration
  13205. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13208. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13210. // NumberOfConnectors
  13211. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13214. {
  13215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13216. }
  13217. else
  13218. {
  13219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13220. }
  13221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13222. // ResetRetries
  13223. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13227. // ConnectorPhaseRotation
  13228. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13232. // ConnectorPhaseRotationMaxLength
  13233. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13237. // StopTransactionOnEVSideDisconnect
  13238. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13242. // StopTransactionOnInvalidId
  13243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13247. // StopTxnAlignedData
  13248. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13252. // StopTxnAlignedDataMaxLength
  13253. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13257. // StopTxnSampledData
  13258. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13262. else
  13263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13265. // StopTxnSampledDataMaxLength
  13266. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13269. {
  13270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13271. }
  13272. else
  13273. {
  13274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13275. }
  13276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13277. // SupportedFeatureProfiles
  13278. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13282. // SupportedFeatureProfilesMaxLength
  13283. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13287. // TransactionMessageAttempts
  13288. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13291. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13293. // TransactionMessageRetryInterval
  13294. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13297. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13299. // UnlockConnectorOnEVSideDisconnect
  13300. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13304. // WebSocketPingInterval
  13305. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13309. // QueueOffLineMeterValues
  13310. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13314. // AuthorizationKey
  13315. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13319. // SecurityProfile
  13320. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13324. // DefaultPrice
  13325. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13329. // CustomDisplayCostAndPrice
  13330. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13334. // CustomIdleFeeAfterStop
  13335. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13339. // TimeOffset
  13340. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13344. // NextTimeOffsetTransitionDateTime
  13345. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13349. // TimeOffsetNextTransition
  13350. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13354. // SystemUptimeSec
  13355. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13359. // FreeVend
  13360. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13364. // Configuration Version
  13365. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13369. //* Local Auth List Management Profile*/
  13370. #if 0
  13371. //For OCTT Test Case
  13372. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13375. #endif
  13376. #if 1
  13377. //LocalAuthListEnabled
  13378. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13382. #endif
  13383. //LocalAuthListMaxLength
  13384. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13388. //SendLocalListMaxLength
  13389. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13393. //ReserveConnectorZeroSupported
  13394. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13398. //* Smart Charging Profile */
  13399. //ChargeProfileMaxStackLevel
  13400. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13404. // ChargingScheduleAllowedChargingRateUnit
  13405. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13409. // ChargingScheduleMaxPeriods
  13410. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13414. // ConnectorSwitch3to1PhaseSupported
  13415. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13419. // MaxChargingProfilesInstalled
  13420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13424. fclose(outfile);
  13425. }
  13426. else
  13427. {
  13428. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13429. char keystr[60]={0};
  13430. char readonlystr[10]={0};
  13431. char valuestr[256]={0};
  13432. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13433. if(fp == NULL) {
  13434. DEBUG_INFO("Error opening file");
  13435. return FALSE;
  13436. }
  13437. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13438. {
  13439. //DEBUG_INFO("Get Configuration \n");
  13440. if(strlen(str) > 0)
  13441. {
  13442. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13443. //*************************key*********************************/
  13444. if(strstr(str, "key") != NULL)
  13445. {
  13446. loc = strstr(str, "key");
  13447. c = 0;
  13448. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13449. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13450. {
  13451. sstr[c] = loc[strlen("key")+3+c];
  13452. c++;
  13453. }
  13454. sstr[c] = '\0';
  13455. strcpy(keystr,sstr);
  13456. }
  13457. //*************************readonly*********************************/
  13458. if(strstr(str, "readonly") != NULL)
  13459. {
  13460. loc = strstr(str, "readonly");
  13461. c = 0;
  13462. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13463. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13464. {
  13465. sstr[c] = loc[strlen("readonly")+2+c];
  13466. c++;
  13467. }
  13468. sstr[c] = '\0';
  13469. strcpy(readonlystr,sstr);
  13470. }
  13471. //*************************value*********************************/
  13472. if(strstr(str, "value") != NULL)
  13473. {
  13474. loc = strstr(str, "value");
  13475. c = 0;
  13476. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13477. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13478. {
  13479. sstr[c] = loc[strlen("value")+3+c];
  13480. c++;
  13481. }
  13482. sstr[c] = '\0';
  13483. strcpy(valuestr,sstr);
  13484. }
  13485. // DEBUG_INFO("keystr=%s\n",keystr);
  13486. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13487. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13488. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13489. {
  13490. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13491. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13493. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13494. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13495. }
  13496. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13497. {
  13498. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13499. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13501. }
  13502. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13503. {
  13504. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13506. }
  13507. if(strcmp(keystr, "BlinkRepeat") == 0)
  13508. {
  13509. //Charger.BlinkRepeat = Integer.parseInt(value);
  13510. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13512. }
  13513. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13514. {
  13515. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13517. }
  13518. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13519. {
  13520. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13522. }
  13523. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13524. {
  13525. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13527. }
  13528. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13529. {
  13530. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13532. HeartBeatWaitTime = atoi(valuestr);
  13533. }
  13534. if(strcmp(keystr, "LightIntensity") == 0)
  13535. {
  13536. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13538. }
  13539. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13540. {
  13541. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13543. }
  13544. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13545. {
  13546. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13548. }
  13549. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13550. {
  13551. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13553. }
  13554. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13555. {
  13556. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13558. }
  13559. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13560. {
  13561. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13563. }
  13564. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13565. {
  13566. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13568. }
  13569. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13570. {
  13571. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13573. }
  13574. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13575. {
  13576. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13578. }
  13579. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13580. {
  13581. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13583. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13584. }
  13585. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13586. {
  13587. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13589. }
  13590. if(strcmp(keystr, "ResetRetries") == 0)
  13591. {
  13592. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13594. }
  13595. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13596. {
  13597. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13599. }
  13600. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13601. {
  13602. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13604. }
  13605. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13606. {
  13607. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13609. }
  13610. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13611. {
  13612. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13614. }
  13615. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13616. {
  13617. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13619. }
  13620. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13621. {
  13622. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13624. }
  13625. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13626. {
  13627. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13629. }
  13630. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13631. {
  13632. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13634. }
  13635. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13636. {
  13637. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13639. }
  13640. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13641. {
  13642. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13644. }
  13645. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13646. {
  13647. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13649. TransactionMessageAttemptsValue = atoi(valuestr);
  13650. }
  13651. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13652. {
  13653. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13655. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13656. }
  13657. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13658. {
  13659. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13661. }
  13662. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13663. {
  13664. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13666. }
  13667. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13668. {
  13669. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13671. }
  13672. if(strcmp(keystr, "AuthorizationKey") == 0)
  13673. {
  13674. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13675. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13677. }
  13678. if(strcmp(keystr, "SecurityProfile") == 0)
  13679. {
  13680. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13682. }
  13683. if(strcmp(keystr, "DefaultPrice") == 0)
  13684. {
  13685. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13687. }
  13688. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13689. {
  13690. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13692. }
  13693. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13694. {
  13695. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13697. }
  13698. if(strcmp(keystr, "TimeOffset") == 0)
  13699. {
  13700. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  13702. }
  13703. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  13704. {
  13705. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  13707. }
  13708. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  13709. {
  13710. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  13712. }
  13713. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13714. {
  13715. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  13717. }
  13718. if(strcmp(keystr, "FreeVend") == 0)
  13719. {
  13720. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13722. }
  13723. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13724. {
  13725. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13727. }
  13728. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13729. {
  13730. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13732. }
  13733. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13734. {
  13735. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13737. }
  13738. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13739. {
  13740. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13742. }
  13743. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13744. {
  13745. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13747. }
  13748. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13749. {
  13750. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13752. }
  13753. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13754. {
  13755. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13757. }
  13758. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13759. {
  13760. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13762. }
  13763. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13764. {
  13765. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13767. }
  13768. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13769. {
  13770. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13772. }
  13773. }
  13774. }
  13775. fclose(fp);
  13776. }
  13777. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13778. {
  13779. return PASS;
  13780. }
  13781. else
  13782. {
  13783. return FAIL;
  13784. }
  13785. }
  13786. void StoreConfigurationTable(void)
  13787. {
  13788. FILE *outfile;
  13789. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13790. if(outfile == NULL)
  13791. {
  13792. DEBUG_INFO("Error opening file");
  13793. return ;
  13794. }
  13795. /*Core Profile*/
  13796. //AllowOfflineTxForUnknownId
  13797. /*
  13798. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13799. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13802. */
  13803. //DEBUG_INFO("data=%s\n",data);
  13804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13805. //AuthorizationCacheEnabled
  13806. /*
  13807. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13810. */
  13811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13812. //AuthorizeRemoteTxRequests
  13813. /*
  13814. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13817. */
  13818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13819. //BlinkRepeat
  13820. /*
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13824. */
  13825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13826. //ClockAlignedDataInterval
  13827. /*
  13828. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13831. */
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13833. //ConnectionTimeOut
  13834. /*
  13835. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13838. */
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13840. //GetConfigurationMaxKeys
  13841. /*
  13842. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13845. */
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13847. // HeartbeatInterval
  13848. /*
  13849. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13852. */
  13853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13854. // LightIntensity
  13855. /*
  13856. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13859. */
  13860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13861. // LocalAuthorizeOffline
  13862. /*
  13863. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13866. */
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13868. // LocalPreAuthorize
  13869. /*
  13870. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13873. */
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13875. // MaxEnergyOnInvalidId
  13876. /*
  13877. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13880. */
  13881. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13883. // MeterValuesAlignedData
  13884. /*
  13885. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13888. */
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13890. // MeterValuesAlignedDataMaxLength
  13891. /*
  13892. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13895. */
  13896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13897. // MeterValuesSampledData
  13898. /*
  13899. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13902. */
  13903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13904. // MeterValuesSampledDataMaxLength
  13905. /*
  13906. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13909. */
  13910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13911. // MeterValueSampleInterval
  13912. /*
  13913. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13916. */
  13917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13918. // MinimumStatusDuration
  13919. /*
  13920. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13923. */
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13925. // NumberOfConnectors
  13926. /*
  13927. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13930. {
  13931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13932. }
  13933. else
  13934. {
  13935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13936. }
  13937. */
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13939. // ResetRetries
  13940. /*
  13941. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13944. */
  13945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13946. // ConnectorPhaseRotation
  13947. /*
  13948. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13951. */
  13952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13953. // ConnectorPhaseRotationMaxLength
  13954. /*
  13955. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13958. */
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13960. // StopTransactionOnEVSideDisconnect
  13961. /*
  13962. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13965. */
  13966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13967. // StopTransactionOnInvalidId
  13968. /*
  13969. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13972. */
  13973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13974. // StopTxnAlignedData
  13975. /*
  13976. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13979. */
  13980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13981. // StopTxnAlignedDataMaxLength
  13982. /*
  13983. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13986. */
  13987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13988. // StopTxnSampledData
  13989. /*
  13990. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13993. */
  13994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13995. // StopTxnSampledDataMaxLength
  13996. /*
  13997. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14000. */
  14001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14002. // SupportedFeatureProfiles
  14003. /*
  14004. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14007. */
  14008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14009. // SupportedFeatureProfilesMaxLength
  14010. /*
  14011. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14014. */
  14015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14016. // TransactionMessageAttempts
  14017. /*
  14018. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14021. */
  14022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14023. // TransactionMessageRetryInterval
  14024. /*
  14025. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14028. */
  14029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14030. // UnlockConnectorOnEVSideDisconnect
  14031. /*
  14032. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14035. */
  14036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14037. // WebSocketPingInterval
  14038. /*
  14039. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14042. */
  14043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14044. // QueueOffLineMeterValues
  14045. /*
  14046. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14049. */
  14050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14051. // AuthorizationKey
  14052. /*
  14053. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14056. */
  14057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14058. // SecurityProfile
  14059. /*
  14060. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14063. */
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14065. // DefaultPrice
  14066. /*
  14067. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14070. */
  14071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14072. // CustomDisplayCostAndPrice
  14073. /*
  14074. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14077. */
  14078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14079. // CustomIdleFeeAfterStop
  14080. /*
  14081. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14084. */
  14085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14086. // TimeOffset
  14087. /*
  14088. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14091. */
  14092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14093. // NextTimeOffsetTransitionDateTime
  14094. /*
  14095. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14098. */
  14099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14100. // TimeOffsetNextTransition
  14101. /*
  14102. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14105. */
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14107. // SystemUptimeSec
  14108. /*
  14109. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14112. */
  14113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14114. // FreeVend
  14115. /*
  14116. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14119. */
  14120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14121. // ConfigurationVersion
  14122. /*
  14123. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14126. */
  14127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14128. //* Local Auth List Management Profile*/
  14129. //LocalAuthListEnabled
  14130. /*
  14131. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14134. */
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14136. //LocalAuthListMaxLength
  14137. /*
  14138. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14141. */
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14143. //SendLocalListMaxLength
  14144. /*
  14145. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14148. */
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14150. //ReserveConnectorZeroSupported
  14151. /*
  14152. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14155. */
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14157. //* Smart Charging Profile */
  14158. //ChargeProfileMaxStackLevel
  14159. /*
  14160. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14163. */
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14165. // ChargingScheduleAllowedChargingRateUnit
  14166. /*
  14167. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14170. */
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14172. // ChargingScheduleMaxPeriods
  14173. /*
  14174. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14177. */
  14178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14179. // ConnectorSwitch3to1PhaseSupported
  14180. /*
  14181. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14184. */
  14185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14186. // MaxChargingProfilesInstalled
  14187. /*
  14188. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14191. */
  14192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14193. fclose(outfile);
  14194. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14195. }
  14196. void getKeyValue(char *keyReq)
  14197. {
  14198. int isEmpty = FALSE;
  14199. int isKnowKey = FALSE;
  14200. DEBUG_INFO("keyReq = %s\n", keyReq);
  14201. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14202. isEmpty = TRUE;
  14203. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14204. {
  14205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14208. {
  14209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14210. }
  14211. else
  14212. {
  14213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14214. }
  14215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14216. isKnowKey = TRUE;
  14217. }
  14218. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14219. {
  14220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14223. {
  14224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14225. }
  14226. else
  14227. {
  14228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14229. }
  14230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14231. isKnowKey = TRUE;
  14232. }
  14233. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14234. {
  14235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14238. {
  14239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14240. }
  14241. else
  14242. {
  14243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14244. }
  14245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14246. isKnowKey = TRUE;
  14247. }
  14248. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14249. {
  14250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14253. {
  14254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14255. }
  14256. else
  14257. {
  14258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14259. }
  14260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14261. isKnowKey = TRUE;
  14262. }
  14263. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14264. {
  14265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14268. {
  14269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14270. }
  14271. else
  14272. {
  14273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14274. }
  14275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14276. isKnowKey = TRUE;
  14277. }
  14278. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14279. {
  14280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14283. {
  14284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14285. }
  14286. else
  14287. {
  14288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14289. }
  14290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14291. isKnowKey = TRUE;
  14292. }
  14293. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14294. {
  14295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14298. {
  14299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14300. }
  14301. else
  14302. {
  14303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14304. }
  14305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14306. isKnowKey = TRUE;
  14307. }
  14308. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14309. {
  14310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14313. {
  14314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14315. }
  14316. else
  14317. {
  14318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14319. }
  14320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14321. isKnowKey = TRUE;
  14322. }
  14323. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14324. {
  14325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14328. {
  14329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14330. }
  14331. else
  14332. {
  14333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14334. }
  14335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14336. isKnowKey = TRUE;
  14337. }
  14338. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14339. {
  14340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14343. {
  14344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14345. }
  14346. else
  14347. {
  14348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14349. }
  14350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14351. isKnowKey = TRUE;
  14352. }
  14353. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14354. {
  14355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14358. {
  14359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14360. }
  14361. else
  14362. {
  14363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14364. }
  14365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14366. isKnowKey = TRUE;
  14367. }
  14368. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14369. {
  14370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14373. {
  14374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14375. }
  14376. else
  14377. {
  14378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14379. }
  14380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14381. isKnowKey = TRUE;
  14382. }
  14383. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14384. {
  14385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14388. {
  14389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14390. }
  14391. else
  14392. {
  14393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14394. }
  14395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14396. isKnowKey = TRUE;
  14397. }
  14398. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14399. {
  14400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14403. {
  14404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14405. }
  14406. else
  14407. {
  14408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14409. }
  14410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14411. isKnowKey = TRUE;
  14412. }
  14413. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14414. {
  14415. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14418. {
  14419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14420. }
  14421. else
  14422. {
  14423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14424. }
  14425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14426. isKnowKey = TRUE;
  14427. }
  14428. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14429. {
  14430. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14433. {
  14434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14435. }
  14436. else
  14437. {
  14438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14439. }
  14440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14441. isKnowKey = TRUE;
  14442. }
  14443. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14444. {
  14445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14448. {
  14449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14450. }
  14451. else
  14452. {
  14453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14454. }
  14455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14456. isKnowKey = TRUE;
  14457. }
  14458. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14459. {
  14460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14463. {
  14464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14465. }
  14466. else
  14467. {
  14468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14469. }
  14470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14471. isKnowKey = TRUE;
  14472. }
  14473. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14474. {
  14475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14478. {
  14479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14480. }
  14481. else
  14482. {
  14483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14484. }
  14485. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14487. isKnowKey = TRUE;
  14488. }
  14489. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14490. {
  14491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14494. {
  14495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14496. }
  14497. else
  14498. {
  14499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14500. }
  14501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14502. isKnowKey = TRUE;
  14503. }
  14504. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14505. {
  14506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14509. {
  14510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14511. }
  14512. else
  14513. {
  14514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14515. }
  14516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14517. isKnowKey = TRUE;
  14518. }
  14519. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14520. {
  14521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14524. {
  14525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14526. }
  14527. else
  14528. {
  14529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14530. }
  14531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14532. isKnowKey = TRUE;
  14533. }
  14534. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14535. {
  14536. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14539. {
  14540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14541. }
  14542. else
  14543. {
  14544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14545. }
  14546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14547. isKnowKey = TRUE;
  14548. }
  14549. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14550. {
  14551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14554. {
  14555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14556. }
  14557. else
  14558. {
  14559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14560. }
  14561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14562. isKnowKey = TRUE;
  14563. }
  14564. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14565. {
  14566. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14569. {
  14570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14571. }
  14572. else
  14573. {
  14574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14575. }
  14576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14577. isKnowKey = TRUE;
  14578. }
  14579. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14580. {
  14581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14584. {
  14585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14586. }
  14587. else
  14588. {
  14589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14590. }
  14591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14592. isKnowKey = TRUE;
  14593. }
  14594. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14595. {
  14596. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14599. {
  14600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14601. }
  14602. else
  14603. {
  14604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14605. }
  14606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14607. isKnowKey = TRUE;
  14608. }
  14609. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14610. {
  14611. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14614. {
  14615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14616. }
  14617. else
  14618. {
  14619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14620. }
  14621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14622. isKnowKey = TRUE;
  14623. }
  14624. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14625. {
  14626. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14629. {
  14630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14631. }
  14632. else
  14633. {
  14634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14635. }
  14636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14637. isKnowKey = TRUE;
  14638. }
  14639. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14640. {
  14641. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14644. {
  14645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14646. }
  14647. else
  14648. {
  14649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14650. }
  14651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14652. isKnowKey = TRUE;
  14653. }
  14654. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14655. {
  14656. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14659. {
  14660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14661. }
  14662. else
  14663. {
  14664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14665. }
  14666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14667. isKnowKey = TRUE;
  14668. }
  14669. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14670. {
  14671. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14674. {
  14675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14676. }
  14677. else
  14678. {
  14679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14680. }
  14681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14682. isKnowKey = TRUE;
  14683. }
  14684. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14685. {
  14686. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14688. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14689. {
  14690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14691. }
  14692. else
  14693. {
  14694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14695. }
  14696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14697. isKnowKey = TRUE;
  14698. }
  14699. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14700. {
  14701. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14704. {
  14705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14706. }
  14707. else
  14708. {
  14709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14710. }
  14711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14712. isKnowKey = TRUE;
  14713. }
  14714. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14715. {
  14716. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14719. {
  14720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14721. }
  14722. else
  14723. {
  14724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14725. }
  14726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14727. isKnowKey = TRUE;
  14728. }
  14729. /*
  14730. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14731. {
  14732. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14735. {
  14736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14737. }
  14738. else
  14739. {
  14740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14741. }
  14742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14743. isKnowKey = TRUE;
  14744. }*/
  14745. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14746. {
  14747. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14750. {
  14751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14752. }
  14753. else
  14754. {
  14755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14756. }
  14757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14758. isKnowKey = TRUE;
  14759. }
  14760. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14761. {
  14762. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14765. {
  14766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14767. }
  14768. else
  14769. {
  14770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14771. }
  14772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14773. isKnowKey = TRUE;
  14774. }
  14775. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14776. {
  14777. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14780. {
  14781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14782. }
  14783. else
  14784. {
  14785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14786. }
  14787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14788. isKnowKey = TRUE;
  14789. }
  14790. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14791. {
  14792. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14795. {
  14796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14797. }
  14798. else
  14799. {
  14800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14801. }
  14802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14803. isKnowKey = TRUE;
  14804. }
  14805. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14806. {
  14807. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14810. {
  14811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14812. }
  14813. else
  14814. {
  14815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14816. }
  14817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14818. isKnowKey = TRUE;
  14819. }
  14820. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14821. {
  14822. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14825. {
  14826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14827. }
  14828. else
  14829. {
  14830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14831. }
  14832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14833. isKnowKey = TRUE;
  14834. }
  14835. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14836. {
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14840. {
  14841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14842. }
  14843. else
  14844. {
  14845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14846. }
  14847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14848. isKnowKey = TRUE;
  14849. }
  14850. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14851. {
  14852. struct sysinfo s_info;
  14853. int error = sysinfo(&s_info);
  14854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14857. {
  14858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14859. }
  14860. else
  14861. {
  14862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14863. }
  14864. if(error != 0)
  14865. {
  14866. DEBUG_WARN("System uptime get error: %d\n", error);
  14867. }
  14868. else
  14869. {
  14870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14871. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14872. }
  14873. isKnowKey = TRUE;
  14874. }
  14875. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14876. {
  14877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14880. {
  14881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14882. }
  14883. else
  14884. {
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14886. }
  14887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  14888. isKnowKey = TRUE;
  14889. }
  14890. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14891. {
  14892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14895. {
  14896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14897. }
  14898. else
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14901. }
  14902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14903. isKnowKey = TRUE;
  14904. }
  14905. #if 1
  14906. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14907. {
  14908. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14910. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14911. {
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14913. }
  14914. else
  14915. {
  14916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14917. }
  14918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14919. isKnowKey = TRUE;
  14920. }
  14921. #endif
  14922. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14923. {
  14924. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14926. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14927. {
  14928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14929. }
  14930. else
  14931. {
  14932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14933. }
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14935. isKnowKey = TRUE;
  14936. }
  14937. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14938. {
  14939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14941. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14942. {
  14943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14944. }
  14945. else
  14946. {
  14947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14948. }
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14950. isKnowKey = TRUE;
  14951. }
  14952. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14953. {
  14954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14956. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14957. {
  14958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14959. }
  14960. else
  14961. {
  14962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14963. }
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14965. isKnowKey = TRUE;
  14966. }
  14967. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14968. {
  14969. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14971. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14972. {
  14973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14974. }
  14975. else
  14976. {
  14977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14978. }
  14979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14980. isKnowKey = TRUE;
  14981. }
  14982. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14983. {
  14984. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14986. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14987. {
  14988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14989. }
  14990. else
  14991. {
  14992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14993. }
  14994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14995. isKnowKey = TRUE;
  14996. }
  14997. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14998. {
  14999. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15001. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15002. {
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15004. }
  15005. else
  15006. {
  15007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15008. }
  15009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15010. isKnowKey = TRUE;
  15011. }
  15012. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15013. {
  15014. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15016. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15017. {
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15019. }
  15020. else
  15021. {
  15022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15023. }
  15024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15025. isKnowKey = TRUE;
  15026. }
  15027. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15028. {
  15029. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15031. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15032. {
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15034. }
  15035. else
  15036. {
  15037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15038. }
  15039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15040. isKnowKey = TRUE;
  15041. }
  15042. //=========================================================
  15043. if(!isEmpty && !isKnowKey)
  15044. {
  15045. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15046. strcpy(unknownkey[UnknownKeynum], keyReq);
  15047. UnknownKeynum = UnknownKeynum + 1;
  15048. }
  15049. }
  15050. void processUnkownKey(void)
  15051. {
  15052. DEBUG_INFO("processUnkownKey...\n");
  15053. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15054. for(int index=0; index < UnknownKeynum; index++)
  15055. {
  15056. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15057. {
  15058. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15059. }
  15060. }
  15061. }
  15062. int setKeyValue(char *key, char *value)
  15063. {
  15064. int isSuccess = NotSupported;
  15065. int check_ascii=0;
  15066. char str[256]={0};
  15067. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15068. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15069. {
  15070. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15072. {
  15073. strcpy(str, (const char*)value);
  15074. for(int i = 0; str[i]; i++){
  15075. str[i] = tolower(str[i]);
  15076. }
  15077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15078. isSuccess = ConfigurationStatus_Accepted;
  15079. }
  15080. else
  15081. {
  15082. isSuccess = ConfigurationStatus_Rejected;
  15083. }
  15084. }
  15085. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15086. {
  15087. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15089. {
  15090. strcpy(str, (const char*)value);
  15091. for(int i = 0; str[i]; i++){
  15092. str[i] = tolower(str[i]);
  15093. }
  15094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15095. isSuccess = ConfigurationStatus_Accepted;
  15096. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15097. }
  15098. else
  15099. {
  15100. isSuccess = ConfigurationStatus_Rejected;
  15101. }
  15102. }
  15103. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15104. {
  15105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15106. {
  15107. strcpy(str, (const char*)value);
  15108. for(int i = 0; str[i]; i++)
  15109. {
  15110. str[i] = tolower(str[i]);
  15111. }
  15112. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15114. isSuccess = ConfigurationStatus_Accepted;
  15115. }
  15116. else
  15117. {
  15118. isSuccess = ConfigurationStatus_Rejected;
  15119. }
  15120. }
  15121. if(strcmp(key, "BlinkRepeat") == 0)
  15122. {
  15123. //Charger.BlinkRepeat = Integer.parseInt(value);
  15124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15125. {
  15126. check_ascii = value[0];
  15127. if( (check_ascii < 48) || (check_ascii > 57) )
  15128. {
  15129. isSuccess = ConfigurationStatus_Rejected;
  15130. }
  15131. else
  15132. {
  15133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15134. isSuccess = ConfigurationStatus_Accepted;
  15135. }
  15136. }
  15137. else
  15138. {
  15139. isSuccess = ConfigurationStatus_Rejected;
  15140. }
  15141. }
  15142. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15143. {
  15144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15145. {
  15146. check_ascii = value[0];
  15147. if( (check_ascii < 48) || (check_ascii > 57) )
  15148. {
  15149. isSuccess = ConfigurationStatus_Rejected;
  15150. }
  15151. else
  15152. {
  15153. if((atoi(value) == 0) || (atoi(value) >= 5))
  15154. {
  15155. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15157. isSuccess = ConfigurationStatus_Accepted;
  15158. }
  15159. else
  15160. isSuccess = ConfigurationStatus_Rejected;
  15161. }
  15162. }
  15163. else
  15164. {
  15165. isSuccess = ConfigurationStatus_Rejected;
  15166. }
  15167. }
  15168. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15169. {
  15170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15171. {
  15172. check_ascii = value[0];
  15173. if( (check_ascii < 48) || (check_ascii > 57) )
  15174. {
  15175. isSuccess = ConfigurationStatus_Rejected;
  15176. }
  15177. else
  15178. {
  15179. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15181. isSuccess = ConfigurationStatus_Accepted;
  15182. }
  15183. }
  15184. else
  15185. {
  15186. isSuccess = ConfigurationStatus_Rejected;
  15187. }
  15188. }
  15189. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15190. {
  15191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15192. {
  15193. check_ascii = value[0];
  15194. if( (check_ascii < 48) || (check_ascii > 57) )
  15195. {
  15196. isSuccess = ConfigurationStatus_Rejected;
  15197. }
  15198. else
  15199. {
  15200. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15202. isSuccess = ConfigurationStatus_Accepted;
  15203. }
  15204. }
  15205. else
  15206. {
  15207. isSuccess = ConfigurationStatus_Rejected;
  15208. }
  15209. }
  15210. if(strcmp(key, "HeartbeatInterval") == 0)
  15211. {
  15212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15213. {
  15214. check_ascii = value[0];
  15215. if( (check_ascii < 48) || (check_ascii > 57) )
  15216. {
  15217. isSuccess = ConfigurationStatus_Rejected;
  15218. }
  15219. else
  15220. {
  15221. if((atoi(value) == 0) || (atoi(value) >= 10))
  15222. {
  15223. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15225. HeartBeatWaitTime = atoi(value);
  15226. isSuccess = ConfigurationStatus_Accepted;
  15227. }
  15228. else
  15229. {
  15230. isSuccess = ConfigurationStatus_Rejected;
  15231. }
  15232. }
  15233. }
  15234. else
  15235. {
  15236. isSuccess = ConfigurationStatus_Rejected;
  15237. }
  15238. }
  15239. if(strcmp(key, "LightIntensity") == 0)
  15240. {
  15241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15242. {
  15243. check_ascii = value[0];
  15244. if( (check_ascii < 48) || (check_ascii > 57) )
  15245. {
  15246. isSuccess = ConfigurationStatus_Rejected;
  15247. }
  15248. else
  15249. {
  15250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15251. isSuccess = ConfigurationStatus_Accepted;
  15252. }
  15253. }
  15254. else
  15255. {
  15256. isSuccess = ConfigurationStatus_Rejected;
  15257. }
  15258. }
  15259. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15260. {
  15261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15262. {
  15263. strcpy(str, (const char*)value);
  15264. for(int i = 0; str[i]; i++)
  15265. {
  15266. str[i] = tolower(str[i]);
  15267. }
  15268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15269. isSuccess = ConfigurationStatus_Accepted;
  15270. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15271. }
  15272. else
  15273. {
  15274. isSuccess = ConfigurationStatus_Rejected;
  15275. }
  15276. }
  15277. if(strcmp(key, "LocalPreAuthorize") == 0)
  15278. {
  15279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15280. {
  15281. strcpy(str, (const char*)value);
  15282. for(int i = 0; str[i]; i++)
  15283. {
  15284. str[i] = tolower(str[i]);
  15285. }
  15286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15287. isSuccess = ConfigurationStatus_Accepted;
  15288. }
  15289. else
  15290. {
  15291. isSuccess = ConfigurationStatus_Rejected;
  15292. }
  15293. }
  15294. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15295. {
  15296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15297. {
  15298. check_ascii = value[0];
  15299. if( (check_ascii < 48) || (check_ascii > 57) )
  15300. {
  15301. isSuccess = ConfigurationStatus_Rejected;
  15302. }
  15303. else
  15304. {
  15305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15306. isSuccess = ConfigurationStatus_Accepted;
  15307. }
  15308. }
  15309. else
  15310. {
  15311. isSuccess = ConfigurationStatus_Rejected;
  15312. }
  15313. }
  15314. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15315. {
  15316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15317. {
  15318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15319. isSuccess = ConfigurationStatus_Accepted;
  15320. }
  15321. else
  15322. {
  15323. isSuccess = ConfigurationStatus_Rejected;
  15324. }
  15325. }
  15326. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15327. {
  15328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15329. {
  15330. check_ascii = value[0];
  15331. if( (check_ascii < 48) || (check_ascii > 57) )
  15332. {
  15333. isSuccess = ConfigurationStatus_Rejected;
  15334. }
  15335. else
  15336. {
  15337. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15339. isSuccess = ConfigurationStatus_Accepted;
  15340. }
  15341. }
  15342. else
  15343. {
  15344. isSuccess = ConfigurationStatus_Rejected;
  15345. }
  15346. }
  15347. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15348. {
  15349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15350. {
  15351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15352. isSuccess = ConfigurationStatus_Accepted;
  15353. }
  15354. else
  15355. {
  15356. isSuccess = ConfigurationStatus_Rejected;
  15357. }
  15358. }
  15359. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15360. {
  15361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15362. {
  15363. check_ascii = value[0];
  15364. if( (check_ascii < 48) || (check_ascii > 57) )
  15365. {
  15366. isSuccess = ConfigurationStatus_Rejected;
  15367. }
  15368. else
  15369. {
  15370. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15372. isSuccess = ConfigurationStatus_Accepted;
  15373. }
  15374. }
  15375. else
  15376. {
  15377. isSuccess = ConfigurationStatus_Rejected;
  15378. }
  15379. }
  15380. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15381. {
  15382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15383. {
  15384. check_ascii = value[0];
  15385. if( (check_ascii < 48) || (check_ascii > 57) )
  15386. {
  15387. isSuccess = ConfigurationStatus_Rejected;
  15388. }
  15389. else
  15390. {
  15391. if((atoi(value) == 0) || (atoi(value) >= 5))
  15392. {
  15393. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15395. isSuccess = ConfigurationStatus_Accepted;
  15396. }
  15397. else
  15398. {
  15399. isSuccess = ConfigurationStatus_Rejected;
  15400. }
  15401. }
  15402. }
  15403. else
  15404. {
  15405. isSuccess = ConfigurationStatus_Rejected;
  15406. }
  15407. }
  15408. if(strcmp(key, "MinimumStatusDuration") == 0)
  15409. {
  15410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15411. {
  15412. check_ascii = value[0];
  15413. if( (check_ascii < 48) || (check_ascii > 57) )
  15414. {
  15415. isSuccess = ConfigurationStatus_Rejected;
  15416. }
  15417. else
  15418. {
  15419. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15420. {
  15421. isSuccess = ConfigurationStatus_Rejected;
  15422. }
  15423. else
  15424. {
  15425. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15427. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15428. isSuccess = ConfigurationStatus_Accepted;
  15429. }
  15430. }
  15431. }
  15432. else
  15433. {
  15434. isSuccess = ConfigurationStatus_Rejected;
  15435. }
  15436. }
  15437. if(strcmp(key, "NumberOfConnectors") == 0)
  15438. {
  15439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15440. {
  15441. check_ascii = value[0];
  15442. if( (check_ascii < 48) || (check_ascii > 57) )
  15443. {
  15444. isSuccess = ConfigurationStatus_Rejected;
  15445. }
  15446. else
  15447. {
  15448. //Charger.ResetRetries = Integer.parseInt(value);
  15449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15450. isSuccess = ConfigurationStatus_Accepted;
  15451. }
  15452. }
  15453. else
  15454. {
  15455. isSuccess = ConfigurationStatus_Rejected;
  15456. }
  15457. }
  15458. if(strcmp(key, "ResetRetries") == 0)
  15459. {
  15460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15461. {
  15462. check_ascii = value[0];
  15463. if( (check_ascii < 48) || (check_ascii > 57) )
  15464. {
  15465. isSuccess = ConfigurationStatus_Rejected;
  15466. }
  15467. else
  15468. {
  15469. //Charger.ResetRetries = Integer.parseInt(value);
  15470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15471. isSuccess = ConfigurationStatus_Accepted;
  15472. }
  15473. }
  15474. else
  15475. {
  15476. isSuccess = ConfigurationStatus_Rejected;
  15477. }
  15478. }
  15479. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15480. {
  15481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15482. {
  15483. strcpy(str, (const char*)value);
  15484. for(int i = 0; str[i]; i++)
  15485. {
  15486. str[i] = tolower(str[i]);
  15487. }
  15488. if(strcmp(str, "notapplicable")== 0)
  15489. {
  15490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15491. isSuccess = ConfigurationStatus_Accepted;
  15492. }
  15493. else if(strcmp(str, "unknown")== 0)
  15494. {
  15495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15496. isSuccess = ConfigurationStatus_Accepted;
  15497. }
  15498. else if(strcmp(str, "rst")== 0)
  15499. {
  15500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15501. isSuccess = ConfigurationStatus_Accepted;
  15502. }
  15503. else if(strcmp(str, "rts")== 0)
  15504. {
  15505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15506. isSuccess = ConfigurationStatus_Accepted;
  15507. }
  15508. else if(strcmp(str, "srt")== 0)
  15509. {
  15510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15511. isSuccess = ConfigurationStatus_Accepted;
  15512. }
  15513. else if(strcmp(str, "str")== 0)
  15514. {
  15515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15516. isSuccess = ConfigurationStatus_Accepted;
  15517. }
  15518. else if(strcmp(str, "trs")== 0)
  15519. {
  15520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15521. isSuccess = ConfigurationStatus_Accepted;
  15522. }
  15523. else if(strcmp(str, "tsr")== 0)
  15524. {
  15525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15526. isSuccess = ConfigurationStatus_Accepted;
  15527. }
  15528. else
  15529. {
  15530. isSuccess = ConfigurationStatus_Rejected;
  15531. }
  15532. }
  15533. else
  15534. {
  15535. isSuccess = ConfigurationStatus_Rejected;
  15536. }
  15537. }
  15538. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15539. {
  15540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15541. {
  15542. check_ascii = value[0];
  15543. if( (check_ascii < 48) || (check_ascii > 57) )
  15544. {
  15545. isSuccess = ConfigurationStatus_Rejected;
  15546. }
  15547. else
  15548. {
  15549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15550. isSuccess = ConfigurationStatus_Accepted;
  15551. }
  15552. }
  15553. else
  15554. {
  15555. isSuccess = ConfigurationStatus_Rejected;
  15556. }
  15557. }
  15558. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15559. {
  15560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15561. {
  15562. strcpy(str, (const char*)value);
  15563. for(int i = 0; str[i]; i++)
  15564. {
  15565. str[i] = tolower(str[i]);
  15566. }
  15567. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15569. isSuccess = ConfigurationStatus_Accepted;
  15570. }
  15571. else
  15572. {
  15573. isSuccess = ConfigurationStatus_Rejected;
  15574. }
  15575. }
  15576. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15577. {
  15578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15579. {
  15580. strcpy(str, (const char*)value);
  15581. for(int i = 0; str[i]; i++)
  15582. {
  15583. str[i] = tolower(str[i]);
  15584. }
  15585. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15587. isSuccess = ConfigurationStatus_Accepted;
  15588. }
  15589. else
  15590. {
  15591. isSuccess = ConfigurationStatus_Rejected;
  15592. }
  15593. }
  15594. if(strcmp(key, "StopTxnAlignedData") == 0)
  15595. {
  15596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15597. {
  15598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15599. isSuccess = ConfigurationStatus_Accepted;
  15600. }
  15601. else
  15602. {
  15603. isSuccess = ConfigurationStatus_Rejected;
  15604. }
  15605. }
  15606. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15607. {
  15608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15609. {
  15610. check_ascii = value[0];
  15611. if( (check_ascii < 48) || (check_ascii > 57) )
  15612. {
  15613. isSuccess = ConfigurationStatus_Rejected;
  15614. }
  15615. else
  15616. {
  15617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15618. isSuccess = ConfigurationStatus_Accepted;
  15619. }
  15620. }
  15621. else
  15622. {
  15623. isSuccess = ConfigurationStatus_Rejected;
  15624. }
  15625. }
  15626. if(strcmp(key, "StopTxnSampledData") == 0)
  15627. {
  15628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15629. {
  15630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15631. isSuccess = ConfigurationStatus_Accepted;
  15632. }
  15633. else
  15634. {
  15635. isSuccess = ConfigurationStatus_Rejected;
  15636. }
  15637. }
  15638. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15639. {
  15640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15641. {
  15642. check_ascii = value[0];
  15643. if( (check_ascii < 48) || (check_ascii > 57) )
  15644. {
  15645. isSuccess = ConfigurationStatus_Rejected;
  15646. }
  15647. else
  15648. {
  15649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15650. isSuccess = ConfigurationStatus_Accepted;
  15651. }
  15652. }
  15653. else
  15654. {
  15655. isSuccess = ConfigurationStatus_Rejected;
  15656. }
  15657. }
  15658. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15659. {
  15660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15661. {
  15662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15663. isSuccess = ConfigurationStatus_Accepted;
  15664. }
  15665. else
  15666. {
  15667. isSuccess = ConfigurationStatus_Rejected;
  15668. }
  15669. }
  15670. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15671. {
  15672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15673. {
  15674. check_ascii = value[0];
  15675. if( (check_ascii < 48) || (check_ascii > 57) )
  15676. {
  15677. isSuccess = ConfigurationStatus_Rejected;
  15678. }
  15679. else
  15680. {
  15681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15682. isSuccess = ConfigurationStatus_Accepted;
  15683. }
  15684. }
  15685. else
  15686. {
  15687. isSuccess = ConfigurationStatus_Rejected;
  15688. }
  15689. }
  15690. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15691. {
  15692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15693. {
  15694. check_ascii = value[0];
  15695. if( (check_ascii < 48) || (check_ascii > 57) )
  15696. {
  15697. isSuccess = ConfigurationStatus_Rejected;
  15698. }
  15699. else
  15700. {
  15701. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15703. TransactionMessageAttemptsValue = atoi(value);
  15704. isSuccess = ConfigurationStatus_Accepted;
  15705. }
  15706. }
  15707. else
  15708. {
  15709. isSuccess = ConfigurationStatus_Rejected;
  15710. }
  15711. }
  15712. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15713. {
  15714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15715. {
  15716. check_ascii = value[0];
  15717. if( (check_ascii < 48) || (check_ascii > 57) )
  15718. {
  15719. isSuccess = ConfigurationStatus_Rejected;
  15720. }
  15721. else
  15722. {
  15723. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15725. TransactionMessageRetryIntervalValue = atoi(value);
  15726. isSuccess = ConfigurationStatus_Accepted;
  15727. }
  15728. }
  15729. else
  15730. {
  15731. isSuccess = ConfigurationStatus_Rejected;
  15732. }
  15733. }
  15734. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15735. {
  15736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15737. {
  15738. strcpy(str, (const char*)value);
  15739. for(int i = 0; str[i]; i++)
  15740. {
  15741. str[i] = tolower(str[i]);
  15742. }
  15743. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15745. isSuccess = ConfigurationStatus_Accepted;
  15746. }
  15747. else
  15748. {
  15749. isSuccess = ConfigurationStatus_Rejected;
  15750. }
  15751. }
  15752. if(strcmp(key, "WebSocketPingInterval") == 0)
  15753. {
  15754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15755. {
  15756. check_ascii = value[0];
  15757. if( (check_ascii < 48) || (check_ascii > 57) )
  15758. {
  15759. isSuccess = ConfigurationStatus_Rejected;
  15760. }
  15761. else
  15762. {
  15763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15764. isSuccess = ConfigurationStatus_Accepted;
  15765. }
  15766. }
  15767. else
  15768. {
  15769. isSuccess = ConfigurationStatus_Rejected;
  15770. }
  15771. }
  15772. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15773. {
  15774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15775. {
  15776. strcpy(str, (const char*)value);
  15777. for(int i = 0; str[i]; i++)
  15778. {
  15779. str[i] = tolower(str[i]);
  15780. }
  15781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15782. isSuccess = ConfigurationStatus_Accepted;
  15783. }
  15784. else
  15785. {
  15786. isSuccess = ConfigurationStatus_Rejected;
  15787. }
  15788. }
  15789. if(strcmp(key, "AuthorizationKey") == 0)
  15790. {
  15791. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15792. {
  15793. strcpy(str, (const char*)value);
  15794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15795. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15796. isSuccess = ConfigurationStatus_Accepted;
  15797. }
  15798. else
  15799. {
  15800. isSuccess = ConfigurationStatus_Rejected;
  15801. }
  15802. }
  15803. if(strcmp(key, "SecurityProfile") == 0)
  15804. {
  15805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15806. {
  15807. check_ascii = value[0];
  15808. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15809. {
  15810. isSuccess = ConfigurationStatus_Rejected;
  15811. }
  15812. else if(check_ascii == 0x33)
  15813. {
  15814. isSuccess = NotSupported;
  15815. }
  15816. else
  15817. {
  15818. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15819. {
  15820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15821. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15822. isSuccess = ConfigurationStatus_Accepted;
  15823. }
  15824. else
  15825. isSuccess = ConfigurationStatus_Rejected;
  15826. }
  15827. }
  15828. else
  15829. {
  15830. isSuccess = ConfigurationStatus_Rejected;
  15831. }
  15832. }
  15833. if(strcmp(key, "DefaultPrice") == 0)
  15834. {
  15835. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15836. {
  15837. strcpy(str, (const char*)value);
  15838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15839. isSuccess = ConfigurationStatus_Accepted;
  15840. }
  15841. else
  15842. {
  15843. isSuccess = ConfigurationStatus_Rejected;
  15844. }
  15845. }
  15846. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15847. {
  15848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15849. {
  15850. strcpy(str, (const char*)value);
  15851. for(int i = 0; str[i]; i++)
  15852. {
  15853. str[i] = tolower(str[i]);
  15854. }
  15855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15856. isSuccess = ConfigurationStatus_Accepted;
  15857. }
  15858. else
  15859. {
  15860. isSuccess = ConfigurationStatus_Rejected;
  15861. }
  15862. }
  15863. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15864. {
  15865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15866. {
  15867. strcpy(str, (const char*)value);
  15868. for(int i = 0; str[i]; i++)
  15869. {
  15870. str[i] = tolower(str[i]);
  15871. }
  15872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15873. isSuccess = ConfigurationStatus_Accepted;
  15874. }
  15875. else
  15876. {
  15877. isSuccess = ConfigurationStatus_Rejected;
  15878. }
  15879. }
  15880. if(strcmp(key, "TimeOffset") == 0)
  15881. {
  15882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15883. {
  15884. strcpy(str, (const char*)value);
  15885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15886. isSuccess = ConfigurationStatus_Accepted;
  15887. }
  15888. else
  15889. {
  15890. isSuccess = ConfigurationStatus_Rejected;
  15891. }
  15892. }
  15893. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15894. {
  15895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15896. {
  15897. strcpy(str, (const char*)value);
  15898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15899. isSuccess = ConfigurationStatus_Accepted;
  15900. }
  15901. else
  15902. {
  15903. isSuccess = ConfigurationStatus_Rejected;
  15904. }
  15905. }
  15906. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15907. {
  15908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15909. {
  15910. strcpy(str, (const char*)value);
  15911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15912. isSuccess = ConfigurationStatus_Accepted;
  15913. }
  15914. else
  15915. {
  15916. isSuccess = ConfigurationStatus_Rejected;
  15917. }
  15918. }
  15919. if(strcmp(key, "SystemUptimeSec") == 0)
  15920. {
  15921. isSuccess = NotSupported;
  15922. }
  15923. if(strcmp(key, "FreeVend") == 0)
  15924. {
  15925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15926. {
  15927. strcpy(str, (const char*)value);
  15928. for(int i = 0; str[i]; i++)
  15929. {
  15930. str[i] = tolower(str[i]);
  15931. }
  15932. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15934. isSuccess = ConfigurationStatus_Accepted;
  15935. }
  15936. else
  15937. {
  15938. isSuccess = ConfigurationStatus_Rejected;
  15939. }
  15940. }
  15941. #if 0
  15942. //For OCPP Test Case
  15943. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15944. {
  15945. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15946. {
  15947. strcpy(str, (const char*)value);
  15948. for(int i = 0; str[i]; i++)
  15949. {
  15950. str[i] = tolower(str[i]);
  15951. }
  15952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15953. isSuccess = ConfigurationStatus_Accepted;
  15954. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15955. }
  15956. else
  15957. {
  15958. isSuccess = ConfigurationStatus_Rejected;
  15959. }
  15960. }
  15961. #endif
  15962. #if 1
  15963. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15964. {
  15965. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15966. {
  15967. strcpy(str, (const char*)value);
  15968. for(int i = 0; str[i]; i++)
  15969. {
  15970. str[i] = tolower(str[i]);
  15971. }
  15972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15973. isSuccess = ConfigurationStatus_Accepted;
  15974. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15975. }
  15976. else
  15977. {
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. #endif
  15982. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15983. {
  15984. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15985. {
  15986. check_ascii = value[0];
  15987. if( (check_ascii < 48) || (check_ascii > 57) )
  15988. {
  15989. isSuccess = ConfigurationStatus_Rejected;
  15990. }
  15991. else
  15992. {
  15993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15994. isSuccess = ConfigurationStatus_Accepted;
  15995. }
  15996. }
  15997. else
  15998. {
  15999. isSuccess = ConfigurationStatus_Rejected;
  16000. }
  16001. }
  16002. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16003. {
  16004. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16005. {
  16006. check_ascii = value[0];
  16007. if( (check_ascii < 48) || (check_ascii > 57) )
  16008. {
  16009. isSuccess = ConfigurationStatus_Rejected;
  16010. }
  16011. else
  16012. {
  16013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16014. isSuccess = ConfigurationStatus_Accepted;
  16015. }
  16016. }
  16017. else
  16018. {
  16019. isSuccess = ConfigurationStatus_Rejected;
  16020. }
  16021. }
  16022. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16023. {
  16024. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16025. {
  16026. strcpy(str, (const char*)value);
  16027. for(int i = 0; str[i]; i++)
  16028. {
  16029. str[i] = tolower(str[i]);
  16030. }
  16031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16032. isSuccess = ConfigurationStatus_Accepted;
  16033. }
  16034. else
  16035. {
  16036. isSuccess = ConfigurationStatus_Rejected;
  16037. }
  16038. }
  16039. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16040. {
  16041. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16042. {
  16043. check_ascii = value[0];
  16044. if( (check_ascii < 48) || (check_ascii > 57) )
  16045. {
  16046. isSuccess = ConfigurationStatus_Rejected;
  16047. }
  16048. else
  16049. {
  16050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16051. isSuccess = ConfigurationStatus_Accepted;
  16052. }
  16053. }
  16054. else
  16055. {
  16056. isSuccess = ConfigurationStatus_Rejected;
  16057. }
  16058. }
  16059. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16060. {
  16061. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16062. {
  16063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16064. isSuccess = ConfigurationStatus_Accepted;
  16065. }
  16066. else
  16067. {
  16068. isSuccess = ConfigurationStatus_Rejected;
  16069. }
  16070. }
  16071. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16072. {
  16073. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16074. {
  16075. check_ascii = value[0];
  16076. if( (check_ascii < 48) || (check_ascii > 57) )
  16077. {
  16078. isSuccess = ConfigurationStatus_Rejected;
  16079. }
  16080. else
  16081. {
  16082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16083. isSuccess = ConfigurationStatus_Accepted;
  16084. }
  16085. }
  16086. else
  16087. {
  16088. isSuccess = ConfigurationStatus_Rejected;
  16089. }
  16090. }
  16091. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16092. {
  16093. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16094. {
  16095. strcpy(str, (const char*)value);
  16096. for(int i = 0; str[i]; i++)
  16097. {
  16098. str[i] = tolower(str[i]);
  16099. }
  16100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16101. isSuccess = ConfigurationStatus_Accepted;
  16102. }
  16103. else
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. }
  16108. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16109. {
  16110. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16111. {
  16112. check_ascii = value[0];
  16113. if( (check_ascii < 48) || (check_ascii > 57) )
  16114. {
  16115. isSuccess = ConfigurationStatus_Rejected;
  16116. }
  16117. else
  16118. {
  16119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16120. isSuccess = ConfigurationStatus_Accepted;
  16121. }
  16122. }
  16123. else
  16124. {
  16125. isSuccess = ConfigurationStatus_Rejected;
  16126. }
  16127. }
  16128. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16129. return isSuccess;
  16130. }
  16131. int TransactionMessageAttemptsGet(void)
  16132. {
  16133. return TransactionMessageAttemptsValue;
  16134. }
  16135. int FirstHeartBeatResponse(void)
  16136. {
  16137. return FirstHeartBeat;
  16138. }
  16139. int TransactionMessageRetryIntervalGet(void)
  16140. {
  16141. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16142. }
  16143. int ReadHttpStatus(int sock)
  16144. {
  16145. //char c;
  16146. char buff[1024]="",*ptr=buff+1;
  16147. int bytes_received, status;
  16148. DEBUG_INFO("Begin Response ..\n");
  16149. while((bytes_received = recv(sock, ptr, 1, 0))){
  16150. if(bytes_received==-1){
  16151. perror("ReadHttpStatus");
  16152. exit(1);
  16153. }
  16154. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16155. ptr++;
  16156. }
  16157. *ptr=0;
  16158. ptr=buff+1;
  16159. sscanf(ptr,"%*s %d ", &status);
  16160. DEBUG_INFO("%s\n",ptr);
  16161. DEBUG_INFO("status=%d\n",status);
  16162. DEBUG_INFO("End Response ..\n");
  16163. return (bytes_received>0)?status:0;
  16164. }
  16165. //the only filed that it parsed is 'Content-Length'
  16166. int ParseHeader(int sock)
  16167. {
  16168. //char c;
  16169. char buff[1024]="",*ptr=buff+4;
  16170. int bytes_received;
  16171. DEBUG_INFO("Begin HEADER ..\n");
  16172. while((bytes_received = recv(sock, ptr, 1, 0))){
  16173. if(bytes_received==-1){
  16174. perror("Parse Header");
  16175. exit(1);
  16176. }
  16177. if(
  16178. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16179. (ptr[-1]=='\r') && (*ptr=='\n' )
  16180. ) break;
  16181. ptr++;
  16182. }
  16183. *ptr=0;
  16184. ptr=buff+4;
  16185. //printf("%s",ptr);
  16186. if(bytes_received){
  16187. ptr=strstr(ptr,"Content-Length:");
  16188. if(ptr){
  16189. sscanf(ptr,"%*s %d",&bytes_received);
  16190. }else
  16191. bytes_received=-1; //unknown size
  16192. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16193. }
  16194. DEBUG_INFO("End HEADER ..\n");
  16195. return bytes_received ;
  16196. }
  16197. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16198. {
  16199. int result = TRUE;
  16200. char rmFileCmd[100]={0};
  16201. char FilePath[100]={0};
  16202. char ftpbuf[200];
  16203. int systemresult;
  16204. sprintf(FilePath,"/mnt/%s",filename);
  16205. system("ping 8.8.8.8 &");
  16206. if((access(FilePath,F_OK))!=-1)
  16207. {
  16208. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16209. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16210. system(rmFileCmd);
  16211. }
  16212. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16213. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16214. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16215. systemresult = system(ftpbuf);
  16216. if(systemresult != 0)
  16217. {
  16218. DEBUG_INFO("http DownLoad error!\n");
  16219. result = FALSE;
  16220. }
  16221. system("pkill ping");
  16222. return result;
  16223. }
  16224. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16225. {
  16226. int result = TRUE;
  16227. char rmFileCmd[100]={0};
  16228. char FilePath[100]={0};
  16229. char ftpbuf[200];
  16230. int systemresult;
  16231. sprintf(FilePath,"/mnt/%s",filename);
  16232. system("ping 8.8.8.8 &");
  16233. if((access(FilePath,F_OK))!=-1)
  16234. {
  16235. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16236. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16237. system(rmFileCmd);
  16238. }
  16239. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16240. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16241. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16242. systemresult = system(ftpbuf);
  16243. if(systemresult != 0)
  16244. {
  16245. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16246. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16247. systemresult = system(ftpbuf);
  16248. if(systemresult != 0)
  16249. {
  16250. DEBUG_WARN("wget error!\n");
  16251. result = FALSE;
  16252. }
  16253. }
  16254. system("pkill ping");
  16255. return result;
  16256. }
  16257. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16258. {
  16259. char rmFileCmd[100]={0};
  16260. char FilePath[100]={0};
  16261. char buf[512];
  16262. int systemresult = 0;
  16263. //DEBUG_INFO("filename=%s\n",filename);
  16264. //DEBUG_INFO("url=%s\n",url);
  16265. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16266. if((access(FilePath,F_OK))!=-1)
  16267. {
  16268. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16269. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16270. system(rmFileCmd);
  16271. }
  16272. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16273. if(fp == NULL)
  16274. {
  16275. DEBUG_INFO("log is NULL\n");
  16276. return FALSE;
  16277. }
  16278. else
  16279. {
  16280. fprintf(fp, "%s\n", url);
  16281. fprintf(fp, "%s\n", filename);
  16282. fclose(fp);
  16283. }
  16284. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16285. if(phpFP == NULL)
  16286. {
  16287. DEBUG_INFO("PHP upload fail.\n");
  16288. return FALSE;
  16289. }
  16290. else
  16291. {
  16292. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16293. {
  16294. if(strstr(buf, "result") != NULL)
  16295. {
  16296. sscanf(buf, "result: %d", &systemresult);
  16297. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16298. }
  16299. }
  16300. pclose(phpFP);
  16301. }
  16302. if(systemresult != 1)
  16303. {
  16304. DEBUG_INFO("HTTP upload error!\n");
  16305. return FALSE;
  16306. }
  16307. return TRUE;
  16308. }
  16309. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16310. {
  16311. int result = FALSE;
  16312. char ftpbuf[200];
  16313. int systemresult;
  16314. /*
  16315. // Domaind name transfer to IP address
  16316. struct hostent* server;
  16317. char *IPbuffer;
  16318. server = gethostbyname(location);
  16319. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16320. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16321. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16322. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16323. systemresult = system(ftpbuf);
  16324. if(systemresult != 0)
  16325. {
  16326. DEBUG_INFO("ftpput error!\n");
  16327. }
  16328. else
  16329. {
  16330. result = TRUE;
  16331. DEBUG_INFO("ftpput OK!\n");
  16332. }
  16333. return result;
  16334. }
  16335. int GetOcppServerURL()
  16336. {
  16337. int result = FALSE;
  16338. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16339. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16340. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16341. struct yuarel url;
  16342. char urlStr[512];
  16343. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16344. {
  16345. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16346. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16347. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16348. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16349. if(yuarel_parse(&url, urlStr) != -1)
  16350. {
  16351. sprintf(OcppProtocol, "%s", url.scheme);
  16352. sprintf(OcppHost, "%s", url.host);
  16353. if(url.path == NULL)
  16354. OcppTempPath[0] = '\0';
  16355. else
  16356. {
  16357. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  16358. {
  16359. sprintf(OcppTempPath, "%s/", url.path);
  16360. }
  16361. else
  16362. {
  16363. sprintf(OcppTempPath, "%s", url.path);
  16364. }
  16365. }
  16366. if(url.port == 0)
  16367. {
  16368. if(strcmp(OcppProtocol, "wss") == 0)
  16369. OcppPort = 443;
  16370. else
  16371. OcppPort = 80;
  16372. }
  16373. else
  16374. OcppPort = url.port;
  16375. result = TRUE;
  16376. }
  16377. }
  16378. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  16379. {
  16380. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  16381. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16382. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16383. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  16384. if(yuarel_parse(&url, urlStr) != -1)
  16385. {
  16386. sprintf(OcppProtocol, "%s", url.scheme);
  16387. sprintf(OcppHost, "%s", url.host);
  16388. if(url.path == NULL)
  16389. OcppTempPath[0] = '\0';
  16390. else
  16391. sprintf(OcppTempPath, "%s", url.path);
  16392. if(url.port == 0)
  16393. {
  16394. if(strcmp(OcppProtocol, "wss") == 0)
  16395. OcppPort = 443;
  16396. else
  16397. OcppPort = 80;
  16398. }
  16399. else
  16400. OcppPort = url.port;
  16401. result = TRUE;
  16402. }
  16403. }
  16404. else
  16405. {
  16406. strcpy(OcppHost,"");
  16407. }
  16408. return result;
  16409. }
  16410. int GetOcppPath()
  16411. {
  16412. int result = FALSE;
  16413. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16414. {
  16415. if(OcppTempPath == NULL)
  16416. {
  16417. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16418. }
  16419. else
  16420. {
  16421. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16422. }
  16423. result = TRUE;
  16424. goto End;
  16425. }
  16426. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  16427. {
  16428. if(OcppTempPath == NULL)
  16429. {
  16430. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  16431. }
  16432. else
  16433. {
  16434. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  16435. }
  16436. result = TRUE;
  16437. goto End;
  16438. }
  16439. else
  16440. {
  16441. strcpy(OcppPath,"");
  16442. }
  16443. End:
  16444. return result;
  16445. }
  16446. int GetOcppPort()
  16447. {
  16448. return OcppPort;
  16449. }
  16450. int GetOcppConnStatus(void)
  16451. {
  16452. return ShmOCPP16Data->OcppConnStatus;
  16453. }
  16454. void SetOcppConnStatus(uint8_t status)
  16455. {
  16456. ShmOCPP16Data->OcppConnStatus = status;
  16457. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16458. }
  16459. int GetHeartBeatWithNOResponse(void)
  16460. {
  16461. return HeartBeatWithNOResponse;
  16462. }
  16463. void SetHeartBeatWithNOResponse(void)
  16464. {
  16465. HeartBeatWithNOResponse = 0;
  16466. }
  16467. void GetStartTransactionIdTag(int gun_index)
  16468. {
  16469. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16470. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16471. }
  16472. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16473. {
  16474. char ch;
  16475. FILE *fptr1;
  16476. int temptransactionId;
  16477. char str[100]={0};
  16478. temptransactionId = 0;
  16479. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16480. {
  16481. DEBUG_INFO("IdTag is empty.\n");
  16482. return temptransactionId;
  16483. }
  16484. /*------ Read the file ----------------*/
  16485. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  16486. if (!fptr1)
  16487. {
  16488. DEBUG_INFO("QueueTransactionId file open error.\n");
  16489. //printf(" File not found or unable to open the input file!!\n");
  16490. return temptransactionId;
  16491. }
  16492. ch=fgetc(fptr1);
  16493. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  16494. rewind(fptr1);
  16495. if(ch!=EOF)
  16496. {
  16497. // printf("%c",ch);
  16498. while (fgets(str, 100, fptr1) != NULL)
  16499. {
  16500. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16501. if(str[0]=='\0')
  16502. {
  16503. break;
  16504. }
  16505. char *revbuf[8] = {0}; // Variable store string split
  16506. int num = 0;// Quantity after string split
  16507. DEBUG_INFO("Transaction queue data= %s\n", str);
  16508. splitstring(str,",",revbuf,&num); // String split
  16509. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16510. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16511. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16512. DEBUG_INFO("------------------------------\n");
  16513. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16514. {
  16515. if(isStopTransaction)
  16516. {
  16517. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16518. {
  16519. temptransactionId = atoi(revbuf[2]);
  16520. //break;
  16521. }
  16522. }
  16523. else
  16524. {
  16525. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16526. {
  16527. temptransactionId = atoi(revbuf[2]);
  16528. //break;
  16529. }
  16530. }
  16531. }
  16532. }
  16533. }
  16534. else
  16535. DEBUG_INFO("EOF\n");
  16536. fclose(fptr1);
  16537. /*------- End of reading ---------------*/
  16538. return temptransactionId;
  16539. }
  16540. void SetTransactionIdZero(int transactionId)
  16541. {
  16542. char ch;
  16543. FILE *fptr1, *fptr2;
  16544. int temptransactionId = 0;
  16545. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  16546. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  16547. if (!fptr1)
  16548. {
  16549. //printf(" File not found or unable to open the input file!!\n");
  16550. return ;
  16551. }
  16552. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16553. if (!fptr2)
  16554. {
  16555. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16556. fclose(fptr1);
  16557. return ;
  16558. }
  16559. ch=fgetc(fptr1);
  16560. rewind(fptr1);
  16561. if(ch!=EOF)
  16562. {
  16563. // copy all contents to the temporary file except the specific line
  16564. while (fgets(str, 100, fptr1) != NULL)
  16565. {
  16566. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16567. if(str[0]=='\0')
  16568. {
  16569. break;
  16570. }
  16571. char *revbuf[8] = {0};
  16572. int num = 0;
  16573. strcpy(strtemp, str);
  16574. splitstring(str,",",revbuf,&num);
  16575. if(revbuf[2][0] != '\0')
  16576. {
  16577. temptransactionId = atoi(revbuf[2]);
  16578. if(transactionId != temptransactionId)
  16579. {
  16580. fprintf(fptr2, "%s\n", strtemp);
  16581. }
  16582. }
  16583. }
  16584. }
  16585. fclose(fptr1);
  16586. fclose(fptr2);
  16587. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  16588. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  16589. /*------ Read the file ----------------*/
  16590. }
  16591. int InternetDisconnect(void)
  16592. {
  16593. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16594. }
  16595. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16596. void storeTempStopTransaction(int gun_index)
  16597. {
  16598. char guid[37]={0};
  16599. int tempIndex = 0;
  16600. char TempStopTransaction[256];
  16601. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16602. DEBUG_INFO("storeTempStopTransaction...\n");
  16603. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16604. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  16605. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16606. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16607. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16608. {
  16609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16610. {
  16611. tempIndex = ((gun_index==2) ? 1: 0);
  16612. }
  16613. else
  16614. {
  16615. tempIndex = gun_index;
  16616. }
  16617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16618. {
  16619. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16620. {
  16621. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16622. }
  16623. }// END OF CHAdeMO_QUANTITY
  16624. }
  16625. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16626. {
  16627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16628. {
  16629. tempIndex = ((gun_index==2) ? 1: 0);
  16630. }
  16631. else
  16632. {
  16633. tempIndex = gun_index;
  16634. }
  16635. for (int index = 0; index < CCS_QUANTITY; index++)
  16636. {
  16637. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16638. {
  16639. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16640. }
  16641. }// END OF CCS_QUANTITY
  16642. }
  16643. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16644. {
  16645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16646. {
  16647. tempIndex = ((gun_index==2) ? 1: 0);
  16648. }
  16649. else
  16650. {
  16651. tempIndex = gun_index;
  16652. }
  16653. for (int index = 0; index < GB_QUANTITY; index++)
  16654. {
  16655. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16656. {
  16657. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16658. }
  16659. }// END OF GB_QUANTITY
  16660. }
  16661. else if(gunType[gun_index] == GUN_TYPE_DO)
  16662. {
  16663. tempIndex = gun_index;
  16664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16665. {
  16666. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16667. {
  16668. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16669. }
  16670. }
  16671. }
  16672. else
  16673. {
  16674. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16675. {
  16676. tempIndex = 2;
  16677. }
  16678. else
  16679. {
  16680. tempIndex = gun_index;
  16681. }
  16682. for (int index = 0; index < AC_QUANTITY; index++)
  16683. {
  16684. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16685. {
  16686. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16687. }
  16688. }// END OF AC_QUANTITY
  16689. }
  16690. //Stop Transaction Time
  16691. struct timeval tmnow;
  16692. struct tm *tm;
  16693. char buf[28];//, usec_buf[6];
  16694. gettimeofday(&tmnow, NULL);
  16695. time_t t;
  16696. t = time(NULL);
  16697. /*UTC time and date*/
  16698. tm = gmtime(&t);
  16699. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  16701. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  16702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16703. random_uuid(guid);
  16704. /***********************************transactionData******************************************************/
  16705. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16707. //=================================
  16708. //1. Transaction_Begin
  16709. //=================================
  16710. //============================== Energy.Active.Import.Interval ===========================================
  16711. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16712. {
  16713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  16717. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16718. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  16719. {
  16720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16721. }
  16722. else
  16723. {
  16724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16725. }
  16726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16728. }
  16729. //=================================
  16730. //2. Transaction_End
  16731. //=================================
  16732. //2.1====================================== Current.Import L1 ==============================================
  16733. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16734. {
  16735. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16736. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16737. {
  16738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16739. {
  16740. tempIndex = ((gun_index==2) ? 1: 0);
  16741. }
  16742. else
  16743. {
  16744. tempIndex = gun_index;
  16745. }
  16746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16747. {
  16748. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16749. {
  16750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16751. }
  16752. }// End of for CHAdeMO_QUANTITY
  16753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16754. }
  16755. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16756. {
  16757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16758. {
  16759. tempIndex = ((gun_index==2) ? 1: 0);
  16760. }
  16761. else
  16762. {
  16763. tempIndex = gun_index;
  16764. }
  16765. for (int index = 0; index < CCS_QUANTITY; index++)
  16766. {
  16767. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16768. {
  16769. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16770. }
  16771. }// End of for CCS_QUANTITY
  16772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16773. }
  16774. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16775. {
  16776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16777. {
  16778. tempIndex = ((gun_index==2) ? 1: 0);
  16779. }
  16780. else
  16781. {
  16782. tempIndex = gun_index;
  16783. }
  16784. for (int index = 0; index < GB_QUANTITY; index++)
  16785. {
  16786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16787. {
  16788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16789. }
  16790. }// End of for GB_QUANTITY
  16791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16792. }
  16793. else if(gunType[gun_index] == GUN_TYPE_DO)
  16794. {
  16795. tempIndex = gun_index;
  16796. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16797. {
  16798. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16799. {
  16800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16801. }
  16802. }
  16803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16804. }
  16805. else
  16806. {
  16807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16808. {
  16809. tempIndex = 2;
  16810. }
  16811. else
  16812. {
  16813. tempIndex = gun_index;
  16814. }
  16815. for (int index = 0; index < AC_QUANTITY; index++)
  16816. {
  16817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16818. {
  16819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16820. }
  16821. }// End of for AC_QUANTITY
  16822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16823. }
  16824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16827. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16830. }
  16831. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16832. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16833. {
  16834. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16835. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16836. {
  16837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16838. {
  16839. tempIndex = ((gun_index==2) ? 1: 0);
  16840. }
  16841. else
  16842. {
  16843. tempIndex = gun_index;
  16844. }
  16845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16846. {
  16847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16848. {
  16849. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16850. }
  16851. }// END OF CHAdeMO_QUANTITY
  16852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16853. }
  16854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16855. {
  16856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16857. {
  16858. tempIndex = ((gun_index==2) ? 1: 0);
  16859. }
  16860. else
  16861. {
  16862. tempIndex = gun_index;
  16863. }
  16864. for (int index = 0; index < CCS_QUANTITY; index++)
  16865. {
  16866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16867. {
  16868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16869. }
  16870. }// END OF CCS_QUANTITY
  16871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16872. }
  16873. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16874. {
  16875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16876. {
  16877. tempIndex = ((gun_index==2) ? 1: 0);
  16878. }
  16879. else
  16880. {
  16881. tempIndex = gun_index;
  16882. }
  16883. for (int index = 0; index < GB_QUANTITY; index++)
  16884. {
  16885. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16886. {
  16887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16888. }
  16889. }// END OF GB_QUANTITY
  16890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16891. }
  16892. else if(gunType[gun_index] == GUN_TYPE_DO)
  16893. {
  16894. tempIndex = gun_index;
  16895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16896. {
  16897. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16898. {
  16899. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16900. }
  16901. }
  16902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16903. }
  16904. else
  16905. {
  16906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16907. {
  16908. tempIndex = 2;
  16909. }
  16910. else
  16911. {
  16912. tempIndex = gun_index;
  16913. }
  16914. for (int index = 0; index < AC_QUANTITY; index++)
  16915. {
  16916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16917. {
  16918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16919. }
  16920. }// END OF AC_QUANTITY
  16921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16922. }
  16923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16926. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16929. }
  16930. //2.3====================================== Power.Active.Import =========================================
  16931. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16932. {
  16933. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16934. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16935. {
  16936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16937. {
  16938. tempIndex = ((gun_index==2) ? 1: 0);
  16939. }
  16940. else
  16941. {
  16942. tempIndex = gun_index;
  16943. }
  16944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16945. {
  16946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16947. {
  16948. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16949. }
  16950. } // End for CHAdeMO_QUANTITY
  16951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16952. }
  16953. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16954. {
  16955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16956. {
  16957. tempIndex = ((gun_index==2) ? 1: 0);
  16958. }
  16959. else
  16960. {
  16961. tempIndex = gun_index;
  16962. }
  16963. for (int index = 0; index < CCS_QUANTITY; index++)
  16964. {
  16965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16966. {
  16967. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16968. }
  16969. } // END for CCS_QUANTITY
  16970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16971. }
  16972. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16973. {
  16974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16975. {
  16976. tempIndex = ((gun_index==2) ? 1: 0);
  16977. }
  16978. else
  16979. {
  16980. tempIndex = gun_index;
  16981. }
  16982. for (int index = 0; index < GB_QUANTITY; index++)
  16983. {
  16984. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16985. {
  16986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16987. }
  16988. }// END for GB_QUANTITY
  16989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16990. }
  16991. else if(gunType[gun_index] == GUN_TYPE_DO)
  16992. {
  16993. tempIndex = gun_index;
  16994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16995. {
  16996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16997. {
  16998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16999. }
  17000. }
  17001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17002. }
  17003. else
  17004. {
  17005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17006. {
  17007. tempIndex = 2;
  17008. }
  17009. else
  17010. {
  17011. tempIndex = gun_index;
  17012. }
  17013. for (int index = 0; index < AC_QUANTITY; index++)
  17014. {
  17015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17016. {
  17017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17018. }
  17019. } // END for AC_QUANTITY
  17020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17021. }
  17022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17025. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17028. }
  17029. //2.4====================================== Voltage L1 ====================================================
  17030. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17031. {
  17032. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17033. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17034. {
  17035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17036. {
  17037. tempIndex = ((gun_index==2) ? 1: 0);
  17038. }
  17039. else
  17040. {
  17041. tempIndex = gun_index;
  17042. }
  17043. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17044. {
  17045. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17046. {
  17047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17048. }
  17049. } // END OF FOR CHAdeMO_QUANTITY
  17050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17051. }
  17052. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17053. {
  17054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17055. {
  17056. tempIndex = ((gun_index==2) ? 1: 0);
  17057. }
  17058. else
  17059. {
  17060. tempIndex = gun_index;
  17061. }
  17062. for (int index = 0; index < CCS_QUANTITY; index++)
  17063. {
  17064. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17065. {
  17066. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17067. }
  17068. } // END OF FOR CCS_QUANTITY
  17069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17070. }
  17071. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17072. {
  17073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17074. {
  17075. tempIndex = ((gun_index==2) ? 1: 0);
  17076. }
  17077. else
  17078. {
  17079. tempIndex = gun_index;
  17080. }
  17081. for (int index = 0; index < GB_QUANTITY; index++)
  17082. {
  17083. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17084. {
  17085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17086. }
  17087. } // END OF FOR GB_QUANTITY
  17088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17089. }
  17090. else if(gunType[gun_index] == GUN_TYPE_DO)
  17091. {
  17092. tempIndex = gun_index;
  17093. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17094. {
  17095. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17096. {
  17097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17098. }
  17099. }
  17100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17101. }
  17102. else
  17103. {
  17104. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17105. {
  17106. tempIndex = 2;
  17107. }
  17108. else
  17109. {
  17110. tempIndex = gun_index;
  17111. }
  17112. for (int index = 0; index < AC_QUANTITY; index++)
  17113. {
  17114. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17115. {
  17116. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17117. }
  17118. } // END OF FOR AC_QUANTITY
  17119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17120. }
  17121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17124. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17127. }
  17128. //2.5============================================== End SoC =========================================================
  17129. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17130. {
  17131. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17132. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  17133. {
  17134. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17135. {
  17136. tempIndex = ((gun_index==2) ? 1: 0);
  17137. }
  17138. else
  17139. {
  17140. tempIndex = gun_index;
  17141. }
  17142. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17143. {
  17144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17145. {
  17146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17147. {
  17148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17149. }
  17150. }
  17151. }
  17152. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17153. {
  17154. for (int index = 0; index < CCS_QUANTITY; index++)
  17155. {
  17156. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17157. {
  17158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17159. }
  17160. }
  17161. }
  17162. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17163. {
  17164. for (int index = 0; index < GB_QUANTITY; index++)
  17165. {
  17166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17167. {
  17168. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17169. }
  17170. }
  17171. }
  17172. else if(gunType[gun_index] == GUN_TYPE_DO)
  17173. {
  17174. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17175. {
  17176. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17177. {
  17178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17179. }
  17180. }
  17181. }
  17182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17188. } // END FOR DC CASE
  17189. }
  17190. //2.6====================================== Current.Import L2 ==============================================
  17191. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17192. {
  17193. // AC 3 phase L2 current
  17194. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17195. {
  17196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17197. {
  17198. tempIndex = 2;
  17199. }
  17200. else
  17201. {
  17202. tempIndex = gun_index;
  17203. }
  17204. for (int index = 0; index < AC_QUANTITY; index++)
  17205. {
  17206. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17207. {
  17208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17209. }
  17210. }// End of for AC_QUANTITY
  17211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17212. }
  17213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17218. }
  17219. //2.7====================================== Current.Import L3 ==============================================
  17220. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17221. {
  17222. // AC 3 phase L3 current
  17223. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17224. {
  17225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17226. {
  17227. tempIndex = 2;
  17228. }
  17229. else
  17230. {
  17231. tempIndex = gun_index;
  17232. }
  17233. for (int index = 0; index < AC_QUANTITY; index++)
  17234. {
  17235. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17236. {
  17237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17238. }
  17239. }// End of for AC_QUANTITY
  17240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17241. }
  17242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17247. }
  17248. //2.9====================================== Voltage L2 ====================================================
  17249. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17250. {
  17251. // AC 3 phase L2 volatge
  17252. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17253. {
  17254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17255. {
  17256. tempIndex = 2;
  17257. }
  17258. else
  17259. {
  17260. tempIndex = gun_index;
  17261. }
  17262. for (int index = 0; index < AC_QUANTITY; index++)
  17263. {
  17264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17265. {
  17266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17267. }
  17268. } // END OF FOR AC_QUANTITY
  17269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17270. }
  17271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17276. }
  17277. //2.10====================================== Voltage L3 ====================================================
  17278. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17279. {
  17280. // AC 3 phase L3 volatge
  17281. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17282. {
  17283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17284. {
  17285. tempIndex = 2;
  17286. }
  17287. else
  17288. {
  17289. tempIndex = gun_index;
  17290. }
  17291. for (int index = 0; index < AC_QUANTITY; index++)
  17292. {
  17293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17294. {
  17295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17296. }
  17297. } // END OF FOR AC_QUANTITY
  17298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17299. }
  17300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17305. }
  17306. //====================== Start SoC ================================
  17307. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17308. {
  17309. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17310. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  17311. {
  17312. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17313. {
  17314. tempIndex = ((gun_index==2) ? 1: 0);
  17315. }
  17316. else
  17317. {
  17318. tempIndex = gun_index;
  17319. }
  17320. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17321. {
  17322. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17323. {
  17324. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17325. {
  17326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17327. }
  17328. }
  17329. }
  17330. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17331. {
  17332. for (int index = 0; index < CCS_QUANTITY; index++)
  17333. {
  17334. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17335. {
  17336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17337. }
  17338. }
  17339. }
  17340. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17341. {
  17342. for (int index = 0; index < GB_QUANTITY; index++)
  17343. {
  17344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17345. {
  17346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17347. }
  17348. }
  17349. }
  17350. else if(gunType[gun_index] == GUN_TYPE_DO)
  17351. {
  17352. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17353. {
  17354. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17355. {
  17356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17357. }
  17358. }
  17359. }
  17360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17366. } // END FOR DC CASE
  17367. }
  17368. //======================================== Message create ==============================================
  17369. json_object *StopTransaction = json_object_new_object();
  17370. json_object *transactionDatas = json_object_new_array();
  17371. json_object *sampledValues = json_object_new_array();
  17372. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  17373. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  17374. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  17375. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  17376. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  17377. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17378. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  17379. {
  17380. json_object *transactionData = json_object_new_object();
  17381. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17382. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17383. {
  17384. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17385. {
  17386. json_object *sampledValue = json_object_new_object();
  17387. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17388. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17389. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17390. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17391. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17392. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17393. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17394. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17395. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17396. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17397. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17398. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17399. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17400. json_object_array_add(sampledValues, sampledValue);
  17401. }
  17402. }
  17403. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17404. json_object_array_add(transactionDatas, transactionData);
  17405. }
  17406. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17407. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17408. ,MESSAGE_TYPE_CALL
  17409. ,guid
  17410. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17411. json_object_put(StopTransaction);
  17412. // Check File "TempStopTransaction" Exist
  17413. if((access(TempStopTransaction,F_OK))!=-1)
  17414. {
  17415. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17416. fclose(fopen(TempStopTransaction, "w"));
  17417. }
  17418. else
  17419. {
  17420. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17421. FILE *log = fopen(TempStopTransaction, "w+");
  17422. if(log == NULL)
  17423. {
  17424. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17425. return ;
  17426. }
  17427. else
  17428. {
  17429. fclose(log);
  17430. }
  17431. }
  17432. //Add TempStopTransaction | Update TempStopTransaction
  17433. // open file for writing
  17434. FILE *outfile;
  17435. outfile = fopen (TempStopTransaction, "a");
  17436. //DEBUG_INFO("data = %s\n", queuedata);
  17437. fputs(queuedata, outfile);
  17438. fputs("\n", outfile);
  17439. fclose (outfile);
  17440. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17441. }
  17442. void checkTempStopTransaction(int gun_index)
  17443. {
  17444. FILE *fptr1;
  17445. char ch;
  17446. char str[QUEUE_MESSAGE_LENGTH]={0};
  17447. char guid[37]={0};
  17448. char tempdata[65]={0};
  17449. char connectorStr[2]={0};
  17450. char TempStopTransaction[256];
  17451. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17452. fptr1 = fopen(TempStopTransaction, "r");
  17453. //TempStopTransaction格式: 槍號,StopTransaction封包
  17454. if (!fptr1)
  17455. {
  17456. //printf(" File not found or unable to open the input file!!\n");
  17457. return ;
  17458. }
  17459. ch=fgetc(fptr1);
  17460. //printf(" Now the content of the file %s is : \n",fname);
  17461. rewind(fptr1);
  17462. if(ch!=EOF)
  17463. {
  17464. // copy all contents to the temporary file except the specific line
  17465. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17466. {
  17467. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17468. if(str[0]=='\0')
  17469. {
  17470. break;
  17471. }
  17472. //TempStopTransaction格式: 槍號,StopTransaction封包
  17473. strncpy(connectorStr, str, 1);
  17474. if(atoi(connectorStr) != (gun_index+1))
  17475. {
  17476. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17477. fclose(fptr1);
  17478. return ;
  17479. }
  17480. //random_uuid(guid);
  17481. strncpy(guid, str+6, 36); //copy guid
  17482. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17483. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17484. {
  17485. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17486. }
  17487. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17488. OCPP_insert_transaction_msg(NO, str);
  17489. memset(str,0,ARRAY_SIZE(str));
  17490. }
  17491. }
  17492. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17493. fclose(fptr1);
  17494. remove(TempStopTransaction); // remove the original file
  17495. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17496. }
  17497. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17498. {
  17499. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17500. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17501. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17502. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17503. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17504. }
  17505. int GetWebSocketPingInterval(void)
  17506. {
  17507. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17508. }
  17509. int GetServerSign(void)
  17510. {
  17511. return server_sign;
  17512. }
  17513. uint8_t GetOcppSecurityProfile()
  17514. {
  17515. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17516. }
  17517. void GetOcppChargerBoxId(uint8_t *data)
  17518. {
  17519. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17520. }
  17521. void GetOcppSecurityPassword(uint8_t *data)
  17522. {
  17523. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17524. }
  17525. void SetOcppVersion(uint8_t *version)
  17526. {
  17527. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17528. DEBUG_INFO("ocpp version: %s\n", version);
  17529. if(strstr((char*)version, "ocpp1.6") != NULL)
  17530. {
  17531. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17532. }
  17533. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17534. {
  17535. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17536. system("pkill OcppBackend");
  17537. }
  17538. }
  17539. void SetServerSign(int value)
  17540. {
  17541. server_sign = value;
  17542. }
  17543. int GetBootNotificationInterval(void)
  17544. {
  17545. return BootNotificationInterval;
  17546. }
  17547. int GetInternetConn(void)
  17548. {
  17549. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17550. }
  17551. int GetBackendConnectionTimeout(void)
  17552. {
  17553. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17554. }
  17555. int isConnectorInitMode(int gun_index)
  17556. {
  17557. int tempIndex = 0;
  17558. int result = TRUE;
  17559. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17560. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17561. {
  17562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17563. {
  17564. tempIndex = ((gun_index==2) ? 1: 0);
  17565. }
  17566. else
  17567. {
  17568. tempIndex = gun_index;
  17569. }
  17570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17571. {
  17572. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17573. {
  17574. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17575. } //end of the same index
  17576. }//end of for CHAdeMO_QUANTITY
  17577. }
  17578. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17579. {
  17580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17581. {
  17582. tempIndex = ((gun_index==2) ? 1: 0);
  17583. }
  17584. else
  17585. {
  17586. tempIndex = gun_index;
  17587. }
  17588. for (int index = 0; index < CCS_QUANTITY; index++)
  17589. {
  17590. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17591. {
  17592. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17593. } //end of the same index
  17594. } // end of for CCS_QUANTITY
  17595. }
  17596. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17597. {
  17598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17599. {
  17600. tempIndex = ((gun_index==2) ? 1: 0);
  17601. }
  17602. else
  17603. {
  17604. tempIndex = gun_index;
  17605. }
  17606. for (int index = 0; index < GB_QUANTITY; index++)
  17607. {
  17608. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17609. {
  17610. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17611. } //end of the same index
  17612. } // end of for GB_QUANTITY
  17613. }
  17614. else if(gunType[gun_index] == GUN_TYPE_DO)
  17615. {
  17616. tempIndex = gun_index;
  17617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17618. {
  17619. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17620. {
  17621. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17622. } //end of the same index
  17623. }
  17624. }
  17625. else
  17626. {
  17627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17628. {
  17629. tempIndex = 2;
  17630. }
  17631. else
  17632. {
  17633. tempIndex = gun_index;
  17634. }
  17635. for (int index = 0; index < AC_QUANTITY; index++)
  17636. {
  17637. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17638. {
  17639. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17640. }//end of the same index
  17641. }//end of for AC_QUANTITY
  17642. }
  17643. return result;
  17644. }
  17645. void refreshProcDogTimer()
  17646. {
  17647. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  17648. }
  17649. void InitialSystemValue(void)
  17650. {
  17651. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17652. locallistVersion=0;
  17653. BootNotificationInterval = 0;
  17654. authorizeRetryTimes = 0;
  17655. GunStatusInterval = 10;
  17656. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17657. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17658. //Hear Beat
  17659. HeartBeatWithNOResponse = 0;
  17660. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17661. FirstHeartBeat = 0;
  17662. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17663. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17664. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17665. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17666. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17667. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17668. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17669. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17670. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17671. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17672. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17673. //Status && ConnectorPlugIn Setting
  17674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17675. {
  17676. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17677. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17678. }
  17679. for (int index = 0; index < CCS_QUANTITY; index++)
  17680. {
  17681. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17682. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17683. }
  17684. for (int index = 0; index < GB_QUANTITY; index++)
  17685. {
  17686. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17687. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17688. }
  17689. for (int index = 0; index < AC_QUANTITY; index++)
  17690. {
  17691. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17692. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17693. }
  17694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17695. {
  17696. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17697. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17698. }
  17699. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17700. {
  17701. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17702. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17703. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17704. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17705. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17706. }
  17707. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17708. refreshStartTimer(&clientTime.Heartbeat);
  17709. sleep(1);
  17710. }
  17711. void LWS_Send(char *str)
  17712. {
  17713. //=====================================================
  17714. // Check InternetConn 0: disconnected, 1: connected
  17715. //====================================================
  17716. if(GetOcppConnStatus() == 0)
  17717. {
  17718. DEBUG_INFO("offline now !!!\n");
  17719. return;
  17720. }
  17721. // Only disable isWebsocketSendable operation initiated by charger
  17722. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17723. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17724. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17725. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17726. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17727. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17728. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17729. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17730. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17731. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17732. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17733. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17734. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17735. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17736. {
  17737. isWebsocketSendable = 0;
  17738. }
  17739. pthread_mutex_lock(&lock_send);
  17740. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17741. sprintf((char *)SendBuffer, "%s", str);
  17742. SendBufLen = strlen(str);
  17743. pthread_mutex_unlock(&lock_send);
  17744. lws_callback_on_writable(wsi_client);
  17745. //lws_service(context, 0);
  17746. //sleep(1);
  17747. }
  17748. void LWS_SendNow(char *str)
  17749. {
  17750. //=====================================================
  17751. // Check InternetConn 0: disconnected, 1: connected
  17752. //====================================================
  17753. if(GetOcppConnStatus() == 0)
  17754. {
  17755. DEBUG_INFO("offline now !!!\n");
  17756. return;
  17757. }
  17758. // Only disable isWebsocketSendable operation initiated by charger
  17759. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17760. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17761. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17762. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17763. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17764. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17765. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17766. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17767. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17768. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17769. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17770. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17771. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17772. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17773. {
  17774. isWebsocketSendable = 0;
  17775. }
  17776. pthread_mutex_lock(&lock_send);
  17777. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17778. sprintf((char *)SendBuffer, "%s", str);
  17779. SendBufLen = strlen(str);
  17780. pthread_mutex_unlock(&lock_send);
  17781. lws_callback_on_writable(wsi_client);
  17782. lws_service(context, 0);
  17783. //sleep(1);
  17784. }