MessageHandler.c 911 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. 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);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. 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);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. 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));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. void reportReaderStatus(int gun_index)
  735. {
  736. struct timeval tmnow;
  737. struct tm *tm;
  738. char buf[28];//, usec_buf[6];
  739. gettimeofday(&tmnow, NULL);
  740. time_t t;
  741. t = time(NULL);
  742. /*UTC time and date*/
  743. tm = gmtime(&t);
  744. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  745. #if 0 // remove temporally
  746. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  747. strcat(buf,".");
  748. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  749. strcat(buf,usec_buf);
  750. #endif
  751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\"}",
  754. (gun_index+1),
  755. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  756. buf,
  757. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  758. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo);
  759. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  760. }
  761. //==========================================
  762. // Check time passed since today
  763. //==========================================
  764. long long DiffTimebWithNow(struct timeb ST)
  765. {
  766. //return milli-second
  767. struct timeb ET;
  768. long long StartTime,StopTime;
  769. ftime(&ET);
  770. StartTime=(long long)ST.time;
  771. StopTime=(long long)ET.time;
  772. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  773. }
  774. int getTimePassSinceToday(uint8_t gun_index)
  775. {
  776. int result = -1;
  777. static time_t lastTime[4];
  778. time_t t;
  779. struct tm *tmStartToday;
  780. struct timeb tbStartToday;
  781. t=time(NULL);
  782. if(difftime(t, lastTime[gun_index])>0)
  783. {
  784. tmStartToday=localtime(&t);
  785. tmStartToday->tm_hour = 0;
  786. tmStartToday->tm_min = 0;
  787. tmStartToday->tm_sec = 0;
  788. tbStartToday.time = mktime(tmStartToday);
  789. tbStartToday.millitm = 0;
  790. result = DiffTimebWithNow(tbStartToday)/1000;
  791. lastTime[gun_index] = t;
  792. }
  793. return result;
  794. }
  795. void getNowDatetime(uint8_t *data)
  796. {
  797. time_t t = time(NULL);
  798. struct tm tm = *localtime(&t);
  799. 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);
  800. }
  801. int syncDateTimeRTC(uint8_t *data)
  802. {
  803. struct ParsingResult
  804. {
  805. int result;
  806. int scanedElement;
  807. int year;
  808. int month;
  809. int mday;
  810. int hour;
  811. int min;
  812. int sec;
  813. int tz_hour;
  814. int tz_min;
  815. float minSec;
  816. }result;
  817. struct tm tmOrg;
  818. struct tm *tmTarget;
  819. struct timeb tbTarget;
  820. char buf[128];
  821. memset(&result, 0x00, sizeof(struct ParsingResult));
  822. result.result = PASS;
  823. if(strstr((char*)data, ".") != NULL)
  824. {
  825. // Original data with mini second
  826. if(strstr((char*)data, "Z") != NULL)
  827. {
  828. // Original data with Z
  829. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  830. &result.year,
  831. &result.month,
  832. &result.mday,
  833. &result.hour,
  834. &result.min,
  835. &result.sec,
  836. &result.minSec);
  837. }
  838. else
  839. {
  840. // Original data without Z
  841. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  842. &result.year,
  843. &result.month,
  844. &result.mday,
  845. &result.hour,
  846. &result.min,
  847. &result.sec,
  848. &result.minSec,
  849. &result.tz_hour,
  850. &result.tz_min);
  851. }
  852. }
  853. else
  854. {
  855. // Original data without mini second
  856. if(strstr((char*)data, "Z") != NULL)
  857. {
  858. // Original data with Z
  859. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  860. &result.year,
  861. &result.month,
  862. &result.mday,
  863. &result.hour,
  864. &result.min,
  865. &result.sec);
  866. }
  867. else
  868. {
  869. // Original data without Z
  870. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  871. &result.year,
  872. &result.month,
  873. &result.mday,
  874. &result.hour,
  875. &result.min,
  876. &result.sec,
  877. &result.tz_hour,
  878. &result.tz_min);
  879. }
  880. }
  881. tmOrg.tm_year = result.year - 1900;
  882. tmOrg.tm_mon = result.month - 1;
  883. tmOrg.tm_mday = result.mday;
  884. tmOrg.tm_hour = result.hour;
  885. tmOrg.tm_min = result.min;
  886. tmOrg.tm_sec = result.sec;
  887. tmOrg.tm_gmtoff = 0;
  888. tbTarget.time = mktime(&tmOrg);
  889. tbTarget.timezone = 0;
  890. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  891. tmTarget = gmtime(&tbTarget.time);
  892. 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);
  893. //DEBUG_INFO(" org date time: %s\n", data);
  894. //DEBUG_INFO("parse date time: %s\n", buf);
  895. system(buf);
  896. system("/sbin/hwclock -w --systohc");
  897. if(result.scanedElement < 6)
  898. result.result = FAIL;
  899. return result.result;
  900. }
  901. //==========================================
  902. // GetCompositeSchedule logic related function
  903. //==========================================
  904. int DiffTimebSec(struct timeb ST, struct timeb ET)
  905. {
  906. //return milli-second
  907. unsigned int StartTime,StopTime;
  908. StartTime=(unsigned int)ST.time;
  909. StopTime=(unsigned int)ET.time;
  910. return (StopTime-StartTime);
  911. }
  912. int DiffTimebWithNowSec(struct timeb ST)
  913. {
  914. //return milli-second
  915. struct timeb ET;
  916. unsigned int StartTime,StopTime;
  917. ftime(&ET);
  918. StartTime=(unsigned int)ST.time;
  919. StopTime=(unsigned int)ET.time;
  920. return (StopTime-StartTime);
  921. }
  922. int getStartStop(uint8_t *start, uint8_t *stop)
  923. {
  924. int result = -1;
  925. struct tm tmStart;
  926. struct timeb tbStart;
  927. struct tm tmStop;
  928. struct timeb tbStop;
  929. 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) &&
  930. (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))
  931. {
  932. //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);
  933. //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);
  934. tmStart.tm_year -= 1900;
  935. tmStart.tm_mon -= 1;
  936. tbStart.time = mktime(&tmStart);
  937. tbStart.millitm = 0;
  938. tmStop.tm_year -= 1900;
  939. tmStop.tm_mon -= 1;
  940. tbStop.time = mktime(&tmStop);
  941. tbStop.millitm = 0;
  942. result = DiffTimebSec(tbStart, tbStop);
  943. //DEBUG_INFO("getStartStop(): %d\n", result);
  944. }
  945. else
  946. {
  947. DEBUG_WARN("Start or stop date parsing error.\r\n");
  948. }
  949. return result;
  950. }
  951. int isOvertNow(uint8_t *start)
  952. {
  953. int result = NO;
  954. struct ParsingResult
  955. {
  956. int result;
  957. int scanedElement;
  958. int year;
  959. int month;
  960. int mday;
  961. int hour;
  962. int min;
  963. int sec;
  964. int tz_hour;
  965. int tz_min;
  966. float minSec;
  967. }parsingResult;
  968. struct tm tmStart;
  969. struct timeb tbStart;
  970. if(strstr((char*)start, ".") != NULL)
  971. {
  972. // Original data with mini second
  973. if(strstr((char*)start, "Z") != NULL)
  974. {
  975. // Original data with Z
  976. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  977. &parsingResult.year,
  978. &parsingResult.month,
  979. &parsingResult.mday,
  980. &parsingResult.hour,
  981. &parsingResult.min,
  982. &parsingResult.sec,
  983. &parsingResult.minSec);
  984. }
  985. else
  986. {
  987. // Original data without Z
  988. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  989. &parsingResult.year,
  990. &parsingResult.month,
  991. &parsingResult.mday,
  992. &parsingResult.hour,
  993. &parsingResult.min,
  994. &parsingResult.sec,
  995. &parsingResult.minSec,
  996. &parsingResult.tz_hour,
  997. &parsingResult.tz_min);
  998. }
  999. }
  1000. else
  1001. {
  1002. // Original data without mini second
  1003. if(strstr((char*)start, "Z") != NULL)
  1004. {
  1005. // Original data with Z
  1006. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1007. &parsingResult.year,
  1008. &parsingResult.month,
  1009. &parsingResult.mday,
  1010. &parsingResult.hour,
  1011. &parsingResult.min,
  1012. &parsingResult.sec);
  1013. }
  1014. else
  1015. {
  1016. // Original data without Z
  1017. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1018. &parsingResult.year,
  1019. &parsingResult.month,
  1020. &parsingResult.mday,
  1021. &parsingResult.hour,
  1022. &parsingResult.min,
  1023. &parsingResult.sec,
  1024. &parsingResult.tz_hour,
  1025. &parsingResult.tz_min);
  1026. }
  1027. }
  1028. if(parsingResult.scanedElement >= 6)
  1029. {
  1030. tmStart.tm_year = parsingResult.year - 1900;
  1031. tmStart.tm_mon = parsingResult.month - 1;
  1032. tmStart.tm_mday = parsingResult.mday;
  1033. tmStart.tm_hour = parsingResult.hour;
  1034. tmStart.tm_min = parsingResult.min;
  1035. tmStart.tm_sec = parsingResult.sec;
  1036. tmStart.tm_gmtoff = 0;
  1037. tbStart.time = mktime(&tmStart);
  1038. tbStart.timezone = 0;
  1039. tbStart.millitm = 0;
  1040. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1041. if(DiffTimebWithNowSec(tbStart) <= 0)
  1042. result = NO;
  1043. else
  1044. result = YES;
  1045. }
  1046. else
  1047. {
  1048. DEBUG_WARN("Start date parsing error.\n");
  1049. }
  1050. return result;
  1051. }
  1052. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1053. {
  1054. int result = -1;
  1055. struct tm tmStart;
  1056. struct timeb tbStart;
  1057. struct tm tmStop;
  1058. struct timeb tbStop;
  1059. 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) &&
  1060. (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))
  1061. {
  1062. tmStart.tm_year -= 1900;
  1063. tmStart.tm_mon -= 1;
  1064. tbStart.time = mktime(&tmStart);
  1065. tbStart.millitm = 0;
  1066. tmStop.tm_year -= 1900;
  1067. tmStop.tm_mon -= 1;
  1068. tbStop.time = mktime(&tmStop);
  1069. tbStop.millitm = 0;
  1070. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1071. }
  1072. return result;
  1073. }
  1074. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1075. {
  1076. FILE *fp;
  1077. char profileFileName[128];
  1078. char *line = NULL;
  1079. size_t len = 0;
  1080. time_t CurrentTime;
  1081. struct tm *tmComposite;
  1082. struct StructChargingProfile maxProfile;
  1083. struct StructChargingProfile compositeProfile;
  1084. uint8_t limitMax=0;
  1085. int compositePeriodIdx = 0;
  1086. CurrentTime = time(NULL);
  1087. tmComposite=localtime(&CurrentTime);
  1088. 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);
  1089. if(isUnitA)
  1090. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1091. else
  1092. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1093. compositeProfile.ChargingSchedule.Duration = durationReq;
  1094. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1095. {
  1096. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1097. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1098. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1099. }
  1100. compositeProfile.ChargingProfileId = 0;
  1101. compositeProfile.StackLevel = 99 ;
  1102. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1103. maxProfile.ChargingProfileId = -1;
  1104. maxProfile.ChargingSchedule.Duration = -1;
  1105. system("rm -f /tmp/*.json");
  1106. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1107. // Search max profile
  1108. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1109. if((access(profileFileName, F_OK))!=-1)
  1110. {
  1111. fp = fopen(profileFileName, "r");
  1112. while(getline(&line, &len, fp) != -1)
  1113. {
  1114. json_object *obj = NULL;
  1115. obj = json_tokener_parse(line);
  1116. if(is_error(obj))
  1117. {
  1118. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1119. }
  1120. else
  1121. {
  1122. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1123. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1124. )
  1125. {
  1126. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1127. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1128. )
  1129. {
  1130. struct tm tmFrom, tmTo;
  1131. struct timeb tbFrom, tbTo;
  1132. 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) &&
  1133. (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))
  1134. {
  1135. tmFrom.tm_year -= 1900;
  1136. tmFrom.tm_mon -= 1;
  1137. tbFrom.time = mktime(&tmFrom);
  1138. tmTo.tm_year -= 1900;
  1139. tmTo.tm_mon -= 1;
  1140. tbTo.time = mktime(&tmTo);
  1141. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1142. {
  1143. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1144. {
  1145. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1146. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1147. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1148. }
  1149. maxProfile.ChargingProfileId = -1;
  1150. maxProfile.StackLevel = -1;
  1151. if(maxProfile.ChargingProfileId == -1)
  1152. DEBUG_INFO("MaxProfile found.\n");
  1153. else
  1154. DEBUG_INFO("MaxProfile updated.\n");
  1155. // Required item
  1156. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1157. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1158. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1159. if(isUnitA)
  1160. {
  1161. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1162. 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++)
  1163. {
  1164. 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"));
  1165. 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?
  1166. 3:
  1167. 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")));
  1168. 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")));
  1169. }
  1170. }
  1171. else
  1172. {
  1173. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1174. 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++)
  1175. {
  1176. 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"));
  1177. 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?
  1178. 3:
  1179. 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")));
  1180. 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));
  1181. }
  1182. }
  1183. // Optional item
  1184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1185. {
  1186. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1187. }
  1188. else
  1189. {
  1190. sprintf((char*)maxProfile.ValidFrom, " ");
  1191. }
  1192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1193. {
  1194. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1195. }
  1196. else
  1197. {
  1198. sprintf((char*)maxProfile.ValidTo, " ");
  1199. }
  1200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1201. {
  1202. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1203. }
  1204. else
  1205. {
  1206. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1207. }
  1208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1209. {
  1210. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1211. }
  1212. else
  1213. {
  1214. maxProfile.TransactionId = -1;
  1215. }
  1216. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1217. {
  1218. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1219. }
  1220. else
  1221. {
  1222. maxProfile.ChargingSchedule.Duration = 86400;
  1223. }
  1224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1225. {
  1226. 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")));
  1227. }
  1228. else
  1229. {
  1230. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1231. }
  1232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1233. {
  1234. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1235. }
  1236. else
  1237. {
  1238. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1239. }
  1240. }
  1241. }
  1242. }
  1243. else
  1244. {
  1245. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1246. {
  1247. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1248. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1249. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1250. }
  1251. maxProfile.ChargingProfileId = -1;
  1252. maxProfile.StackLevel = -1;
  1253. if(maxProfile.ChargingProfileId == -1)
  1254. DEBUG_INFO("MaxProfile found.\n");
  1255. else
  1256. DEBUG_INFO("MaxProfile updated.\n");
  1257. // Required item
  1258. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1259. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1260. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1261. if(isUnitA)
  1262. {
  1263. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1264. 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++)
  1265. {
  1266. 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"));
  1267. 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?
  1268. 3:
  1269. 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")));
  1270. 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")));
  1271. }
  1272. }
  1273. else
  1274. {
  1275. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1276. 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++)
  1277. {
  1278. 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"));
  1279. 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?
  1280. 3:
  1281. 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")));
  1282. 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));
  1283. }
  1284. }
  1285. // Optional item
  1286. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1287. {
  1288. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1289. }
  1290. else
  1291. {
  1292. sprintf((char*)maxProfile.ValidFrom, " ");
  1293. }
  1294. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1295. {
  1296. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1297. }
  1298. else
  1299. {
  1300. sprintf((char*)maxProfile.ValidTo, " ");
  1301. }
  1302. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1303. {
  1304. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1305. }
  1306. else
  1307. {
  1308. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1309. }
  1310. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1311. {
  1312. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1313. }
  1314. else
  1315. {
  1316. maxProfile.TransactionId = -1;
  1317. }
  1318. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1319. {
  1320. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1321. }
  1322. else
  1323. {
  1324. maxProfile.ChargingSchedule.Duration = 86400;
  1325. }
  1326. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1327. {
  1328. 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")));
  1329. }
  1330. else
  1331. {
  1332. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1333. }
  1334. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1335. {
  1336. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1337. }
  1338. else
  1339. {
  1340. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1341. }
  1342. }
  1343. }
  1344. }
  1345. json_object_put(obj);
  1346. }
  1347. fclose(fp);
  1348. /*
  1349. if(maxProfile.ChargingProfileId !=-1)
  1350. {
  1351. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1352. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1353. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1354. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1355. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1356. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1357. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1358. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1359. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1360. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1361. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1362. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1363. {
  1364. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1365. {
  1366. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1367. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1368. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1369. }
  1370. }
  1371. }
  1372. else
  1373. DEBUG_INFO("MaxProfile not found.\n");
  1374. DEBUG_INFO("------------------------------------\n");*/
  1375. }
  1376. if(maxProfile.ChargingProfileId != -1)
  1377. {
  1378. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1379. {
  1380. if(maxProfile.ChargingSchedule.Duration != -1)
  1381. {
  1382. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1383. 0:
  1384. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1385. }
  1386. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1387. {
  1388. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1389. {
  1390. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1391. 0:
  1392. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1393. if(idxPeriod > 0)
  1394. {
  1395. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1396. {
  1397. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1404. {
  1405. if(maxProfile.ChargingSchedule.Duration != -1)
  1406. {
  1407. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1408. }
  1409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1410. {
  1411. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1412. {
  1413. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1414. if(idxPeriod > 0)
  1415. {
  1416. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1417. {
  1418. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1419. }
  1420. }
  1421. }
  1422. }
  1423. }
  1424. else
  1425. {
  1426. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1427. {
  1428. if(maxProfile.ChargingSchedule.Duration != -1)
  1429. {
  1430. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1431. 0:
  1432. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1433. }
  1434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1435. {
  1436. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1437. {
  1438. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1439. 0:
  1440. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1441. if(idxPeriod > 0)
  1442. {
  1443. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1444. {
  1445. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if(maxProfile.ChargingSchedule.Duration != -1)
  1454. {
  1455. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1456. 0:
  1457. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1458. }
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1462. {
  1463. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1464. 0:
  1465. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1466. if(idxPeriod > 0)
  1467. {
  1468. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1469. {
  1470. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1471. }
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. /*
  1478. DEBUG_INFO("MaxProfile after align.\n");
  1479. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1480. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1481. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1482. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1483. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1484. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1485. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1486. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1487. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1488. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1489. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1490. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1491. {
  1492. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1493. {
  1494. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1495. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1496. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1497. }
  1498. }
  1499. DEBUG_INFO("------------------------------------\n");*/
  1500. }
  1501. // Find each profile period quantity
  1502. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1503. {
  1504. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1505. limitMax = idx+1;
  1506. }
  1507. if(maxProfile.ChargingProfileId != -1)
  1508. {
  1509. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1510. {
  1511. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1512. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1513. (maxProfile.ChargingSchedule.Duration > 0))
  1514. {
  1515. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1516. {
  1517. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1518. compositePeriodIdx++;
  1519. }
  1520. else
  1521. {
  1522. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1523. }
  1524. }
  1525. }
  1526. }
  1527. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1528. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1529. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1530. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1531. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1532. {
  1533. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1534. {
  1535. compositeProfile.ChargingProfileId = 1;
  1536. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1537. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1538. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1539. }
  1540. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1541. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1542. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1543. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1544. }
  1545. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1546. if(line)
  1547. free(line);
  1548. }
  1549. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1550. {
  1551. FILE *fp;
  1552. char profileFileName[128];
  1553. char *line = NULL;
  1554. size_t len = 0;
  1555. time_t CurrentTime;
  1556. struct tm *tmComposite;
  1557. struct StructChargingProfile maxProfile;
  1558. struct StructChargingProfile defaultTxProfile;
  1559. struct StructChargingProfile txProfile;
  1560. struct StructChargingProfile compositeProfile;
  1561. struct StructChargingSchedulePeriod tmpPeriod;
  1562. uint8_t limitMax=0;
  1563. uint8_t limitDef=0;
  1564. uint8_t limitTx=0;
  1565. int compositePeriodIdx = 0;
  1566. CurrentTime = time(NULL);
  1567. tmComposite=localtime(&CurrentTime);
  1568. 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);
  1569. if(isUnitA)
  1570. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1571. else
  1572. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1573. compositeProfile.ChargingSchedule.Duration = durationReq;
  1574. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1575. {
  1576. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1577. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1578. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1579. }
  1580. compositeProfile.ChargingProfileId = 0;
  1581. compositeProfile.StackLevel = 99 ;
  1582. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1583. maxProfile.ChargingProfileId = -1;
  1584. defaultTxProfile.ChargingProfileId = -1;
  1585. txProfile.ChargingProfileId = -1;
  1586. maxProfile.ChargingSchedule.Duration = -1;
  1587. defaultTxProfile.ChargingSchedule.Duration = -1;
  1588. txProfile.ChargingSchedule.Duration = -1;
  1589. system("rm -f /tmp/*.json");
  1590. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1591. /*
  1592. * Search valid charging profile
  1593. */
  1594. //DEBUG_INFO("====================================\n");
  1595. // Search tx profile
  1596. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1597. if((access(profileFileName, F_OK))!=-1)
  1598. {
  1599. fp = fopen(profileFileName, "r");
  1600. while(getline(&line, &len, fp) != -1)
  1601. {
  1602. json_object *obj = NULL;
  1603. obj = json_tokener_parse(line);
  1604. if(is_error(obj))
  1605. {
  1606. DEBUG_ERROR("Parse txProfile from file error.\n");
  1607. }
  1608. else
  1609. {
  1610. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1611. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1612. )
  1613. {
  1614. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1615. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1616. )
  1617. {
  1618. struct tm tmFrom, tmTo;
  1619. struct timeb tbFrom, tbTo;
  1620. 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) &&
  1621. (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))
  1622. {
  1623. tmFrom.tm_year -= 1900;
  1624. tmFrom.tm_mon -= 1;
  1625. tbFrom.time = mktime(&tmFrom);
  1626. tmTo.tm_year -= 1900;
  1627. tmTo.tm_mon -= 1;
  1628. tbTo.time = mktime(&tmTo);
  1629. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1630. {
  1631. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1632. {
  1633. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1634. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1635. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1636. }
  1637. txProfile.ChargingProfileId = -1;
  1638. txProfile.StackLevel = -1;
  1639. if(txProfile.ChargingProfileId == -1)
  1640. DEBUG_INFO("TxProfile found.\n");
  1641. else
  1642. DEBUG_INFO("TxProfile updated.\n");
  1643. // Required item
  1644. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1645. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1646. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1647. if(isUnitA)
  1648. {
  1649. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1650. 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++)
  1651. {
  1652. 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"));
  1653. 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?
  1654. 3:
  1655. 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")));
  1656. 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")));
  1657. }
  1658. }
  1659. else
  1660. {
  1661. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1662. 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++)
  1663. {
  1664. 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"));
  1665. 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?
  1666. 3:
  1667. 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")));
  1668. 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));
  1669. }
  1670. }
  1671. // Optional item
  1672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1673. {
  1674. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1675. }
  1676. else
  1677. {
  1678. sprintf((char*)txProfile.ValidFrom, " ");
  1679. }
  1680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1681. {
  1682. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1683. }
  1684. else
  1685. {
  1686. sprintf((char*)txProfile.ValidTo, " ");
  1687. }
  1688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1689. {
  1690. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1691. }
  1692. else
  1693. {
  1694. sprintf((char*)txProfile.RecurrencyKind, " ");
  1695. }
  1696. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1697. {
  1698. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1699. }
  1700. else
  1701. {
  1702. txProfile.TransactionId = -1;
  1703. }
  1704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1705. {
  1706. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1707. }
  1708. else
  1709. {
  1710. txProfile.ChargingSchedule.Duration = 86400;
  1711. }
  1712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1713. {
  1714. 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")));
  1715. }
  1716. else
  1717. {
  1718. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1719. }
  1720. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1721. {
  1722. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1723. }
  1724. else
  1725. {
  1726. txProfile.ChargingSchedule.MinChargingRate = -1;
  1727. }
  1728. }
  1729. }
  1730. }
  1731. else
  1732. {
  1733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1734. {
  1735. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1736. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1737. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1738. }
  1739. txProfile.ChargingProfileId = -1;
  1740. txProfile.StackLevel = -1;
  1741. if(txProfile.ChargingProfileId == -1)
  1742. DEBUG_INFO("TxProfile found.\n");
  1743. else
  1744. DEBUG_INFO("TxProfile updated.\n");
  1745. // Required item
  1746. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1747. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1748. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1749. if(isUnitA)
  1750. {
  1751. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1752. 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++)
  1753. {
  1754. 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"));
  1755. 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?
  1756. 3:
  1757. 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")));
  1758. 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")));
  1759. }
  1760. }
  1761. else
  1762. {
  1763. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1764. 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++)
  1765. {
  1766. 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"));
  1767. 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?
  1768. 3:
  1769. 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")));
  1770. 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));
  1771. }
  1772. }
  1773. // Optional item
  1774. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1775. {
  1776. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1777. }
  1778. else
  1779. {
  1780. sprintf((char*)txProfile.ValidFrom, " ");
  1781. }
  1782. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1783. {
  1784. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1785. }
  1786. else
  1787. {
  1788. sprintf((char*)txProfile.ValidTo, " ");
  1789. }
  1790. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1791. {
  1792. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1793. }
  1794. else
  1795. {
  1796. sprintf((char*)txProfile.RecurrencyKind, " ");
  1797. }
  1798. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1799. {
  1800. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1801. }
  1802. else
  1803. {
  1804. txProfile.TransactionId = -1;
  1805. }
  1806. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1807. {
  1808. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1809. }
  1810. else
  1811. {
  1812. txProfile.ChargingSchedule.Duration = 86400;
  1813. }
  1814. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1815. {
  1816. 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")));
  1817. }
  1818. else
  1819. {
  1820. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1821. }
  1822. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1823. {
  1824. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1825. }
  1826. else
  1827. {
  1828. txProfile.ChargingSchedule.MinChargingRate = -1;
  1829. }
  1830. }
  1831. }
  1832. }
  1833. json_object_put(obj);
  1834. }
  1835. fclose(fp);
  1836. /*
  1837. if(txProfile.ChargingProfileId != -1)
  1838. {
  1839. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1840. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1841. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1842. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1843. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1844. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1845. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1846. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1847. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1848. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1849. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1850. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1851. {
  1852. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1853. {
  1854. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1855. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1856. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1857. }
  1858. }
  1859. }
  1860. else
  1861. DEBUG_INFO("TxProfile not found.\n");*/
  1862. }
  1863. // Search default tx profile
  1864. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1865. if((access(profileFileName, F_OK))==-1)
  1866. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1867. if((access(profileFileName, F_OK))!=-1)
  1868. {
  1869. fp = fopen(profileFileName, "r");
  1870. while(getline(&line, &len, fp) != -1)
  1871. {
  1872. json_object *obj = NULL;
  1873. obj = json_tokener_parse(line);
  1874. if(is_error(obj))
  1875. {
  1876. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1877. }
  1878. else
  1879. {
  1880. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1881. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1882. )
  1883. {
  1884. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1885. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1886. )
  1887. {
  1888. struct tm tmFrom, tmTo;
  1889. struct timeb tbFrom, tbTo;
  1890. 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) &&
  1891. (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))
  1892. {
  1893. tmFrom.tm_year -= 1900;
  1894. tmFrom.tm_mon -= 1;
  1895. tbFrom.time = mktime(&tmFrom);
  1896. tmTo.tm_year -= 1900;
  1897. tmTo.tm_mon -= 1;
  1898. tbTo.time = mktime(&tmTo);
  1899. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1900. {
  1901. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1902. {
  1903. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1904. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1905. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1906. }
  1907. defaultTxProfile.ChargingProfileId = -1;
  1908. defaultTxProfile.StackLevel = -1;
  1909. if(defaultTxProfile.ChargingProfileId == -1)
  1910. DEBUG_INFO("TxDefaultProfile found.\n");
  1911. else
  1912. DEBUG_INFO("TxDefaultProfile updated.\n");
  1913. // Required item
  1914. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1915. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1916. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1917. if(isUnitA)
  1918. {
  1919. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1920. 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++)
  1921. {
  1922. 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"));
  1923. 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?
  1924. 3:
  1925. 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")));
  1926. 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")));
  1927. }
  1928. }
  1929. else
  1930. {
  1931. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1932. 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++)
  1933. {
  1934. 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"));
  1935. 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?
  1936. 3:
  1937. 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")));
  1938. 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));
  1939. }
  1940. }
  1941. // Optional item
  1942. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1943. {
  1944. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1945. }
  1946. else
  1947. {
  1948. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1949. }
  1950. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1951. {
  1952. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1953. }
  1954. else
  1955. {
  1956. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1957. }
  1958. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1959. {
  1960. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1961. }
  1962. else
  1963. {
  1964. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1965. }
  1966. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1967. {
  1968. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1969. }
  1970. else
  1971. {
  1972. defaultTxProfile.TransactionId = -1;
  1973. }
  1974. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1975. {
  1976. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1977. }
  1978. else
  1979. {
  1980. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1981. }
  1982. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1983. {
  1984. 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")));
  1985. }
  1986. else
  1987. {
  1988. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1989. }
  1990. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1991. {
  1992. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1993. }
  1994. else
  1995. {
  1996. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1997. }
  1998. }
  1999. }
  2000. }
  2001. else
  2002. {
  2003. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2004. {
  2005. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2006. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2007. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2008. }
  2009. defaultTxProfile.ChargingProfileId = -1;
  2010. defaultTxProfile.StackLevel = -1;
  2011. if(defaultTxProfile.ChargingProfileId == -1)
  2012. DEBUG_INFO("TxDefaultProfile found.\n");
  2013. else
  2014. DEBUG_INFO("TxDefaultProfile updated.\n");
  2015. // Required item
  2016. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2017. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2018. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2019. if(isUnitA)
  2020. {
  2021. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2022. 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++)
  2023. {
  2024. 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"));
  2025. 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?
  2026. 3:
  2027. 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")));
  2028. 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")));
  2029. }
  2030. }
  2031. else
  2032. {
  2033. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2034. 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++)
  2035. {
  2036. 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"));
  2037. 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?
  2038. 3:
  2039. 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")));
  2040. 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));
  2041. }
  2042. }
  2043. // Optional item
  2044. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2045. {
  2046. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2047. }
  2048. else
  2049. {
  2050. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2051. }
  2052. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2053. {
  2054. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2055. }
  2056. else
  2057. {
  2058. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2059. }
  2060. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2061. {
  2062. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2063. }
  2064. else
  2065. {
  2066. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2067. }
  2068. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2069. {
  2070. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2071. }
  2072. else
  2073. {
  2074. defaultTxProfile.TransactionId = -1;
  2075. }
  2076. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2077. {
  2078. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2079. }
  2080. else
  2081. {
  2082. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2083. }
  2084. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2085. {
  2086. 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")));
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2091. }
  2092. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2093. {
  2094. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2095. }
  2096. else
  2097. {
  2098. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2099. }
  2100. }
  2101. }
  2102. }
  2103. json_object_put(obj);
  2104. }
  2105. fclose(fp);
  2106. /*
  2107. if(defaultTxProfile.ChargingProfileId != -1)
  2108. {
  2109. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2110. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2111. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2112. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2113. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2114. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2115. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2116. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2117. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2118. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2119. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2120. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2121. {
  2122. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2123. {
  2124. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2125. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2126. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2127. }
  2128. }
  2129. }
  2130. else
  2131. DEBUG_INFO("TxDefaultProfile not found.\n");
  2132. DEBUG_INFO("------------------------------------\n");*/
  2133. }
  2134. // Search max profile
  2135. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2136. if((access(profileFileName, F_OK))!=-1)
  2137. {
  2138. fp = fopen(profileFileName, "r");
  2139. while(getline(&line, &len, fp) != -1)
  2140. {
  2141. json_object *obj = NULL;
  2142. obj = json_tokener_parse(line);
  2143. if(is_error(obj))
  2144. {
  2145. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2146. }
  2147. else
  2148. {
  2149. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2150. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2151. )
  2152. {
  2153. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2154. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2155. )
  2156. {
  2157. struct tm tmFrom, tmTo;
  2158. struct timeb tbFrom, tbTo;
  2159. 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) &&
  2160. (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))
  2161. {
  2162. tmFrom.tm_year -= 1900;
  2163. tmFrom.tm_mon -= 1;
  2164. tbFrom.time = mktime(&tmFrom);
  2165. tmTo.tm_year -= 1900;
  2166. tmTo.tm_mon -= 1;
  2167. tbTo.time = mktime(&tmTo);
  2168. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2169. {
  2170. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2171. {
  2172. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2174. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2175. }
  2176. maxProfile.ChargingProfileId = -1;
  2177. maxProfile.StackLevel = -1;
  2178. if(maxProfile.ChargingProfileId == -1)
  2179. DEBUG_INFO("MaxProfile found.\n");
  2180. else
  2181. DEBUG_INFO("MaxProfile updated.\n");
  2182. // Required item
  2183. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2184. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2185. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2186. if(isUnitA)
  2187. {
  2188. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2189. 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++)
  2190. {
  2191. 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"));
  2192. 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?
  2193. 3:
  2194. 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")));
  2195. 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")));
  2196. }
  2197. }
  2198. else
  2199. {
  2200. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2201. 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++)
  2202. {
  2203. 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"));
  2204. 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?
  2205. 3:
  2206. 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")));
  2207. 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));
  2208. }
  2209. }
  2210. // Optional item
  2211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2212. {
  2213. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2214. }
  2215. else
  2216. {
  2217. sprintf((char*)maxProfile.ValidFrom, " ");
  2218. }
  2219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2220. {
  2221. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)maxProfile.ValidTo, " ");
  2226. }
  2227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2228. {
  2229. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2230. }
  2231. else
  2232. {
  2233. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2234. }
  2235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2236. {
  2237. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2238. }
  2239. else
  2240. {
  2241. maxProfile.TransactionId = -1;
  2242. }
  2243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2244. {
  2245. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2246. }
  2247. else
  2248. {
  2249. maxProfile.ChargingSchedule.Duration = 86400;
  2250. }
  2251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2252. {
  2253. 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")));
  2254. }
  2255. else
  2256. {
  2257. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2258. }
  2259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2260. {
  2261. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2262. }
  2263. else
  2264. {
  2265. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2266. }
  2267. }
  2268. }
  2269. }
  2270. else
  2271. {
  2272. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2273. {
  2274. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2277. }
  2278. maxProfile.ChargingProfileId = -1;
  2279. maxProfile.StackLevel = -1;
  2280. if(maxProfile.ChargingProfileId == -1)
  2281. DEBUG_INFO("MaxProfile found.\n");
  2282. else
  2283. DEBUG_INFO("MaxProfile updated.\n");
  2284. // Required item
  2285. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2286. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2287. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2288. if(isUnitA)
  2289. {
  2290. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2291. 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++)
  2292. {
  2293. 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"));
  2294. 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?
  2295. 3:
  2296. 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")));
  2297. 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")));
  2298. }
  2299. }
  2300. else
  2301. {
  2302. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2303. 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++)
  2304. {
  2305. 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"));
  2306. 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?
  2307. 3:
  2308. 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")));
  2309. 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));
  2310. }
  2311. }
  2312. // Optional item
  2313. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2314. {
  2315. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2316. }
  2317. else
  2318. {
  2319. sprintf((char*)maxProfile.ValidFrom, " ");
  2320. }
  2321. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2322. {
  2323. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2324. }
  2325. else
  2326. {
  2327. sprintf((char*)maxProfile.ValidTo, " ");
  2328. }
  2329. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2330. {
  2331. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2332. }
  2333. else
  2334. {
  2335. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2336. }
  2337. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2338. {
  2339. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2340. }
  2341. else
  2342. {
  2343. maxProfile.TransactionId = -1;
  2344. }
  2345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2346. {
  2347. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2348. }
  2349. else
  2350. {
  2351. maxProfile.ChargingSchedule.Duration = 86400;
  2352. }
  2353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2354. {
  2355. 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")));
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2360. }
  2361. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2362. {
  2363. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2364. }
  2365. else
  2366. {
  2367. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2368. }
  2369. }
  2370. }
  2371. }
  2372. json_object_put(obj);
  2373. }
  2374. fclose(fp);
  2375. /*
  2376. if(maxProfile.ChargingProfileId !=-1)
  2377. {
  2378. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2379. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2380. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2381. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2382. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2383. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2384. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2385. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2386. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2387. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2388. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2389. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2390. {
  2391. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2392. {
  2393. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2394. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2395. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2396. }
  2397. }
  2398. }
  2399. else
  2400. DEBUG_INFO("MaxProfile not found.\n");
  2401. DEBUG_INFO("------------------------------------\n");*/
  2402. }
  2403. /*
  2404. * Align found profile start schedule & periods
  2405. */
  2406. //DEBUG_INFO("====================================\n");
  2407. /*
  2408. // For local test usage, force modify found profile start schedule info
  2409. 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);
  2410. 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);
  2411. 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);
  2412. */
  2413. if(txProfile.ChargingProfileId != -1)
  2414. {
  2415. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2416. {
  2417. if(txProfile.ChargingSchedule.Duration != -1)
  2418. {
  2419. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2420. 0:
  2421. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2422. }
  2423. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2424. {
  2425. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2426. {
  2427. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2428. 0:
  2429. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2430. if(idxPeriod > 0)
  2431. {
  2432. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2433. {
  2434. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2441. {
  2442. if(txProfile.ChargingSchedule.Duration != -1)
  2443. {
  2444. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2445. 0:
  2446. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2447. }
  2448. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2449. {
  2450. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2451. {
  2452. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2453. 0:
  2454. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2455. if(idxPeriod > 0)
  2456. {
  2457. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2458. {
  2459. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. }
  2465. else
  2466. {
  2467. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2468. {
  2469. if(txProfile.ChargingSchedule.Duration != -1)
  2470. {
  2471. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2472. 0:
  2473. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2474. }
  2475. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2476. {
  2477. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2478. {
  2479. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2480. 0:
  2481. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2482. if(idxPeriod > 0)
  2483. {
  2484. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2485. {
  2486. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2487. }
  2488. }
  2489. }
  2490. }
  2491. }
  2492. else
  2493. {
  2494. if(txProfile.ChargingSchedule.Duration != -1)
  2495. {
  2496. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2497. 0:
  2498. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2499. }
  2500. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2501. {
  2502. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2503. {
  2504. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2505. 0:
  2506. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2507. if(idxPeriod > 0)
  2508. {
  2509. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2510. {
  2511. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. /*
  2519. DEBUG_INFO("txProfile after align.\n");
  2520. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2521. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2522. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2523. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2524. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2525. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2526. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2527. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2528. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2529. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2530. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2531. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2532. {
  2533. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2534. {
  2535. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2536. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2537. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2538. }
  2539. }*/
  2540. }
  2541. if(defaultTxProfile.ChargingProfileId != -1)
  2542. {
  2543. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2544. {
  2545. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2546. {
  2547. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2548. 0:
  2549. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2550. }
  2551. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2552. {
  2553. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2554. {
  2555. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2556. 0:
  2557. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2558. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2559. {
  2560. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2561. }
  2562. if(idxPeriod > 0)
  2563. {
  2564. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2565. {
  2566. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2567. }
  2568. }
  2569. }
  2570. }
  2571. }
  2572. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2573. {
  2574. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2575. {
  2576. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2577. 0:
  2578. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2579. }
  2580. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2581. {
  2582. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2583. {
  2584. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2585. 0:
  2586. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2587. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2588. {
  2589. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2590. }
  2591. if(idxPeriod > 0)
  2592. {
  2593. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2594. {
  2595. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2596. }
  2597. }
  2598. }
  2599. }
  2600. }
  2601. else
  2602. {
  2603. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2604. {
  2605. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2606. {
  2607. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2608. 0:
  2609. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2610. }
  2611. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2612. {
  2613. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2614. {
  2615. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2616. 0:
  2617. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2618. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2619. {
  2620. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2621. }
  2622. if(idxPeriod > 0)
  2623. {
  2624. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2625. {
  2626. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2627. }
  2628. }
  2629. }
  2630. }
  2631. }
  2632. else
  2633. {
  2634. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2635. {
  2636. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2637. 0:
  2638. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2639. }
  2640. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2641. {
  2642. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2643. {
  2644. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2645. 0:
  2646. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2648. {
  2649. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2650. }
  2651. if(idxPeriod > 0)
  2652. {
  2653. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2654. {
  2655. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. /*
  2663. DEBUG_INFO("defaultTxProfile after align.\n");
  2664. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2665. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2666. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2667. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2668. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2669. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2670. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2671. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2672. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2673. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2674. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2675. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2676. {
  2677. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2678. {
  2679. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2680. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2681. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2682. }
  2683. }
  2684. DEBUG_INFO("------------------------------------\n");*/
  2685. }
  2686. if(maxProfile.ChargingProfileId != -1)
  2687. {
  2688. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2689. {
  2690. if(maxProfile.ChargingSchedule.Duration != -1)
  2691. {
  2692. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2693. 0:
  2694. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2695. }
  2696. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2697. {
  2698. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2699. {
  2700. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2701. 0:
  2702. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2703. if(idxPeriod > 0)
  2704. {
  2705. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2706. {
  2707. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2708. }
  2709. }
  2710. }
  2711. }
  2712. }
  2713. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2714. {
  2715. if(maxProfile.ChargingSchedule.Duration != -1)
  2716. {
  2717. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2718. 0:
  2719. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2720. }
  2721. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2722. {
  2723. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2724. {
  2725. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2726. 0:
  2727. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2728. if(idxPeriod > 0)
  2729. {
  2730. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2731. {
  2732. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2733. }
  2734. }
  2735. }
  2736. }
  2737. }
  2738. else
  2739. {
  2740. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2741. {
  2742. if(maxProfile.ChargingSchedule.Duration != -1)
  2743. {
  2744. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2745. 0:
  2746. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2747. }
  2748. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2749. {
  2750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2751. {
  2752. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2753. 0:
  2754. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2755. if(idxPeriod > 0)
  2756. {
  2757. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2758. {
  2759. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2760. }
  2761. }
  2762. }
  2763. }
  2764. }
  2765. else
  2766. {
  2767. if(maxProfile.ChargingSchedule.Duration != -1)
  2768. {
  2769. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2770. 0:
  2771. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2772. }
  2773. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2774. {
  2775. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2776. {
  2777. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2778. 0:
  2779. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2780. if(idxPeriod > 0)
  2781. {
  2782. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2783. {
  2784. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2785. }
  2786. }
  2787. }
  2788. }
  2789. }
  2790. }
  2791. /*
  2792. DEBUG_INFO("MaxProfile after align.\n");
  2793. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2794. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2795. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2796. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2797. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2798. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2799. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2800. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2801. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2802. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2803. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2805. {
  2806. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2807. {
  2808. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2809. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2810. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2811. }
  2812. }
  2813. DEBUG_INFO("------------------------------------\n");*/
  2814. }
  2815. /*
  2816. * Merge to conposite schedule
  2817. */
  2818. //DEBUG_INFO("====================================\n");
  2819. // Find each profile period quantity
  2820. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2821. {
  2822. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2823. limitMax = idx+1;
  2824. }
  2825. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2826. {
  2827. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2828. limitDef = idx+1;
  2829. }
  2830. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2831. {
  2832. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2833. limitTx = idx+1;
  2834. }
  2835. // TxProfile found, composite schedule based on it
  2836. if(txProfile.ChargingProfileId != -1)
  2837. {
  2838. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2839. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2840. {
  2841. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2842. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2843. (txProfile.ChargingSchedule.Duration > 0))
  2844. {
  2845. if(maxProfile.ChargingProfileId != -1)
  2846. {
  2847. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2848. {
  2849. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2850. {
  2851. if((maxProfile.ChargingSchedule.Duration > 0))
  2852. {
  2853. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2854. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2855. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2856. }
  2857. else
  2858. {
  2859. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2860. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2861. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2862. }
  2863. }
  2864. if(idxMaxPeriod == (limitMax-1))
  2865. {
  2866. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2867. {
  2868. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2869. {
  2870. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2871. compositePeriodIdx++;
  2872. }
  2873. else
  2874. {
  2875. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. else
  2882. {
  2883. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2884. {
  2885. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2886. compositePeriodIdx++;
  2887. }
  2888. else
  2889. {
  2890. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2891. }
  2892. }
  2893. }
  2894. if(idxTxPeriod == (limitTx-1))
  2895. {
  2896. if(defaultTxProfile.ChargingProfileId != -1)
  2897. {
  2898. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  2899. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2900. {
  2901. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2902. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2903. (defaultTxProfile.ChargingSchedule.Duration>0))
  2904. {
  2905. if(maxProfile.ChargingProfileId != -1)
  2906. {
  2907. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2908. {
  2909. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2910. {
  2911. if((maxProfile.ChargingSchedule.Duration > 0))
  2912. {
  2913. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2914. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2915. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2916. }
  2917. else
  2918. {
  2919. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2920. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2921. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2922. }
  2923. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2924. {
  2925. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2926. {
  2927. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2928. compositePeriodIdx++;
  2929. }
  2930. else
  2931. {
  2932. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2933. }
  2934. }
  2935. // Delete duplicate period
  2936. if(compositePeriodIdx > 1)
  2937. {
  2938. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2939. {
  2940. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2941. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2942. compositePeriodIdx -= 1;
  2943. }
  2944. }
  2945. }
  2946. else
  2947. {
  2948. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2949. {
  2950. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2951. compositePeriodIdx++;
  2952. }
  2953. else
  2954. {
  2955. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2956. }
  2957. break;
  2958. }
  2959. }
  2960. }
  2961. else
  2962. {
  2963. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2964. {
  2965. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2966. compositePeriodIdx++;
  2967. }
  2968. else
  2969. {
  2970. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2971. }
  2972. }
  2973. }
  2974. }
  2975. }
  2976. }
  2977. }
  2978. }
  2979. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2980. else if(defaultTxProfile.ChargingProfileId != -1)
  2981. {
  2982. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2983. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2984. {
  2985. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2986. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2987. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2988. {
  2989. if(maxProfile.ChargingProfileId != -1)
  2990. {
  2991. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2992. {
  2993. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2994. {
  2995. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2996. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2997. if((maxProfile.ChargingSchedule.Duration > 0))
  2998. {
  2999. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3000. }
  3001. else
  3002. {
  3003. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3004. }
  3005. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3006. {
  3007. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3008. {
  3009. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3010. compositePeriodIdx++;
  3011. }
  3012. else
  3013. {
  3014. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3015. }
  3016. }
  3017. // Delete duplicate period
  3018. if(compositePeriodIdx > 1)
  3019. {
  3020. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3021. {
  3022. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3023. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3024. compositePeriodIdx -= 1;
  3025. }
  3026. }
  3027. }
  3028. else
  3029. {
  3030. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3031. {
  3032. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3033. compositePeriodIdx++;
  3034. }
  3035. else
  3036. {
  3037. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3038. }
  3039. break;
  3040. }
  3041. }
  3042. }
  3043. else
  3044. {
  3045. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3046. {
  3047. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3048. compositePeriodIdx++;
  3049. }
  3050. else
  3051. {
  3052. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3053. }
  3054. }
  3055. }
  3056. }
  3057. }
  3058. // Fill other period by MaxProfile
  3059. if(maxProfile.ChargingProfileId != -1)
  3060. {
  3061. if(compositePeriodIdx==0)
  3062. {
  3063. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3064. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3065. {
  3066. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3067. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3068. (maxProfile.ChargingSchedule.Duration > 0))
  3069. {
  3070. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3071. {
  3072. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3073. compositePeriodIdx++;
  3074. }
  3075. else
  3076. {
  3077. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3078. }
  3079. }
  3080. }
  3081. }
  3082. else
  3083. {
  3084. int lastCompositePeriodIdx = compositePeriodIdx;
  3085. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3086. {
  3087. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3088. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3089. (maxProfile.ChargingSchedule.Duration > 0))
  3090. {
  3091. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3092. {
  3093. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3094. {
  3095. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3096. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3097. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3098. }
  3099. else
  3100. {
  3101. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3102. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3103. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3104. }
  3105. }
  3106. if(tmpPeriod.Limit != -1)
  3107. {
  3108. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3109. {
  3110. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3111. {
  3112. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3113. compositePeriodIdx++;
  3114. }
  3115. else
  3116. {
  3117. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3118. }
  3119. }
  3120. // Delete duplicate period
  3121. if(compositePeriodIdx > 1)
  3122. {
  3123. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3124. {
  3125. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3126. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3127. compositePeriodIdx -= 1;
  3128. }
  3129. }
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. compositeProfile.ChargingSchedule.Duration = durationReq;
  3136. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3137. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3138. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3139. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3140. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3141. {
  3142. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3143. {
  3144. compositeProfile.ChargingProfileId = 1;
  3145. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3146. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3147. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3148. }
  3149. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3150. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3151. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3152. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3153. }
  3154. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3155. if(line)
  3156. free(line);
  3157. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3158. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3159. }
  3160. //==========================================
  3161. // Init all share memory
  3162. //==========================================
  3163. int InitShareMemory()
  3164. {
  3165. int result = PASS;
  3166. int MeterSMId;
  3167. //creat ShmSysConfigAndInfo
  3168. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3169. {
  3170. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3171. result = FAIL;
  3172. }
  3173. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3174. {
  3175. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3176. result = FAIL;
  3177. }
  3178. else
  3179. {}
  3180. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3181. {
  3182. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3183. result = FAIL;
  3184. }
  3185. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3186. {
  3187. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3188. result = FAIL;
  3189. }
  3190. else
  3191. {}
  3192. //creat ShmPsuData
  3193. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3194. {
  3195. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3196. result = FAIL;
  3197. }
  3198. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3199. {
  3200. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3201. result = FAIL;
  3202. }
  3203. else
  3204. {}
  3205. //link ShmOCPP16Data
  3206. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3207. {
  3208. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3209. result = FAIL;
  3210. }
  3211. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3212. {
  3213. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3214. result = FAIL;
  3215. }
  3216. else
  3217. {}
  3218. //creat ShmOCPP16DataPH
  3219. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3220. {
  3221. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3222. result = FAIL;
  3223. }
  3224. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3225. {
  3226. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3227. result = FAIL;
  3228. }
  3229. else
  3230. {}
  3231. /****************************** For Initial Settings************************************************/
  3232. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3233. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3234. // allocate Configuration memory address
  3235. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3236. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3237. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3238. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3239. //offline MeterValue Interval
  3240. TempMeterValueInterval = 0;
  3241. return result;
  3242. }
  3243. int ProcessShareMemory()
  3244. {
  3245. int result = PASS;
  3246. if(InitShareMemory() == FAIL)
  3247. {
  3248. DEBUG_ERROR("InitShareMemory NG\n");
  3249. if(ShmStatusCodeData!=NULL)
  3250. {
  3251. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3252. }
  3253. result = FAIL;
  3254. }
  3255. // Model name parsing
  3256. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3257. {
  3258. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3259. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3260. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3261. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3262. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3263. ) // 'D' means DC
  3264. {
  3265. // DO series
  3266. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3267. {
  3268. SystemInitial += 1;
  3269. gunTotalNumber += 1;
  3270. gunType[gun_index] = GUN_TYPE_DO;
  3271. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3272. {
  3273. case Gun_Type_Chademo:
  3274. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3275. break;
  3276. case Gun_Type_CCS_2:
  3277. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3278. break;
  3279. case Gun_Type_GB:
  3280. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3281. break;
  3282. case Gun_Type_AC:
  3283. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3284. break;
  3285. default:
  3286. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3287. break;
  3288. }
  3289. }
  3290. }
  3291. else
  3292. {
  3293. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3294. {
  3295. SystemInitial += 1;
  3296. gunTotalNumber += 1;
  3297. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3298. {
  3299. case Gun_Type_Chademo:
  3300. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3301. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3302. break;
  3303. case Gun_Type_CCS_2:
  3304. gunType[gun_index] = GUN_TYPE_CCS;
  3305. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3306. break;
  3307. case Gun_Type_GB:
  3308. gunType[gun_index] = GUN_TYPE_GBT;
  3309. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3310. break;
  3311. case Gun_Type_AC:
  3312. gunType[gun_index] = GUN_TYPE_AC;
  3313. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3314. break;
  3315. default:
  3316. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3317. break;
  3318. }
  3319. }
  3320. }
  3321. }
  3322. else
  3323. {
  3324. DEBUG_ERROR("Model name parsing fail.\n");
  3325. result = FAIL;
  3326. }
  3327. if(result != PASS)sleep(5);
  3328. return result;
  3329. }
  3330. void checkRemoteStart(uint8_t connectorIdInt)
  3331. {
  3332. uint8_t tempIndex;
  3333. int result = PASS;
  3334. char cmdBuf[512];
  3335. //check Transaction active
  3336. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3337. {
  3338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3339. {
  3340. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3341. }
  3342. else
  3343. {
  3344. tempIndex = connectorIdInt -1;
  3345. }
  3346. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3347. {
  3348. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3349. {
  3350. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3351. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3352. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3353. {
  3354. //Reserved
  3355. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3356. }
  3357. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3358. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3359. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3360. {
  3361. //Reserved
  3362. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3363. result = FAIL;
  3364. goto end;
  3365. }
  3366. else
  3367. {
  3368. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3369. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3370. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3371. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3372. {
  3373. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3374. result = FAIL;
  3375. goto end;
  3376. }
  3377. }//END FOR ELSE
  3378. }
  3379. }// END FOR CHAdeMO_QUANTITY
  3380. }
  3381. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3382. {
  3383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3384. {
  3385. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3386. }
  3387. else
  3388. {
  3389. tempIndex = connectorIdInt -1;
  3390. }
  3391. for (int index = 0; index < CCS_QUANTITY; index++)
  3392. {
  3393. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3394. {
  3395. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3396. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3397. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3398. {
  3399. //Reserved
  3400. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3401. }
  3402. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3403. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3404. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3405. {
  3406. //Reserved
  3407. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3408. result = FAIL;
  3409. goto end;
  3410. }
  3411. else
  3412. {
  3413. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3414. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3415. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3416. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3417. {
  3418. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3419. result = FAIL;
  3420. goto end;
  3421. }
  3422. }// END FOR ELSE
  3423. }
  3424. }// END FOR CCS_QUANTITY
  3425. }
  3426. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3427. {
  3428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3429. {
  3430. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3431. }
  3432. else
  3433. {
  3434. tempIndex = connectorIdInt -1;
  3435. }
  3436. for (int index = 0; index < GB_QUANTITY; index++)
  3437. {
  3438. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3439. {
  3440. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3441. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3442. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3443. {
  3444. //Reserved
  3445. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3446. }
  3447. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3448. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3449. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3450. {
  3451. //Reserved
  3452. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3453. result = FAIL;
  3454. goto end;
  3455. }
  3456. else
  3457. {
  3458. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3459. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3460. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3461. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3462. {
  3463. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3464. result = FAIL;
  3465. goto end;
  3466. }
  3467. }// END FOR ELSE
  3468. }
  3469. } // END FOR GB_QUANTITY
  3470. }
  3471. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3472. {
  3473. tempIndex = connectorIdInt -1;
  3474. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3475. {
  3476. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3477. {
  3478. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3479. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3480. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3481. {
  3482. //Reserved
  3483. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3484. }
  3485. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3486. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3487. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3488. {
  3489. //Reserved
  3490. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3491. result = FAIL;
  3492. goto end;
  3493. }
  3494. else
  3495. {
  3496. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3497. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3498. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3499. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3500. {
  3501. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3502. result = FAIL;
  3503. goto end;
  3504. }
  3505. }// END FOR ELSE
  3506. }
  3507. } // END FOR GB_QUANTITY
  3508. }
  3509. else
  3510. {
  3511. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3512. {
  3513. tempIndex = 2;
  3514. }
  3515. else
  3516. {
  3517. tempIndex = connectorIdInt -1;
  3518. }
  3519. for (int index = 0; index < AC_QUANTITY; index++)
  3520. {
  3521. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3522. {
  3523. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3524. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3525. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3526. {
  3527. //Reserved
  3528. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3529. }
  3530. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3531. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3532. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3533. {
  3534. //Reserved
  3535. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3536. result = FAIL;
  3537. goto end;
  3538. }
  3539. else
  3540. {
  3541. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3542. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3543. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3544. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3545. {
  3546. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3547. result = FAIL;
  3548. goto end;
  3549. }
  3550. }//END FOR ELSE
  3551. }
  3552. }// END FOR AC_QUANTITY
  3553. }
  3554. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3555. {
  3556. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3557. {
  3558. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3559. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3560. {
  3561. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3562. system(cmdBuf);
  3563. }
  3564. }
  3565. else
  3566. {
  3567. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3568. result = FAIL;
  3569. }
  3570. }
  3571. end:
  3572. if(result == PASS)
  3573. {
  3574. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3575. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3576. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3577. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3579. }
  3580. }
  3581. void CheckSystemValue(void)
  3582. {
  3583. char filenmae[100]={0};
  3584. char str[100]={0};
  3585. int tempIndex = 0;
  3586. //===============================
  3587. // send Heartbeat
  3588. //===============================
  3589. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3590. {
  3591. //parameter for test
  3592. sendHeartbeatRequest(0);
  3593. //==============================================
  3594. // Reset Waiting Time
  3595. //==============================================
  3596. HeartBeatWithNOResponse += 2;
  3597. }
  3598. //===============================
  3599. // Credit deduct report
  3600. //===============================
  3601. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3602. {
  3603. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3604. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3605. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3606. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3607. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3608. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3609. }
  3610. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3611. {
  3612. OCPP_query_deduct_info();
  3613. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3614. }
  3615. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3616. {
  3617. // ClockAlign MeterValue
  3618. 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))
  3619. {
  3620. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3621. {
  3622. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3623. {
  3624. tempIndex = ((gun_index==2) ? 1: 0);
  3625. }
  3626. else
  3627. {
  3628. tempIndex = gun_index;
  3629. }
  3630. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3631. {
  3632. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3633. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3634. {
  3635. reqClockAlignMeter[gun_index] = 1;
  3636. }
  3637. }// End for CHAdeMO
  3638. }
  3639. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3640. {
  3641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3642. {
  3643. tempIndex = ((gun_index==2) ? 1: 0);
  3644. }
  3645. else
  3646. {
  3647. tempIndex = gun_index;
  3648. }
  3649. for (int index = 0; index < CCS_QUANTITY; index++)
  3650. {
  3651. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3652. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3653. {
  3654. reqClockAlignMeter[gun_index] = 1;
  3655. }
  3656. } // End for CCS
  3657. }
  3658. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3659. {
  3660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3661. {
  3662. tempIndex = ((gun_index==2) ? 1: 0);
  3663. }
  3664. else
  3665. {
  3666. tempIndex = gun_index;
  3667. }
  3668. for (int index = 0; index < GB_QUANTITY; index++)
  3669. {
  3670. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3671. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3672. {
  3673. reqClockAlignMeter[gun_index] = 1;
  3674. }
  3675. }// End for GB
  3676. }
  3677. else if(gunType[gun_index] == GUN_TYPE_DO)
  3678. {
  3679. tempIndex = gun_index;
  3680. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3681. {
  3682. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3683. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3684. {
  3685. reqClockAlignMeter[gun_index] = 1;
  3686. }
  3687. }
  3688. }
  3689. else
  3690. {
  3691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3692. {
  3693. tempIndex = 2;
  3694. }
  3695. else
  3696. {
  3697. tempIndex = gun_index;
  3698. }
  3699. for (int index = 0; index < AC_QUANTITY; index++)
  3700. {
  3701. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3702. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3703. {
  3704. reqClockAlignMeter[gun_index] = 1;
  3705. }
  3706. }//End for AC
  3707. }
  3708. }
  3709. }
  3710. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3711. {
  3712. //==========================================
  3713. // Check remote start without connector id
  3714. //==========================================
  3715. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3716. {
  3717. int connectorIdInt = -1;
  3718. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3719. {
  3720. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3721. {
  3722. connectorIdInt = (gun_index+1);
  3723. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3724. checkRemoteStart(connectorIdInt);
  3725. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3726. break;
  3727. }
  3728. }
  3729. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3730. {
  3731. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3732. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3733. }
  3734. }
  3735. //==========================================
  3736. // csu trigger DataTransferReq
  3737. //==========================================
  3738. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3739. {
  3740. sendDataTransferRequest(gun_index);
  3741. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3742. }
  3743. //===============================
  3744. // CSU Trigger Authorize Request
  3745. //===============================
  3746. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3747. {
  3748. sendAuthorizeRequest(0);
  3749. authorizeRetryTimes = authorizeRetryTimes + 1;
  3750. if(authorizeRetryTimes < 3)
  3751. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3752. }
  3753. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3754. {
  3755. authorizeRetryTimes = 0;
  3756. SetOcppConnStatus(FALSE);
  3757. server_sign = FALSE;
  3758. }
  3759. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  3760. {
  3761. sendAuthorizeRequest(0);
  3762. }
  3763. //==============================================
  3764. // Charger start transaction
  3765. //==============================================
  3766. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3767. {
  3768. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3769. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3770. sendStartTransactionRequest(gun_index);
  3771. refreshStartTimer(&clientTime.StartTransaction);
  3772. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3773. //storeTempStopTransaction(gun_index);
  3774. }
  3775. //==============================================
  3776. // Charger stop transaction
  3777. //==============================================
  3778. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3779. {
  3780. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3781. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3782. sendStopTransactionRequest(gun_index);
  3783. refreshStartTimer(&clientTime.StopTransaction);
  3784. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3785. }
  3786. //==============================================
  3787. // Charger status report
  3788. //==============================================
  3789. //--- Check Mode Change ---//
  3790. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3792. {
  3793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3794. {
  3795. tempIndex = ((gun_index==2) ? 1: 0);
  3796. }
  3797. else
  3798. {
  3799. tempIndex = gun_index;
  3800. }
  3801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3802. {
  3803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3804. {
  3805. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3806. {
  3807. // Sent unplug message for California pricing logic
  3808. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3809. {
  3810. uint8_t ts[20];
  3811. getNowDatetime(ts);
  3812. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3813. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3814. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3815. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3816. }
  3817. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3818. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3819. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3820. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3821. {
  3822. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3823. if((access(filenmae,F_OK))!=-1)
  3824. {
  3825. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3826. sprintf(str,"rm -f %s",filenmae);
  3827. system(str);
  3828. }
  3829. }
  3830. }
  3831. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3832. #if 1 // for TempStopTransaction
  3833. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3834. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3835. {
  3836. checkTempStopTransaction(gun_index);
  3837. }
  3838. #endif
  3839. }
  3840. }
  3841. }
  3842. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3843. {
  3844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3845. {
  3846. tempIndex = ((gun_index==2) ? 1: 0);
  3847. }
  3848. else
  3849. {
  3850. tempIndex = gun_index;
  3851. }
  3852. for (int index = 0; index < CCS_QUANTITY; index++)
  3853. {
  3854. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3855. {
  3856. 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]*/ )
  3857. {
  3858. // Sent unplug message for California pricing logic
  3859. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3860. {
  3861. uint8_t ts[20];
  3862. getNowDatetime(ts);
  3863. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3864. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3865. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3866. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3867. }
  3868. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3869. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3870. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3871. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3872. {
  3873. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3874. if((access(filenmae,F_OK))!=-1)
  3875. {
  3876. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3877. sprintf(str,"rm -f %s",filenmae);
  3878. system(str);
  3879. }
  3880. }
  3881. }
  3882. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3883. #if 1 // for TempStopTransaction
  3884. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3885. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3886. {
  3887. checkTempStopTransaction(gun_index);
  3888. }
  3889. #endif
  3890. }
  3891. }
  3892. }
  3893. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3896. {
  3897. tempIndex = ((gun_index==2) ? 1: 0);
  3898. }
  3899. else
  3900. {
  3901. tempIndex = gun_index;
  3902. }
  3903. for (int index = 0; index < GB_QUANTITY; index++)
  3904. {
  3905. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3906. {
  3907. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3908. {
  3909. // Sent unplug message for California pricing logic
  3910. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3911. {
  3912. uint8_t ts[20];
  3913. getNowDatetime(ts);
  3914. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3915. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3916. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3917. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3918. }
  3919. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3920. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3921. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3922. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3923. {
  3924. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3925. if((access(filenmae,F_OK))!=-1)
  3926. {
  3927. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3928. sprintf(str,"rm -f %s",filenmae);
  3929. system(str);
  3930. }
  3931. }
  3932. }
  3933. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3934. #if 1 // for TempStopTransaction
  3935. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3936. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3937. {
  3938. checkTempStopTransaction(gun_index);
  3939. }
  3940. #endif
  3941. }
  3942. }
  3943. }
  3944. else if(gunType[gun_index] == GUN_TYPE_DO)
  3945. {
  3946. tempIndex = gun_index;
  3947. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3948. {
  3949. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3950. {
  3951. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3952. {
  3953. // Sent unplug message for California pricing logic
  3954. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3955. {
  3956. uint8_t ts[20];
  3957. getNowDatetime(ts);
  3958. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3959. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3960. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3961. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3962. }
  3963. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3964. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3965. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3966. 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
  3967. {
  3968. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3969. if((access(filenmae,F_OK))!=-1)
  3970. {
  3971. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3972. sprintf(str,"rm -f %s",filenmae);
  3973. system(str);
  3974. }
  3975. }
  3976. }
  3977. 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);
  3978. #if 1 // for TempStopTransaction
  3979. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3980. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3981. {
  3982. checkTempStopTransaction(gun_index);
  3983. }
  3984. #endif
  3985. }
  3986. }
  3987. }
  3988. else
  3989. {
  3990. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3991. {
  3992. tempIndex = 2;
  3993. }
  3994. else
  3995. {
  3996. tempIndex = gun_index;
  3997. }
  3998. for (int index = 0; index < AC_QUANTITY; index++)
  3999. {
  4000. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4001. {
  4002. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4003. {
  4004. // Sent unplug message for California pricing logic
  4005. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4006. {
  4007. uint8_t ts[20];
  4008. getNowDatetime(ts);
  4009. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4010. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4011. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4012. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4013. }
  4014. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4015. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4016. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4017. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4018. {
  4019. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4020. if((access(filenmae,F_OK))!=-1)
  4021. {
  4022. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4023. sprintf(str,"rm -f %s",filenmae);
  4024. system(str);
  4025. }
  4026. }
  4027. }
  4028. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4029. #if 1 // for TempStopTransaction
  4030. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4031. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4032. {
  4033. checkTempStopTransaction(gun_index);
  4034. }
  4035. #endif
  4036. }
  4037. }// END
  4038. }
  4039. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4040. (
  4041. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4042. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4043. )
  4044. )
  4045. {
  4046. if(SystemInitial > 0)
  4047. SystemInitial -= 1;
  4048. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4049. sendStatusNotificationRequest(gun_index);
  4050. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4051. }
  4052. //==============================================
  4053. // TCCI reader status report
  4054. //==============================================
  4055. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4056. {
  4057. reportReaderStatus(gun_index);
  4058. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4059. }
  4060. //==============================================
  4061. // CSU Trigger Smart Charging Profile
  4062. //==============================================
  4063. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4064. {
  4065. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4066. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4067. }
  4068. //==============================================
  4069. // Meter report
  4070. //==============================================
  4071. // Trigger MeterValue
  4072. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4073. {
  4074. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4075. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4076. }
  4077. // Clock-aligned Meter value
  4078. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4079. {
  4080. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4081. reqClockAlignMeter[gun_index] = 0;
  4082. }
  4083. // Sample period MeterValue
  4084. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4085. {
  4086. //check Transaction active
  4087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4088. {
  4089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4090. {
  4091. tempIndex = ((gun_index==2) ? 1: 0);
  4092. }
  4093. else
  4094. {
  4095. tempIndex = gun_index;
  4096. }
  4097. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4098. {
  4099. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4100. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4101. {
  4102. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4103. {
  4104. reqSampleMeter[gun_index] = 1;
  4105. }
  4106. }
  4107. }// End for CHAdeMO
  4108. }
  4109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CCS_QUANTITY; index++)
  4120. {
  4121. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4122. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4123. {
  4124. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4125. {
  4126. reqSampleMeter[gun_index] = 1;
  4127. }
  4128. }
  4129. } // End for CCS
  4130. }
  4131. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4132. {
  4133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4134. {
  4135. tempIndex = ((gun_index==2) ? 1: 0);
  4136. }
  4137. else
  4138. {
  4139. tempIndex = gun_index;
  4140. }
  4141. for (int index = 0; index < GB_QUANTITY; index++)
  4142. {
  4143. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4144. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4145. {
  4146. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4147. {
  4148. reqSampleMeter[gun_index] = 1;
  4149. }
  4150. }
  4151. }// End for GB
  4152. }
  4153. else if(gunType[gun_index] == GUN_TYPE_DO)
  4154. {
  4155. tempIndex = gun_index;
  4156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4157. {
  4158. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4159. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4160. {
  4161. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4162. {
  4163. reqSampleMeter[gun_index] = 1;
  4164. }
  4165. }
  4166. }
  4167. }
  4168. else
  4169. {
  4170. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4171. {
  4172. tempIndex = 2;
  4173. }
  4174. else
  4175. {
  4176. tempIndex = gun_index;
  4177. }
  4178. for (int index = 0; index < AC_QUANTITY; index++)
  4179. {
  4180. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4181. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4182. {
  4183. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4184. {
  4185. reqSampleMeter[gun_index] = 1;
  4186. }
  4187. }
  4188. }//End for AC
  4189. }
  4190. if(reqSampleMeter[gun_index] == 1)
  4191. {
  4192. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4193. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4194. //storeTempStopTransaction(gun_index);
  4195. reqSampleMeter[gun_index] = 0;
  4196. }
  4197. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4198. }
  4199. //==============================================
  4200. // Check Connector reserved
  4201. //==============================================
  4202. //===============================
  4203. // Check if Reserve is expired
  4204. //===============================
  4205. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4206. {
  4207. double diff_t;
  4208. struct tm tp;
  4209. // current time
  4210. time_t t = time(NULL);
  4211. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4212. tp.tm_isdst = -1;
  4213. time_t utc = mktime(&tp);
  4214. diff_t = difftime(utc, t);
  4215. if(diff_t <= 0)
  4216. {
  4217. DEBUG_INFO("reserve expired.\n");
  4218. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4219. }
  4220. }//END OF Check if Reserve is expired
  4221. //==========================================
  4222. // csu trigger FirmwareStatusNotificationReq
  4223. //==========================================
  4224. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4225. {
  4226. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4227. }
  4228. //==========================================
  4229. // csu trigger DiagnosticsStatusNotificationReq
  4230. //==========================================
  4231. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4232. {
  4233. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4234. }
  4235. //==========================================
  4236. // csu trigger CancelReservationConf
  4237. //==========================================
  4238. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4239. {
  4240. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4241. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4242. }
  4243. //==========================================
  4244. // csu trigger ChangeAvailabilityConf
  4245. //==========================================
  4246. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4247. {
  4248. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4249. }
  4250. //==========================================
  4251. // csu trigger UnlockConnectorConf
  4252. //==========================================
  4253. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4254. {
  4255. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4256. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4257. }
  4258. //==========================================
  4259. // csu trigger ReserveNowConf
  4260. //==========================================
  4261. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4262. {
  4263. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4264. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4265. }
  4266. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4267. {
  4268. sendSignCertificateRequest();
  4269. }
  4270. }
  4271. }
  4272. //==========================================
  4273. // send request routine
  4274. //==========================================
  4275. int sendAuthorizeRequest(int gun_index)
  4276. {
  4277. mtrace();
  4278. int result = FAIL;
  4279. char message[100]={0};
  4280. char guid[37];
  4281. char tempdata[65]={0};
  4282. DEBUG_INFO("sendAuthorizeRequest...\n");
  4283. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4284. //Local Authorize
  4285. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4286. {
  4287. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4288. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4289. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4290. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4291. result = PASS;
  4292. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4293. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4294. authorizeRetryTimes = 0;
  4295. return result;
  4296. }
  4297. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  4298. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4299. {
  4300. // Query from cache
  4301. DEBUG_INFO("Authorize from cache.\n");
  4302. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4303. // Query from list
  4304. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4305. {
  4306. DEBUG_INFO("Authorize from list.\n");
  4307. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4308. }
  4309. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4310. {
  4311. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4312. {
  4313. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4314. }
  4315. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4316. {
  4317. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4318. }
  4319. if(!GetOcppConnStatus())
  4320. {
  4321. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4322. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4323. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4324. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4325. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4326. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4327. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4328. authorizeRetryTimes = 0;
  4329. return result;
  4330. }
  4331. }
  4332. else
  4333. {
  4334. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4335. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4336. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4337. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4338. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4339. else
  4340. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4341. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4342. result = PASS;
  4343. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4344. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4345. authorizeRetryTimes = 0;
  4346. return result;
  4347. }
  4348. }
  4349. //initialize struct Authorize
  4350. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4351. //get data from shared memory
  4352. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4353. random_uuid(guid);
  4354. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4355. LWS_Send(message);
  4356. sprintf(tempdata, "Authorize,%d", gun_index);
  4357. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4358. {
  4359. result = PASS;
  4360. DEBUG_INFO("Authorize mapItem pass\n");
  4361. }
  4362. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4363. return result;
  4364. }
  4365. int sendBootNotificationRequest(void)
  4366. {
  4367. mtrace();
  4368. int result = FAIL;
  4369. char message[500]={0}, payload[700]={0};
  4370. char guid[37]={0};
  4371. char tempdata[65]={0};
  4372. // Fill BootNotification fields
  4373. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4374. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4375. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4376. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4377. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4378. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4379. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4380. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4381. ShmOCPP16DataPH->ChargeBoxId
  4382. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4383. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4384. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4385. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4386. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4387. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4388. random_uuid(guid);
  4389. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4390. LWS_Send(message);
  4391. sprintf(tempdata, "BootNotification,0");
  4392. 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*/)
  4393. {
  4394. result = PASS;
  4395. }
  4396. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4397. strcpy(queuedata,message);
  4398. return result;
  4399. }
  4400. int sendDataTransferRequest(int gun_index)
  4401. {
  4402. mtrace();
  4403. char message[1000]={0};
  4404. char guid[37]={0};
  4405. char tempdata[65]={0};
  4406. int result = FAIL;
  4407. random_uuid(guid);
  4408. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4409. MESSAGE_TYPE_CALL,
  4410. guid,
  4411. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4412. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4413. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4414. LWS_Send(message);
  4415. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4416. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4417. {
  4418. result = PASS;
  4419. DEBUG_INFO("DataTransfer mapItem pass\n");
  4420. }
  4421. return result;
  4422. }
  4423. int sendDiagnosticsStatusNotificationRequest(char *status)
  4424. {
  4425. mtrace();
  4426. int result = FAIL;
  4427. char message[110]={0};
  4428. char guid[37]={0};
  4429. char tempdata[65]={0};
  4430. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4431. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4432. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4433. random_uuid(guid);
  4434. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4435. LWS_SendNow(message);
  4436. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4437. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4438. {
  4439. result = PASS;
  4440. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4441. }
  4442. //#ifdef SystemLogMessage
  4443. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4444. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4445. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4446. //#endif
  4447. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4448. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4449. //record status
  4450. if(strcmp(status,"Idle")==0)
  4451. {
  4452. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4453. }
  4454. else if(strcmp(status,"Uploaded")==0)
  4455. {
  4456. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4457. }
  4458. else if(strcmp(status,"UploadFailed")==0)
  4459. {
  4460. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4461. }
  4462. else if(strcmp(status,"Uploading")==0)
  4463. {
  4464. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4465. }
  4466. return result;
  4467. }
  4468. int sendFirmwareStatusNotificationRequest(char *status)
  4469. {
  4470. mtrace();
  4471. int result = FAIL;
  4472. char message[110]={0};
  4473. char guid[37]={0};
  4474. char tempdata[65]={0};
  4475. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4476. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4477. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4478. random_uuid(guid);
  4479. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4480. LWS_SendNow(message);
  4481. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4482. 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*/)
  4483. {
  4484. result = PASS;
  4485. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4486. }
  4487. //#ifdef SystemLogMessage
  4488. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4489. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4490. //#endif
  4491. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4492. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4493. //record status
  4494. if(strcmp(status,"Downloaded")==0)
  4495. {
  4496. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4497. }
  4498. else if(strcmp(status,"DownloadFailed")==0)
  4499. {
  4500. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4501. }
  4502. else if(strcmp(status,"Downloading")==0)
  4503. {
  4504. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4505. }
  4506. else if(strcmp(status,"Idle")==0)
  4507. {
  4508. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4509. }
  4510. else if(strcmp(status,"InstallationFailed")==0)
  4511. {
  4512. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4513. }
  4514. else if(strcmp(status,"Installing")==0)
  4515. {
  4516. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4517. }
  4518. else if(strcmp(status,"Installed")==0)
  4519. {
  4520. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4521. }
  4522. return result;
  4523. }
  4524. int sendHeartbeatRequest(int gun_index)
  4525. {
  4526. mtrace();
  4527. int result = FAIL;
  4528. char message[80]={0};
  4529. char guid[37]={0};
  4530. char tempdata[65]={0};
  4531. random_uuid(guid);
  4532. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4533. , MESSAGE_TYPE_CALL
  4534. , guid );
  4535. LWS_Send(message);
  4536. sprintf(tempdata, "Heartbeat,%d", 0);
  4537. 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*/)
  4538. {
  4539. result = PASS;
  4540. }
  4541. return result;
  4542. }
  4543. int sendStartTransactionRequest(int gun_index)
  4544. {
  4545. mtrace();
  4546. int result = FAIL;
  4547. char message[250]={0};
  4548. char guid[37]={0};
  4549. struct timeval tmnow;
  4550. struct tm *tm;
  4551. char buf[28];//, usec_buf[6];
  4552. char tempdata[65]={0};
  4553. int tempIndex = 0;
  4554. DEBUG_INFO("sendStartTransactionRequest...\n");
  4555. gettimeofday(&tmnow, NULL);
  4556. time_t t;
  4557. t = time(NULL);
  4558. /*UTC time and date*/
  4559. tm = gmtime(&t);
  4560. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4561. #if 0 // remove temporally
  4562. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4563. strcat(buf,".");
  4564. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4565. strcat(buf,usec_buf);
  4566. #endif
  4567. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4568. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4569. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4570. // clear StartTransaction Response
  4571. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4572. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4573. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4574. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4575. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4577. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4578. {
  4579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4580. {
  4581. tempIndex = ((gun_index==2) ? 1: 0);
  4582. }
  4583. else
  4584. {
  4585. tempIndex = gun_index;
  4586. }
  4587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4588. {
  4589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4590. {
  4591. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4592. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4593. }
  4594. }
  4595. }
  4596. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4597. {
  4598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4599. {
  4600. tempIndex = ((gun_index==2) ? 1: 0);
  4601. }
  4602. else
  4603. {
  4604. tempIndex = gun_index;
  4605. }
  4606. for (int index = 0; index < CCS_QUANTITY; index++)
  4607. {
  4608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4609. {
  4610. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4611. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4612. }
  4613. }
  4614. }
  4615. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4616. {
  4617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4618. {
  4619. tempIndex = ((gun_index==2) ? 1: 0);
  4620. }
  4621. else
  4622. {
  4623. tempIndex = gun_index;
  4624. }
  4625. for (int index = 0; index < GB_QUANTITY; index++)
  4626. {
  4627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4628. {
  4629. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4630. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4631. }
  4632. }
  4633. }
  4634. else if(gunType[gun_index] == GUN_TYPE_DO)
  4635. {
  4636. tempIndex = gun_index;
  4637. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4638. {
  4639. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4640. {
  4641. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4642. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4643. }
  4644. }
  4645. }
  4646. else
  4647. {
  4648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4649. {
  4650. tempIndex = 2;
  4651. }
  4652. else
  4653. {
  4654. tempIndex = gun_index;
  4655. }
  4656. for (int index = 0; index < AC_QUANTITY; index++)
  4657. {
  4658. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4659. {
  4660. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4661. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4662. }
  4663. }
  4664. }
  4665. random_uuid(guid);
  4666. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4667. {
  4668. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4669. , gun_index +1
  4670. , MESSAGE_TYPE_CALL
  4671. , guid
  4672. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4673. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4674. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4675. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4676. }
  4677. else
  4678. {
  4679. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4680. , gun_index +1
  4681. , MESSAGE_TYPE_CALL
  4682. , guid
  4683. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4684. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4685. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4686. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4687. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4688. }
  4689. #if 1
  4690. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4691. 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*/)
  4692. {
  4693. result = PASS;
  4694. }
  4695. #endif
  4696. strcpy(queuedata, message);
  4697. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4698. OCPP_insert_transaction_msg(YES, queuedata);
  4699. return result;
  4700. }
  4701. int sendStatusNotificationRequest(int gun_index)
  4702. {
  4703. mtrace();
  4704. int result = FAIL;
  4705. char message[600]={0};
  4706. char guid[37];
  4707. int currentStatus = 0;
  4708. struct timeval tmnow;
  4709. struct tm *tm;
  4710. char buf[28];//, usec_buf[6];
  4711. char tempdata[65]={0};
  4712. int tempIndex = 0;
  4713. uint8_t isStateChanged = TRUE;
  4714. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4715. gettimeofday(&tmnow, NULL);
  4716. time_t t;
  4717. t = time(NULL);
  4718. /*UTC time and date*/
  4719. tm = gmtime(&t);
  4720. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4721. #if 0 // remove temporally
  4722. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4723. strcat(buf,".");
  4724. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4725. strcat(buf,usec_buf);
  4726. #endif
  4727. //printf("%s",buf);
  4728. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4729. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4730. // it's option
  4731. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4732. /*
  4733. enum _SYSTEM_STATUS
  4734. {
  4735. S_BOOTING = 0,
  4736. S_IDLE, = 1
  4737. S_AUTHORIZING, =2
  4738. S_REASSIGN_CHECK, =3
  4739. S_REASSIGN, =4
  4740. S_PRECHARGE, =5
  4741. S_PREPARING_FOR_EV, =6
  4742. S_PREPARING_FOR_EVSE, =7
  4743. S_CHARGING, =8
  4744. S_TERMINATING, =9
  4745. S_COMPLETE, =10
  4746. S_ALARM, =11
  4747. S_FAULT =12
  4748. }
  4749. */
  4750. //check Transaction active
  4751. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4752. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4753. {
  4754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4755. {
  4756. tempIndex = ((gun_index==2) ? 1: 0);
  4757. }
  4758. else
  4759. {
  4760. tempIndex = gun_index;
  4761. }
  4762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4763. {
  4764. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4765. {
  4766. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4767. {
  4768. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4769. {
  4770. currentStatus = Preparing; //OCPP Status: Preparing
  4771. }
  4772. else
  4773. {
  4774. currentStatus = Available; //OCPP Status: Available
  4775. }
  4776. }
  4777. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4778. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4779. ) //S_PRECHARGE
  4780. {
  4781. currentStatus = Preparing; //OCPP Status: Preparing
  4782. }
  4783. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4784. {
  4785. currentStatus = Charging; //OCPP Status: Charging
  4786. }
  4787. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4788. {
  4789. currentStatus = Finishing; //OCPP Status: Finishing
  4790. }
  4791. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4792. {
  4793. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4794. }
  4795. 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
  4796. {
  4797. currentStatus = Unavailable; //OCPP Status: Unavailable
  4798. }
  4799. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4800. {
  4801. currentStatus = Faulted; //OCPP Status: Faulted
  4802. }
  4803. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4804. {
  4805. currentStatus = Reserved; //OCPP Status: Reserved
  4806. }
  4807. } //end of the same index
  4808. }//end of for CHAdeMO_QUANTITY
  4809. }
  4810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4811. {
  4812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4813. {
  4814. tempIndex = ((gun_index==2) ? 1: 0);
  4815. }
  4816. else
  4817. {
  4818. tempIndex = gun_index;
  4819. }
  4820. for (int index = 0; index < CCS_QUANTITY; index++)
  4821. {
  4822. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4825. {
  4826. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4827. {
  4828. currentStatus = Preparing; //OCPP Status: Preparing
  4829. }
  4830. else
  4831. {
  4832. currentStatus = Available; //OCPP Status: Available
  4833. }
  4834. }
  4835. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4836. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4837. ) //S_PRECHARGE
  4838. {
  4839. currentStatus = Preparing; //OCPP Status: Preparing
  4840. }
  4841. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4842. {
  4843. currentStatus = Charging; //OCPP Status: Charging
  4844. }
  4845. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4846. {
  4847. currentStatus = Finishing; //OCPP Status: Finishing
  4848. }
  4849. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4850. {
  4851. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4852. }
  4853. 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
  4854. {
  4855. currentStatus = Unavailable; //OCPP Status : Unavailable
  4856. }
  4857. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4858. {
  4859. currentStatus = Faulted; //OCPP Status: Faulted
  4860. }
  4861. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4862. {
  4863. currentStatus = Reserved; //OCPP Status: Reserved
  4864. }
  4865. } //end of the same index
  4866. } // end of for CCS_QUANTITY
  4867. }
  4868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4869. {
  4870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4871. {
  4872. tempIndex = ((gun_index==2) ? 1: 0);
  4873. }
  4874. else
  4875. {
  4876. tempIndex = gun_index;
  4877. }
  4878. for (int index = 0; index < GB_QUANTITY; index++)
  4879. {
  4880. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4881. {
  4882. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4883. {
  4884. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4885. {
  4886. currentStatus = Preparing; //OCPP Status: Preparing
  4887. }
  4888. else
  4889. {
  4890. currentStatus = Available; //OCPP Status: Available
  4891. }
  4892. }
  4893. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4894. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4895. ) //S_PRECHARGE
  4896. {
  4897. currentStatus = Preparing; //OCPP Status: Preparing
  4898. }
  4899. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4900. {
  4901. currentStatus = Charging; //OCPP Status: Charging
  4902. }
  4903. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4904. {
  4905. currentStatus = Finishing; //OCPP Status: Finishing
  4906. }
  4907. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4908. {
  4909. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4910. }
  4911. 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
  4912. {
  4913. currentStatus = Unavailable; //OCPP Status: Unavailable
  4914. }
  4915. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4916. {
  4917. currentStatus = Faulted; //OCPP Status: Faulted
  4918. }
  4919. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4920. {
  4921. currentStatus = Reserved; //OCPP Status: Reserved
  4922. }
  4923. } //end of the same index
  4924. } // end of for GB_QUANTITY
  4925. }
  4926. else if(gunType[gun_index] == GUN_TYPE_DO)
  4927. {
  4928. tempIndex = gun_index;
  4929. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4930. {
  4931. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4932. {
  4933. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4934. {
  4935. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4936. {
  4937. currentStatus = Preparing; //OCPP Status: Preparing
  4938. }
  4939. else
  4940. {
  4941. currentStatus = Available; //OCPP Status: Available
  4942. }
  4943. }
  4944. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4945. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4946. ) //S_PRECHARGE
  4947. {
  4948. currentStatus = Preparing; //OCPP Status: Preparing
  4949. }
  4950. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4951. {
  4952. currentStatus = Charging; //OCPP Status: Charging
  4953. }
  4954. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4955. {
  4956. currentStatus = Finishing; //OCPP Status: Finishing
  4957. }
  4958. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4959. {
  4960. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4961. }
  4962. 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
  4963. {
  4964. currentStatus = Unavailable; //OCPP Status: Unavailable
  4965. }
  4966. 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
  4967. {
  4968. currentStatus = Faulted; //OCPP Status: Faulted
  4969. }
  4970. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4971. {
  4972. currentStatus = Reserved; //OCPP Status: Reserved
  4973. }
  4974. } //end of the same index
  4975. }
  4976. }
  4977. else
  4978. {
  4979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4980. {
  4981. tempIndex = 2;
  4982. }
  4983. else
  4984. {
  4985. tempIndex = gun_index;
  4986. }
  4987. for (int index = 0; index < AC_QUANTITY; index++)
  4988. {
  4989. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4990. {
  4991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4992. {
  4993. 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))
  4994. {
  4995. currentStatus = Preparing; //OCPP Status: Preparing
  4996. }
  4997. else
  4998. {
  4999. currentStatus = Available; //OCPP Status: Available
  5000. }
  5001. }
  5002. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5003. {
  5004. currentStatus = Preparing; //OCPP Status: Preparing
  5005. }
  5006. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5007. {
  5008. currentStatus = Charging; //OCPP Status: Charging
  5009. }
  5010. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5011. {
  5012. currentStatus = Finishing; //OCPP Status: Finishing
  5013. }
  5014. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5015. {
  5016. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5017. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5018. else
  5019. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5020. }
  5021. 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
  5022. {
  5023. currentStatus = Unavailable; //OCPP Status: Unavailable
  5024. }
  5025. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5026. {
  5027. currentStatus = Faulted; //OCPP Status: Faulted
  5028. }
  5029. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5030. {
  5031. currentStatus = Reserved; //OCPP Status: Reserved
  5032. }
  5033. }//end of the same index
  5034. }//end of for AC_QUANTITY
  5035. }
  5036. //it's option
  5037. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5038. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5039. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5040. {
  5041. isStateChanged = FALSE;
  5042. }
  5043. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5044. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5045. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5046. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5047. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5048. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5049. random_uuid(guid);
  5050. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5051. , MESSAGE_TYPE_CALL
  5052. , guid
  5053. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5054. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5055. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5056. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5057. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5058. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5059. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5060. if((server_sign == TRUE) && isStateChanged)
  5061. {
  5062. LWS_Send(message);
  5063. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5064. 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*/)
  5065. {
  5066. //DEBUG_ERROR("statusNotification mapitem pass");
  5067. result = PASS;
  5068. }
  5069. }
  5070. else
  5071. {
  5072. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5073. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5074. result = PASS;
  5075. }
  5076. return result;
  5077. }
  5078. int sendStopTransactionRequest(int gun_index)
  5079. {
  5080. mtrace();
  5081. int result = FAIL;
  5082. //char message[1500]={0};
  5083. char guid[37]={0};
  5084. char tempdata[65]={0};
  5085. int tempIndex = 0;
  5086. char TempStopTransaction[256];
  5087. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5088. //int idx_sample=0;
  5089. DEBUG_INFO("sendStopTransactionRequest \n");
  5090. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5091. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5092. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5093. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5094. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5095. {
  5096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5097. {
  5098. tempIndex = ((gun_index==2) ? 1: 0);
  5099. }
  5100. else
  5101. {
  5102. tempIndex = gun_index;
  5103. }
  5104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5105. {
  5106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5107. {
  5108. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5109. }
  5110. }// END OF CHAdeMO_QUANTITY
  5111. }
  5112. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5113. {
  5114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5115. {
  5116. tempIndex = ((gun_index==2) ? 1: 0);
  5117. }
  5118. else
  5119. {
  5120. tempIndex = gun_index;
  5121. }
  5122. for (int index = 0; index < CCS_QUANTITY; index++)
  5123. {
  5124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5125. {
  5126. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5127. }
  5128. }// END OF CCS_QUANTITY
  5129. }
  5130. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5131. {
  5132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5133. {
  5134. tempIndex = ((gun_index==2) ? 1: 0);
  5135. }
  5136. else
  5137. {
  5138. tempIndex = gun_index;
  5139. }
  5140. for (int index = 0; index < GB_QUANTITY; index++)
  5141. {
  5142. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5143. {
  5144. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5145. }
  5146. }// END OF GB_QUANTITY
  5147. }
  5148. else if(gunType[gun_index] == GUN_TYPE_DO)
  5149. {
  5150. tempIndex = gun_index;
  5151. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5152. {
  5153. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5154. {
  5155. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5156. }
  5157. }// END OF GB_QUANTITY
  5158. }
  5159. else
  5160. {
  5161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5162. {
  5163. tempIndex = 2;
  5164. }
  5165. else
  5166. {
  5167. tempIndex = gun_index;
  5168. }
  5169. for (int index = 0; index < AC_QUANTITY; index++)
  5170. {
  5171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5172. {
  5173. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5174. }
  5175. }// END OF AC_QUANTITY
  5176. }
  5177. //====================================== Stop Transaction Time =====================================================
  5178. struct timeval tmnow;
  5179. struct tm *tm;
  5180. char buf[28];//, usec_buf[6];
  5181. gettimeofday(&tmnow, NULL);
  5182. time_t t;
  5183. t = time(NULL);
  5184. /*UTC time and date*/
  5185. tm = gmtime(&t);
  5186. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5187. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5188. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5189. random_uuid(guid);
  5190. /***********************************transactionData******************************************************/
  5191. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5192. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5193. //=================================
  5194. // Transaction_Begin
  5195. //=================================
  5196. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5197. {
  5198. //============================================ Energy.Active.Import.Interval ================================
  5199. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5203. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5204. 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))
  5205. {
  5206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5207. }
  5208. else
  5209. {
  5210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5211. }
  5212. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5214. }
  5215. //=================================
  5216. // Transaction_End
  5217. //=================================
  5218. // ================================= Current.Import L1 ===============================================
  5219. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5220. {
  5221. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5222. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5223. {
  5224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5225. {
  5226. tempIndex = ((gun_index==2) ? 1: 0);
  5227. }
  5228. else
  5229. {
  5230. tempIndex = gun_index;
  5231. }
  5232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5233. {
  5234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5235. {
  5236. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5237. }
  5238. }// End of for CHAdeMO_QUANTITY
  5239. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5240. }
  5241. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5242. {
  5243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5244. {
  5245. tempIndex = ((gun_index==2) ? 1: 0);
  5246. }
  5247. else
  5248. {
  5249. tempIndex = gun_index;
  5250. }
  5251. for (int index = 0; index < CCS_QUANTITY; index++)
  5252. {
  5253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5254. {
  5255. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5256. }
  5257. }// End of for CCS_QUANTITY
  5258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5259. }
  5260. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5263. {
  5264. tempIndex = ((gun_index==2) ? 1: 0);
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < GB_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5275. }
  5276. }// End of for GB_QUANTITY
  5277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5278. }
  5279. else if(gunType[gun_index] == GUN_TYPE_DO)
  5280. {
  5281. tempIndex = gun_index;
  5282. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5283. {
  5284. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5285. {
  5286. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5287. }
  5288. }
  5289. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5290. }
  5291. else
  5292. {
  5293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5294. {
  5295. tempIndex = 2;
  5296. }
  5297. else
  5298. {
  5299. tempIndex = gun_index;
  5300. }
  5301. for (int index = 0; index < AC_QUANTITY; index++)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5304. {
  5305. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5306. }
  5307. }// End of for AC_QUANTITY
  5308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5309. }
  5310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5313. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5314. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5315. }
  5316. // ================================= Energy.Active.Import.Interval ==============================================
  5317. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5318. {
  5319. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5320. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5321. {
  5322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5323. {
  5324. tempIndex = ((gun_index==2) ? 1: 0);
  5325. }
  5326. else
  5327. {
  5328. tempIndex = gun_index;
  5329. }
  5330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5331. {
  5332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5333. {
  5334. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5335. }
  5336. }// END OF CHAdeMO_QUANTITY
  5337. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5338. }
  5339. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5340. {
  5341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5342. {
  5343. tempIndex = ((gun_index==2) ? 1: 0);
  5344. }
  5345. else
  5346. {
  5347. tempIndex = gun_index;
  5348. }
  5349. for (int index = 0; index < CCS_QUANTITY; index++)
  5350. {
  5351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5352. {
  5353. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5354. }
  5355. }// END OF CCS_QUANTITY
  5356. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5357. }
  5358. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5359. {
  5360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5361. {
  5362. tempIndex = ((gun_index==2) ? 1: 0);
  5363. }
  5364. else
  5365. {
  5366. tempIndex = gun_index;
  5367. }
  5368. for (int index = 0; index < GB_QUANTITY; index++)
  5369. {
  5370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5371. {
  5372. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5373. }
  5374. }// END OF GB_QUANTITY
  5375. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5376. }
  5377. else if(gunType[gun_index] == GUN_TYPE_DO)
  5378. {
  5379. tempIndex = gun_index;
  5380. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5383. {
  5384. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5385. }
  5386. }
  5387. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5388. }
  5389. else
  5390. {
  5391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5392. {
  5393. tempIndex = 2;
  5394. }
  5395. else
  5396. {
  5397. tempIndex = gun_index;
  5398. }
  5399. for (int index = 0; index < AC_QUANTITY; index++)
  5400. {
  5401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5402. {
  5403. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5404. }
  5405. }// END OF AC_QUANTITY
  5406. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5407. }
  5408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5412. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5413. }
  5414. //=================================== Power.Active.Import ==================================================
  5415. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5416. {
  5417. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5418. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5419. {
  5420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5421. {
  5422. tempIndex = ((gun_index==2) ? 1: 0);
  5423. }
  5424. else
  5425. {
  5426. tempIndex = gun_index;
  5427. }
  5428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5429. {
  5430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5431. {
  5432. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5433. }
  5434. } // End for CHAdeMO_QUANTITY
  5435. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5436. }
  5437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5438. {
  5439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5440. {
  5441. tempIndex = ((gun_index==2) ? 1: 0);
  5442. }
  5443. else
  5444. {
  5445. tempIndex = gun_index;
  5446. }
  5447. for (int index = 0; index < CCS_QUANTITY; index++)
  5448. {
  5449. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5450. {
  5451. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5452. }
  5453. } // END for CCS_QUANTITY
  5454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5455. }
  5456. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5457. {
  5458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5459. {
  5460. tempIndex = ((gun_index==2) ? 1: 0);
  5461. }
  5462. else
  5463. {
  5464. tempIndex = gun_index;
  5465. }
  5466. for (int index = 0; index < GB_QUANTITY; index++)
  5467. {
  5468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5469. {
  5470. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5471. }
  5472. }// END for GB_QUANTITY
  5473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5474. }
  5475. else if(gunType[gun_index] == GUN_TYPE_DO)
  5476. {
  5477. tempIndex = gun_index;
  5478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5479. {
  5480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5481. {
  5482. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5483. }
  5484. }
  5485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5486. }
  5487. else
  5488. {
  5489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5490. {
  5491. tempIndex = 2;
  5492. }
  5493. else
  5494. {
  5495. tempIndex = gun_index;
  5496. }
  5497. for (int index = 0; index < AC_QUANTITY; index++)
  5498. {
  5499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5500. {
  5501. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5502. }
  5503. } // END for AC_QUANTITY
  5504. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5505. }
  5506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5511. }
  5512. //============================ Voltage L1 ====================================
  5513. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5514. {
  5515. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5516. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5517. {
  5518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5519. {
  5520. tempIndex = ((gun_index==2) ? 1: 0);
  5521. }
  5522. else
  5523. {
  5524. tempIndex = gun_index;
  5525. }
  5526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5529. {
  5530. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5531. }
  5532. } // END OF FOR CHAdeMO_QUANTITY
  5533. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5534. }
  5535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5536. {
  5537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5538. {
  5539. tempIndex = ((gun_index==2) ? 1: 0);
  5540. }
  5541. else
  5542. {
  5543. tempIndex = gun_index;
  5544. }
  5545. for (int index = 0; index < CCS_QUANTITY; index++)
  5546. {
  5547. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5548. {
  5549. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5550. }
  5551. } // END OF FOR CCS_QUANTITY
  5552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5553. }
  5554. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5555. {
  5556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5557. {
  5558. tempIndex = ((gun_index==2) ? 1: 0);
  5559. }
  5560. else
  5561. {
  5562. tempIndex = gun_index;
  5563. }
  5564. for (int index = 0; index < GB_QUANTITY; index++)
  5565. {
  5566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5567. {
  5568. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5569. }
  5570. } // END OF FOR GB_QUANTITY
  5571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5572. }
  5573. else if(gunType[gun_index] == GUN_TYPE_DO)
  5574. {
  5575. tempIndex = gun_index;
  5576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5579. {
  5580. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5581. }
  5582. }
  5583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5584. }
  5585. else
  5586. {
  5587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5588. {
  5589. tempIndex = 2;
  5590. }
  5591. else
  5592. {
  5593. tempIndex = gun_index;
  5594. }
  5595. for (int index = 0; index < AC_QUANTITY; index++)
  5596. {
  5597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5598. {
  5599. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5600. }
  5601. } // END OF FOR AC_QUANTITY
  5602. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5603. }
  5604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5609. }
  5610. //====================== End SoC ================================
  5611. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5612. {
  5613. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5614. 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))
  5615. {
  5616. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5617. {
  5618. tempIndex = ((gun_index==2) ? 1: 0);
  5619. }
  5620. else
  5621. {
  5622. tempIndex = gun_index;
  5623. }
  5624. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5625. {
  5626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5629. {
  5630. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5631. }
  5632. }
  5633. }
  5634. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5635. {
  5636. for (int index = 0; index < CCS_QUANTITY; index++)
  5637. {
  5638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5639. {
  5640. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5641. }
  5642. }
  5643. }
  5644. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5645. {
  5646. for (int index = 0; index < GB_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5649. {
  5650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5651. }
  5652. }
  5653. }
  5654. else if(gunType[gun_index] == GUN_TYPE_DO)
  5655. {
  5656. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5659. {
  5660. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5661. }
  5662. }
  5663. }
  5664. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5665. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5666. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5667. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5668. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5669. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5670. } // END FOR DC CASE
  5671. }
  5672. // ================================= Current.Import L2 ===============================================
  5673. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5674. {
  5675. // AC 3 phse L2 current
  5676. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5677. {
  5678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5679. {
  5680. tempIndex = 2;
  5681. }
  5682. else
  5683. {
  5684. tempIndex = gun_index;
  5685. }
  5686. for (int index = 0; index < AC_QUANTITY; index++)
  5687. {
  5688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5689. {
  5690. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5691. }
  5692. }// End of for AC_QUANTITY
  5693. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5694. }
  5695. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5697. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5700. }
  5701. // ================================= Current.Import L3 ===============================================
  5702. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5703. {
  5704. // AC 3 phse L3 current
  5705. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5706. {
  5707. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5708. {
  5709. tempIndex = 2;
  5710. }
  5711. else
  5712. {
  5713. tempIndex = gun_index;
  5714. }
  5715. for (int index = 0; index < AC_QUANTITY; index++)
  5716. {
  5717. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5718. {
  5719. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5720. }
  5721. }// End of for AC_QUANTITY
  5722. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5723. }
  5724. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5725. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5727. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5729. }
  5730. //============================ Voltage L2 ====================================
  5731. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5732. {
  5733. // AC 3 phse L2 voltage
  5734. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5735. {
  5736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5737. {
  5738. tempIndex = 2;
  5739. }
  5740. else
  5741. {
  5742. tempIndex = gun_index;
  5743. }
  5744. for (int index = 0; index < AC_QUANTITY; index++)
  5745. {
  5746. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5747. {
  5748. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5749. }
  5750. } // END OF FOR AC_QUANTITY
  5751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5752. }
  5753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5756. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5757. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5758. }
  5759. //============================ Voltage L3 ====================================
  5760. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5761. {
  5762. // AC 3 phse L3 voltage
  5763. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5764. {
  5765. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5766. {
  5767. tempIndex = 2;
  5768. }
  5769. else
  5770. {
  5771. tempIndex = gun_index;
  5772. }
  5773. for (int index = 0; index < AC_QUANTITY; index++)
  5774. {
  5775. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5776. {
  5777. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5778. }
  5779. } // END OF FOR AC_QUANTITY
  5780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5781. }
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5786. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5787. }
  5788. //====================== Start SoC ================================
  5789. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5790. {
  5791. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5792. 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))
  5793. {
  5794. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5795. {
  5796. tempIndex = ((gun_index==2) ? 1: 0);
  5797. }
  5798. else
  5799. {
  5800. tempIndex = gun_index;
  5801. }
  5802. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5803. {
  5804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5805. {
  5806. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5807. {
  5808. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5809. }
  5810. }
  5811. }
  5812. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5813. {
  5814. for (int index = 0; index < CCS_QUANTITY; index++)
  5815. {
  5816. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5817. {
  5818. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5819. }
  5820. }
  5821. }
  5822. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5823. {
  5824. for (int index = 0; index < GB_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5829. }
  5830. }
  5831. }
  5832. else if(gunType[gun_index] == GUN_TYPE_DO)
  5833. {
  5834. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5835. {
  5836. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5837. {
  5838. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5839. }
  5840. }
  5841. }
  5842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5843. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5848. } // END FOR DC CASE
  5849. }
  5850. //================================================ Message create ====================================================
  5851. json_object *StopTransaction = json_object_new_object();
  5852. json_object *transactionDatas = json_object_new_array();
  5853. json_object *sampledValues = json_object_new_array();
  5854. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5855. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5856. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5857. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5858. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5859. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5860. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5861. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5862. {
  5863. json_object *transactionData = json_object_new_object();
  5864. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5865. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5866. {
  5867. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5868. {
  5869. json_object *sampledValue = json_object_new_object();
  5870. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5871. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5872. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5873. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5874. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5875. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5876. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5877. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5878. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5879. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5880. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5881. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5882. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5883. json_object_array_add(sampledValues, sampledValue);
  5884. }
  5885. }
  5886. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5887. json_object_array_add(transactionDatas, transactionData);
  5888. }
  5889. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5890. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5891. ,MESSAGE_TYPE_CALL
  5892. ,guid
  5893. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5894. json_object_put(StopTransaction);
  5895. #if 1 // for TempStopTransaction
  5896. //Delete TempStopTransaction
  5897. if((access(TempStopTransaction,F_OK))!=-1)
  5898. {
  5899. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5900. }
  5901. #endif
  5902. #if 1
  5903. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5904. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5905. {
  5906. result = PASS;
  5907. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5908. }
  5909. #endif
  5910. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5911. OCPP_insert_transaction_msg(NO, queuedata);
  5912. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5913. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5914. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5915. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5916. {
  5917. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5918. }
  5919. //for test
  5920. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5921. return result;
  5922. }
  5923. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5924. {
  5925. mtrace();
  5926. int result = FAIL;
  5927. char guid[37]={0};
  5928. char tempdata[65]={0};
  5929. int tempIndex = 0;
  5930. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5931. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5932. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5933. //set value
  5934. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5935. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5936. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5937. -1);
  5938. random_uuid(guid);
  5939. //UTC Date time
  5940. struct timeval tmnow;
  5941. struct tm *tm;
  5942. char buf[28];//, usec_buf[6];
  5943. gettimeofday(&tmnow, NULL);
  5944. time_t t;
  5945. t = time(NULL);
  5946. /*UTC time and date*/
  5947. tm = gmtime(&t);
  5948. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5950. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5951. //********************************(1)Current.Import L1************************************************/
  5952. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5953. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5954. (dataType == ReadingContext_Trigger))
  5955. {
  5956. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5957. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5958. {
  5959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5960. {
  5961. tempIndex = ((gun_index==2) ? 1: 0);
  5962. }
  5963. else
  5964. {
  5965. tempIndex = gun_index;
  5966. }
  5967. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5968. {
  5969. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5970. {
  5971. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5972. }
  5973. }
  5974. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5975. }
  5976. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5977. {
  5978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5979. {
  5980. tempIndex = ((gun_index==2) ? 1: 0);
  5981. }
  5982. else
  5983. {
  5984. tempIndex = gun_index;
  5985. }
  5986. for (int index = 0; index < CCS_QUANTITY; index++)
  5987. {
  5988. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5989. {
  5990. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5991. }
  5992. }
  5993. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5994. }
  5995. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5996. {
  5997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5998. {
  5999. tempIndex = ((gun_index==2) ? 1: 0);
  6000. }
  6001. else
  6002. {
  6003. tempIndex = gun_index;
  6004. }
  6005. for (int index = 0; index < GB_QUANTITY; index++)
  6006. {
  6007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6008. {
  6009. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6010. }
  6011. }
  6012. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6013. }
  6014. else if(gunType[gun_index] == GUN_TYPE_DO)
  6015. {
  6016. tempIndex = gun_index;
  6017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6018. {
  6019. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6020. {
  6021. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6022. }
  6023. }
  6024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6025. }
  6026. else
  6027. {
  6028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6029. {
  6030. tempIndex = 2;
  6031. }
  6032. else
  6033. {
  6034. tempIndex = gun_index;
  6035. }
  6036. for (int index = 0; index < AC_QUANTITY; index++)
  6037. {
  6038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6039. {
  6040. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6041. }
  6042. }
  6043. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6044. }
  6045. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6046. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6050. }
  6051. //********************************(2)Energy.Active.Import.Register ************************************************/
  6052. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6053. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != 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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6072. }
  6073. }
  6074. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6091. }
  6092. }
  6093. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6110. }
  6111. }
  6112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6122. }
  6123. }
  6124. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6141. }
  6142. }
  6143. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6144. }
  6145. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6146. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6148. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6149. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6150. }
  6151. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6152. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6153. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != 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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6172. }
  6173. } // END OF FOR CHAdeMO_QUANTITY
  6174. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6191. }
  6192. } // END OF CCS_QUANTITY
  6193. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6210. }
  6211. } // END OF GB_QUANTITY
  6212. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6222. }
  6223. }
  6224. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6241. }
  6242. }
  6243. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6244. }
  6245. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6250. }
  6251. //********************************(4)Power.Active.Import************************************************/
  6252. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6253. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != 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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6272. }
  6273. } // END OF FOR
  6274. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6291. }
  6292. }
  6293. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].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. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6310. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6311. }
  6312. }
  6313. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6314. }
  6315. else if(gunType[gun_index] == GUN_TYPE_DO)
  6316. {
  6317. tempIndex = gun_index;
  6318. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6321. {
  6322. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6323. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6324. }
  6325. }
  6326. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6327. }
  6328. else
  6329. {
  6330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6331. {
  6332. tempIndex = 2;
  6333. }
  6334. else
  6335. {
  6336. tempIndex = gun_index;
  6337. }
  6338. for (int index = 0; index < AC_QUANTITY; index++)
  6339. {
  6340. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6341. {
  6342. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6343. }
  6344. }
  6345. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6346. }
  6347. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6348. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6352. }
  6353. //***********************************************(5)VOLTAGE L1******************************************************/
  6354. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6355. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6356. (dataType == ReadingContext_Trigger))
  6357. {
  6358. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6359. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6360. {
  6361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6362. {
  6363. tempIndex = ((gun_index==2) ? 1: 0);
  6364. }
  6365. else
  6366. {
  6367. tempIndex = gun_index;
  6368. }
  6369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6370. {
  6371. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6372. {
  6373. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6374. }
  6375. }
  6376. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6377. }
  6378. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6379. {
  6380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6381. {
  6382. tempIndex = ((gun_index==2) ? 1: 0);
  6383. }
  6384. else
  6385. {
  6386. tempIndex = gun_index;
  6387. }
  6388. for (int index = 0; index < CCS_QUANTITY; index++)
  6389. {
  6390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6391. {
  6392. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6393. }
  6394. }
  6395. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6396. }
  6397. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6398. {
  6399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6400. {
  6401. tempIndex = ((gun_index==2) ? 1: 0);
  6402. }
  6403. else
  6404. {
  6405. tempIndex = gun_index;
  6406. }
  6407. for (int index = 0; index < GB_QUANTITY; index++)
  6408. {
  6409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6410. {
  6411. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6412. }
  6413. }
  6414. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6415. }
  6416. else if(gunType[gun_index] == GUN_TYPE_DO)
  6417. {
  6418. tempIndex = gun_index;
  6419. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6420. {
  6421. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6422. {
  6423. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6424. }
  6425. }
  6426. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6443. }
  6444. }
  6445. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6446. }
  6447. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6452. }
  6453. //***********************************************(6)SOC******************************************************/
  6454. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6455. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6456. (dataType == ReadingContext_Trigger))
  6457. {
  6458. 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))
  6459. {
  6460. //idx_sample=5;
  6461. //sampledValue = NULL;
  6462. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6463. {
  6464. tempIndex = ((gun_index==2) ? 1: 0);
  6465. }
  6466. else
  6467. {
  6468. tempIndex = gun_index;
  6469. }
  6470. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6471. {
  6472. //tempIndex = ((gun_index==2) ? 1: 0);
  6473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6474. {
  6475. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6476. {
  6477. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6478. }
  6479. }
  6480. }
  6481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6482. {
  6483. //tempIndex = ((gun_index==2) ? 1: 0);
  6484. for (int index = 0; index < CCS_QUANTITY; index++)
  6485. {
  6486. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6487. {
  6488. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6489. }
  6490. }
  6491. }
  6492. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6493. {
  6494. //tempIndex = ((gun_index==2) ? 1: 0);
  6495. for (int index = 0; index < GB_QUANTITY; index++)
  6496. {
  6497. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6498. {
  6499. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6500. }
  6501. }
  6502. }
  6503. else if(gunType[gun_index] == GUN_TYPE_DO)
  6504. {
  6505. //tempIndex = ((gun_index==2) ? 1: 0);
  6506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6507. {
  6508. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6509. {
  6510. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6511. }
  6512. }
  6513. }
  6514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6518. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6519. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6520. }
  6521. }
  6522. //********************************(7)Current.Import L2************************************************/
  6523. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6524. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6525. (dataType == ReadingContext_Trigger))
  6526. {
  6527. // Only for AC 3 phase
  6528. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  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 *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6543. }
  6544. }
  6545. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6546. }
  6547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6549. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6550. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6551. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6552. }
  6553. //********************************(8)Current.Import L3************************************************/
  6554. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6555. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6556. (dataType == ReadingContext_Trigger))
  6557. {
  6558. // Only for AC 3 phase
  6559. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6560. {
  6561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6562. {
  6563. tempIndex = 2;
  6564. }
  6565. else
  6566. {
  6567. tempIndex = gun_index;
  6568. }
  6569. for (int index = 0; index < AC_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6572. {
  6573. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6574. }
  6575. }
  6576. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6577. }
  6578. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6579. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6580. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6581. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6582. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6583. }
  6584. //***********************************************(9)VOLTAGE L2******************************************************/
  6585. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6586. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6587. (dataType == ReadingContext_Trigger))
  6588. {
  6589. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6590. {
  6591. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6592. {
  6593. tempIndex = 2;
  6594. }
  6595. else
  6596. {
  6597. tempIndex = gun_index;
  6598. }
  6599. for (int index = 0; index < AC_QUANTITY; index++)
  6600. {
  6601. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6602. {
  6603. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6604. }
  6605. }
  6606. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6607. }
  6608. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6609. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6610. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6611. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6612. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6613. }
  6614. //***********************************************(10)VOLTAGE L3******************************************************/
  6615. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6616. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6617. (dataType == ReadingContext_Trigger))
  6618. {
  6619. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6620. {
  6621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6622. {
  6623. tempIndex = 2;
  6624. }
  6625. else
  6626. {
  6627. tempIndex = gun_index;
  6628. }
  6629. for (int index = 0; index < AC_QUANTITY; index++)
  6630. {
  6631. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6632. {
  6633. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6634. }
  6635. }
  6636. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6637. }
  6638. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6639. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6640. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6641. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6642. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6643. }
  6644. //***********************************************(11)Current.Offered******************************************************/
  6645. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6646. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6647. (dataType == ReadingContext_Trigger))
  6648. {
  6649. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6650. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6651. {
  6652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6653. {
  6654. tempIndex = ((gun_index==2) ? 1: 0);
  6655. }
  6656. else
  6657. {
  6658. tempIndex = gun_index;
  6659. }
  6660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6661. {
  6662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6663. {
  6664. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6665. }
  6666. } // END OF FOR CHAdeMO_QUANTITY
  6667. }
  6668. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6669. {
  6670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6671. {
  6672. tempIndex = ((gun_index==2) ? 1: 0);
  6673. }
  6674. else
  6675. {
  6676. tempIndex = gun_index;
  6677. }
  6678. for (int index = 0; index < CCS_QUANTITY; index++)
  6679. {
  6680. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6681. {
  6682. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6683. }
  6684. } // END OF CCS_QUANTITY
  6685. }
  6686. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6687. {
  6688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6689. {
  6690. tempIndex = ((gun_index==2) ? 1: 0);
  6691. }
  6692. else
  6693. {
  6694. tempIndex = gun_index;
  6695. }
  6696. for (int index = 0; index < GB_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6699. {
  6700. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6701. }
  6702. } // END OF GB_QUANTITY
  6703. }
  6704. else if(gunType[gun_index] == GUN_TYPE_DO)
  6705. {
  6706. tempIndex = gun_index;
  6707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6708. {
  6709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6710. {
  6711. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6712. }
  6713. }
  6714. }
  6715. else
  6716. {
  6717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6718. {
  6719. tempIndex = 2;
  6720. }
  6721. else
  6722. {
  6723. tempIndex = gun_index;
  6724. }
  6725. for (int index = 0; index < AC_QUANTITY; index++)
  6726. {
  6727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6728. {
  6729. uint16_t currentOffer;
  6730. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6731. {
  6732. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6733. }
  6734. else
  6735. {
  6736. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6737. }
  6738. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6739. }
  6740. }
  6741. }
  6742. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6743. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6744. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6745. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6746. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6747. }
  6748. //***********************************************(12)Power.Offered******************************************************/
  6749. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6750. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6751. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6752. {
  6753. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6754. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6755. {
  6756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6757. {
  6758. tempIndex = ((gun_index==2) ? 1: 0);
  6759. }
  6760. else
  6761. {
  6762. tempIndex = gun_index;
  6763. }
  6764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6765. {
  6766. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6767. {
  6768. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6769. }
  6770. } // END OF FOR CHAdeMO_QUANTITY
  6771. }
  6772. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6773. {
  6774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6775. {
  6776. tempIndex = ((gun_index==2) ? 1: 0);
  6777. }
  6778. else
  6779. {
  6780. tempIndex = gun_index;
  6781. }
  6782. for (int index = 0; index < CCS_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6785. {
  6786. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6787. }
  6788. } // END OF CCS_QUANTITY
  6789. }
  6790. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6791. {
  6792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6793. {
  6794. tempIndex = ((gun_index==2) ? 1: 0);
  6795. }
  6796. else
  6797. {
  6798. tempIndex = gun_index;
  6799. }
  6800. for (int index = 0; index < GB_QUANTITY; index++)
  6801. {
  6802. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6803. {
  6804. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6805. }
  6806. } // END OF GB_QUANTITY
  6807. }
  6808. else if(gunType[gun_index] == GUN_TYPE_DO)
  6809. {
  6810. tempIndex = gun_index;
  6811. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6814. {
  6815. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6816. }
  6817. }
  6818. }
  6819. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6823. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6824. }
  6825. // Message create ====================================================================================================
  6826. if(TRUE)
  6827. {
  6828. json_object *MeterValueReq = json_object_new_object();
  6829. json_object *MeterValues = json_object_new_array();
  6830. json_object *sampledValues = json_object_new_array();
  6831. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6832. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6833. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6834. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6835. {
  6836. json_object *MeterValue = json_object_new_object();
  6837. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6838. {
  6839. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6840. {
  6841. json_object *sampledValue = json_object_new_object();
  6842. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6843. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6844. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6845. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6846. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6847. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6848. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6849. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6850. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6851. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6852. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6853. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6854. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6855. json_object_array_add(sampledValues, sampledValue);
  6856. }
  6857. }
  6858. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6859. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6860. json_object_array_add(MeterValues, MeterValue);
  6861. }
  6862. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6863. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6864. ,gun_index + 1
  6865. ,MESSAGE_TYPE_CALL
  6866. ,guid
  6867. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6868. json_object_put(MeterValueReq);
  6869. }
  6870. // Put request guid to hash map
  6871. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6872. 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*/)
  6873. {
  6874. result = PASS;
  6875. //DEBUG_INFO("MeterValues mapitem pass\n");
  6876. }
  6877. if((dataType != ReadingContext_Trigger) &&
  6878. (dataType != ReadingContext_Sample_Clock) &&
  6879. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6880. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6881. else
  6882. {
  6883. if(FirstHeartBeat)
  6884. LWS_Send(queuedata +2);
  6885. }
  6886. return result;
  6887. }
  6888. int sendLogStatusNotificationRequest(char *status)
  6889. {
  6890. mtrace();
  6891. int result = PASS;
  6892. char message[4096]={0};
  6893. char guid[37]={0};
  6894. char tempdata[128]={0};
  6895. json_object *LogStatusNotification = json_object_new_object();
  6896. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6897. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6898. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6899. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6900. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6901. random_uuid(guid);
  6902. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6903. json_object_put(LogStatusNotification);
  6904. LWS_Send(message);
  6905. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6906. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6907. {
  6908. result = PASS;
  6909. }
  6910. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6911. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6912. return result;
  6913. }
  6914. int sendSecurityEventNotificationRequest()
  6915. {
  6916. mtrace();
  6917. int result = PASS;
  6918. char message[4096]={0};
  6919. char guid[37]={0};
  6920. char tempdata[128]={0};
  6921. json_object *SecurityEventNotification = json_object_new_object();
  6922. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6923. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6924. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6925. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6926. random_uuid(guid);
  6927. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6928. json_object_put(SecurityEventNotification);
  6929. LWS_Send(message);
  6930. sprintf(tempdata, "SecurityEventNotification,0");
  6931. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6932. {
  6933. result = PASS;
  6934. }
  6935. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6936. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6937. return result;
  6938. }
  6939. int sendSignCertificateRequest()
  6940. {
  6941. mtrace();
  6942. int result = PASS;
  6943. char message[4096]={0};
  6944. char guid[37]={0};
  6945. char tempdata[128]={0};
  6946. json_object *SignCertificate = json_object_new_object();
  6947. DEBUG_INFO("sendSignCertificateRequest...\n");
  6948. // Read csr file content
  6949. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6950. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6951. char *line = NULL;
  6952. size_t len = 0;
  6953. while(getline(&line, &len, fp) != -1)
  6954. {
  6955. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6956. {
  6957. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6958. }
  6959. }
  6960. fclose(fp);
  6961. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6962. random_uuid(guid);
  6963. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6964. json_object_put(SignCertificate);
  6965. LWS_Send(message);
  6966. sprintf(tempdata, "SignCertificate,0");
  6967. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6968. {
  6969. result = PASS;
  6970. }
  6971. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6972. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6973. return result;
  6974. }
  6975. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6976. {
  6977. mtrace();
  6978. int result = PASS;
  6979. char message[110]={0};
  6980. char guid[37]={0};
  6981. char tempdata[65]={0};
  6982. json_object *FirmwareStatusNotification = json_object_new_object();
  6983. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6984. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6985. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6986. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6987. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6988. random_uuid(guid);
  6989. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6990. json_object_put(FirmwareStatusNotification);
  6991. LWS_Send(message);
  6992. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6993. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6994. {
  6995. result = PASS;
  6996. }
  6997. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6998. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6999. return result;
  7000. }
  7001. //==========================================
  7002. // send confirm routine
  7003. //==========================================
  7004. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7005. {
  7006. mtrace();
  7007. int result = FAIL;
  7008. char message[100]={0};
  7009. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7010. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7011. LWS_Send(message);
  7012. result = TRUE;
  7013. return result;
  7014. }
  7015. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7016. {
  7017. mtrace();
  7018. int result = FAIL;
  7019. char message[100]={0};
  7020. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7021. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7022. LWS_Send(message);
  7023. result = TRUE;
  7024. return result;
  7025. }
  7026. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7027. {
  7028. mtrace();
  7029. int result = FAIL;
  7030. char message[100]={0};
  7031. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7032. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7033. LWS_Send(message);
  7034. result = TRUE;
  7035. return result;
  7036. }
  7037. int sendClearCacheConfirmation(char *uuid,char *payload)
  7038. {
  7039. mtrace();
  7040. int result = FAIL;
  7041. char message[500]={0};
  7042. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7043. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7044. LWS_Send(message);
  7045. return result;
  7046. }
  7047. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7048. {
  7049. mtrace();
  7050. int result = FAIL;
  7051. char message[500]={0};
  7052. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7053. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7054. LWS_Send(message);
  7055. return result;
  7056. }
  7057. int sendDataTransferConfirmation(char *uuid,char *payload)
  7058. {
  7059. mtrace();
  7060. char statusStr[20]={0};
  7061. char dataStr[10]={0};
  7062. char sstr[20]={0};
  7063. int c = 0;
  7064. char *loc;
  7065. int result = FAIL;
  7066. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7067. /**********************status**************************/
  7068. loc = strstr(payload, "status");
  7069. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7070. c = 0;
  7071. while (loc[3+strlen("status")+c] != '\"')
  7072. {
  7073. sstr[c] = loc[3+strlen("status")+c];
  7074. c++;
  7075. }
  7076. sstr[c] = '\0';
  7077. strcpy(statusStr, sstr);
  7078. /**********************data**************************/
  7079. loc = strstr(payload, "data");
  7080. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7081. c = 0;
  7082. while (loc[3+strlen("data")+c] != '\"')
  7083. {
  7084. sstr[c] = loc[3+strlen("data")+c];
  7085. c++;
  7086. }
  7087. sstr[c] = '\0';
  7088. strcpy(dataStr, sstr);
  7089. return result;
  7090. }
  7091. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7092. {
  7093. mtrace();
  7094. int result = FAIL;
  7095. char message[1000]={0};
  7096. int CompositeScheduleIndex = 0;
  7097. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7098. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7099. if(nPeriod == 0)
  7100. {
  7101. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7102. {
  7103. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7104. ,MESSAGE_TYPE_CALLRESULT
  7105. ,uuid
  7106. ,payload
  7107. ,connectorIdInt);
  7108. }
  7109. else
  7110. {
  7111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7112. ,MESSAGE_TYPE_CALLRESULT
  7113. ,uuid
  7114. ,payload
  7115. ,connectorIdInt
  7116. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7117. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7118. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7119. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7120. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7121. }
  7122. }
  7123. else
  7124. {
  7125. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7126. ,MESSAGE_TYPE_CALLRESULT
  7127. ,uuid
  7128. ,payload
  7129. ,connectorIdInt
  7130. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7131. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7132. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7133. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7134. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7135. {
  7136. if (idx_sample == 0)
  7137. {
  7138. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7139. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7140. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7141. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7142. }
  7143. else
  7144. {
  7145. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7146. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7147. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7148. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7149. }
  7150. }
  7151. sprintf(message + strlen(message), "]}}]");
  7152. }
  7153. LWS_Send(message);
  7154. result = TRUE;
  7155. return result;
  7156. }
  7157. int sendGetConfigurationConfirmation(char *uuid)
  7158. {
  7159. mtrace();
  7160. int result = FAIL;
  7161. int MaxKeySupported = 0;
  7162. int sentConfigurationNumber= 0;
  7163. int sentunConfigurationNumber= 0;
  7164. char message[1024*10]={0};
  7165. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7166. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7167. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7168. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7169. ,MESSAGE_TYPE_CALLRESULT
  7170. ,uuid );
  7171. //configuration key
  7172. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7173. {
  7174. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7175. {
  7176. if (sentConfigurationNumber == 0)
  7177. {
  7178. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7179. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7180. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7181. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7182. }
  7183. else
  7184. {
  7185. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7186. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7187. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7188. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7189. }
  7190. sentConfigurationNumber = sentConfigurationNumber + 1;
  7191. }
  7192. }
  7193. sprintf(message + strlen(message), "]");
  7194. if(UnknownKeynum != 0)
  7195. {
  7196. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7197. //unkown key
  7198. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7199. {
  7200. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7201. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7202. if(sentunConfigurationNumber == 0)
  7203. {
  7204. sprintf(message + strlen(message), "\"%s\""
  7205. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7206. }
  7207. else
  7208. {
  7209. sprintf(message + strlen(message), ",\"%s\""
  7210. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7211. }
  7212. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7213. }
  7214. sprintf(message + strlen(message), "]");
  7215. }
  7216. sprintf(message + strlen(message), "}]");
  7217. LWS_Send(message);
  7218. return result;
  7219. }
  7220. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7221. {
  7222. mtrace();
  7223. int result = FAIL;
  7224. char message[400]={0};
  7225. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7226. if(strcmp(payload,"")==0)
  7227. {
  7228. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7229. }
  7230. else
  7231. {
  7232. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7233. }
  7234. LWS_Send(message);
  7235. result = TRUE;
  7236. return result;
  7237. }
  7238. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7239. {
  7240. mtrace();
  7241. int result = FAIL;
  7242. char message[80]={0};
  7243. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7244. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7245. LWS_Send(message);
  7246. result = TRUE;
  7247. return result;
  7248. }
  7249. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7250. {
  7251. mtrace();
  7252. int result = FAIL;
  7253. char message[80]={0};
  7254. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7255. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7256. LWS_Send(message);
  7257. result = TRUE;
  7258. return result;
  7259. }
  7260. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7261. {
  7262. mtrace();
  7263. int result = FAIL;
  7264. char message[80]={0};
  7265. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7266. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7267. LWS_Send(message);
  7268. result = TRUE;
  7269. return result;
  7270. }
  7271. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7272. {
  7273. mtrace();
  7274. int result = FAIL;
  7275. char message[80]={0};
  7276. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7277. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7278. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7279. LWS_Send(message);
  7280. result = TRUE;
  7281. return result;
  7282. }
  7283. int sendResetConfirmation(char *uuid,char *payload)
  7284. {
  7285. mtrace();
  7286. int result = FAIL;
  7287. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7288. char message[80]={0};
  7289. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7290. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7291. LWS_Send(message);
  7292. result = TRUE;
  7293. return result;
  7294. }
  7295. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7296. {
  7297. mtrace();
  7298. int result = FAIL;
  7299. char message[500]={0};
  7300. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7301. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7302. LWS_Send(message);
  7303. result = TRUE;
  7304. return result;
  7305. }
  7306. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7307. {
  7308. mtrace();
  7309. int result = FAIL;
  7310. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7311. char message[80]={0};
  7312. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7313. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7314. LWS_Send(message);
  7315. result = TRUE;
  7316. return result;
  7317. }
  7318. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7319. {
  7320. mtrace();
  7321. int result = FAIL;
  7322. char message[80]={0};
  7323. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7324. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7325. LWS_Send(message);
  7326. result = TRUE;
  7327. return result;
  7328. }
  7329. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7330. {
  7331. mtrace();
  7332. int result = FAIL;
  7333. char message[80]={0};
  7334. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7335. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7336. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7337. LWS_Send(message);
  7338. result = TRUE;
  7339. return result;
  7340. }
  7341. int sendUpdateFirmwareConfirmation(char *uuid)
  7342. {
  7343. mtrace();
  7344. int result = FAIL;
  7345. char message[60]={0};
  7346. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7347. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7348. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7349. LWS_Send(message);
  7350. result = TRUE;
  7351. return result;
  7352. }
  7353. int sendCertificateSignedConfirmation(char *uuid)
  7354. {
  7355. mtrace();
  7356. int result = PASS;
  7357. char message[4096]={0};
  7358. json_object *CertificateSigned = json_object_new_object();
  7359. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7360. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7361. sprintf(message,"[%d,\"%s\",%s]"
  7362. ,MESSAGE_TYPE_CALLRESULT
  7363. ,uuid
  7364. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7365. json_object_put(CertificateSigned);
  7366. LWS_Send(message);
  7367. return result;
  7368. }
  7369. int sendDeleteCertificateConfirmation(char *uuid)
  7370. {
  7371. mtrace();
  7372. int result = PASS;
  7373. char message[4096]={0};
  7374. json_object *DeleteCertificate = json_object_new_object();
  7375. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7376. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7377. sprintf(message,"[%d,\"%s\",%s]"
  7378. ,MESSAGE_TYPE_CALLRESULT
  7379. ,uuid
  7380. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7381. json_object_put(DeleteCertificate);
  7382. LWS_Send(message);
  7383. return result;
  7384. }
  7385. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7386. {
  7387. mtrace();
  7388. int result = PASS;
  7389. char message[4096]={0};
  7390. json_object *ExtendedTriggerMessage = json_object_new_object();
  7391. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7392. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7393. sprintf(message,"[%d,\"%s\",%s]"
  7394. ,MESSAGE_TYPE_CALLRESULT
  7395. ,uuid
  7396. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7397. json_object_put(ExtendedTriggerMessage);
  7398. LWS_Send(message);
  7399. return result;
  7400. }
  7401. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7402. {
  7403. mtrace();
  7404. int result = PASS;
  7405. char message[4096]={0};
  7406. json_object *GetInstalledCertificateIds = json_object_new_object();
  7407. json_object *certificateHashDataDatas = json_object_new_array();
  7408. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7409. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7410. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7411. {
  7412. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7413. {
  7414. json_object *certificateHashData = json_object_new_object();
  7415. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7416. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7417. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7418. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7419. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7420. }
  7421. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7422. }
  7423. else
  7424. {
  7425. json_object_put(certificateHashDataDatas);
  7426. }
  7427. sprintf(message,"[%d,\"%s\",%s]"
  7428. ,MESSAGE_TYPE_CALLRESULT
  7429. ,uuid
  7430. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7431. json_object_put(GetInstalledCertificateIds);
  7432. LWS_Send(message);
  7433. return result;
  7434. }
  7435. int sendGetLogConfirmation(char *uuid)
  7436. {
  7437. mtrace();
  7438. int result = PASS;
  7439. char message[4096]={0};
  7440. json_object *GetLog = json_object_new_object();
  7441. DEBUG_INFO("sendGetLogConfirmation...\n");
  7442. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7443. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7444. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7445. sprintf(message,"[%d,\"%s\",%s]"
  7446. ,MESSAGE_TYPE_CALLRESULT
  7447. ,uuid
  7448. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7449. json_object_put(GetLog);
  7450. LWS_Send(message);
  7451. return result;
  7452. }
  7453. int sendInstallCertificateConfirmation(char *uuid)
  7454. {
  7455. mtrace();
  7456. int result = PASS;
  7457. char message[4096]={0};
  7458. json_object *InstallCertificate = json_object_new_object();
  7459. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7460. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7461. sprintf(message,"[%d,\"%s\",%s]"
  7462. ,MESSAGE_TYPE_CALLRESULT
  7463. ,uuid
  7464. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7465. json_object_put(InstallCertificate);
  7466. LWS_Send(message);
  7467. return result;
  7468. }
  7469. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7470. {
  7471. mtrace();
  7472. int result = PASS;
  7473. char message[4096]={0};
  7474. json_object *SignedUpdateFirmware = json_object_new_object();
  7475. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7476. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7477. sprintf(message,"[%d,\"%s\",%s]"
  7478. ,MESSAGE_TYPE_CALLRESULT
  7479. ,uuid
  7480. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7481. json_object_put(SignedUpdateFirmware);
  7482. LWS_Send(message);
  7483. return result;
  7484. }
  7485. int sendUnknownConfirmation(char *uuid)
  7486. {
  7487. mtrace();
  7488. int result = PASS;
  7489. char message[256]={0};
  7490. DEBUG_INFO("sendUnknownConfirmation...\n");
  7491. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7492. LWS_Send(message);
  7493. return result;
  7494. }
  7495. //==========================================
  7496. // Handle server request routine Start
  7497. //==========================================
  7498. int handleCancelReservationRequest(char *uuid, char *payload)
  7499. {
  7500. mtrace();
  7501. int result = FAIL;
  7502. int gunNO = 0;
  7503. int reservationIdInt = -1;
  7504. char comfirmstr[20];
  7505. DEBUG_INFO("handleCancelReservationRequest...\n");
  7506. json_object *CancelReservation;
  7507. CancelReservation = json_tokener_parse(payload);
  7508. if(!is_error(CancelReservation))
  7509. {
  7510. // Required data
  7511. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7512. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7513. }
  7514. json_object_put(CancelReservation);
  7515. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7516. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7517. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7518. if(reservationIdInt != -1)
  7519. {
  7520. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7521. //check Transaction active
  7522. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7524. {
  7525. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7526. {
  7527. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7528. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7529. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7530. {
  7531. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7532. }
  7533. else
  7534. {
  7535. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7536. }
  7537. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7538. goto end;
  7539. }
  7540. }
  7541. for (int index = 0; index < CCS_QUANTITY; index++)
  7542. {
  7543. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7544. {
  7545. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7546. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7547. if(gunType[2] == GUN_TYPE_CCS)
  7548. {
  7549. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7550. }
  7551. else
  7552. {
  7553. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7554. }
  7555. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7556. goto end;
  7557. }
  7558. }
  7559. for (int index = 0; index < GB_QUANTITY; index++)
  7560. {
  7561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7562. {
  7563. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7564. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7565. if(gunType[2] == GUN_TYPE_GBT)
  7566. {
  7567. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7568. }
  7569. else
  7570. {
  7571. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7572. }
  7573. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7574. goto end;
  7575. }
  7576. }
  7577. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7578. {
  7579. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7580. {
  7581. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7582. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7583. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7584. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7585. goto end;
  7586. }
  7587. }
  7588. for (int index = 0; index < AC_QUANTITY; index++)
  7589. {
  7590. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7591. {
  7592. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7593. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7595. {
  7596. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7597. }
  7598. else
  7599. {
  7600. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7601. }
  7602. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7603. goto end;
  7604. }
  7605. }
  7606. }
  7607. //The reservationId does NOT match the reservationId
  7608. sendCancelReservationConfirmation(uuid, comfirmstr);
  7609. end:
  7610. // Fill in ocpp packet uuid
  7611. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7612. return result;
  7613. }
  7614. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7615. {
  7616. mtrace();
  7617. int result = FAIL;
  7618. int gunIndex = -1;
  7619. char typeStr[16]={0};
  7620. char comfirmstr[20];
  7621. int specificId = FALSE;
  7622. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7623. json_object *ChangeAvailability;
  7624. ChangeAvailability = json_tokener_parse(payload);
  7625. if(!is_error(ChangeAvailability))
  7626. {
  7627. // Required data
  7628. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7629. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7630. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7631. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7632. }
  7633. json_object_put(ChangeAvailability);
  7634. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7635. {
  7636. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7637. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7638. }
  7639. else if(gunIndex == 0)
  7640. {
  7641. for(int i=0; i < gunTotalNumber; i++)
  7642. {
  7643. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7644. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7645. }
  7646. }
  7647. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7648. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7649. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7650. {
  7651. specificId = TRUE;
  7652. }
  7653. if(specificId == FALSE)
  7654. goto end;
  7655. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7656. {
  7657. //----------------------gunIndex is 0 ------------------------------------------------//
  7658. if(gunIndex == 0)
  7659. {
  7660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7661. {
  7662. for(int i=0; i < gunTotalNumber; i++)
  7663. {
  7664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7665. {
  7666. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7667. {
  7668. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7669. {
  7670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7671. goto end;
  7672. }
  7673. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7678. {
  7679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7680. goto end;
  7681. }
  7682. }
  7683. }//END FOR CHAdeMO_QUANTITY
  7684. for (int index = 0; index < CCS_QUANTITY; index++)
  7685. {
  7686. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7687. {
  7688. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7689. {
  7690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7691. goto end;
  7692. }
  7693. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7694. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7695. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7696. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7697. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7698. {
  7699. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7700. goto end;
  7701. }
  7702. }
  7703. }//END FOR CCS_QUANTITY
  7704. for (int index = 0; index < GB_QUANTITY; index++)
  7705. {
  7706. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7707. {
  7708. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7709. {
  7710. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7711. goto end;
  7712. }
  7713. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7714. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7715. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7716. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7717. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7718. {
  7719. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7720. goto end;
  7721. }
  7722. }
  7723. }// END FOR GB_QUANTITY
  7724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7725. {
  7726. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7727. {
  7728. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7729. {
  7730. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7731. goto end;
  7732. }
  7733. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7734. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7735. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7736. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7737. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7738. {
  7739. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7740. goto end;
  7741. }
  7742. }
  7743. }// END FOR GENERAL_GUN_QUANTITY
  7744. for (int index = 0; index < AC_QUANTITY; index++)
  7745. {
  7746. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7747. {
  7748. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7749. {
  7750. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7751. goto end;
  7752. }
  7753. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7754. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7755. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7756. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7757. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7758. {
  7759. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7760. goto end;
  7761. }
  7762. }
  7763. }//END FOR AC_QUANTITY
  7764. }// END FOR gunTotalNumber
  7765. }
  7766. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7767. {
  7768. for(int i=0; i < gunTotalNumber; i++)
  7769. {
  7770. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7771. {
  7772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7773. goto end;
  7774. }
  7775. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7776. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7777. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7780. {
  7781. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7782. goto end;
  7783. }
  7784. }
  7785. }
  7786. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7787. goto end;
  7788. }
  7789. //----------------------gunIndex is not 0 ------------------------------------------------//
  7790. //check Transaction active
  7791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7792. {
  7793. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7794. {
  7795. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7796. {
  7797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7798. goto end;
  7799. }
  7800. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7801. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7802. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7803. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7804. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7805. {
  7806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7807. goto end;
  7808. }
  7809. else
  7810. {
  7811. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7812. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7813. goto end;
  7814. }
  7815. }
  7816. }//END FOR CHAdeMO_QUANTITY
  7817. for (int index = 0; index < CCS_QUANTITY; index++)
  7818. {
  7819. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7820. {
  7821. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7822. {
  7823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7824. goto end;
  7825. }
  7826. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7827. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7828. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7829. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7830. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7831. {
  7832. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7833. goto end;
  7834. }
  7835. else
  7836. {
  7837. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7838. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7839. goto end;
  7840. }
  7841. }
  7842. }//END FOR CCS_QUANTITY
  7843. for (int index = 0; index < GB_QUANTITY; index++)
  7844. {
  7845. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7846. {
  7847. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7848. {
  7849. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7850. goto end;
  7851. }
  7852. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7853. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7854. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7855. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7856. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7857. {
  7858. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7859. goto end;
  7860. }
  7861. else
  7862. {
  7863. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7864. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7865. goto end;
  7866. }
  7867. }
  7868. }// END FOR GB_QUANTITY
  7869. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7870. {
  7871. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7872. {
  7873. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7874. {
  7875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7876. goto end;
  7877. }
  7878. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7879. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7880. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7881. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7882. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7883. {
  7884. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7885. goto end;
  7886. }
  7887. else
  7888. {
  7889. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7890. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7891. goto end;
  7892. }
  7893. }
  7894. }// END FOR GENERAL_GUN_QUANTITY
  7895. for (int index = 0; index < AC_QUANTITY; index++)
  7896. {
  7897. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7898. {
  7899. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7900. {
  7901. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7902. goto end;
  7903. }
  7904. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7905. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7906. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7907. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7908. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7909. {
  7910. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7911. goto end;
  7912. }
  7913. else
  7914. {
  7915. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7916. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7917. goto end;
  7918. }
  7919. }
  7920. }//END FOR AC_QUANTITY
  7921. }//END FOR AvailabilityTypeStr[Inoperative]
  7922. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7923. {
  7924. //----------------------gunIndex is 0 ------------------------------------------------//
  7925. if(gunIndex == 0)
  7926. {
  7927. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7928. {
  7929. for(int i=0; i < gunTotalNumber; i++)
  7930. {
  7931. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7932. {
  7933. 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
  7934. {
  7935. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7936. goto end;
  7937. }
  7938. }//END FOR CHAdeMO_QUANTITY
  7939. for (int index = 0; index < CCS_QUANTITY; index++)
  7940. {
  7941. 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
  7942. {
  7943. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7944. goto end;
  7945. }
  7946. }//END FOR CCS_QUANTITY
  7947. for (int index = 0; index < GB_QUANTITY; index++)
  7948. {
  7949. 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
  7950. {
  7951. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7952. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7953. goto end;
  7954. }
  7955. }// END FOR GB_QUANTITY
  7956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7957. {
  7958. 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
  7959. {
  7960. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7961. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7962. goto end;
  7963. }
  7964. }// END FOR GENERAL_GUN_QUANTITY
  7965. for (int index = 0; index < AC_QUANTITY; index++)
  7966. {
  7967. 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
  7968. {
  7969. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7970. goto end;
  7971. }
  7972. }//END FOR CHAdeMO_QUANTITY
  7973. }// END FOR gunTotalNumber
  7974. }
  7975. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7976. {
  7977. for(int i=0; i < gunTotalNumber; i++)
  7978. {
  7979. for (int index = 0; index < AC_QUANTITY; index++)
  7980. {
  7981. 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
  7982. {
  7983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7984. goto end;
  7985. }
  7986. }//END FOR CHAdeMO_QUANTITY
  7987. } // END FOR gunTotalNumber
  7988. }
  7989. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7990. goto end;
  7991. }
  7992. //----------------------gunIndex is not 0 ------------------------------------------------//
  7993. //check Transaction active
  7994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7995. {
  7996. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7997. {
  7998. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7999. goto end;
  8000. }
  8001. }//END FOR CHAdeMO_QUANTITY
  8002. for (int index = 0; index < CCS_QUANTITY; index++)
  8003. {
  8004. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8005. {
  8006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8007. goto end;
  8008. }
  8009. }//END FOR CCS_QUANTITY
  8010. for (int index = 0; index < GB_QUANTITY; index++)
  8011. {
  8012. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8013. {
  8014. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8015. goto end;
  8016. }
  8017. }// END FOR GB_QUANTITY
  8018. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8019. {
  8020. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8021. {
  8022. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8023. goto end;
  8024. }
  8025. }// END FOR GENERAL_GUN_QUANTITY
  8026. for (int index = 0; index < AC_QUANTITY; index++)
  8027. {
  8028. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8029. {
  8030. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8031. goto end;
  8032. }
  8033. }//END FOR AC_QUANTITY
  8034. }//END FOR AvailabilityTypeStr[Operative]
  8035. end:
  8036. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8037. {
  8038. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8039. }
  8040. else
  8041. {
  8042. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8043. }
  8044. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8045. {
  8046. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8047. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8048. }
  8049. else if(gunIndex == 0)
  8050. {
  8051. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8052. {
  8053. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8054. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8055. }
  8056. }
  8057. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8058. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8059. return result;
  8060. }
  8061. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8062. {
  8063. mtrace();
  8064. int valueInvalid = NO;
  8065. int result = FAIL;
  8066. char keystr[40]={0};
  8067. char valuestr[501]={0}; //value should be limited in 500 bytes
  8068. char comfirmstr[20]={0};
  8069. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8070. json_object *ChangeConfiguration;
  8071. ChangeConfiguration = json_tokener_parse(payload);
  8072. if(!is_error(ChangeConfiguration))
  8073. {
  8074. // Required data
  8075. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8076. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8077. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8078. {
  8079. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8080. }
  8081. else
  8082. {
  8083. valueInvalid = YES;
  8084. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8085. }
  8086. }
  8087. json_object_put(ChangeConfiguration);
  8088. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8089. {
  8090. DEBUG_ERROR("Payload is null or not accepted.\n");
  8091. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8092. }
  8093. else
  8094. {
  8095. int status = setKeyValue(keystr, valuestr);
  8096. switch(status)
  8097. {
  8098. case ConfigurationStatus_Accepted:
  8099. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8100. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8101. StoreConfigurationTable();
  8102. break;
  8103. case RebootRequired:
  8104. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8105. StoreConfigurationTable();
  8106. break;
  8107. case NotSupported:
  8108. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8109. break;
  8110. case ConfigurationStatus_Rejected:
  8111. default:
  8112. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8113. break;
  8114. }
  8115. }
  8116. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8117. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8118. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8119. {
  8120. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8121. SetOcppConnStatus(FALSE);
  8122. }
  8123. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8124. {
  8125. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8126. }
  8127. return result;
  8128. }
  8129. int handleClearCacheRequest(char *uuid, char *payload)
  8130. {
  8131. mtrace();
  8132. int result = FAIL;
  8133. char comfirmstr[20];
  8134. char rmFileCmd[100]={0};
  8135. struct stat stats;
  8136. DEBUG_INFO("handleClearCacheRequest...\n");
  8137. stat("/Storage/OCPP_PH", &stats);
  8138. // Check for directory existence
  8139. if (S_ISDIR(stats.st_mode) == 1)
  8140. {}
  8141. else
  8142. {
  8143. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8144. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8145. system(rmFileCmd);
  8146. }
  8147. if(OCPP_cleanLocalCache())
  8148. {
  8149. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8150. }
  8151. else
  8152. {
  8153. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8154. }
  8155. sendClearCacheConfirmation(uuid, comfirmstr);
  8156. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8157. return result;
  8158. }
  8159. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8160. {
  8161. mtrace();
  8162. int result = FAIL;
  8163. int resultRename;
  8164. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8165. char chargingProfilePurposeStr[26]={0};
  8166. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8167. char tempchargingProfilePurposeStr[26]={0};
  8168. char str[100]={0};
  8169. char fname[200]={0};
  8170. char comfirmstr[20]={0};
  8171. char word[1600]={0};
  8172. int clearflag = FALSE;
  8173. int chargingProfileIdIsNULL = FALSE;
  8174. int connectorIsNULL = FALSE;
  8175. int chargingProfilePurposeIsNULL = FALSE;
  8176. int stackLevelIsNULL = FALSE;
  8177. //int GotoEnd = FALSE;
  8178. FILE *fptr1, *fptr2;
  8179. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8180. int n_chargingProfile=0;
  8181. int isEmptyFile = FALSE;
  8182. char sLineWord[1600]={0};
  8183. char chargingProfiles[10][100]={0};
  8184. int ChargeProfileCount = 0;
  8185. int ch;
  8186. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8187. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8188. json_object *ClearChargingProfile;
  8189. ClearChargingProfile = json_tokener_parse(payload);
  8190. if(!is_error(ClearChargingProfile))
  8191. {
  8192. // Optional data
  8193. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8194. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8195. else
  8196. chargingProfileIdIsNULL = TRUE;
  8197. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8198. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8199. else
  8200. connectorIsNULL = TRUE;
  8201. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8202. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8203. else
  8204. chargingProfilePurposeIsNULL = TRUE;
  8205. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8206. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8207. else
  8208. stackLevelIsNULL = TRUE;
  8209. }
  8210. json_object_put(ClearChargingProfile);
  8211. if(connectorIsNULL == FALSE)
  8212. {
  8213. switch(connectorIdInt)
  8214. {
  8215. case 0:
  8216. if(chargingProfilePurposeIsNULL == TRUE)
  8217. {
  8218. int l = 0;
  8219. strcpy(fname, ChargePointMaxProfile_JSON);
  8220. if((access(fname,F_OK))!=-1)
  8221. {
  8222. strcpy(chargingProfiles[l], fname);
  8223. l = l + 1;
  8224. }
  8225. strcpy(fname, TxDefaultProfile_0_JSON);
  8226. if((access(fname,F_OK))!=-1)
  8227. {
  8228. strcpy(chargingProfiles[l], fname);
  8229. l = l + 1;
  8230. }
  8231. ChargeProfileCount = l;
  8232. }
  8233. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8234. {
  8235. strcpy(fname, ChargePointMaxProfile_JSON);
  8236. if((access(fname,F_OK))!=-1)
  8237. {
  8238. strcpy(chargingProfiles[0], fname);
  8239. ChargeProfileCount = 1;
  8240. }
  8241. }
  8242. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8243. {
  8244. strcpy(fname, TxDefaultProfile_0_JSON);
  8245. if((access(fname,F_OK))!=-1)
  8246. {
  8247. strcpy(chargingProfiles[0], fname);
  8248. ChargeProfileCount = 1;
  8249. }
  8250. }
  8251. break;
  8252. default:
  8253. if(chargingProfilePurposeIsNULL == TRUE)
  8254. {
  8255. int m = 0;
  8256. memset(fname, 0, ARRAY_SIZE(fname));
  8257. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8258. if((access(fname,F_OK))!=-1)
  8259. {
  8260. strcpy(chargingProfiles[m], fname);
  8261. m = m + 1;
  8262. }
  8263. memset(fname, 0, ARRAY_SIZE(fname));
  8264. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8265. if((access(fname,F_OK))!=-1)
  8266. {
  8267. strcpy(chargingProfiles[m], fname);
  8268. m = m + 1;
  8269. }
  8270. ChargeProfileCount = m;
  8271. }
  8272. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8273. {
  8274. //strcpy(fname, TxDefaultProfile_1_JSON);
  8275. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8276. if((access(fname,F_OK))!=-1)
  8277. {
  8278. strcpy(chargingProfiles[0], fname);
  8279. ChargeProfileCount = 1;
  8280. }
  8281. }
  8282. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8283. {
  8284. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8285. if((access(fname,F_OK))!=-1)
  8286. {
  8287. strcpy(chargingProfiles[0], fname);
  8288. ChargeProfileCount = 1;
  8289. }
  8290. //strcpy(fname, TxProfile_1_JSON);
  8291. }
  8292. //strcpy(fname, ChargePointMaxProfile_JSON );
  8293. break;
  8294. }
  8295. }
  8296. else // Check all Charging Profiles
  8297. {
  8298. int i = 0;
  8299. char fnametemp[200]={0};
  8300. ChargeProfileCount = 0;
  8301. //Check ChargePointMaxProfile.json exit
  8302. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8303. {
  8304. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8305. i = i + 1;
  8306. }
  8307. //Check TxDefaultProfile_0.json exit
  8308. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8309. {
  8310. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8311. i = i + 1;
  8312. }
  8313. //Check TxDefaultProfile_%d.json
  8314. for(int j=1; j <= gunTotalNumber; j++)
  8315. {
  8316. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8317. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8318. if((access(fnametemp,F_OK))!=-1)
  8319. {
  8320. strcpy(chargingProfiles[i], fnametemp);
  8321. i = i + 1;
  8322. }
  8323. }
  8324. //Check TxProfile_%d.json
  8325. for(int j=1; j <= gunTotalNumber; j++)
  8326. {
  8327. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8328. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8329. if((access(fnametemp,F_OK))!=-1)
  8330. {
  8331. strcpy(chargingProfiles[i], fnametemp);
  8332. i = i + 1;
  8333. }
  8334. }
  8335. ChargeProfileCount = i;
  8336. }// End connectorIsNULL is TRUE
  8337. if(ChargeProfileCount == 0)
  8338. {
  8339. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8340. goto end;
  8341. }
  8342. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8343. {
  8344. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8345. goto end;
  8346. }
  8347. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8348. {
  8349. memset(str, 0, ARRAY_SIZE(str));
  8350. // clear temp file
  8351. sprintf(str,"rm -f %s",temp);
  8352. system(str);
  8353. for(int k=0; k < ChargeProfileCount; k++)
  8354. {
  8355. memset(str, 0, ARRAY_SIZE(str));
  8356. //clear file in C
  8357. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8358. system(str);
  8359. }
  8360. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8361. goto end;
  8362. }
  8363. else if(connectorIsNULL == TRUE)
  8364. {
  8365. for(int k=0; k < ChargeProfileCount; k++)
  8366. {
  8367. fptr1 = fopen(chargingProfiles[k], "r");
  8368. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8369. //Check Charging Profile Count
  8370. while(fscanf(fptr1, "%s", word) != EOF)
  8371. {
  8372. //DEBUG_INFO("word=%s\n",word);
  8373. if(strstr(word, "chargingProfileId")!= NULL)
  8374. {
  8375. //DEBUG_INFO("test chargingProfileId \n");
  8376. n_chargingProfile = n_chargingProfile + 1;
  8377. //DEBUG_INFO("chargingProfileId Found\n");
  8378. }
  8379. }
  8380. rewind(fptr1);
  8381. //search Charging Profile Element
  8382. //int i= 0;
  8383. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8384. {
  8385. json_object *tmpProfilee;
  8386. tmpProfilee = json_tokener_parse(sLineWord);
  8387. if(!is_error(tmpProfilee))
  8388. {
  8389. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8390. {
  8391. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8392. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8393. }
  8394. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8395. {
  8396. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8397. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8398. }
  8399. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8400. {
  8401. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8402. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8403. }
  8404. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8405. {
  8406. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8407. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8408. }
  8409. }
  8410. json_object_put(tmpProfilee);
  8411. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8412. {
  8413. //------- not write to fptr2-------//
  8414. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8415. //clearflag = TRUE;
  8416. }
  8417. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8418. {
  8419. //------- not write to fptr2-------//
  8420. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8421. }
  8422. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8423. {
  8424. //------- not write to fptr2-------//
  8425. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8426. }
  8427. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8428. {
  8429. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8430. }
  8431. else
  8432. {
  8433. fprintf(fptr2, sLineWord);//writing data into file
  8434. }
  8435. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8436. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8437. if(clearflag == TRUE)
  8438. {
  8439. fclose(fptr1);
  8440. fclose(fptr2);
  8441. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8442. system(str);
  8443. // clear temp file
  8444. sprintf(str,"rm -f %s",temp);
  8445. system(str);
  8446. }
  8447. else
  8448. {
  8449. fclose(fptr1);
  8450. fclose(fptr2);
  8451. memset(str, 0, ARRAY_SIZE(str));
  8452. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8453. system(str);
  8454. resultRename = rename(temp, chargingProfiles[k]);
  8455. if(resultRename == 0)
  8456. {
  8457. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8458. }
  8459. else
  8460. {
  8461. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8462. }
  8463. if(comfirmstr[0]== 0)
  8464. {
  8465. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8466. }
  8467. //Check chargingProfile is empty file
  8468. /*------ Read the file ----------------*/
  8469. fptr1=fopen(chargingProfiles[k],"r");
  8470. ch=fgetc(fptr1);
  8471. rewind(fptr1);
  8472. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8473. if(ch!=EOF)
  8474. {
  8475. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8476. {
  8477. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8478. if(sLineWord[0]=='\0')
  8479. {
  8480. isEmptyFile = TRUE;
  8481. break;
  8482. }
  8483. else
  8484. {
  8485. isEmptyFile = FALSE;
  8486. break;
  8487. }
  8488. }
  8489. }
  8490. else
  8491. isEmptyFile = TRUE;
  8492. fclose(fptr1);
  8493. if(isEmptyFile == TRUE)
  8494. {
  8495. memset(str, 0, ARRAY_SIZE(str));
  8496. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8497. system(str);
  8498. }
  8499. }
  8500. }// End of while(int k=0; k < ChargePointCount; k++)
  8501. }
  8502. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8503. {
  8504. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8505. for(int k=0; k < ChargeProfileCount; k++)
  8506. {
  8507. fptr1 = fopen(chargingProfiles[k], "r");
  8508. fptr2 = fopen(temp, "w+");
  8509. //Check Charging Profile Count
  8510. while(fscanf(fptr1, "%s", word) != EOF)
  8511. {
  8512. //DEBUG_INFO("word=%s\n",word);
  8513. if(strstr(word, "chargingProfileId")!= NULL)
  8514. {
  8515. n_chargingProfile = n_chargingProfile + 1;
  8516. }
  8517. }
  8518. rewind(fptr1);
  8519. //search Charging Profile Element
  8520. //int i= 0;
  8521. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8522. {
  8523. json_object *tmpProfilee;
  8524. tmpProfilee = json_tokener_parse(sLineWord);
  8525. if(!is_error(tmpProfilee))
  8526. {
  8527. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8528. {
  8529. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8530. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8531. }
  8532. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8533. {
  8534. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8535. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8536. }
  8537. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8538. {
  8539. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8540. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8541. }
  8542. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8543. {
  8544. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8545. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8546. }
  8547. }
  8548. json_object_put(tmpProfilee);
  8549. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8550. {
  8551. //------- not write to fptr2-------//
  8552. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8553. //clearflag = TRUE;
  8554. }
  8555. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8556. {
  8557. //------- not write to fptr2-------//
  8558. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8559. }
  8560. else if(stackLevelIsNULL == TRUE)
  8561. {
  8562. //Clear Whole File
  8563. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8564. clearflag = TRUE;
  8565. break;
  8566. }
  8567. else
  8568. {
  8569. fprintf(fptr2, sLineWord);//writing data into file
  8570. }
  8571. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8572. }
  8573. if(clearflag == TRUE)
  8574. {
  8575. fclose(fptr1);
  8576. fclose(fptr2);
  8577. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8578. system(str);
  8579. // clear temp file
  8580. sprintf(str,"rm -f %s",temp);
  8581. system(str);
  8582. }
  8583. else
  8584. {
  8585. fclose(fptr1);
  8586. fclose(fptr2);
  8587. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8588. system(str);
  8589. resultRename = rename(temp, chargingProfiles[k]);
  8590. if(resultRename == 0)
  8591. {
  8592. DEBUG_INFO("File ChargingProfile renamed successfully");
  8593. }
  8594. else
  8595. {
  8596. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8597. }
  8598. if(comfirmstr[0]== 0)
  8599. {
  8600. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8601. }
  8602. //Check chargingProfile is empty file
  8603. /*------ Read the file ----------------*/
  8604. fptr1=fopen(chargingProfiles[k],"r");
  8605. ch=fgetc(fptr1);
  8606. rewind(fptr1);
  8607. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8608. if(ch!=EOF)
  8609. {
  8610. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8611. {
  8612. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8613. if(sLineWord[0]=='\0')
  8614. {
  8615. isEmptyFile = TRUE;
  8616. break;
  8617. }
  8618. else
  8619. {
  8620. isEmptyFile = FALSE;
  8621. break;
  8622. }
  8623. }
  8624. }
  8625. else
  8626. isEmptyFile = TRUE;
  8627. fclose(fptr1);
  8628. if(isEmptyFile == TRUE)
  8629. {
  8630. memset(str, 0, ARRAY_SIZE(str));
  8631. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8632. system(str);
  8633. }
  8634. /*------- End of reading ---------------*/
  8635. }
  8636. } // while(int k=0; k < ChargeProfileCount; k++)
  8637. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8638. end:
  8639. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8640. {
  8641. if(connectorIdInt == 0)
  8642. {
  8643. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8644. {
  8645. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8646. }
  8647. }
  8648. else
  8649. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8650. }
  8651. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8652. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8653. return result;
  8654. }
  8655. void createFirmwareVersionByDataTransfer(void)
  8656. {
  8657. json_object *FirmwareDataTransfer = json_object_new_object();
  8658. // AC & DC model
  8659. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8660. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8661. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8662. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8663. // DC model
  8664. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8665. {
  8666. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8667. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8668. (gunType[3] != GUN_TYPE_UNKNOWN))
  8669. {
  8670. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8671. }
  8672. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8673. {
  8674. // DS DM DW
  8675. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8676. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8677. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8678. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8679. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8680. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8681. }
  8682. else
  8683. {
  8684. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8685. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8686. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8687. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8688. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8689. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8690. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8691. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8692. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8693. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8694. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8695. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8696. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8697. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8698. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8699. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8700. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8701. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8702. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8703. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8704. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8705. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8706. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8707. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8708. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8709. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8710. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8711. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8712. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8713. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8714. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8715. }
  8716. }
  8717. // 4G model
  8718. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8719. {
  8720. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8721. }
  8722. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8723. json_object_put(FirmwareDataTransfer);
  8724. }
  8725. int handleDataTransferRequest(char *uuid, char *payload)
  8726. {
  8727. mtrace();
  8728. json_object *response = json_object_new_object();
  8729. int result = FAIL;
  8730. char tempvendorId[255]={0};
  8731. char tempmessageId[50]={0};
  8732. char tempdata[512]={0};
  8733. char message[2048]={0};
  8734. DEBUG_INFO("handleDataTransferRequest...\n");
  8735. if((uuid != NULL) && (payload != NULL))
  8736. {
  8737. json_object *DataTransfer;
  8738. DataTransfer = json_tokener_parse(payload);
  8739. if(!is_error(DataTransfer))
  8740. {
  8741. // Required data
  8742. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8743. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8744. // Optional data
  8745. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8746. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8747. if(json_object_object_get(DataTransfer, "data") != NULL)
  8748. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8749. result = PASS;
  8750. }
  8751. json_object_put(DataTransfer);
  8752. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8753. {
  8754. // Send all moudle firmware version on EVSE
  8755. createFirmwareVersionByDataTransfer();
  8756. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8757. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8758. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8759. json_object_put(response);
  8760. }
  8761. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8762. {
  8763. system("/usr/bin/run_tmate_restart.sh &");
  8764. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8765. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8766. json_object_put(response);
  8767. }
  8768. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8769. {
  8770. json_object *data;
  8771. data = json_tokener_parse(tempdata);
  8772. if(!is_error(data))
  8773. {
  8774. 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))
  8775. {
  8776. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8777. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8778. if(json_object_object_get(data, "SOC") != NULL)
  8779. {
  8780. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8781. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8782. }
  8783. if(json_object_object_get(data, "Energy") != NULL)
  8784. {
  8785. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8786. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8787. }
  8788. if(json_object_object_get(data, "Duration") != NULL)
  8789. {
  8790. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8791. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8792. }
  8793. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8794. }
  8795. else
  8796. {
  8797. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8798. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8799. }
  8800. }
  8801. else
  8802. {
  8803. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8804. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8805. }
  8806. json_object_put(data);
  8807. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8808. json_object_put(response);
  8809. }
  8810. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8811. {
  8812. json_object *data;
  8813. data = json_tokener_parse(tempdata);
  8814. if(!is_error(data))
  8815. {
  8816. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8817. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8818. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8819. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8820. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8821. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8822. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8823. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8824. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8825. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8826. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8827. }
  8828. else
  8829. {
  8830. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8831. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8832. }
  8833. json_object_put(data);
  8834. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8835. json_object_put(response);
  8836. }
  8837. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8838. {
  8839. json_object *data;
  8840. data = json_tokener_parse(tempdata);
  8841. if(!is_error(data))
  8842. {
  8843. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8844. if(json_object_object_get(data, "idToken") != NULL)
  8845. {
  8846. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8847. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8848. }
  8849. if(json_object_object_get(data, "price") != NULL)
  8850. {
  8851. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8852. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8853. }
  8854. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8855. }
  8856. else
  8857. {
  8858. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8859. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8860. }
  8861. json_object_put(data);
  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, "RunningCost") != 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, "txId") != NULL)
  8872. {
  8873. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8874. for(int idx = 0;idx<gunTotalNumber;idx++)
  8875. {
  8876. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8877. {
  8878. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8879. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8880. if(json_object_object_get(data, "description") != NULL)
  8881. {
  8882. // California pricing V1.0
  8883. DEBUG_INFO("California pricing V1.0\n");
  8884. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8885. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8886. }
  8887. else
  8888. {
  8889. // California pricing V1.1
  8890. DEBUG_INFO("California pricing V1.1\n");
  8891. if(json_object_object_get(data, "timestamp") != NULL)
  8892. {
  8893. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8894. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8895. }
  8896. if(json_object_object_get(data, "meterValue") != NULL)
  8897. {
  8898. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8899. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8900. }
  8901. if(json_object_object_get(data, "cost") != NULL)
  8902. {
  8903. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8904. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8905. }
  8906. if(json_object_object_get(data, "state") != NULL)
  8907. {
  8908. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8909. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8910. }
  8911. if(json_object_object_get(data, "chargingPrice") != NULL)
  8912. {
  8913. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8914. {
  8915. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8916. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8917. }
  8918. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8919. {
  8920. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8921. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8922. }
  8923. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8924. {
  8925. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8926. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8927. }
  8928. }
  8929. if(json_object_object_get(data, "idlePrice") != NULL)
  8930. {
  8931. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8932. {
  8933. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8934. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8935. }
  8936. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8937. {
  8938. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8939. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8940. }
  8941. }
  8942. if(json_object_object_get(data, "nextPeriod") != NULL)
  8943. {
  8944. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8945. {
  8946. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8947. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8948. }
  8949. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8950. {
  8951. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8952. {
  8953. 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")));
  8954. ShmOCPP16DataPH->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"));
  8955. }
  8956. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8957. {
  8958. 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")));
  8959. ShmOCPP16DataPH->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"));
  8960. }
  8961. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8962. {
  8963. 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")));
  8964. ShmOCPP16DataPH->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"));
  8965. }
  8966. }
  8967. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8968. {
  8969. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8970. {
  8971. 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")));
  8972. ShmOCPP16DataPH->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"));
  8973. }
  8974. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8975. {
  8976. 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")));
  8977. ShmOCPP16DataPH->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"));
  8978. }
  8979. }
  8980. }
  8981. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8982. {
  8983. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8984. {
  8985. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8986. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8987. }
  8988. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8989. {
  8990. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8991. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8992. }
  8993. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8994. {
  8995. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8996. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8997. }
  8998. }
  8999. }
  9000. }
  9001. }
  9002. }
  9003. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9004. }
  9005. else
  9006. {
  9007. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9008. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9009. }
  9010. json_object_put(data);
  9011. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9012. json_object_put(response);
  9013. }
  9014. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9015. {
  9016. json_object *data;
  9017. data = json_tokener_parse(tempdata);
  9018. if(!is_error(data))
  9019. {
  9020. if(json_object_object_get(data, "txId") != NULL)
  9021. {
  9022. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9023. for(int idx = 0;idx<gunTotalNumber;idx++)
  9024. {
  9025. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9026. {
  9027. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9028. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9029. if(json_object_object_get(data, "description") != NULL)
  9030. {
  9031. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9032. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9033. }
  9034. }
  9035. }
  9036. }
  9037. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9038. }
  9039. else
  9040. {
  9041. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9042. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9043. }
  9044. json_object_put(data);
  9045. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9046. json_object_put(response);
  9047. }
  9048. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9049. {
  9050. json_object *data;
  9051. data = json_tokener_parse(tempdata);
  9052. if(!is_error(data))
  9053. {
  9054. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9055. if(json_object_object_get(data, "Content_Type") != NULL)
  9056. {
  9057. 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))
  9058. {
  9059. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9060. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9061. {
  9062. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9063. }
  9064. }
  9065. else
  9066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9067. }
  9068. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9069. }
  9070. else
  9071. {
  9072. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9073. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9074. }
  9075. json_object_put(data);
  9076. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9077. json_object_put(response);
  9078. }
  9079. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9080. {
  9081. json_object *data;
  9082. data = json_tokener_parse(tempdata);
  9083. if(!is_error(data))
  9084. {
  9085. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9086. if(json_object_object_get(data, "ConnectorId") != NULL)
  9087. {
  9088. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9089. }
  9090. if(json_object_object_get(data, "SerialNo") != NULL)
  9091. {
  9092. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9093. }
  9094. if(json_object_object_get(data, "Page_Index") != NULL)
  9095. {
  9096. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9097. }
  9098. if(json_object_object_get(data, "Duration") != NULL)
  9099. {
  9100. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9101. }
  9102. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9103. }
  9104. else
  9105. {
  9106. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9107. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9108. }
  9109. json_object_put(data);
  9110. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9111. json_object_put(response);
  9112. }
  9113. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9114. {
  9115. json_object *data;
  9116. data = json_tokener_parse(tempdata);
  9117. if(!is_error(data))
  9118. {
  9119. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9120. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9121. {
  9122. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9123. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9124. else
  9125. {
  9126. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9127. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9128. }
  9129. }
  9130. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9131. {
  9132. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9133. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9134. else
  9135. {
  9136. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9137. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9138. }
  9139. }
  9140. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9141. {
  9142. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9143. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9144. else
  9145. {
  9146. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9147. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9148. }
  9149. }
  9150. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9151. {
  9152. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9153. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9154. else
  9155. {
  9156. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9157. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9158. }
  9159. }
  9160. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9161. {
  9162. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9163. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9164. else
  9165. {
  9166. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9167. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9168. }
  9169. }
  9170. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9171. {
  9172. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9173. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9174. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9175. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9176. else
  9177. {
  9178. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9179. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9180. }
  9181. }
  9182. if(json_object_object_get(data, "isAuthentication") != NULL)
  9183. {
  9184. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9185. {
  9186. case 0:
  9187. case 1:
  9188. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9189. break;
  9190. default:
  9191. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9192. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9193. break;
  9194. }
  9195. }
  9196. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9197. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9198. }
  9199. else
  9200. {
  9201. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9202. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9203. }
  9204. json_object_put(data);
  9205. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9206. json_object_put(response);
  9207. }
  9208. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9209. {
  9210. json_object *data;
  9211. data = json_tokener_parse(tempdata);
  9212. if(!is_error(data))
  9213. {
  9214. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9215. if(json_object_object_get(data, "stationName") != NULL)
  9216. {
  9217. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9218. }
  9219. else
  9220. {
  9221. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9222. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9223. }
  9224. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9225. {
  9226. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9227. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9228. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9229. }
  9230. }
  9231. else
  9232. {
  9233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9234. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9235. }
  9236. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9237. json_object_put(response);
  9238. }
  9239. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9240. {
  9241. json_object *data;
  9242. data = json_tokener_parse(tempdata);
  9243. if(!is_error(data))
  9244. {
  9245. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9246. if(json_object_object_get(data, "weatherId") != NULL)
  9247. {
  9248. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9249. }
  9250. else
  9251. {
  9252. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9253. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9254. }
  9255. if(json_object_object_get(data, "Temperature") != NULL)
  9256. {
  9257. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9258. }
  9259. else
  9260. {
  9261. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9262. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9263. }
  9264. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9265. {
  9266. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9267. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9268. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9269. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9270. }
  9271. }
  9272. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9273. {
  9274. json_object *data;
  9275. data = json_tokener_parse(tempdata);
  9276. if(!is_error(data))
  9277. {
  9278. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9279. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9280. {
  9281. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9282. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9283. }
  9284. else
  9285. {
  9286. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9287. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9288. }
  9289. }
  9290. else
  9291. {
  9292. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9293. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9294. }
  9295. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9296. json_object_put(response);
  9297. }
  9298. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9299. {
  9300. json_object *data;
  9301. data = json_tokener_parse(tempdata);
  9302. if(!is_error(data))
  9303. {
  9304. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9305. {
  9306. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9307. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9308. if(gun_index < gunTotalNumber)
  9309. {
  9310. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9311. {
  9312. json_object *responsedata = json_object_new_object();
  9313. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9314. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9315. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9316. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9317. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9318. }
  9319. else
  9320. {
  9321. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9322. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9323. }
  9324. }
  9325. else
  9326. {
  9327. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9328. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9329. }
  9330. }
  9331. else
  9332. {
  9333. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9334. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9335. }
  9336. }
  9337. else
  9338. {
  9339. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9340. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9341. }
  9342. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9343. json_object_put(response);
  9344. }
  9345. else
  9346. {
  9347. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9348. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9349. }
  9350. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9351. json_object_put(response);
  9352. }
  9353. else
  9354. {
  9355. // Can not find valid message id
  9356. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9357. }
  9358. }
  9359. else
  9360. {
  9361. // Payload is null
  9362. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9363. }
  9364. LWS_Send(message);
  9365. return result;
  9366. }
  9367. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9368. {
  9369. mtrace();
  9370. int result = FAIL;
  9371. int connectorIdInt, durationInt;
  9372. char chargingRateUnitStr[4]={0};
  9373. char comfirmstr[20];
  9374. int confirmPeriods = 0;
  9375. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9376. json_object *GetCompositeSchedule;
  9377. GetCompositeSchedule = json_tokener_parse(payload);
  9378. if(!is_error(GetCompositeSchedule))
  9379. {
  9380. // Required data
  9381. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9382. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9383. else
  9384. connectorIdInt = -1;
  9385. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9386. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9387. else
  9388. durationInt = 86400;
  9389. // Optional data
  9390. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9391. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9392. }
  9393. json_object_put(GetCompositeSchedule);
  9394. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9395. if((connectorIdInt == 0) ||
  9396. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9397. {
  9398. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9399. struct StructChargingProfile tmpProfile[1];
  9400. if(strstr(chargingRateUnitStr, "W") != NULL)
  9401. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9402. else
  9403. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9404. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9405. {
  9406. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9407. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9408. }
  9409. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9410. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9411. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9412. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9413. {
  9414. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9415. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9416. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9417. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9418. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9419. {
  9420. confirmPeriods = idx;
  9421. break;
  9422. }
  9423. }
  9424. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9425. {
  9426. confirmPeriods += 1;
  9427. }
  9428. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9429. }
  9430. else
  9431. {
  9432. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9433. }
  9434. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9435. return result;
  9436. }
  9437. int handleGetConfigurationRequest(char *uuid, char *payload)
  9438. {
  9439. mtrace();
  9440. int result = FAIL;
  9441. int MaxKeySupported = 0;
  9442. int n_keys = 0;
  9443. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9444. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9445. json_object *GetConfiguration;
  9446. GetConfiguration = json_tokener_parse(payload);
  9447. if(!is_error(GetConfiguration))
  9448. {
  9449. // Optional data
  9450. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9451. {
  9452. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9453. {
  9454. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9455. n_keys = idx + 1;
  9456. }
  9457. }
  9458. }
  9459. json_object_put(GetConfiguration);
  9460. UnknownKeynum = 0;
  9461. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9462. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9463. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9464. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9465. if(n_keys != 0)
  9466. {
  9467. for(int i=0;i<n_keys;i++)
  9468. {
  9469. getKeyValue(requestKey[i]);
  9470. }
  9471. }
  9472. else
  9473. {
  9474. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9475. getKeyValue("");
  9476. }
  9477. processUnkownKey();
  9478. sendGetConfigurationConfirmation(uuid);
  9479. return result;
  9480. }
  9481. static char fnamePlusPath[100]={0};
  9482. static char fnamePWithNoPath[60]={0};
  9483. void checkUploadLog(void)
  9484. {
  9485. FILE *fp;
  9486. /* Open the command for reading. */
  9487. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9488. if (fp == NULL) {
  9489. DEBUG_WARN("Failed to run command\n" );
  9490. exit(1);
  9491. }
  9492. int ftppathlen = 0;
  9493. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9494. int i = 0;
  9495. /* Read the output a line at a time - output it. */
  9496. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9497. if(i==0)
  9498. {
  9499. ftppathlen = strlen(fnamePlusPath);
  9500. DEBUG_INFO("%s\n", fnamePlusPath);
  9501. fnamePlusPath[ftppathlen]='\0';
  9502. break;
  9503. }
  9504. i= i+1;
  9505. }
  9506. /* close */
  9507. pclose(fp);
  9508. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9509. {
  9510. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9511. {
  9512. fnamePlusPath[k]='\0';
  9513. }
  9514. }
  9515. i=1;
  9516. //char fname[60]={0};
  9517. while(i < ftppathlen)
  9518. {
  9519. int len=ftppathlen-i;
  9520. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9521. {
  9522. DEBUG_INFO("compare '/' all right\n");
  9523. break;
  9524. }
  9525. i=i+1;
  9526. }
  9527. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9528. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9529. fnamePWithNoPath[i+1] = '\0';
  9530. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9531. {
  9532. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9533. {
  9534. fnamePWithNoPath[j]='\0';
  9535. }
  9536. }
  9537. FILE* fp1 = fopen(fnamePlusPath, "r");
  9538. if (fp1)
  9539. {
  9540. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9541. // file exists
  9542. fclose(fp1);
  9543. }
  9544. else
  9545. {
  9546. // file doesn't exist
  9547. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9548. }
  9549. }
  9550. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9551. {
  9552. mtrace();
  9553. int result = FAIL;
  9554. time_t CurrentTime;
  9555. struct tm *tm;
  9556. pthread_t th_Status;
  9557. CurrentTime = time(NULL);
  9558. tm = localtime(&CurrentTime);
  9559. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9560. sprintf((char*)ShmOCPP16DataPH->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);
  9561. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9562. if(!interLock.isGetDiagnosticGoing)
  9563. {
  9564. interLock.isGetDiagnosticGoing = 1;
  9565. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9566. sleep(1);
  9567. }
  9568. else
  9569. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9570. return result;
  9571. }
  9572. void* GetDiagnosticsProcess(void* data)
  9573. {
  9574. pthread_detach(pthread_self());
  9575. mtrace();
  9576. int retriesInt=0, retryIntervalInt=0;
  9577. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9578. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  9579. int port=0;
  9580. int isSuccess = FALSE;
  9581. char ftpbuf[200]={0};
  9582. char cmdBuf[2048];
  9583. struct tm *tmNow;
  9584. time_t CurrentTime;
  9585. struct tm tmStart;
  9586. struct tm tmStop;
  9587. CurrentTime = time(NULL);
  9588. tmNow=localtime(&CurrentTime);
  9589. uint16_t targetYear, targetMonth;
  9590. json_object *GetDiagnostics;
  9591. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9592. GetDiagnostics = json_tokener_parse(data);
  9593. if(!is_error(GetDiagnostics))
  9594. {
  9595. // Required data
  9596. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9597. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9598. // Optional data
  9599. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9600. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9601. else
  9602. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9603. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9604. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9605. else
  9606. retryIntervalInt = 30;
  9607. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9608. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9609. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9610. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9611. }
  9612. json_object_put(GetDiagnostics);
  9613. // Pack log to compress file
  9614. 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) &&
  9615. (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))
  9616. {
  9617. // Pack system log
  9618. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9619. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9620. targetYear = tmStart.tm_year;
  9621. targetMonth = tmStart.tm_mon;
  9622. do
  9623. {
  9624. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9625. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9626. if(targetMonth+1>=13)
  9627. {
  9628. targetYear += 1;
  9629. targetMonth = 1;
  9630. }
  9631. else
  9632. {
  9633. targetMonth += 1;
  9634. }
  9635. }while((targetYear < (tmNow->tm_year+1900)) ||
  9636. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9637. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9638. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9639. system(cmdBuf);
  9640. // Pack charging & event log
  9641. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9642. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9643. targetYear = tmStart.tm_year;
  9644. targetMonth = tmStart.tm_mon;
  9645. do
  9646. {
  9647. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9648. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9649. if(targetMonth+1>=13)
  9650. {
  9651. targetYear += 1;
  9652. targetMonth = 1;
  9653. }
  9654. else
  9655. {
  9656. targetMonth += 1;
  9657. }
  9658. }while((targetYear < (tmNow->tm_year+1900)) ||
  9659. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9660. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9661. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9662. system(cmdBuf);
  9663. // Combine log file
  9664. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9665. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9666. }
  9667. else
  9668. {
  9669. system("exec /root/logPackTools 'log' 6");
  9670. }
  9671. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9672. system(cmdBuf);
  9673. checkUploadLog();
  9674. //****************location*******************/
  9675. if(strcmp(locationstr,"")==0)
  9676. {
  9677. DEBUG_INFO("location is <Empty>!\n");
  9678. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9679. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9680. goto end;
  9681. }
  9682. memset(protocol, 0, ARRAY_SIZE(protocol));
  9683. memset(user, 0, ARRAY_SIZE(user) );
  9684. memset(password, 0, ARRAY_SIZE(password));
  9685. memset(host, 0, ARRAY_SIZE(host));
  9686. memset(path, 0, ARRAY_SIZE(path));
  9687. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9688. memset(host1, 0, ARRAY_SIZE(host1));
  9689. memset(path1, 0, ARRAY_SIZE(path1));
  9690. /*location: ftp://user:password@host:port/path*/
  9691. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9692. if((access(fnamePlusPath,F_OK))!=-1)
  9693. {
  9694. DEBUG_INFO("fnamePlusPath exist.\n");
  9695. }
  9696. else
  9697. {
  9698. DEBUG_INFO("fnamePlusPath not exist!\n");
  9699. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9700. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9701. goto end;
  9702. }
  9703. if(strchr(locationstr,'@')==NULL)
  9704. {
  9705. sscanf(locationstr,
  9706. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9707. protocol, host, &port, path);
  9708. strcpy(user,"anonymous");
  9709. strcpy(password,"");
  9710. }
  9711. else
  9712. {
  9713. //DEBUG_INFO("pch=%s\n", pch);
  9714. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9715. protocol, user, password, host, &port, path);
  9716. }
  9717. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9718. {
  9719. DEBUG_INFO("protocol is not ftp/http ! \n");
  9720. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9721. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9722. goto end;
  9723. }
  9724. if(strncmp(locationstr,"http", 4) == 0)
  9725. {
  9726. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9727. sprintf(ftppath,"/%s", path);
  9728. do
  9729. {
  9730. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9731. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9732. sleep(3);
  9733. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9734. if(!isSuccess)
  9735. {
  9736. DEBUG_INFO("Diagnostics fail.\n");
  9737. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9738. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9739. sleep(retryIntervalInt);
  9740. }
  9741. else
  9742. {
  9743. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9744. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9745. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9746. }
  9747. retriesInt--;
  9748. }while((isSuccess == 0)&&(retriesInt >= 0));
  9749. }
  9750. else
  9751. {
  9752. sscanf(host,"%[^/]%s",host1, path1);
  9753. if(strlen(path) > 0)
  9754. sprintf(ftppath,"/%s", path);
  9755. else
  9756. sprintf(ftppath,"/%s", path1);
  9757. int ftppathlen=strlen(ftppath);
  9758. int i=1;
  9759. char filenametemp[50];
  9760. while(i < ftppathlen)
  9761. {
  9762. int len=ftppathlen-i;
  9763. if(ftppath[len]== 47) // '/' ascll code: 47
  9764. {
  9765. DEBUG_INFO("find '/' all right\n");
  9766. break;
  9767. }
  9768. i=i+1;
  9769. }
  9770. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9771. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9772. filenametemp[i+1] = 0;
  9773. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9774. if(port == 0)
  9775. port = 21;
  9776. do
  9777. {
  9778. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9779. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9780. sleep(3);
  9781. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9782. if(!isSuccess)
  9783. {
  9784. DEBUG_INFO("Diagnostics fail.\n");
  9785. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9786. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9787. sleep(retryIntervalInt);
  9788. }
  9789. else
  9790. {
  9791. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9792. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9793. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9794. }
  9795. retriesInt--;
  9796. }while((!isSuccess)&&(retriesInt >= 0));
  9797. }
  9798. end:
  9799. system("rm -f /mnt/*");
  9800. sleep(5);
  9801. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9802. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9803. interLock.isGetDiagnosticGoing = 0;
  9804. pthread_exit(NULL);
  9805. }
  9806. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9807. {
  9808. mtrace();
  9809. int result = FAIL;
  9810. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9811. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9812. {
  9813. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9814. locallistVersion = -1;
  9815. }
  9816. else
  9817. {
  9818. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9819. OCPP_getListVerion();
  9820. }
  9821. //from db.OCPP_getListVerion
  9822. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9823. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9824. sendGetLocalListVersionConfirmation(uuid,"");
  9825. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9826. return result;
  9827. }
  9828. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9829. {
  9830. mtrace();
  9831. int result = FAIL;
  9832. int connectorIdInt=-1;
  9833. int tempIndex = 0;
  9834. int connectorIdIsNULL, chargingProfileIsNULL;
  9835. char comfirmstr[20]={0};
  9836. char cmdBuf[512];
  9837. json_object *RemoteStartTransaction;
  9838. FILE *fp;
  9839. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9840. if(server_pending == TRUE)
  9841. {
  9842. return 0;
  9843. }
  9844. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9845. RemoteStartTransaction = json_tokener_parse(payload);
  9846. if(!is_error(RemoteStartTransaction))
  9847. {
  9848. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9849. {
  9850. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9851. }
  9852. else
  9853. {
  9854. connectorIdIsNULL = TRUE;
  9855. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9856. {
  9857. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9858. {
  9859. connectorIdIsNULL = FALSE;
  9860. connectorIdInt = (gun_index+1);
  9861. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9862. break;
  9863. }
  9864. }
  9865. }
  9866. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9867. {
  9868. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9869. // Required data
  9870. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9871. // Optional data
  9872. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9873. {
  9874. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9875. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9876. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9877. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9878. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9879. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9880. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9881. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9882. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9883. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9884. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9885. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9886. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9887. {
  9888. sprintf((char*)ShmOCPP16DataPH->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")));
  9889. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9890. ShmOCPP16DataPH->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"));
  9891. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9892. ShmOCPP16DataPH->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"));
  9893. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9894. sprintf((char*)ShmOCPP16DataPH->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")));
  9895. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9896. {
  9897. 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++)
  9898. {
  9899. ShmOCPP16DataPH->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"));
  9900. ShmOCPP16DataPH->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"));
  9901. 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)
  9902. ShmOCPP16DataPH->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"));
  9903. }
  9904. }
  9905. }
  9906. }
  9907. else
  9908. {
  9909. chargingProfileIsNULL = TRUE;
  9910. }
  9911. }
  9912. }
  9913. else
  9914. {
  9915. connectorIdIsNULL = TRUE;
  9916. }
  9917. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9918. {
  9919. DEBUG_WARN("Connector id is NULL\n.");
  9920. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9921. goto end;
  9922. }
  9923. /*
  9924. enum _SYSTEM_STATUS
  9925. {
  9926. S_BOOTING = 0,
  9927. S_IDLE, = 1
  9928. S_AUTHORIZING, = 2
  9929. S_REASSIGN_CHECK, = 3
  9930. S_REASSIGN, = 4
  9931. S_PRECHARGE, = 5
  9932. S_PREPARING_FOR_EV, = 6
  9933. S_PREPARING_FOR_EVSE, = 7
  9934. S_CHARGING, = 8
  9935. S_TERMINATING, = 9
  9936. S_COMPLETE, = 10
  9937. S_ALARM, = 11
  9938. S_FAULT = 12
  9939. }
  9940. */
  9941. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9942. {
  9943. //check Transaction active
  9944. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9945. {
  9946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9947. {
  9948. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9949. }
  9950. else
  9951. {
  9952. tempIndex = connectorIdInt -1;
  9953. }
  9954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9955. {
  9956. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9957. {
  9958. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9959. {
  9960. //Reserved
  9961. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9962. }
  9963. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9964. {
  9965. //Reserved
  9966. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9967. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9968. goto end;
  9969. }
  9970. else
  9971. {
  9972. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9973. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9974. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9975. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9976. {
  9977. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9978. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9979. goto end;
  9980. }
  9981. }//END FOR ELSE
  9982. }
  9983. }// END FOR CHAdeMO_QUANTITY
  9984. }
  9985. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9986. {
  9987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9988. {
  9989. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9990. }
  9991. else
  9992. {
  9993. tempIndex = connectorIdInt -1;
  9994. }
  9995. for (int index = 0; index < CCS_QUANTITY; index++)
  9996. {
  9997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9998. {
  9999. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10000. {
  10001. //Reserved
  10002. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10003. }
  10004. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10005. {
  10006. //Reserved
  10007. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10008. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10009. goto end;
  10010. }
  10011. else
  10012. {
  10013. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10014. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10015. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10016. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10017. {
  10018. DEBUG_WARN("CCS connector not allow start\n.");
  10019. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10020. goto end;
  10021. }
  10022. }// END FOR ELSE
  10023. }
  10024. }// END FOR CCS_QUANTITY
  10025. }
  10026. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10027. {
  10028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10029. {
  10030. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10031. }
  10032. else
  10033. {
  10034. tempIndex = connectorIdInt -1;
  10035. }
  10036. for (int index = 0; index < GB_QUANTITY; index++)
  10037. {
  10038. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10039. {
  10040. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10041. {
  10042. //Reserved
  10043. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10044. }
  10045. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10046. {
  10047. //Reserved
  10048. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10049. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10050. goto end;
  10051. }
  10052. else
  10053. {
  10054. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10055. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10056. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10057. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10058. {
  10059. DEBUG_WARN("GB connector not allow start\n.");
  10060. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10061. goto end;
  10062. }
  10063. }// END FOR ELSE
  10064. }
  10065. } // END FOR GB_QUANTITY
  10066. }
  10067. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10068. {
  10069. tempIndex = connectorIdInt -1;
  10070. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10071. {
  10072. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10073. {
  10074. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10075. {
  10076. //Reserved
  10077. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10078. }
  10079. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10080. {
  10081. //Reserved
  10082. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10084. goto end;
  10085. }
  10086. else
  10087. {
  10088. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10089. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10090. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10091. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10092. {
  10093. DEBUG_WARN("GB connector not allow start\n.");
  10094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10095. goto end;
  10096. }
  10097. }// END FOR ELSE
  10098. }
  10099. } // END FOR GB_QUANTITY
  10100. }
  10101. else
  10102. {
  10103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10104. {
  10105. tempIndex = 2;
  10106. }
  10107. else
  10108. {
  10109. tempIndex = connectorIdInt -1;
  10110. }
  10111. for (int index = 0; index < AC_QUANTITY; index++)
  10112. {
  10113. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10114. {
  10115. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10116. {
  10117. //Reserved
  10118. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10119. }
  10120. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10121. {
  10122. //Reserved
  10123. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10125. goto end;
  10126. }
  10127. else
  10128. {
  10129. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10130. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10131. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10132. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10133. {
  10134. DEBUG_WARN("AC connector not allow start\n.");
  10135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10136. goto end;
  10137. }
  10138. }//END FOR ELSE
  10139. }
  10140. }// END FOR AC_QUANTITY
  10141. }
  10142. if(chargingProfileIsNULL == FALSE)
  10143. {
  10144. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10145. {
  10146. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10148. //memset idTag
  10149. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10150. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10151. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10152. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10153. // Save profile to file
  10154. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10155. system(cmdBuf);
  10156. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10157. fp = fopen(cmdBuf, "w");
  10158. 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));
  10159. fclose(fp);
  10160. }
  10161. else
  10162. {
  10163. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10164. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10165. }
  10166. }
  10167. else
  10168. {
  10169. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10171. //memset idTag
  10172. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10173. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10174. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10176. }
  10177. }
  10178. else
  10179. {
  10180. DEBUG_WARN("Connector id over\n.");
  10181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10182. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10183. }
  10184. end:
  10185. json_object_put(RemoteStartTransaction);
  10186. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10187. {
  10188. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10189. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10190. }
  10191. //OCPP send RemoteStartConfirmation by first.
  10192. sendRemoteStartConfirmation(uuid, comfirmstr);
  10193. return result;
  10194. }
  10195. int handleRemoteStartRequest(char *uuid, char *payload)
  10196. {
  10197. mtrace();
  10198. int result = PASS;
  10199. int connectorIdInt=-1;
  10200. int tempIndex = 0;
  10201. char comfirmstr[20]={0};
  10202. char cmdBuf[512];
  10203. json_object *RemoteStartTransaction;
  10204. FILE *fp;
  10205. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10206. if(server_pending == TRUE)
  10207. {
  10208. result = FAIL;
  10209. }
  10210. RemoteStartTransaction = json_tokener_parse(payload);
  10211. if(!is_error(RemoteStartTransaction))
  10212. {
  10213. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10214. {
  10215. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10216. }
  10217. else
  10218. {
  10219. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10220. {
  10221. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10222. {
  10223. connectorIdInt = (gun_index+1);
  10224. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10225. break;
  10226. }
  10227. }
  10228. }
  10229. if(connectorIdInt == 0)
  10230. {
  10231. DEBUG_WARN("Connector id shall not equal 0.\n");
  10232. result = FAIL;
  10233. }
  10234. else if(connectorIdInt == -1)
  10235. {
  10236. DEBUG_INFO("Connector id does not specific.\n");
  10237. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10238. {
  10239. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10240. // Required data
  10241. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10242. // Optional data
  10243. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10244. {
  10245. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10246. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10247. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10248. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10249. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10250. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10251. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10252. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10253. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10254. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10255. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10256. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10257. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10258. {
  10259. sprintf((char*)ShmOCPP16DataPH->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")));
  10260. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10261. ShmOCPP16DataPH->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"));
  10262. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10263. ShmOCPP16DataPH->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"));
  10264. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10265. sprintf((char*)ShmOCPP16DataPH->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")));
  10266. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10267. {
  10268. 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++)
  10269. {
  10270. ShmOCPP16DataPH->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"));
  10271. ShmOCPP16DataPH->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"));
  10272. 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)
  10273. ShmOCPP16DataPH->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"));
  10274. }
  10275. }
  10276. }
  10277. }
  10278. else
  10279. {
  10280. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10281. }
  10282. }
  10283. }
  10284. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10285. {
  10286. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10287. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10288. // Required data
  10289. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10290. // Optional data
  10291. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10292. {
  10293. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10294. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10295. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10296. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10297. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10298. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10299. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10300. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10301. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10302. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10303. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10304. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10305. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10306. {
  10307. sprintf((char*)ShmOCPP16DataPH->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")));
  10308. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10309. ShmOCPP16DataPH->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"));
  10310. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10311. ShmOCPP16DataPH->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"));
  10312. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10313. sprintf((char*)ShmOCPP16DataPH->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")));
  10314. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10315. {
  10316. 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++)
  10317. {
  10318. ShmOCPP16DataPH->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"));
  10319. ShmOCPP16DataPH->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"));
  10320. 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)
  10321. ShmOCPP16DataPH->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"));
  10322. }
  10323. }
  10324. }
  10325. }
  10326. else
  10327. {
  10328. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10329. }
  10330. }
  10331. else
  10332. {
  10333. DEBUG_WARN("Connector id is over maximun value.\n");
  10334. result = FAIL;
  10335. }
  10336. }
  10337. if(result == PASS)
  10338. {
  10339. if(connectorIdInt > 0)
  10340. {
  10341. //check Transaction active
  10342. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10343. {
  10344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10345. {
  10346. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10347. }
  10348. else
  10349. {
  10350. tempIndex = connectorIdInt -1;
  10351. }
  10352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10353. {
  10354. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10355. {
  10356. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10357. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10358. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10359. {
  10360. //Reserved
  10361. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10362. }
  10363. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10364. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10365. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10366. {
  10367. //Reserved
  10368. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10369. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10370. goto end;
  10371. }
  10372. else
  10373. {
  10374. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10375. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10376. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10377. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10378. {
  10379. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10380. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10381. goto end;
  10382. }
  10383. }//END FOR ELSE
  10384. }
  10385. }// END FOR CHAdeMO_QUANTITY
  10386. }
  10387. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10388. {
  10389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10390. {
  10391. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10392. }
  10393. else
  10394. {
  10395. tempIndex = connectorIdInt -1;
  10396. }
  10397. for (int index = 0; index < CCS_QUANTITY; index++)
  10398. {
  10399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10400. {
  10401. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10402. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10403. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10404. {
  10405. //Reserved
  10406. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10407. }
  10408. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10409. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10410. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10411. {
  10412. //Reserved
  10413. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10414. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10415. goto end;
  10416. }
  10417. else
  10418. {
  10419. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10420. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10421. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10422. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10423. {
  10424. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10425. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10426. goto end;
  10427. }
  10428. }// END FOR ELSE
  10429. }
  10430. }// END FOR CCS_QUANTITY
  10431. }
  10432. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10433. {
  10434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10435. {
  10436. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10437. }
  10438. else
  10439. {
  10440. tempIndex = connectorIdInt -1;
  10441. }
  10442. for (int index = 0; index < GB_QUANTITY; index++)
  10443. {
  10444. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10445. {
  10446. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10447. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10448. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10449. {
  10450. //Reserved
  10451. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10452. }
  10453. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10454. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10455. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10456. {
  10457. //Reserved
  10458. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10460. goto end;
  10461. }
  10462. else
  10463. {
  10464. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10465. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10466. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10467. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10468. {
  10469. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10471. goto end;
  10472. }
  10473. }// END FOR ELSE
  10474. }
  10475. } // END FOR GB_QUANTITY
  10476. }
  10477. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10478. {
  10479. tempIndex = connectorIdInt -1;
  10480. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10481. {
  10482. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10483. {
  10484. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10485. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10486. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10487. {
  10488. //Reserved
  10489. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10490. }
  10491. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10492. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10493. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10494. {
  10495. //Reserved
  10496. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10498. goto end;
  10499. }
  10500. else
  10501. {
  10502. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10503. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10504. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10505. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10506. {
  10507. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10509. goto end;
  10510. }
  10511. }// END FOR ELSE
  10512. }
  10513. } // END FOR GB_QUANTITY
  10514. }
  10515. else
  10516. {
  10517. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10518. {
  10519. tempIndex = 2;
  10520. }
  10521. else
  10522. {
  10523. tempIndex = connectorIdInt -1;
  10524. }
  10525. for (int index = 0; index < AC_QUANTITY; index++)
  10526. {
  10527. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10528. {
  10529. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10530. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10531. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10532. {
  10533. //Reserved
  10534. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10535. }
  10536. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10537. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10538. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10539. {
  10540. //Reserved
  10541. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10543. goto end;
  10544. }
  10545. else
  10546. {
  10547. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10548. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10549. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10550. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10551. {
  10552. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10553. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10554. goto end;
  10555. }
  10556. }//END FOR ELSE
  10557. }
  10558. }// END FOR AC_QUANTITY
  10559. }
  10560. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10561. {
  10562. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10563. {
  10564. // Save profile to file
  10565. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10566. system(cmdBuf);
  10567. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10568. fp = fopen(cmdBuf, "w");
  10569. 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));
  10570. fclose(fp);
  10571. }
  10572. else
  10573. {
  10574. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10575. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10576. goto end;
  10577. }
  10578. }
  10579. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10581. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10582. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10583. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10585. }
  10586. else
  10587. {
  10588. uint8_t isHasIdleConnector = FALSE;
  10589. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10590. {
  10591. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10592. {
  10593. isHasIdleConnector = TRUE;
  10594. break;
  10595. }
  10596. }
  10597. if(isHasIdleConnector == TRUE)
  10598. {
  10599. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10600. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10601. {
  10602. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10603. {
  10604. // Save profile to file
  10605. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10606. system(cmdBuf);
  10607. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10608. fp = fopen(cmdBuf, "w");
  10609. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10610. fclose(fp);
  10611. refreshStartTimer(&clientTime.RemoteStartWait);
  10612. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10613. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10614. }
  10615. else
  10616. {
  10617. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10618. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10619. }
  10620. }
  10621. else
  10622. {
  10623. refreshStartTimer(&clientTime.RemoteStartWait);
  10624. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10626. }
  10627. }
  10628. else
  10629. {
  10630. DEBUG_INFO("There is not any connector is idle.\n");
  10631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10632. }
  10633. }
  10634. }
  10635. else
  10636. {
  10637. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10638. }
  10639. end:
  10640. json_object_put(RemoteStartTransaction);
  10641. sendRemoteStartConfirmation(uuid, comfirmstr);
  10642. return result;
  10643. }
  10644. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10645. {
  10646. mtrace();
  10647. int result = FAIL;
  10648. int match = FALSE;
  10649. int GunNO = 0;
  10650. int tempIndex = 0;
  10651. int transactionIdInt=0;
  10652. int transactionIdIsNULL= TRUE;
  10653. char comfirmstr[20];
  10654. json_object *RemoteStopTransaction;
  10655. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10656. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10657. if(server_pending == TRUE)
  10658. {
  10659. return 0;
  10660. }
  10661. RemoteStopTransaction = json_tokener_parse(payload);
  10662. if(!is_error(RemoteStopTransaction))
  10663. {
  10664. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10665. {
  10666. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10667. transactionIdIsNULL = FALSE;
  10668. }
  10669. }
  10670. json_object_put(RemoteStopTransaction);
  10671. if(transactionIdIsNULL == FALSE)
  10672. {
  10673. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10674. {
  10675. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10676. {
  10677. //check Transaction active
  10678. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10679. {
  10680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10681. {
  10682. tempIndex = ((gun_index==2) ? 1: 0);
  10683. }
  10684. else
  10685. {
  10686. tempIndex = gun_index;
  10687. }
  10688. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10689. {
  10690. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10691. {
  10692. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10693. {
  10694. match = TRUE;
  10695. GunNO = gun_index;
  10696. }
  10697. }
  10698. }// END FOR CHAdeMO_QUANTITY
  10699. }
  10700. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10701. {
  10702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10703. {
  10704. tempIndex = ((gun_index==2) ? 1: 0);
  10705. }
  10706. else
  10707. {
  10708. tempIndex = gun_index;
  10709. }
  10710. for (int index = 0; index < CCS_QUANTITY; index++)
  10711. {
  10712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10713. {
  10714. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10715. {
  10716. match = TRUE;
  10717. GunNO = gun_index;
  10718. }
  10719. }
  10720. }// END FOR CCS_QUANTITY
  10721. }
  10722. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10723. {
  10724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10725. {
  10726. tempIndex = ((gun_index==2) ? 1: 0);
  10727. }
  10728. else
  10729. {
  10730. tempIndex = gun_index;
  10731. }
  10732. for (int index = 0; index < GB_QUANTITY; index++)
  10733. {
  10734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10735. {
  10736. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10737. {
  10738. match = TRUE;
  10739. GunNO = gun_index;
  10740. }
  10741. }
  10742. }// END FOR GB_QUANTITY
  10743. }
  10744. else if(gunType[gun_index] == GUN_TYPE_DO)
  10745. {
  10746. tempIndex = gun_index;
  10747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10748. {
  10749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10750. {
  10751. 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
  10752. {
  10753. match = TRUE;
  10754. GunNO = gun_index;
  10755. }
  10756. }
  10757. }// END FOR GB_QUANTITY
  10758. }
  10759. else
  10760. {
  10761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10762. {
  10763. tempIndex = 2;
  10764. }
  10765. else
  10766. {
  10767. tempIndex = gun_index;
  10768. }
  10769. for (int index = 0; index < AC_QUANTITY; index++)
  10770. {
  10771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10772. {
  10773. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10774. {
  10775. match = TRUE;
  10776. GunNO = gun_index;
  10777. }
  10778. }
  10779. }// END FOR CHAdeMO_QUANTITY
  10780. } // END FOR AC ELSE
  10781. }// CHECK IF ResponseTransactionId == transactionIdInt
  10782. }//END FOR
  10783. if( match == TRUE)
  10784. {
  10785. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10787. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10788. }
  10789. else
  10790. {
  10791. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10792. }
  10793. }
  10794. else
  10795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10796. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10797. return result;
  10798. }
  10799. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10800. {
  10801. mtrace();
  10802. int result = FAIL;
  10803. int connectorIdInt=0, reservationIdInt=0;
  10804. int tempIndex = 0;
  10805. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10806. char comfirmstr[20]={0};
  10807. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10808. int c = 0;
  10809. char *loc;
  10810. //char *ptr;
  10811. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10812. strcpy(sstrtemp, stringtrimspace(payload));
  10813. //***(1)connectorId ****/
  10814. c=0;
  10815. loc = strstr(sstrtemp, "connectorId");
  10816. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10817. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10818. {
  10819. sstr[c] = loc[strlen("connectorId")+2+c];
  10820. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10821. c++;
  10822. }
  10823. sstr[c] = '\0';
  10824. connectorIdInt = atoi(sstr);
  10825. //***(2)expiryDate ****/
  10826. loc = strstr(sstrtemp, "expiryDate");
  10827. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10828. c = 0;
  10829. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10830. {
  10831. sstr[c] = loc[3+strlen("expiryDate")+c];
  10832. c++;
  10833. }
  10834. sstr[c] = '\0';
  10835. strcpy(expiryDatestr, sstr);
  10836. //***(3)idTag ****/
  10837. loc = strstr(sstrtemp, "idTag");
  10838. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10839. c = 0;
  10840. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10841. {
  10842. sstr[c] = loc[3+strlen("idTag")+c];
  10843. c++;
  10844. }
  10845. sstr[c] = '\0';
  10846. strcpy(idTagstr, sstr);
  10847. //***(4)parentIdTag ****/
  10848. loc = strstr(sstrtemp, "parentIdTag");
  10849. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10850. c = 0;
  10851. if(loc == NULL)
  10852. {
  10853. strcpy(parentIdTagstr, "");
  10854. }
  10855. else
  10856. {
  10857. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10858. {
  10859. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10860. c++;
  10861. }
  10862. sstr[c] = '\0';
  10863. strcpy(parentIdTagstr, sstr);
  10864. }
  10865. //***(5)reservationId ****/
  10866. c=0;
  10867. loc = strstr(sstrtemp, "reservationId");
  10868. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10869. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10870. {
  10871. sstr[c] = loc[strlen("reservationId")+2+c];
  10872. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10873. c++;
  10874. }
  10875. sstr[c] = '\0';
  10876. reservationIdInt = atoi(sstr);
  10877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10878. /*
  10879. enum SYSTEM_STATUS
  10880. {
  10881. SYS_MODE_BOOTING = 0,
  10882. SYS_MODE_IDLE = 1,
  10883. SYS_MODE_AUTHORIZING = 2,
  10884. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10885. SYS_MODE_REASSIGN = 4,
  10886. SYS_MODE_PREPARING = 5,
  10887. SYS_MODE_PREPARE_FOR_EV = 6,
  10888. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10889. SYS_MODE_CHARGING = 8,
  10890. SYS_MODE_TERMINATING = 9,
  10891. SYS_MODE_COMPLETE = 10,
  10892. SYS_MODE_ALARM = 11,
  10893. SYS_MODE_FAULT = 12,
  10894. SYS_MODE_RESERVATION = 13,
  10895. SYS_MODE_BOOKING = 14,
  10896. SYS_MODE_MAINTAIN = 15,
  10897. SYS_MODE_DEBUG = 16,
  10898. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10899. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10900. SYS_MODE_UPDATE = 19
  10901. };
  10902. */
  10903. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10904. {
  10905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10906. goto end;
  10907. }
  10908. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10909. {
  10910. //check Transaction active
  10911. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10912. {
  10913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10914. {
  10915. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10916. }
  10917. else
  10918. {
  10919. tempIndex = connectorIdInt -1;
  10920. }
  10921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10922. {
  10923. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10924. {
  10925. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10926. {
  10927. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10928. {
  10929. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10930. {
  10931. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10933. }
  10934. 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'))
  10935. {
  10936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10937. }
  10938. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10939. {
  10940. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10941. }
  10942. else
  10943. {
  10944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10945. }
  10946. }
  10947. 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
  10948. {
  10949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10950. }
  10951. }
  10952. else
  10953. {
  10954. //replace reservation
  10955. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10957. }
  10958. }
  10959. } // END FOR CHAdeMO_QUANTITY
  10960. }
  10961. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10962. {
  10963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10964. {
  10965. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10966. }
  10967. else
  10968. {
  10969. tempIndex = connectorIdInt -1;
  10970. }
  10971. for (int index = 0; index < CCS_QUANTITY; index++)
  10972. {
  10973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10974. {
  10975. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10976. {
  10977. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10978. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10979. {
  10980. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10981. {
  10982. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10984. }
  10985. 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'))
  10986. {
  10987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10988. }
  10989. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10990. {
  10991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10992. }
  10993. else
  10994. {
  10995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10996. }
  10997. }
  10998. 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
  10999. {
  11000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11001. }
  11002. }
  11003. else
  11004. {
  11005. //replace reservation
  11006. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11008. }
  11009. }
  11010. } // END FOR CCS_QUANTITY
  11011. }
  11012. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11013. {
  11014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11015. {
  11016. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11017. }
  11018. else
  11019. {
  11020. tempIndex = connectorIdInt -1;
  11021. }
  11022. for (int index = 0; index < GB_QUANTITY; index++)
  11023. {
  11024. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11025. {
  11026. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11027. {
  11028. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11029. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11030. {
  11031. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11032. {
  11033. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11035. }
  11036. 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'))
  11037. {
  11038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11039. }
  11040. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11041. {
  11042. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11043. }
  11044. else
  11045. {
  11046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11047. }
  11048. }
  11049. 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
  11050. {
  11051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11052. }
  11053. }
  11054. else
  11055. {
  11056. //replace reservation
  11057. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11059. }
  11060. }
  11061. }// END FOR GB_QUANTITY
  11062. }
  11063. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11064. {
  11065. tempIndex = connectorIdInt -1;
  11066. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11067. {
  11068. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11069. {
  11070. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11071. {
  11072. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11073. 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
  11074. {
  11075. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11076. {
  11077. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11079. }
  11080. 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'))
  11081. {
  11082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11083. }
  11084. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11085. {
  11086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11087. }
  11088. else
  11089. {
  11090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11091. }
  11092. }
  11093. 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
  11094. {
  11095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11096. }
  11097. }
  11098. else
  11099. {
  11100. //replace reservation
  11101. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11103. }
  11104. }
  11105. }// END FOR GB_QUANTITY
  11106. }
  11107. else
  11108. {
  11109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11110. {
  11111. tempIndex = 2;
  11112. }
  11113. else
  11114. {
  11115. tempIndex = (connectorIdInt -1);
  11116. }
  11117. for (int index = 0; index < AC_QUANTITY; index++)
  11118. {
  11119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11120. {
  11121. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11122. {
  11123. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11124. {
  11125. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11126. {
  11127. 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))
  11128. {
  11129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11130. }
  11131. else
  11132. {
  11133. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11135. }
  11136. }
  11137. 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'))
  11138. {
  11139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11140. }
  11141. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11142. {
  11143. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11144. }
  11145. else
  11146. {
  11147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11148. }
  11149. }
  11150. 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
  11151. {
  11152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11153. }
  11154. }
  11155. else
  11156. {
  11157. //replace reservation
  11158. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11160. }
  11161. }
  11162. } // END FOR AC_QUANTITY
  11163. }
  11164. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11165. }
  11166. else if(connectorIdInt == 0)
  11167. {
  11168. //check Transaction active
  11169. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11170. {
  11171. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11172. {
  11173. 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'))
  11174. {
  11175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11176. goto end;
  11177. }
  11178. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11179. {
  11180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11181. goto end;
  11182. }
  11183. 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
  11184. {
  11185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11186. goto end;
  11187. }
  11188. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11189. {
  11190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11191. goto end;
  11192. }
  11193. }
  11194. }// END FOR CHAdeMO_QUANTITY
  11195. for (int index = 0; index < CCS_QUANTITY; index++)
  11196. {
  11197. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11198. {
  11199. 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'))
  11200. {
  11201. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11202. goto end;
  11203. }
  11204. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11205. {
  11206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11207. goto end;
  11208. }
  11209. 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
  11210. {
  11211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11212. goto end;
  11213. }
  11214. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11215. {
  11216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11217. goto end;
  11218. }
  11219. }
  11220. } // END FOR CCS_QUANTITY
  11221. for (int index = 0; index < GB_QUANTITY; index++)
  11222. {
  11223. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11224. {
  11225. 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'))
  11226. {
  11227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11228. goto end;
  11229. }
  11230. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11231. {
  11232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11233. goto end;
  11234. }
  11235. 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
  11236. {
  11237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11238. goto end;
  11239. }
  11240. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11241. {
  11242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11243. goto end;
  11244. }
  11245. }
  11246. } // END FOR GB_QUANTITY
  11247. for (int index = 0; index < AC_QUANTITY; index++)
  11248. {
  11249. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11250. {
  11251. 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'))
  11252. {
  11253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11254. goto end;
  11255. }
  11256. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11257. {
  11258. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11259. goto end;
  11260. }
  11261. 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
  11262. {
  11263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11264. goto end;
  11265. }
  11266. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11267. {
  11268. 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))
  11269. {
  11270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11271. goto end;
  11272. }
  11273. }
  11274. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11275. {
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11277. goto end;
  11278. }
  11279. }
  11280. }// END FOR AC_QUANTITY
  11281. //The connectorId is 0
  11282. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11284. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11285. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11286. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11287. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11288. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11289. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11290. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11291. result = TRUE;
  11292. return result;
  11293. }
  11294. else
  11295. {
  11296. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11297. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11298. }
  11299. if(strcmp(comfirmstr,"Accepted") == 0)
  11300. {
  11301. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11302. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11303. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11304. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11305. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11306. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11307. result = TRUE;
  11308. return result;
  11309. }
  11310. end:
  11311. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11312. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11313. return result;
  11314. }
  11315. int handleResetRequest(char *uuid, char *payload)
  11316. {
  11317. mtrace();
  11318. int result = FAIL;
  11319. char sstr[10]={0},sstrtemp[30]={ 0 };
  11320. char typestr[10]={0};
  11321. char comfirmstr[20]={0};
  11322. int c = 0;
  11323. char *loc;
  11324. DEBUG_INFO("handleResetRequest...\n");
  11325. strcpy(sstrtemp, stringtrimspace(payload));
  11326. loc = strstr(sstrtemp, "type");
  11327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11328. c = 0;
  11329. while (loc[3+strlen("type")+c] != '\"')
  11330. {
  11331. sstr[c] = loc[3+strlen("type")+c];
  11332. c++;
  11333. }
  11334. sstr[c] = '\0';
  11335. strcpy(typestr,sstr);
  11336. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11337. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11338. {
  11339. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11340. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11341. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11342. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11343. }
  11344. else
  11345. {
  11346. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11347. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11348. result = PASS;
  11349. }
  11350. sendResetConfirmation(uuid, comfirmstr);
  11351. return result;
  11352. }
  11353. int handleSendLocalListRequest(char *uuid, char *payload)
  11354. {
  11355. mtrace();
  11356. int result = FAIL;
  11357. char comfirmstr[20];
  11358. int checkState_Faulted = FALSE;
  11359. json_object *SendLocalList;
  11360. DEBUG_INFO("handleSendLocalListRequest...\n");
  11361. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11362. {
  11363. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11364. goto end;
  11365. }
  11366. //check Charge Point state
  11367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11368. {
  11369. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11370. {
  11371. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11372. }
  11373. }
  11374. for (int index = 0; index < CCS_QUANTITY; index++)
  11375. {
  11376. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11377. {
  11378. checkState_Faulted = TRUE; //OCPP Status
  11379. }
  11380. }
  11381. for (int index = 0; index < GB_QUANTITY; index++)
  11382. {
  11383. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11384. {
  11385. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11386. }
  11387. }
  11388. //check Charge Point state
  11389. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11390. {
  11391. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11392. {
  11393. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11394. }
  11395. }
  11396. //check Charge Point state
  11397. for (int index = 0; index < AC_QUANTITY; index++)
  11398. {
  11399. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11400. {
  11401. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11402. }
  11403. }
  11404. if(checkState_Faulted == TRUE)
  11405. {
  11406. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11407. goto end;
  11408. }
  11409. // Parsing payload
  11410. SendLocalList = json_tokener_parse(payload);
  11411. if(!is_error(SendLocalList))
  11412. {
  11413. // Required data
  11414. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11415. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11416. // Optional data
  11417. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11418. {
  11419. //Check UpdateType
  11420. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11421. {
  11422. //Local list full update
  11423. DEBUG_INFO("Local list full update.\n");
  11424. OCPP_getListVerion();
  11425. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11426. {
  11427. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11428. goto end;
  11429. }
  11430. OCPP_cleanLocalList();
  11431. }
  11432. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11433. {
  11434. //Local list different update
  11435. DEBUG_INFO("Local list different update.\n");
  11436. OCPP_getListVerion();
  11437. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11438. {
  11439. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11440. goto end;
  11441. }
  11442. }
  11443. else
  11444. {
  11445. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11446. goto end;
  11447. }
  11448. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11449. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11450. {
  11451. sprintf((char*)ShmOCPP16DataPH->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")));
  11452. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11453. {
  11454. sprintf((char*)ShmOCPP16DataPH->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")));
  11455. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11456. sprintf((char*)ShmOCPP16DataPH->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")));
  11457. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11458. sprintf((char*)ShmOCPP16DataPH->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")));
  11459. }
  11460. // Add to db
  11461. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11462. {
  11463. //Local list full update
  11464. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11465. idx,
  11466. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11467. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11468. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11469. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11470. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11471. // update list
  11472. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11473. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11474. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11475. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11476. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11477. }
  11478. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11479. {
  11480. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11481. idx,
  11482. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11483. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11484. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11485. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11486. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11487. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11488. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11489. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11490. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11491. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11492. }
  11493. }
  11494. }
  11495. else
  11496. {
  11497. //Check UpdateType
  11498. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11499. {
  11500. //Local list full update
  11501. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11502. OCPP_cleanLocalList();
  11503. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11504. goto end;
  11505. }
  11506. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11507. {
  11508. //Local list different update
  11509. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11510. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11511. goto end;
  11512. }
  11513. }
  11514. result = PASS;
  11515. }
  11516. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11517. end:
  11518. json_object_put(SendLocalList);
  11519. sendSendLocalListConfirmation(uuid, comfirmstr);
  11520. return result;
  11521. }
  11522. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11523. {
  11524. mtrace();
  11525. int result = FAIL;
  11526. struct StructSetChargingProfile SetProfileReq = {0};
  11527. int tempchargingProfileIdInt;
  11528. int chargingSchedulePeriodCount = 0;
  11529. char comfirmstr[20]={0};
  11530. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11531. char rmFileCmd[128]={0};
  11532. int profileQuantity = 0;
  11533. json_object *SetChargingProfile;
  11534. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11535. SetChargingProfile = json_tokener_parse(payload);
  11536. if(!is_error(SetChargingProfile))
  11537. {
  11538. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11539. {
  11540. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11541. }
  11542. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11543. {
  11544. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11545. {
  11546. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11547. }
  11548. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11549. {
  11550. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11551. }
  11552. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11553. {
  11554. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11555. }
  11556. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11557. {
  11558. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11559. }
  11560. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11561. {
  11562. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11563. }
  11564. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11565. {
  11566. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11567. }
  11568. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11569. {
  11570. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11571. }
  11572. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11573. {
  11574. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11575. }
  11576. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11577. {
  11578. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11579. {
  11580. 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")));
  11581. }
  11582. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11583. {
  11584. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11585. }
  11586. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11587. {
  11588. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11589. }
  11590. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11591. {
  11592. 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")));
  11593. }
  11594. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11595. {
  11596. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11597. if(chargingSchedulePeriodCount <= 10)
  11598. {
  11599. 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++)
  11600. {
  11601. 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)
  11602. {
  11603. 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"));
  11604. }
  11605. 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)
  11606. {
  11607. 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"));
  11608. }
  11609. 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)
  11610. {
  11611. 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"));
  11612. }
  11613. }
  11614. }
  11615. }
  11616. }
  11617. }
  11618. }
  11619. // Profile periods quantity check
  11620. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11621. {
  11622. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11623. goto end;
  11624. }
  11625. // Check invalid limit
  11626. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11627. {
  11628. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11629. {
  11630. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  11631. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11632. {
  11633. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11634. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11635. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11636. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11637. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11638. goto end;
  11639. }
  11640. }
  11641. }
  11642. else
  11643. {
  11644. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11645. {
  11646. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower))
  11647. {
  11648. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11649. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11650. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11651. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11652. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11653. goto end;
  11654. }
  11655. }
  11656. }
  11657. // Profile purpose info check
  11658. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11659. {
  11660. FILE *fp;
  11661. char dataLine[4096]={0};
  11662. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11663. if(SetProfileReq.ConnectorId != 0)
  11664. {
  11665. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11666. goto end;
  11667. }
  11668. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11669. if (!fp)
  11670. {
  11671. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11672. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11673. }
  11674. else
  11675. {
  11676. while(fscanf(fp, "%s", dataLine) != EOF)
  11677. {
  11678. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11679. {
  11680. profileQuantity += 1;
  11681. }
  11682. }
  11683. }
  11684. fclose(fp);
  11685. }
  11686. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11687. {
  11688. FILE *fp;
  11689. char dataLine[4096]={0};
  11690. char filename[128]={0};
  11691. int tmpProfileQuantity;
  11692. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11693. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11694. {
  11695. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11696. goto end;
  11697. }
  11698. if(SetProfileReq.ConnectorId == 0)
  11699. {
  11700. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11701. {
  11702. tmpProfileQuantity = 0;
  11703. memset(filename, 0, ARRAY_SIZE(filename));
  11704. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11705. fp = fopen(filename, "r");
  11706. if (!fp)
  11707. {
  11708. DEBUG_INFO("%s does not create.\n", filename);
  11709. fp = fopen(filename, "w+");
  11710. }
  11711. else
  11712. {
  11713. while(fscanf(fp, "%s", dataLine) != EOF)
  11714. {
  11715. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11716. {
  11717. tmpProfileQuantity += 1;
  11718. }
  11719. }
  11720. }
  11721. fclose(fp);
  11722. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11723. }
  11724. }
  11725. else
  11726. {
  11727. memset(filename, 0, ARRAY_SIZE(filename));
  11728. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11729. fp = fopen(filename, "r");
  11730. if (!fp)
  11731. {
  11732. DEBUG_INFO("%s does not create.\n", filename);
  11733. fp = fopen(filename, "w+");
  11734. }
  11735. else
  11736. {
  11737. while(fscanf(fp, "%s", dataLine) != EOF)
  11738. {
  11739. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11740. {
  11741. profileQuantity += 1;
  11742. }
  11743. }
  11744. }
  11745. fclose(fp);
  11746. }
  11747. }
  11748. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11749. {
  11750. int isMatchTransactiodId= FALSE;
  11751. FILE *fp;
  11752. char dataLine[4096]={0};
  11753. char filename[128]={0};
  11754. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11755. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11756. if(SetProfileReq.ConnectorId == 0)
  11757. {
  11758. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11759. goto end;
  11760. }
  11761. int tempIndex = 0;
  11762. //check Transaction active
  11763. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11764. {
  11765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11766. {
  11767. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11768. }
  11769. else
  11770. {
  11771. tempIndex = SetProfileReq.ConnectorId -1;
  11772. }
  11773. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11774. {
  11775. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11776. {
  11777. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11778. {
  11779. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11780. {
  11781. isMatchTransactiodId = TRUE;
  11782. break;
  11783. }
  11784. }
  11785. }
  11786. }
  11787. }
  11788. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11789. {
  11790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11791. {
  11792. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11793. }
  11794. else
  11795. {
  11796. tempIndex = SetProfileReq.ConnectorId -1;
  11797. }
  11798. for (int index = 0; index < CCS_QUANTITY; index++)
  11799. {
  11800. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11801. {
  11802. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11803. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11804. {
  11805. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11806. {
  11807. isMatchTransactiodId = TRUE;
  11808. break;
  11809. }
  11810. }
  11811. }
  11812. }
  11813. }
  11814. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11815. {
  11816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11817. {
  11818. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11819. }
  11820. else
  11821. {
  11822. tempIndex = SetProfileReq.ConnectorId -1;
  11823. }
  11824. for (int index = 0; index < GB_QUANTITY; index++)
  11825. {
  11826. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11827. {
  11828. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11829. {
  11830. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11831. {
  11832. isMatchTransactiodId = TRUE;
  11833. break;
  11834. }
  11835. }
  11836. }
  11837. }
  11838. }
  11839. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11840. {
  11841. tempIndex = SetProfileReq.ConnectorId -1;
  11842. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11843. {
  11844. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11845. {
  11846. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11847. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11848. {
  11849. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11850. {
  11851. isMatchTransactiodId = TRUE;
  11852. break;
  11853. }
  11854. }
  11855. }
  11856. }
  11857. }
  11858. else
  11859. {
  11860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11861. {
  11862. tempIndex = 2;
  11863. }
  11864. else
  11865. {
  11866. tempIndex = (SetProfileReq.ConnectorId -1);
  11867. }
  11868. for (int index = 0; index < AC_QUANTITY; index++)
  11869. {
  11870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11871. {
  11872. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11873. {
  11874. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11875. {
  11876. isMatchTransactiodId = TRUE;
  11877. break;
  11878. }
  11879. }
  11880. }
  11881. }
  11882. }
  11883. //check Transaction active
  11884. if(isMatchTransactiodId == FALSE)
  11885. {
  11886. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11887. goto end;
  11888. }
  11889. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11890. {
  11891. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11892. goto end;
  11893. }
  11894. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11895. fp = fopen(filename, "r");
  11896. if (!fp)
  11897. {
  11898. DEBUG_INFO("%s does not create.\n", filename);
  11899. fp = fopen(filename, "w+");
  11900. }
  11901. else
  11902. {
  11903. //Check Charging Profile Count
  11904. while(fscanf(fp, "%s", dataLine) != EOF)
  11905. {
  11906. //DEBUG_INFO("word=%s\n",word);
  11907. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11908. {
  11909. profileQuantity += 1;
  11910. }
  11911. }
  11912. }
  11913. fclose(fp);
  11914. }
  11915. // Check ChargeProfileMaxStackLevel
  11916. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11917. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11918. {
  11919. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11920. goto end;
  11921. }
  11922. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11923. {
  11924. FILE *fp;
  11925. char dataLine[4096]={0};
  11926. char fnametemp[128]={0};
  11927. int tmpProfileQuantity;
  11928. //Check ChargePointMaxProfile.json exit
  11929. profileQuantity = 0;
  11930. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11931. {
  11932. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11933. //Check Charging Profile Count
  11934. tmpProfileQuantity = 0;
  11935. while(fscanf(fp, "%s", dataLine) != EOF)
  11936. {
  11937. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11938. {
  11939. profileQuantity += 1;
  11940. tmpProfileQuantity += 1;
  11941. }
  11942. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11943. }
  11944. fclose(fp);
  11945. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11946. }
  11947. //Check TxDefaultProfile_%d.json
  11948. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11949. {
  11950. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11951. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11952. if((access(fnametemp,F_OK))!=-1)
  11953. {
  11954. fp = fopen(fnametemp, "r");
  11955. //Check Charging Profile Count
  11956. tmpProfileQuantity = 0;
  11957. while(fscanf(fp, "%s", dataLine) != EOF)
  11958. {
  11959. //DEBUG_INFO("word=%s\n",word);
  11960. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11961. {
  11962. profileQuantity += 1;
  11963. tmpProfileQuantity += 1;
  11964. }
  11965. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11966. }
  11967. fclose(fp);
  11968. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11969. }
  11970. }
  11971. //Check TxProfile_%d.json
  11972. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11973. {
  11974. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11975. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11976. if((access(fnametemp,F_OK))!=-1)
  11977. {
  11978. fp = fopen(fnametemp, "r");
  11979. //Check Charging Profile Count
  11980. tmpProfileQuantity = 0;
  11981. while(fscanf(fp, "%s", dataLine) != EOF)
  11982. {
  11983. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11984. {
  11985. profileQuantity += 1;
  11986. tmpProfileQuantity += 1;
  11987. }
  11988. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11989. }
  11990. fclose(fp);
  11991. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11992. }
  11993. }
  11994. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11995. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11996. {
  11997. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11998. goto end;
  11999. }
  12000. }
  12001. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12002. //**********************************Write to File********************************************************/
  12003. {
  12004. FILE *infile;
  12005. FILE *outfile;
  12006. char dataLine[4096]={0};
  12007. char filename[128]={0};
  12008. int chkChar=0;
  12009. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12010. {
  12011. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12012. {
  12013. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12014. }
  12015. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12016. {
  12017. if(SetProfileReq.ConnectorId==0)
  12018. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12019. else
  12020. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12021. }
  12022. else
  12023. {
  12024. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12025. }
  12026. infile = fopen (filename, "r");
  12027. outfile = fopen (tempfile, "w");
  12028. chkChar = fgetc(infile);
  12029. rewind(infile);
  12030. if(chkChar == EOF)
  12031. {
  12032. // Profile is empty
  12033. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12034. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12035. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12036. fclose(infile);
  12037. fclose(outfile);
  12038. sprintf(rmFileCmd,"rm -f %s",filename);
  12039. system(rmFileCmd);
  12040. rename(tempfile, filename);
  12041. }
  12042. else
  12043. {
  12044. // Profile is not empty
  12045. int ChargingProfileAdded = FALSE;
  12046. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12047. {
  12048. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12049. json_object *tmpChargingProfile;
  12050. tmpChargingProfile = json_tokener_parse(dataLine);
  12051. if(!is_error(SetChargingProfile))
  12052. {
  12053. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12054. {
  12055. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12056. {
  12057. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12058. }
  12059. }
  12060. }
  12061. json_object_put(tmpChargingProfile);
  12062. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12063. {
  12064. if(ChargingProfileAdded == FALSE)
  12065. {
  12066. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12067. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12068. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12069. ChargingProfileAdded = TRUE;
  12070. }
  12071. }
  12072. else
  12073. {
  12074. fprintf(outfile,"%s\n",dataLine);
  12075. if(ChargingProfileAdded == FALSE)
  12076. {
  12077. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12078. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12079. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12080. ChargingProfileAdded = TRUE;
  12081. }
  12082. }
  12083. } // end of while loop
  12084. fclose(infile);
  12085. fclose(outfile);
  12086. sprintf(rmFileCmd,"rm -f %s",filename);
  12087. system(rmFileCmd);
  12088. rename(tempfile, filename);
  12089. }
  12090. }
  12091. sleep(1);
  12092. result = TRUE;
  12093. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12094. }
  12095. end:
  12096. json_object_put(SetChargingProfile);
  12097. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12098. {
  12099. if(SetProfileReq.ConnectorId == 0)
  12100. {
  12101. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12102. {
  12103. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12104. }
  12105. }
  12106. else
  12107. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12108. }
  12109. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12110. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12111. return result;
  12112. }
  12113. int handleTriggerMessageRequest(char *uuid, char *payload)
  12114. {
  12115. mtrace();
  12116. int result = FAIL;
  12117. int connectorIdIsNULL = FALSE;
  12118. int connectorIdInt =0;
  12119. char sstr[40]={0},sstrtemp[100]={ 0 };
  12120. char requestedMessagestr[40]={0};
  12121. char comfirmstr[20]={0};
  12122. int c = 0;
  12123. char *loc;
  12124. DEBUG_INFO("handleTriggerMessageRequest\n");
  12125. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12126. strcpy(sstrtemp, stringtrimspace(payload));
  12127. c = 0;
  12128. loc = strstr(sstrtemp, "requestedMessage");
  12129. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12130. {
  12131. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12132. c++;
  12133. }
  12134. sstr[c] = '\0';
  12135. strcpy(requestedMessagestr, sstr);
  12136. c = 0;
  12137. loc = strstr(sstrtemp, "connectorId");
  12138. if(loc == NULL)
  12139. {
  12140. connectorIdIsNULL = TRUE;
  12141. }
  12142. else
  12143. {
  12144. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12145. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12146. {
  12147. sstr[c] = loc[strlen("connectorId")+2+c];
  12148. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12149. c++;
  12150. }
  12151. sstr[c] = '\0';
  12152. connectorIdInt = atoi(sstr);
  12153. }
  12154. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12155. {
  12156. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12157. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12158. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12159. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12160. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12161. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12162. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12163. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12164. {
  12165. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12166. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12167. return TRUE;
  12168. }
  12169. else
  12170. {
  12171. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12172. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12173. }
  12174. }
  12175. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12176. {
  12177. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12178. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12179. return TRUE;
  12180. }
  12181. //==========================
  12182. // Trigger message
  12183. //==========================
  12184. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12185. {
  12186. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12187. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12188. {
  12189. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12190. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12191. }
  12192. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12193. }
  12194. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12195. {
  12196. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12197. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12198. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12199. }
  12200. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12201. {
  12202. //sendBootNotificationRequest();
  12203. server_sign = FALSE;
  12204. }
  12205. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12206. {
  12207. refreshStartTimer(&clientTime.Heartbeat);
  12208. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12209. }
  12210. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12211. {
  12212. if(connectorIdIsNULL == FALSE)
  12213. {
  12214. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12215. {
  12216. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12217. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12218. }
  12219. }
  12220. else
  12221. {
  12222. for(int idx=0;idx< gunTotalNumber;idx++)
  12223. {
  12224. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12225. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12226. }
  12227. }
  12228. }
  12229. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12230. {
  12231. if(connectorIdIsNULL == FALSE)
  12232. {
  12233. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12234. {
  12235. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12236. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12237. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12238. }
  12239. }
  12240. else
  12241. {
  12242. for(int idx=0;idx< gunTotalNumber;idx++)
  12243. {
  12244. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12245. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12246. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12247. }
  12248. }
  12249. }
  12250. return result;
  12251. }
  12252. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12253. {
  12254. mtrace();
  12255. int result = FAIL;
  12256. int connectorIdInt =0;
  12257. char comfirmstr[20]={0};
  12258. int tempIndex = 0;
  12259. json_object *UnlockConnector;
  12260. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12261. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12262. UnlockConnector = json_tokener_parse(payload);
  12263. if(!is_error(UnlockConnector))
  12264. {
  12265. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12266. {
  12267. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12268. }
  12269. }
  12270. json_object_put(UnlockConnector);
  12271. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12272. if(gunTotalNumber == 0)
  12273. {
  12274. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12275. goto end;
  12276. }
  12277. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12278. {
  12279. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12280. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12281. goto end;
  12282. }
  12283. else
  12284. {
  12285. //check Transaction active
  12286. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12287. {
  12288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12289. {
  12290. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12291. }
  12292. else
  12293. {
  12294. tempIndex = connectorIdInt -1;
  12295. }
  12296. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12297. {
  12298. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12299. {
  12300. //stop Transaction
  12301. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12302. }
  12303. }
  12304. }
  12305. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12306. {
  12307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12308. {
  12309. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12310. }
  12311. else
  12312. {
  12313. tempIndex = connectorIdInt -1;
  12314. }
  12315. for (int index = 0; index < CCS_QUANTITY; index++)
  12316. {
  12317. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12318. {
  12319. //stop Transaction
  12320. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12321. }
  12322. }
  12323. }
  12324. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12325. {
  12326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12327. {
  12328. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12329. }
  12330. else
  12331. {
  12332. tempIndex = connectorIdInt -1;
  12333. }
  12334. for (int index = 0; index < GB_QUANTITY; index++)
  12335. {
  12336. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12337. {
  12338. //stop Transaction
  12339. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12340. }
  12341. }
  12342. }
  12343. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12344. {
  12345. tempIndex = connectorIdInt -1;
  12346. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12347. {
  12348. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12349. {
  12350. //stop Transaction
  12351. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12352. }
  12353. }
  12354. }
  12355. else
  12356. {
  12357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12358. {
  12359. tempIndex = 2;
  12360. }
  12361. else
  12362. {
  12363. tempIndex = connectorIdInt-1;
  12364. }
  12365. for (int index = 0; index < AC_QUANTITY; index++)
  12366. {
  12367. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12368. {
  12369. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12370. }
  12371. }
  12372. }
  12373. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12374. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12375. result = TRUE;
  12376. return result;
  12377. }
  12378. end:
  12379. //json_object_put(obj); --- remove temporally
  12380. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12381. return result;
  12382. }
  12383. static char UpdateFirmwarepayloadData[300]={0};
  12384. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12385. {
  12386. mtrace();
  12387. int result = FAIL;
  12388. pthread_t t;
  12389. sendUpdateFirmwareConfirmation(uuid);
  12390. memset(UpdateFirmwarepayloadData, 0, 300);
  12391. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12392. if(!interLock.isUpdateFirmwareGoing)
  12393. {
  12394. interLock.isUpdateFirmwareGoing = 1;
  12395. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12396. sleep(1);
  12397. }
  12398. else
  12399. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12400. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12401. return result;
  12402. }
  12403. void *UpdateFirmwareProcess(void *data)
  12404. {
  12405. pthread_detach(pthread_self());
  12406. mtrace();
  12407. int retriesInt =0, retryIntervalInt=0;
  12408. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12409. int port=0;
  12410. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12411. int isSuccess = 0;
  12412. char ftpbuf[512];
  12413. char temp[100];
  12414. char * pch;
  12415. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12416. json_object *UpdateFirmware;
  12417. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12418. if(!is_error(UpdateFirmware))
  12419. {
  12420. // Required data
  12421. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12422. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12423. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12424. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12425. // Optional data
  12426. if(json_object_object_get(UpdateFirmware, "retries"))
  12427. {
  12428. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12429. }
  12430. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12431. {
  12432. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12433. }
  12434. }
  12435. json_object_put(UpdateFirmware);
  12436. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12437. memset(path, 0, ARRAY_SIZE(path));
  12438. // Wait retrieveData
  12439. if(strlen(retrieveDatestr) > 10)
  12440. {
  12441. do
  12442. {
  12443. sleep(1);
  12444. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12445. }
  12446. // Ready to download
  12447. system("rm -f /mnt/*");
  12448. if(strncmp(locationstr,"http", 4) == 0)
  12449. {
  12450. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12451. sprintf(ftppath,"/%s", path);
  12452. DEBUG_INFO("locationstr: %s\n", locationstr);
  12453. DEBUG_INFO("protocol: %s\n",protocol);
  12454. DEBUG_INFO("host: %s\n",host);
  12455. DEBUG_INFO("path: %s\n",path);
  12456. DEBUG_INFO("ftppath: %s\n",ftppath);
  12457. int ftppathlen=strlen(ftppath);
  12458. int i=1;
  12459. char filenametemp[50];
  12460. while(i < ftppathlen)
  12461. {
  12462. int len=ftppathlen-i;
  12463. if(ftppath[len]== 47) // '/' ascll code: 47
  12464. {
  12465. DEBUG_INFO("compare '/' all right\n");
  12466. break;
  12467. }
  12468. i=i+1;
  12469. }
  12470. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12471. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12472. filenametemp[i+1] = 0;
  12473. do
  12474. {
  12475. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12476. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12477. sleep(1);
  12478. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12479. if(!isSuccess)
  12480. {
  12481. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12482. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12483. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12484. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12485. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12486. }
  12487. else
  12488. {
  12489. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12490. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12491. }
  12492. retriesInt--;
  12493. }while((isSuccess == 0)&&(retriesInt >= 0));
  12494. }
  12495. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12496. {
  12497. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12498. memset(temp, 0, ARRAY_SIZE(temp));
  12499. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12500. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12501. int ftppathlen=strlen(ftpbuf);
  12502. int i=1;
  12503. char filenametemp[50];
  12504. while(i < ftppathlen)
  12505. {
  12506. int len=ftppathlen-i;
  12507. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12508. {
  12509. DEBUG_INFO(" compare '/' all right\n");
  12510. break;
  12511. }
  12512. i=i+1;
  12513. }
  12514. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12515. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12516. filenametemp[i+1] = 0;
  12517. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12518. pch=strchr(temp,'@');
  12519. if(pch==NULL)
  12520. {
  12521. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12522. protocol, host, &port, path);
  12523. strcpy(user,"anonymous");
  12524. strcpy(password,"");
  12525. }
  12526. else
  12527. {
  12528. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12529. protocol, user, password, host, &port, path);
  12530. }
  12531. sscanf(host,"%[^/]%s",host1, path1);
  12532. sprintf(ftppath,"%s", path1);
  12533. //DEBUG_INFO("protocol =%s\n",protocol);
  12534. //DEBUG_INFO("user =%s\n",user);
  12535. //DEBUG_INFO("password =%s\n",password);
  12536. //DEBUG_INFO("host1 =%s\n",host1);
  12537. //DEBUG_INFO("port =%d\n",port);
  12538. //DEBUG_INFO("path1 =%s\n",path1);
  12539. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12540. //ftpFile(host, user, password, port, ftppath, fname);
  12541. //download firmware pthred
  12542. if(port == 0)
  12543. {
  12544. port = 21;
  12545. }
  12546. do
  12547. {
  12548. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12549. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12550. sleep(1);
  12551. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12552. if(!isSuccess)
  12553. {
  12554. //BulldogUtil.sleepMs(interval*1000);
  12555. DEBUG_INFO("Update firmware request and download file fail.\n");
  12556. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12557. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12558. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12559. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12560. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12561. }
  12562. else
  12563. {
  12564. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12565. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12566. }
  12567. retriesInt--;
  12568. }while((!isSuccess)&&(retriesInt >= 0));
  12569. }
  12570. else
  12571. {
  12572. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12573. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12574. sleep(1);
  12575. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12576. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12577. }
  12578. // OCPPPH only, must announce CSU upgrade firmware
  12579. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12580. interLock.isUpdateFirmwareGoing = 0;
  12581. pthread_exit(NULL);
  12582. }
  12583. int handleCertificateSignedRequest(char *uuid, char *payload)
  12584. {
  12585. mtrace();
  12586. int result = PASS;
  12587. json_object *CertificateSigned;
  12588. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12589. CertificateSigned = json_tokener_parse(payload);
  12590. if(!is_error(CertificateSigned))
  12591. {
  12592. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12593. }
  12594. json_object_put(CertificateSigned);
  12595. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12596. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12597. fclose(fp);
  12598. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12599. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12600. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12601. sendCertificateSignedConfirmation(uuid);
  12602. return result;
  12603. }
  12604. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12605. {
  12606. mtrace();
  12607. int result = PASS;
  12608. json_object *DeleteCertificate;
  12609. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12610. DeleteCertificate = json_tokener_parse(payload);
  12611. if(!is_error(DeleteCertificate))
  12612. {
  12613. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12614. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12615. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12616. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12617. }
  12618. json_object_put(DeleteCertificate);
  12619. /*
  12620. * TODO: Delete certificateSigned process
  12621. */
  12622. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12623. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12624. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12625. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12626. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12627. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12628. sendDeleteCertificateConfirmation(uuid);
  12629. return result;
  12630. }
  12631. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12632. {
  12633. mtrace();
  12634. int result = PASS;
  12635. json_object *ExtendedTriggerMessage;
  12636. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12637. ExtendedTriggerMessage = json_tokener_parse(payload);
  12638. if(!is_error(ExtendedTriggerMessage))
  12639. {
  12640. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12641. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12642. {
  12643. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12644. }
  12645. else
  12646. {
  12647. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12648. }
  12649. }
  12650. json_object_put(ExtendedTriggerMessage);
  12651. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12652. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12653. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12654. {
  12655. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12656. }
  12657. else
  12658. {
  12659. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12660. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12661. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12662. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12663. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12664. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12665. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12666. {
  12667. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12668. }
  12669. else
  12670. {
  12671. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12672. }
  12673. }
  12674. sendExtendedTriggerMessageConfirmation(uuid);
  12675. //==========================
  12676. // Trigger message
  12677. //==========================
  12678. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12679. {
  12680. //sendBootNotificationRequest();
  12681. server_sign = FALSE;
  12682. }
  12683. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12684. {
  12685. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12686. }
  12687. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12688. {
  12689. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12690. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12691. {
  12692. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12693. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12694. }
  12695. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12696. }
  12697. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12698. {
  12699. refreshStartTimer(&clientTime.Heartbeat);
  12700. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12701. }
  12702. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12703. {
  12704. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12705. {
  12706. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12707. }
  12708. else
  12709. {
  12710. for(int idx=0;idx< gunTotalNumber;idx++)
  12711. {
  12712. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12713. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12714. }
  12715. }
  12716. }
  12717. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12718. {
  12719. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12720. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12721. {
  12722. system("openssl req -newkey rsa:2048 -out /Storage/OCPP_PH/certCP.csr -nodes -keyout /Storage/OCPP_PH/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  12723. }
  12724. }
  12725. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12726. {
  12727. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12728. {
  12729. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12730. }
  12731. else
  12732. {
  12733. for(int idx=0;idx< gunTotalNumber;idx++)
  12734. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12735. }
  12736. }
  12737. return result;
  12738. }
  12739. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12740. {
  12741. mtrace();
  12742. int result = PASS;
  12743. json_object *GetInstalledCertificateIds;
  12744. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12745. GetInstalledCertificateIds = json_tokener_parse(payload);
  12746. if(!is_error(GetInstalledCertificateIds))
  12747. {
  12748. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12749. }
  12750. json_object_put(GetInstalledCertificateIds);
  12751. /*
  12752. * TODO: Return installed certificate process
  12753. */
  12754. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12755. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12756. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12757. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12758. sendGetInstalledCertificateIdsConfirmation(uuid);
  12759. return result;
  12760. }
  12761. int handleGetLogRequest(char *uuid, char *payload)
  12762. {
  12763. mtrace();
  12764. int result = PASS;
  12765. json_object *GetLog;
  12766. DEBUG_INFO("handleGetLogRequest...\n");
  12767. GetLog = json_tokener_parse(payload);
  12768. if(!is_error(GetLog))
  12769. {
  12770. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12771. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12772. if(json_object_object_get(GetLog, "retries") != NULL)
  12773. {
  12774. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12775. }
  12776. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12777. {
  12778. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12779. }
  12780. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12781. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12782. {
  12783. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12784. }
  12785. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12786. {
  12787. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12788. }
  12789. }
  12790. json_object_put(GetLog);
  12791. /*
  12792. * TODO: Upload log process
  12793. */
  12794. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12795. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12796. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12797. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12798. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12799. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12800. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12801. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12802. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12803. sendGetLogConfirmation(uuid);
  12804. return result;
  12805. }
  12806. int handleInstallCertificateRequest(char *uuid, char *payload)
  12807. {
  12808. mtrace();
  12809. int result = PASS;
  12810. json_object *InstallCertificate;
  12811. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12812. InstallCertificate = json_tokener_parse(payload);
  12813. if(!is_error(InstallCertificate))
  12814. {
  12815. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12816. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12817. /*
  12818. * TODO: Install certificate process
  12819. */
  12820. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12821. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12822. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12823. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12824. sendInstallCertificateConfirmation(uuid);
  12825. }
  12826. json_object_put(InstallCertificate);
  12827. return result;
  12828. }
  12829. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12830. {
  12831. mtrace();
  12832. int result = PASS;
  12833. json_object *SignedUpdateFirmware;
  12834. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12835. SignedUpdateFirmware = json_tokener_parse(payload);
  12836. if(!is_error(SignedUpdateFirmware))
  12837. {
  12838. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12839. {
  12840. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12841. }
  12842. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12843. {
  12844. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12845. }
  12846. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12847. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12848. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12849. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12850. {
  12851. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12852. }
  12853. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12854. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12855. }
  12856. json_object_put(SignedUpdateFirmware);
  12857. /*
  12858. * TODO: Upgrade firmware process
  12859. */
  12860. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12861. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12862. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12863. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12864. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12865. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12866. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12867. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12868. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12869. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12870. sendInstallCertificateConfirmation(uuid);
  12871. return result;
  12872. }
  12873. int handleUnknownRequest(char *uuid, char *payload)
  12874. {
  12875. mtrace();
  12876. int result = PASS;
  12877. DEBUG_INFO("handleUnknownRequest...\n");
  12878. sendUnknownConfirmation(uuid);
  12879. result = PASS;
  12880. return result;
  12881. }
  12882. //==========================================
  12883. // Handle server response routine
  12884. //==========================================
  12885. void handleAuthorizeResponse(char *payload, int gun_index)
  12886. {
  12887. mtrace();
  12888. char expiryDatestr[30]={0};
  12889. char parentIdTagstr[20]={0};
  12890. char statusstr[20]={0};
  12891. int expiryDateISNULL=FALSE;
  12892. int parentIdTagISNULL=FALSE;
  12893. DEBUG_INFO("handleAuthorizeResponse...\n");
  12894. json_object *Authorize;
  12895. Authorize = json_tokener_parse(payload);
  12896. if(!is_error(Authorize))
  12897. {
  12898. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12899. {
  12900. // Required data
  12901. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12902. // Optional data
  12903. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12904. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12905. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12906. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12907. }
  12908. }
  12909. json_object_put(Authorize);
  12910. if(expiryDateISNULL == FALSE)
  12911. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12912. if(parentIdTagISNULL == FALSE)
  12913. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12914. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12915. //Update idTag information to authorization cache if supproted
  12916. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12917. {
  12918. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12919. }
  12920. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12921. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12922. authorizeRetryTimes = 0;
  12923. }
  12924. void handleBootNotificationResponse(char *payload, int gun_index)
  12925. {
  12926. mtrace();
  12927. char statusStr[12]={0};
  12928. char currentTimeStr[30]={0};
  12929. int intervalInt = 0;
  12930. DEBUG_INFO("handleBootNotificationResponse...\n");
  12931. json_object *BootNotification;
  12932. BootNotification = json_tokener_parse(payload);
  12933. if(!is_error(BootNotification))
  12934. {
  12935. // Required data
  12936. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12937. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12938. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12939. }
  12940. json_object_put(BootNotification);
  12941. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12942. BootNotificationInterval = intervalInt;
  12943. HeartBeatWaitTime = intervalInt;
  12944. //write back to ShmOCPP16DataPH->BootNotification
  12945. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12946. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12947. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12948. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12949. {
  12950. if((intervalInt == 0) || (intervalInt >= 10))
  12951. {
  12952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12953. HeartBeatWaitTime = intervalInt;
  12954. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12955. }
  12956. server_sign = TRUE;
  12957. server_pending =FALSE;
  12958. }
  12959. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12960. {
  12961. server_pending = TRUE;
  12962. }
  12963. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12964. srand(time(NULL));
  12965. refreshStartTimer(&clientTime.Heartbeat);
  12966. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12967. SetOcppConnStatus(TRUE);
  12968. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12969. }
  12970. void handleDataTransferResponse(char *payload, int gun_index)
  12971. {
  12972. json_object *DataTransfer = json_tokener_parse(payload);
  12973. if(!is_error(DataTransfer))
  12974. {
  12975. // Required data
  12976. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12977. // Optional data
  12978. if(json_object_object_get(DataTransfer, "data") != NULL)
  12979. {
  12980. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12981. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12982. if(!is_error(Data))
  12983. {
  12984. if(json_object_object_get(Data, "msgId") != NULL)
  12985. {
  12986. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12987. {
  12988. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  12989. }
  12990. }
  12991. }
  12992. json_object_put(Data);
  12993. }
  12994. }
  12995. json_object_put(DataTransfer);
  12996. }
  12997. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12998. {
  12999. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13000. //struct json_object *obj;
  13001. // obj = json_tokener_parse(payload);
  13002. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13003. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13004. //No fields are defined.
  13005. }
  13006. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13007. {
  13008. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13009. //struct json_object *obj;
  13010. // obj = json_tokener_parse(payload);
  13011. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13012. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13013. //No fields are defined.
  13014. }
  13015. void handleHeartbeatResponse(char *payload, int gun_index)
  13016. {
  13017. mtrace();
  13018. DEBUG_INFO("handleHeartbeatResponse...\n");
  13019. json_object *Heartbeat;
  13020. Heartbeat = json_tokener_parse(payload);
  13021. if(!is_error(Heartbeat))
  13022. {
  13023. // Required data
  13024. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13025. }
  13026. json_object_put(Heartbeat);
  13027. if(FirstHeartBeat == 0)
  13028. {
  13029. FirstHeartBeat = 1;
  13030. DEBUG_INFO("FirstHeartBeat \n");
  13031. }
  13032. HeartBeatWithNOResponse = 0;
  13033. refreshStartTimer(&clientTime.Heartbeat);
  13034. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13035. }
  13036. void handleMeterValuesResponse(char *payload, int gun_index)
  13037. {
  13038. mtrace();
  13039. DEBUG_INFO("handleMeterValuesResponse...\n");
  13040. isQueueSendable = 1;
  13041. }
  13042. void handleStartTransactionResponse(char *payload, int gun_index)
  13043. {
  13044. mtrace();
  13045. //int transactionIdInt = 0;
  13046. FILE *outfile;
  13047. char data[100]={0};
  13048. DEBUG_INFO("handleStartTransactionResponse...\n");
  13049. json_object *StartTransaction;
  13050. StartTransaction = json_tokener_parse(payload);
  13051. if(!is_error(StartTransaction))
  13052. {
  13053. // Required data
  13054. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13055. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13056. // Optional data
  13057. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13058. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13059. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13060. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13061. }
  13062. json_object_put(StartTransaction);
  13063. isQueueSendable = 1;
  13064. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13065. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13066. //-----------Start : write to the Queue TransactionId file -----------------//
  13067. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13068. {}
  13069. else
  13070. {
  13071. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13072. if(log == NULL)
  13073. {
  13074. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13075. return ;
  13076. }
  13077. else
  13078. {
  13079. fclose(log);
  13080. }
  13081. }
  13082. // open file for writing
  13083. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13084. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13085. {
  13086. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13087. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13088. fputs(data, outfile);
  13089. fclose (outfile);
  13090. }
  13091. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13092. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13093. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13094. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13095. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13096. }
  13097. void handleStatusNotificationResponse(char *payload, int gun_index)
  13098. {
  13099. mtrace();
  13100. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13101. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13102. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13103. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13104. }
  13105. void handleStopTransactionnResponse(char *payload, int gun_index)
  13106. {
  13107. mtrace();
  13108. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13109. json_object *StopTransaction;
  13110. StopTransaction = json_tokener_parse(payload);
  13111. if(!is_error(StopTransaction))
  13112. {
  13113. // Optional data
  13114. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13115. {
  13116. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13117. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13118. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13119. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13120. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13121. }
  13122. }
  13123. json_object_put(StopTransaction);
  13124. isQueueSendable = 1;
  13125. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13126. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13127. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13128. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13129. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13130. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13131. }
  13132. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13133. {
  13134. mtrace();
  13135. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13136. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13137. }
  13138. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13139. {
  13140. mtrace();
  13141. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13142. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13143. }
  13144. void handleSignCertificateResponse(char *payload, int gun_index)
  13145. {
  13146. mtrace();
  13147. DEBUG_INFO("handleSignCertificateResponse...\n");
  13148. json_object *SignCertificate;
  13149. SignCertificate = json_tokener_parse(payload);
  13150. if(!is_error(SignCertificate))
  13151. {
  13152. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13153. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13154. }
  13155. json_object_put(SignCertificate);
  13156. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13157. }
  13158. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13159. {
  13160. mtrace();
  13161. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13162. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13163. }
  13164. //==========================================
  13165. // Handle Error routine
  13166. //==========================================
  13167. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13168. {
  13169. mtrace();
  13170. #ifdef SystemLogMessage
  13171. DEBUG_INFO("errorCode: %s\n", errorCode);
  13172. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13173. DEBUG_INFO("errorDetails: %s\n", payload);
  13174. #endif
  13175. }
  13176. //===============================================
  13177. // Common routine
  13178. //===============================================
  13179. int initialConfigurationTable(void)
  13180. {
  13181. //clock_t start_t, end_t, total_t;
  13182. FILE *fp;
  13183. FILE *outfile;
  13184. char str[512]={0};
  13185. char sstr[256]={0};
  13186. int c = 0;
  13187. char *loc;
  13188. int confVersion = 13;
  13189. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13190. //start_t = clock();
  13191. //printf("Starting of the program, start_t = %ld\n", start_t);
  13192. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13193. // Check configuration file size is correct
  13194. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13195. {
  13196. struct stat st;
  13197. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13198. if(st.st_size < 3100)
  13199. {
  13200. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13201. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13202. }
  13203. }
  13204. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13205. {
  13206. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13207. if(outfile == NULL)
  13208. {
  13209. DEBUG_INFO("Error opening file\n");
  13210. return FALSE;
  13211. }
  13212. /*Core Profile*/
  13213. //AllowOfflineTxForUnknownId
  13214. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13218. //AuthorizationCacheEnabled
  13219. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13223. //AuthorizeRemoteTxRequests
  13224. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13228. //BlinkRepeat
  13229. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13233. //ClockAlignedDataInterval
  13234. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13238. //ConnectionTimeOut
  13239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13243. //GetConfigurationMaxKeys
  13244. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13246. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13248. // HeartbeatInterval
  13249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13253. // LightIntensity
  13254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13258. // LocalAuthorizeOffline
  13259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13263. // LocalPreAuthorize
  13264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13268. // MaxEnergyOnInvalidId
  13269. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13273. // MeterValuesAlignedData
  13274. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13278. else
  13279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13281. // MeterValuesAlignedDataMaxLength
  13282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13286. else
  13287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13289. // MeterValuesSampledData
  13290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13294. else
  13295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13297. // MeterValuesSampledDataMaxLength
  13298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13302. else
  13303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13305. // MeterValueSampleInterval
  13306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13310. // MinimumStatusDuration
  13311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13314. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13316. // NumberOfConnectors
  13317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13320. {
  13321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13322. }
  13323. else
  13324. {
  13325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13326. }
  13327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13328. // ResetRetries
  13329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13333. // ConnectorPhaseRotation
  13334. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13338. // ConnectorPhaseRotationMaxLength
  13339. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13343. // StopTransactionOnEVSideDisconnect
  13344. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13345. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13348. // StopTransactionOnInvalidId
  13349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13353. // StopTxnAlignedData
  13354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13358. // StopTxnAlignedDataMaxLength
  13359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13363. // StopTxnSampledData
  13364. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13365. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13368. else
  13369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13371. // StopTxnSampledDataMaxLength
  13372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13374. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13375. {
  13376. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13377. }
  13378. else
  13379. {
  13380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13381. }
  13382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13383. // SupportedFeatureProfiles
  13384. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13388. // SupportedFeatureProfilesMaxLength
  13389. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13393. // TransactionMessageAttempts
  13394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13396. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13397. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13399. // TransactionMessageRetryInterval
  13400. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13403. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13405. // UnlockConnectorOnEVSideDisconnect
  13406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13410. // WebSocketPingInterval
  13411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13415. // QueueOffLineMeterValues
  13416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13420. // AuthorizationKey
  13421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13425. // SecurityProfile
  13426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13430. // DefaultPrice
  13431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13435. // CustomDisplayCostAndPrice
  13436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13440. // CustomIdleFeeAfterStop
  13441. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13445. // SystemUptimeSec
  13446. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13450. // FreeVend
  13451. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13453. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13455. // FreeVendIdtag
  13456. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13460. // OcppServer
  13461. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13463. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13465. // MaintainServer
  13466. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13468. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13470. // StatusNotificationPeriodically
  13471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13475. // StatusNotificationInterval
  13476. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13478. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13480. // Configuration Version
  13481. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13485. //* Local Auth List Management Profile*/
  13486. #if 0
  13487. //For OCTT Test Case
  13488. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13490. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13491. #endif
  13492. #if 1
  13493. //LocalAuthListEnabled
  13494. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13496. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13498. #endif
  13499. //LocalAuthListMaxLength
  13500. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13501. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13504. //SendLocalListMaxLength
  13505. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13506. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13507. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13509. //ReserveConnectorZeroSupported
  13510. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13514. //* Smart Charging Profile */
  13515. //ChargeProfileMaxStackLevel
  13516. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13517. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13520. // ChargingScheduleAllowedChargingRateUnit
  13521. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13523. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13525. // ChargingScheduleMaxPeriods
  13526. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13530. // ConnectorSwitch3to1PhaseSupported
  13531. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13532. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13535. // MaxChargingProfilesInstalled
  13536. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13537. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13538. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13540. fclose(outfile);
  13541. }
  13542. else
  13543. {
  13544. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13545. char keystr[60]={0};
  13546. char readonlystr[10]={0};
  13547. char valuestr[256]={0};
  13548. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13549. if(fp == NULL) {
  13550. DEBUG_INFO("Error opening file");
  13551. return FALSE;
  13552. }
  13553. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13554. {
  13555. //DEBUG_INFO("Get Configuration \n");
  13556. if(strlen(str) > 0)
  13557. {
  13558. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13559. //*************************key*********************************/
  13560. if(strstr(str, "key") != NULL)
  13561. {
  13562. loc = strstr(str, "key");
  13563. c = 0;
  13564. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13565. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13566. {
  13567. sstr[c] = loc[strlen("key")+3+c];
  13568. c++;
  13569. }
  13570. sstr[c] = '\0';
  13571. strcpy(keystr,sstr);
  13572. }
  13573. //*************************readonly*********************************/
  13574. if(strstr(str, "readonly") != NULL)
  13575. {
  13576. loc = strstr(str, "readonly");
  13577. c = 0;
  13578. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13579. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13580. {
  13581. sstr[c] = loc[strlen("readonly")+2+c];
  13582. c++;
  13583. }
  13584. sstr[c] = '\0';
  13585. strcpy(readonlystr,sstr);
  13586. }
  13587. //*************************value*********************************/
  13588. if(strstr(str, "value") != NULL)
  13589. {
  13590. loc = strstr(str, "value");
  13591. c = 0;
  13592. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13593. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13594. {
  13595. sstr[c] = loc[strlen("value")+3+c];
  13596. c++;
  13597. }
  13598. sstr[c] = '\0';
  13599. strcpy(valuestr,sstr);
  13600. }
  13601. // DEBUG_INFO("keystr=%s\n",keystr);
  13602. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13603. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13604. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13605. {
  13606. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13609. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13610. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13611. }
  13612. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13613. {
  13614. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13615. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13616. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13617. }
  13618. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13619. {
  13620. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13621. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13622. }
  13623. if(strcmp(keystr, "BlinkRepeat") == 0)
  13624. {
  13625. //Charger.BlinkRepeat = Integer.parseInt(value);
  13626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13627. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13628. }
  13629. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13630. {
  13631. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13633. }
  13634. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13635. {
  13636. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13638. }
  13639. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13640. {
  13641. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13643. }
  13644. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13645. {
  13646. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13648. HeartBeatWaitTime = atoi(valuestr);
  13649. }
  13650. if(strcmp(keystr, "LightIntensity") == 0)
  13651. {
  13652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13654. }
  13655. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13656. {
  13657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13659. }
  13660. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13661. {
  13662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13663. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13664. }
  13665. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13666. {
  13667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13668. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13669. }
  13670. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13671. {
  13672. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13674. }
  13675. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13676. {
  13677. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13678. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13679. }
  13680. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13681. {
  13682. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13683. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13684. }
  13685. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13686. {
  13687. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13688. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13689. }
  13690. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13691. {
  13692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13693. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13694. }
  13695. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13696. {
  13697. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13699. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13700. }
  13701. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13702. {
  13703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13705. }
  13706. if(strcmp(keystr, "ResetRetries") == 0)
  13707. {
  13708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13710. }
  13711. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13712. {
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13714. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13715. }
  13716. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13717. {
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13720. }
  13721. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13722. {
  13723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13725. }
  13726. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13727. {
  13728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13730. }
  13731. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13732. {
  13733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13735. }
  13736. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13737. {
  13738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13740. }
  13741. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13742. {
  13743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13745. }
  13746. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13747. {
  13748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13750. }
  13751. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13752. {
  13753. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13755. }
  13756. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13757. {
  13758. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13759. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13760. }
  13761. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13762. {
  13763. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13765. TransactionMessageAttemptsValue = atoi(valuestr);
  13766. }
  13767. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13768. {
  13769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13770. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13771. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13772. }
  13773. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13774. {
  13775. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13777. }
  13778. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13779. {
  13780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13782. }
  13783. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13784. {
  13785. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13787. }
  13788. if(strcmp(keystr, "AuthorizationKey") == 0)
  13789. {
  13790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13791. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13793. }
  13794. if(strcmp(keystr, "SecurityProfile") == 0)
  13795. {
  13796. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13797. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13798. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13799. }
  13800. if(strcmp(keystr, "DefaultPrice") == 0)
  13801. {
  13802. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13804. }
  13805. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13806. {
  13807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13809. }
  13810. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13811. {
  13812. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13813. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13814. }
  13815. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13816. {
  13817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13818. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13819. }
  13820. if(strcmp(keystr, "FreeVend") == 0)
  13821. {
  13822. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13823. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13824. }
  13825. if(strcmp(keystr, "FreeVendIdtag") == 0)
  13826. {
  13827. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  13829. }
  13830. if(strcmp(keystr, "OcppServer") == 0)
  13831. {
  13832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13833. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13834. }
  13835. if(strcmp(keystr, "MaintainServer") == 0)
  13836. {
  13837. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13838. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13839. }
  13840. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13841. {
  13842. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13843. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13844. }
  13845. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13846. {
  13847. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13848. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13849. }
  13850. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13851. {
  13852. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13854. }
  13855. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13856. {
  13857. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13858. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13859. }
  13860. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13861. {
  13862. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13863. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13864. }
  13865. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13866. {
  13867. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13868. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13869. }
  13870. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13871. {
  13872. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13873. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13874. }
  13875. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13876. {
  13877. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13878. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13879. }
  13880. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13881. {
  13882. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13883. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13884. }
  13885. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13886. {
  13887. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13888. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13889. }
  13890. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13891. {
  13892. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13894. }
  13895. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13896. {
  13897. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13898. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13899. }
  13900. }
  13901. }
  13902. fclose(fp);
  13903. }
  13904. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13905. {
  13906. return PASS;
  13907. }
  13908. else
  13909. {
  13910. return FAIL;
  13911. }
  13912. }
  13913. void StoreConfigurationTable(void)
  13914. {
  13915. FILE *outfile;
  13916. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13917. if(outfile == NULL)
  13918. {
  13919. DEBUG_INFO("Error opening file");
  13920. return ;
  13921. }
  13922. /*Core Profile*/
  13923. //AllowOfflineTxForUnknownId
  13924. /*
  13925. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13926. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13929. */
  13930. //DEBUG_INFO("data=%s\n",data);
  13931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13932. //AuthorizationCacheEnabled
  13933. /*
  13934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13937. */
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13939. //AuthorizeRemoteTxRequests
  13940. /*
  13941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13944. */
  13945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13946. //BlinkRepeat
  13947. /*
  13948. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13951. */
  13952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13953. //ClockAlignedDataInterval
  13954. /*
  13955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13958. */
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13960. //ConnectionTimeOut
  13961. /*
  13962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13965. */
  13966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13967. //GetConfigurationMaxKeys
  13968. /*
  13969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13972. */
  13973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13974. // HeartbeatInterval
  13975. /*
  13976. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13979. */
  13980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13981. // LightIntensity
  13982. /*
  13983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13986. */
  13987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13988. // LocalAuthorizeOffline
  13989. /*
  13990. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13993. */
  13994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13995. // LocalPreAuthorize
  13996. /*
  13997. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14000. */
  14001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14002. // MaxEnergyOnInvalidId
  14003. /*
  14004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14007. */
  14008. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14010. // MeterValuesAlignedData
  14011. /*
  14012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14015. */
  14016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14017. // MeterValuesAlignedDataMaxLength
  14018. /*
  14019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14022. */
  14023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14024. // MeterValuesSampledData
  14025. /*
  14026. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14029. */
  14030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14031. // MeterValuesSampledDataMaxLength
  14032. /*
  14033. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14036. */
  14037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14038. // MeterValueSampleInterval
  14039. /*
  14040. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14043. */
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14045. // MinimumStatusDuration
  14046. /*
  14047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14050. */
  14051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14052. // NumberOfConnectors
  14053. /*
  14054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14057. {
  14058. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14059. }
  14060. else
  14061. {
  14062. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14063. }
  14064. */
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14066. // ResetRetries
  14067. /*
  14068. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14071. */
  14072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14073. // ConnectorPhaseRotation
  14074. /*
  14075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14078. */
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14080. // ConnectorPhaseRotationMaxLength
  14081. /*
  14082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14085. */
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14087. // StopTransactionOnEVSideDisconnect
  14088. /*
  14089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14092. */
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14094. // StopTransactionOnInvalidId
  14095. /*
  14096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14099. */
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14101. // StopTxnAlignedData
  14102. /*
  14103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14106. */
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14108. // StopTxnAlignedDataMaxLength
  14109. /*
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14113. */
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14115. // StopTxnSampledData
  14116. /*
  14117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14120. */
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14122. // StopTxnSampledDataMaxLength
  14123. /*
  14124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14127. */
  14128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14129. // SupportedFeatureProfiles
  14130. /*
  14131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14134. */
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14136. // SupportedFeatureProfilesMaxLength
  14137. /*
  14138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14141. */
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14143. // TransactionMessageAttempts
  14144. /*
  14145. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14148. */
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14150. // TransactionMessageRetryInterval
  14151. /*
  14152. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14155. */
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14157. // UnlockConnectorOnEVSideDisconnect
  14158. /*
  14159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14162. */
  14163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14164. // WebSocketPingInterval
  14165. /*
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14169. */
  14170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14171. // QueueOffLineMeterValues
  14172. /*
  14173. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14176. */
  14177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14178. // AuthorizationKey
  14179. /*
  14180. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14183. */
  14184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14185. // SecurityProfile
  14186. /*
  14187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14190. */
  14191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14192. // DefaultPrice
  14193. /*
  14194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14197. */
  14198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14199. // CustomDisplayCostAndPrice
  14200. /*
  14201. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14204. */
  14205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14206. // CustomIdleFeeAfterStop
  14207. /*
  14208. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14211. */
  14212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14213. // SystemUptimeSec
  14214. /*
  14215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14218. */
  14219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14220. // FreeVend
  14221. /*
  14222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14225. */
  14226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14227. // FreeVendIdtag
  14228. /*
  14229. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14232. */
  14233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14234. // OcppServer
  14235. /*
  14236. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14237. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14238. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14239. */
  14240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14241. // MaintainServer
  14242. /*
  14243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14246. */
  14247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14248. // StatusNotificationPeriodically
  14249. /*
  14250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14252. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14253. */
  14254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14255. // StatusNotificationInterval
  14256. /*
  14257. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14258. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14260. */
  14261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14262. // ConfigurationVersion
  14263. /*
  14264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14267. */
  14268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14269. //* Local Auth List Management Profile*/
  14270. //LocalAuthListEnabled
  14271. /*
  14272. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14273. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14275. */
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14277. //LocalAuthListMaxLength
  14278. /*
  14279. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14280. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14281. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14282. */
  14283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14284. //SendLocalListMaxLength
  14285. /*
  14286. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14289. */
  14290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14291. //ReserveConnectorZeroSupported
  14292. /*
  14293. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14296. */
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14298. //* Smart Charging Profile */
  14299. //ChargeProfileMaxStackLevel
  14300. /*
  14301. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14304. */
  14305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14306. // ChargingScheduleAllowedChargingRateUnit
  14307. /*
  14308. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14311. */
  14312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14313. // ChargingScheduleMaxPeriods
  14314. /*
  14315. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14318. */
  14319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14320. // ConnectorSwitch3to1PhaseSupported
  14321. /*
  14322. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14325. */
  14326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14327. // MaxChargingProfilesInstalled
  14328. /*
  14329. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14332. */
  14333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14334. fclose(outfile);
  14335. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14336. }
  14337. void getKeyValue(char *keyReq)
  14338. {
  14339. int isEmpty = FALSE;
  14340. int isKnowKey = FALSE;
  14341. DEBUG_INFO("keyReq = %s\n", keyReq);
  14342. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14343. isEmpty = TRUE;
  14344. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14345. {
  14346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14348. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14349. {
  14350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14351. }
  14352. else
  14353. {
  14354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14355. }
  14356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14357. isKnowKey = TRUE;
  14358. }
  14359. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14360. {
  14361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14363. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14364. {
  14365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14366. }
  14367. else
  14368. {
  14369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14370. }
  14371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14372. isKnowKey = TRUE;
  14373. }
  14374. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14375. {
  14376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14378. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14379. {
  14380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14381. }
  14382. else
  14383. {
  14384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14385. }
  14386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14387. isKnowKey = TRUE;
  14388. }
  14389. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14390. {
  14391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14394. {
  14395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14396. }
  14397. else
  14398. {
  14399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14400. }
  14401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14402. isKnowKey = TRUE;
  14403. }
  14404. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14405. {
  14406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14408. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14409. {
  14410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14411. }
  14412. else
  14413. {
  14414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14415. }
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14417. isKnowKey = TRUE;
  14418. }
  14419. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14420. {
  14421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14423. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14424. {
  14425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14426. }
  14427. else
  14428. {
  14429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14430. }
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14432. isKnowKey = TRUE;
  14433. }
  14434. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14435. {
  14436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14438. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14439. {
  14440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14441. }
  14442. else
  14443. {
  14444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14445. }
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14447. isKnowKey = TRUE;
  14448. }
  14449. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14450. {
  14451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14453. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14454. {
  14455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14456. }
  14457. else
  14458. {
  14459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14460. }
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14462. isKnowKey = TRUE;
  14463. }
  14464. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14465. {
  14466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14468. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14469. {
  14470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14471. }
  14472. else
  14473. {
  14474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14475. }
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14477. isKnowKey = TRUE;
  14478. }
  14479. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14480. {
  14481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14484. {
  14485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14486. }
  14487. else
  14488. {
  14489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14490. }
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14492. isKnowKey = TRUE;
  14493. }
  14494. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14495. {
  14496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14498. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14499. {
  14500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14501. }
  14502. else
  14503. {
  14504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14505. }
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14507. isKnowKey = TRUE;
  14508. }
  14509. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14510. {
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14513. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14514. {
  14515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14516. }
  14517. else
  14518. {
  14519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14520. }
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14522. isKnowKey = TRUE;
  14523. }
  14524. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14525. {
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14528. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14529. {
  14530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14531. }
  14532. else
  14533. {
  14534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14535. }
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14537. isKnowKey = TRUE;
  14538. }
  14539. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14540. {
  14541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14543. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14544. {
  14545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14546. }
  14547. else
  14548. {
  14549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14550. }
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14552. isKnowKey = TRUE;
  14553. }
  14554. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14555. {
  14556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14558. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14559. {
  14560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14561. }
  14562. else
  14563. {
  14564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14565. }
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14567. isKnowKey = TRUE;
  14568. }
  14569. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14570. {
  14571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14573. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14574. {
  14575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14576. }
  14577. else
  14578. {
  14579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14580. }
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14582. isKnowKey = TRUE;
  14583. }
  14584. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14585. {
  14586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14588. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14589. {
  14590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14591. }
  14592. else
  14593. {
  14594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14595. }
  14596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14597. isKnowKey = TRUE;
  14598. }
  14599. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14600. {
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14603. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14604. {
  14605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14606. }
  14607. else
  14608. {
  14609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14610. }
  14611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14612. isKnowKey = TRUE;
  14613. }
  14614. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14615. {
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14619. {
  14620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14621. }
  14622. else
  14623. {
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14625. }
  14626. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14628. isKnowKey = TRUE;
  14629. }
  14630. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14631. {
  14632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14634. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14635. {
  14636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14637. }
  14638. else
  14639. {
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14641. }
  14642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14643. isKnowKey = TRUE;
  14644. }
  14645. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14646. {
  14647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14649. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14650. {
  14651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14652. }
  14653. else
  14654. {
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14656. }
  14657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14658. isKnowKey = TRUE;
  14659. }
  14660. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14661. {
  14662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14664. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14665. {
  14666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14667. }
  14668. else
  14669. {
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14671. }
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14673. isKnowKey = TRUE;
  14674. }
  14675. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14676. {
  14677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14680. {
  14681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14682. }
  14683. else
  14684. {
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14686. }
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14688. isKnowKey = TRUE;
  14689. }
  14690. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14691. {
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14694. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14695. {
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14697. }
  14698. else
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14701. }
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14703. isKnowKey = TRUE;
  14704. }
  14705. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14706. {
  14707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14709. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14710. {
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14712. }
  14713. else
  14714. {
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14716. }
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14718. isKnowKey = TRUE;
  14719. }
  14720. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14721. {
  14722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14724. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14725. {
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14727. }
  14728. else
  14729. {
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14731. }
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14733. isKnowKey = TRUE;
  14734. }
  14735. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14736. {
  14737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14739. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14740. {
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14742. }
  14743. else
  14744. {
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14746. }
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14748. isKnowKey = TRUE;
  14749. }
  14750. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14751. {
  14752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14754. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14755. {
  14756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14757. }
  14758. else
  14759. {
  14760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14761. }
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14763. isKnowKey = TRUE;
  14764. }
  14765. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14766. {
  14767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14769. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14770. {
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14772. }
  14773. else
  14774. {
  14775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14776. }
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14778. isKnowKey = TRUE;
  14779. }
  14780. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14781. {
  14782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14784. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14785. {
  14786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14787. }
  14788. else
  14789. {
  14790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14791. }
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14793. isKnowKey = TRUE;
  14794. }
  14795. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14796. {
  14797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14799. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14800. {
  14801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14802. }
  14803. else
  14804. {
  14805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14806. }
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14808. isKnowKey = TRUE;
  14809. }
  14810. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14811. {
  14812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14814. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14815. {
  14816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14817. }
  14818. else
  14819. {
  14820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14821. }
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14823. isKnowKey = TRUE;
  14824. }
  14825. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14826. {
  14827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14829. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14830. {
  14831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14832. }
  14833. else
  14834. {
  14835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14836. }
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14838. isKnowKey = TRUE;
  14839. }
  14840. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14841. {
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14844. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14845. {
  14846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14847. }
  14848. else
  14849. {
  14850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14851. }
  14852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14853. isKnowKey = TRUE;
  14854. }
  14855. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14856. {
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14860. {
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14862. }
  14863. else
  14864. {
  14865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14866. }
  14867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14868. isKnowKey = TRUE;
  14869. }
  14870. /*
  14871. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14872. {
  14873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14875. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14876. {
  14877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14878. }
  14879. else
  14880. {
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14882. }
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14884. isKnowKey = TRUE;
  14885. }*/
  14886. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14887. {
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14890. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14891. {
  14892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14893. }
  14894. else
  14895. {
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14897. }
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14899. isKnowKey = TRUE;
  14900. }
  14901. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14902. {
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14905. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14906. {
  14907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14908. }
  14909. else
  14910. {
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14912. }
  14913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14914. isKnowKey = TRUE;
  14915. }
  14916. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14917. {
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14920. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14921. {
  14922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14923. }
  14924. else
  14925. {
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14927. }
  14928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14929. isKnowKey = TRUE;
  14930. }
  14931. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14932. {
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14935. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14936. {
  14937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14938. }
  14939. else
  14940. {
  14941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14942. }
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14944. isKnowKey = TRUE;
  14945. }
  14946. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14947. {
  14948. struct sysinfo s_info;
  14949. int error = sysinfo(&s_info);
  14950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14952. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14953. {
  14954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14955. }
  14956. else
  14957. {
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14959. }
  14960. if(error != 0)
  14961. {
  14962. DEBUG_WARN("System uptime get error: %d\n", error);
  14963. }
  14964. else
  14965. {
  14966. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14967. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14968. }
  14969. isKnowKey = TRUE;
  14970. }
  14971. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14972. {
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14975. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14978. }
  14979. else
  14980. {
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14982. }
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14984. isKnowKey = TRUE;
  14985. }
  14986. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  14987. {
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  14989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  14990. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  14991. {
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  14993. }
  14994. else
  14995. {
  14996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  14997. }
  14998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14999. isKnowKey = TRUE;
  15000. }
  15001. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15002. {
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15005. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15006. {
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15008. }
  15009. else
  15010. {
  15011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15012. }
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15014. isKnowKey = TRUE;
  15015. }
  15016. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15017. {
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15020. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15023. }
  15024. else
  15025. {
  15026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15027. }
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15029. isKnowKey = TRUE;
  15030. }
  15031. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15032. {
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15035. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15036. {
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15038. }
  15039. else
  15040. {
  15041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15042. }
  15043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15044. isKnowKey = TRUE;
  15045. }
  15046. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15050. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15053. }
  15054. else
  15055. {
  15056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15057. }
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15059. isKnowKey = TRUE;
  15060. }
  15061. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15062. {
  15063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15065. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15066. {
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15068. }
  15069. else
  15070. {
  15071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15072. }
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15074. isKnowKey = TRUE;
  15075. }
  15076. #if 1
  15077. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15081. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15084. }
  15085. else
  15086. {
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15088. }
  15089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15090. isKnowKey = TRUE;
  15091. }
  15092. #endif
  15093. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15094. {
  15095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15097. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15098. {
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15100. }
  15101. else
  15102. {
  15103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15104. }
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15106. isKnowKey = TRUE;
  15107. }
  15108. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15109. {
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15112. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15113. {
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15115. }
  15116. else
  15117. {
  15118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15119. }
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15121. isKnowKey = TRUE;
  15122. }
  15123. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15124. {
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15127. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15128. {
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15130. }
  15131. else
  15132. {
  15133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15134. }
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15136. isKnowKey = TRUE;
  15137. }
  15138. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15139. {
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15142. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15143. {
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15145. }
  15146. else
  15147. {
  15148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15149. }
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15151. isKnowKey = TRUE;
  15152. }
  15153. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15154. {
  15155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15157. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15158. {
  15159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15160. }
  15161. else
  15162. {
  15163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15164. }
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15166. isKnowKey = TRUE;
  15167. }
  15168. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15169. {
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15172. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15173. {
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15175. }
  15176. else
  15177. {
  15178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15179. }
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15181. isKnowKey = TRUE;
  15182. }
  15183. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15184. {
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15187. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15188. {
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15190. }
  15191. else
  15192. {
  15193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15194. }
  15195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15196. isKnowKey = TRUE;
  15197. }
  15198. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15199. {
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15202. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15203. {
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15205. }
  15206. else
  15207. {
  15208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15209. }
  15210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15211. isKnowKey = TRUE;
  15212. }
  15213. //=========================================================
  15214. if(!isEmpty && !isKnowKey)
  15215. {
  15216. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15217. strcpy(unknownkey[UnknownKeynum], keyReq);
  15218. UnknownKeynum = UnknownKeynum + 1;
  15219. }
  15220. }
  15221. void processUnkownKey(void)
  15222. {
  15223. DEBUG_INFO("processUnkownKey...\n");
  15224. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15225. for(int index=0; index < UnknownKeynum; index++)
  15226. {
  15227. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15228. {
  15229. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15230. }
  15231. }
  15232. }
  15233. int setKeyValue(char *key, char *value)
  15234. {
  15235. int isSuccess = NotSupported;
  15236. int check_ascii=0;
  15237. char str[501]={0};
  15238. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15239. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15240. {
  15241. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15242. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15243. {
  15244. strcpy(str, (const char*)value);
  15245. for(int i = 0; str[i]; i++){
  15246. str[i] = tolower(str[i]);
  15247. }
  15248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15249. isSuccess = ConfigurationStatus_Accepted;
  15250. }
  15251. else
  15252. {
  15253. isSuccess = ConfigurationStatus_Rejected;
  15254. }
  15255. }
  15256. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15257. {
  15258. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15260. {
  15261. strcpy(str, (const char*)value);
  15262. for(int i = 0; str[i]; i++){
  15263. str[i] = tolower(str[i]);
  15264. }
  15265. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15266. isSuccess = ConfigurationStatus_Accepted;
  15267. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15268. }
  15269. else
  15270. {
  15271. isSuccess = ConfigurationStatus_Rejected;
  15272. }
  15273. }
  15274. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15275. {
  15276. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15277. {
  15278. strcpy(str, (const char*)value);
  15279. for(int i = 0; str[i]; i++)
  15280. {
  15281. str[i] = tolower(str[i]);
  15282. }
  15283. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15284. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15285. isSuccess = ConfigurationStatus_Accepted;
  15286. }
  15287. else
  15288. {
  15289. isSuccess = ConfigurationStatus_Rejected;
  15290. }
  15291. }
  15292. if(strcmp(key, "BlinkRepeat") == 0)
  15293. {
  15294. //Charger.BlinkRepeat = Integer.parseInt(value);
  15295. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15296. {
  15297. check_ascii = value[0];
  15298. if( (check_ascii < 48) || (check_ascii > 57) )
  15299. {
  15300. isSuccess = ConfigurationStatus_Rejected;
  15301. }
  15302. else
  15303. {
  15304. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15305. isSuccess = ConfigurationStatus_Accepted;
  15306. }
  15307. }
  15308. else
  15309. {
  15310. isSuccess = ConfigurationStatus_Rejected;
  15311. }
  15312. }
  15313. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15314. {
  15315. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15316. {
  15317. check_ascii = value[0];
  15318. if( (check_ascii < 48) || (check_ascii > 57) )
  15319. {
  15320. isSuccess = ConfigurationStatus_Rejected;
  15321. }
  15322. else
  15323. {
  15324. if((atoi(value) == 0) || (atoi(value) >= 5))
  15325. {
  15326. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15328. isSuccess = ConfigurationStatus_Accepted;
  15329. }
  15330. else
  15331. isSuccess = ConfigurationStatus_Rejected;
  15332. }
  15333. }
  15334. else
  15335. {
  15336. isSuccess = ConfigurationStatus_Rejected;
  15337. }
  15338. }
  15339. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15340. {
  15341. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15342. {
  15343. check_ascii = value[0];
  15344. if( (check_ascii < 48) || (check_ascii > 57) )
  15345. {
  15346. isSuccess = ConfigurationStatus_Rejected;
  15347. }
  15348. else
  15349. {
  15350. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15352. isSuccess = ConfigurationStatus_Accepted;
  15353. }
  15354. }
  15355. else
  15356. {
  15357. isSuccess = ConfigurationStatus_Rejected;
  15358. }
  15359. }
  15360. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15361. {
  15362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15363. {
  15364. check_ascii = value[0];
  15365. if( (check_ascii < 48) || (check_ascii > 57) )
  15366. {
  15367. isSuccess = ConfigurationStatus_Rejected;
  15368. }
  15369. else
  15370. {
  15371. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15372. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15373. isSuccess = ConfigurationStatus_Accepted;
  15374. }
  15375. }
  15376. else
  15377. {
  15378. isSuccess = ConfigurationStatus_Rejected;
  15379. }
  15380. }
  15381. if(strcmp(key, "HeartbeatInterval") == 0)
  15382. {
  15383. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15384. {
  15385. check_ascii = value[0];
  15386. if( (check_ascii < 48) || (check_ascii > 57) )
  15387. {
  15388. isSuccess = ConfigurationStatus_Rejected;
  15389. }
  15390. else
  15391. {
  15392. if((atoi(value) == 0) || (atoi(value) >= 10))
  15393. {
  15394. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15396. HeartBeatWaitTime = atoi(value);
  15397. isSuccess = ConfigurationStatus_Accepted;
  15398. }
  15399. else
  15400. {
  15401. isSuccess = ConfigurationStatus_Rejected;
  15402. }
  15403. }
  15404. }
  15405. else
  15406. {
  15407. isSuccess = ConfigurationStatus_Rejected;
  15408. }
  15409. }
  15410. if(strcmp(key, "LightIntensity") == 0)
  15411. {
  15412. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15413. {
  15414. check_ascii = value[0];
  15415. if( (check_ascii < 48) || (check_ascii > 57) )
  15416. {
  15417. isSuccess = ConfigurationStatus_Rejected;
  15418. }
  15419. else
  15420. {
  15421. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15422. isSuccess = ConfigurationStatus_Accepted;
  15423. }
  15424. }
  15425. else
  15426. {
  15427. isSuccess = ConfigurationStatus_Rejected;
  15428. }
  15429. }
  15430. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15431. {
  15432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15433. {
  15434. strcpy(str, (const char*)value);
  15435. for(int i = 0; str[i]; i++)
  15436. {
  15437. str[i] = tolower(str[i]);
  15438. }
  15439. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15440. isSuccess = ConfigurationStatus_Accepted;
  15441. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15442. }
  15443. else
  15444. {
  15445. isSuccess = ConfigurationStatus_Rejected;
  15446. }
  15447. }
  15448. if(strcmp(key, "LocalPreAuthorize") == 0)
  15449. {
  15450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15451. {
  15452. strcpy(str, (const char*)value);
  15453. for(int i = 0; str[i]; i++)
  15454. {
  15455. str[i] = tolower(str[i]);
  15456. }
  15457. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15458. isSuccess = ConfigurationStatus_Accepted;
  15459. }
  15460. else
  15461. {
  15462. isSuccess = ConfigurationStatus_Rejected;
  15463. }
  15464. }
  15465. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15466. {
  15467. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15468. {
  15469. check_ascii = value[0];
  15470. if( (check_ascii < 48) || (check_ascii > 57) )
  15471. {
  15472. isSuccess = ConfigurationStatus_Rejected;
  15473. }
  15474. else
  15475. {
  15476. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15477. isSuccess = ConfigurationStatus_Accepted;
  15478. }
  15479. }
  15480. else
  15481. {
  15482. isSuccess = ConfigurationStatus_Rejected;
  15483. }
  15484. }
  15485. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15486. {
  15487. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15488. {
  15489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15490. isSuccess = ConfigurationStatus_Accepted;
  15491. }
  15492. else
  15493. {
  15494. isSuccess = ConfigurationStatus_Rejected;
  15495. }
  15496. }
  15497. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15498. {
  15499. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15500. {
  15501. check_ascii = value[0];
  15502. if( (check_ascii < 48) || (check_ascii > 57) )
  15503. {
  15504. isSuccess = ConfigurationStatus_Rejected;
  15505. }
  15506. else
  15507. {
  15508. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15509. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15510. isSuccess = ConfigurationStatus_Accepted;
  15511. }
  15512. }
  15513. else
  15514. {
  15515. isSuccess = ConfigurationStatus_Rejected;
  15516. }
  15517. }
  15518. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15519. {
  15520. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15521. {
  15522. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15523. isSuccess = ConfigurationStatus_Accepted;
  15524. }
  15525. else
  15526. {
  15527. isSuccess = ConfigurationStatus_Rejected;
  15528. }
  15529. }
  15530. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15531. {
  15532. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15533. {
  15534. check_ascii = value[0];
  15535. if( (check_ascii < 48) || (check_ascii > 57) )
  15536. {
  15537. isSuccess = ConfigurationStatus_Rejected;
  15538. }
  15539. else
  15540. {
  15541. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15543. isSuccess = ConfigurationStatus_Accepted;
  15544. }
  15545. }
  15546. else
  15547. {
  15548. isSuccess = ConfigurationStatus_Rejected;
  15549. }
  15550. }
  15551. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15552. {
  15553. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15554. {
  15555. check_ascii = value[0];
  15556. if( (check_ascii < 48) || (check_ascii > 57) )
  15557. {
  15558. isSuccess = ConfigurationStatus_Rejected;
  15559. }
  15560. else
  15561. {
  15562. if((atoi(value) == 0) || (atoi(value) >= 3))
  15563. {
  15564. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15565. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15566. isSuccess = ConfigurationStatus_Accepted;
  15567. }
  15568. else
  15569. {
  15570. isSuccess = ConfigurationStatus_Rejected;
  15571. }
  15572. }
  15573. }
  15574. else
  15575. {
  15576. isSuccess = ConfigurationStatus_Rejected;
  15577. }
  15578. }
  15579. if(strcmp(key, "MinimumStatusDuration") == 0)
  15580. {
  15581. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15582. {
  15583. check_ascii = value[0];
  15584. if( (check_ascii < 48) || (check_ascii > 57) )
  15585. {
  15586. isSuccess = ConfigurationStatus_Rejected;
  15587. }
  15588. else
  15589. {
  15590. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15591. {
  15592. isSuccess = ConfigurationStatus_Rejected;
  15593. }
  15594. else
  15595. {
  15596. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15597. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15598. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15599. isSuccess = ConfigurationStatus_Accepted;
  15600. }
  15601. }
  15602. }
  15603. else
  15604. {
  15605. isSuccess = ConfigurationStatus_Rejected;
  15606. }
  15607. }
  15608. if(strcmp(key, "NumberOfConnectors") == 0)
  15609. {
  15610. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15611. {
  15612. check_ascii = value[0];
  15613. if( (check_ascii < 48) || (check_ascii > 57) )
  15614. {
  15615. isSuccess = ConfigurationStatus_Rejected;
  15616. }
  15617. else
  15618. {
  15619. //Charger.ResetRetries = Integer.parseInt(value);
  15620. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15621. isSuccess = ConfigurationStatus_Accepted;
  15622. }
  15623. }
  15624. else
  15625. {
  15626. isSuccess = ConfigurationStatus_Rejected;
  15627. }
  15628. }
  15629. if(strcmp(key, "ResetRetries") == 0)
  15630. {
  15631. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15632. {
  15633. check_ascii = value[0];
  15634. if( (check_ascii < 48) || (check_ascii > 57) )
  15635. {
  15636. isSuccess = ConfigurationStatus_Rejected;
  15637. }
  15638. else
  15639. {
  15640. //Charger.ResetRetries = Integer.parseInt(value);
  15641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15642. isSuccess = ConfigurationStatus_Accepted;
  15643. }
  15644. }
  15645. else
  15646. {
  15647. isSuccess = ConfigurationStatus_Rejected;
  15648. }
  15649. }
  15650. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15651. {
  15652. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15653. {
  15654. strcpy(str, (const char*)value);
  15655. for(int i = 0; str[i]; i++)
  15656. {
  15657. str[i] = tolower(str[i]);
  15658. }
  15659. if(strcmp(str, "notapplicable")== 0)
  15660. {
  15661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15662. isSuccess = ConfigurationStatus_Accepted;
  15663. }
  15664. else if(strcmp(str, "unknown")== 0)
  15665. {
  15666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15667. isSuccess = ConfigurationStatus_Accepted;
  15668. }
  15669. else if(strcmp(str, "rst")== 0)
  15670. {
  15671. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15672. isSuccess = ConfigurationStatus_Accepted;
  15673. }
  15674. else if(strcmp(str, "rts")== 0)
  15675. {
  15676. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15677. isSuccess = ConfigurationStatus_Accepted;
  15678. }
  15679. else if(strcmp(str, "srt")== 0)
  15680. {
  15681. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15682. isSuccess = ConfigurationStatus_Accepted;
  15683. }
  15684. else if(strcmp(str, "str")== 0)
  15685. {
  15686. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15687. isSuccess = ConfigurationStatus_Accepted;
  15688. }
  15689. else if(strcmp(str, "trs")== 0)
  15690. {
  15691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15692. isSuccess = ConfigurationStatus_Accepted;
  15693. }
  15694. else if(strcmp(str, "tsr")== 0)
  15695. {
  15696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15697. isSuccess = ConfigurationStatus_Accepted;
  15698. }
  15699. else
  15700. {
  15701. isSuccess = ConfigurationStatus_Rejected;
  15702. }
  15703. }
  15704. else
  15705. {
  15706. isSuccess = ConfigurationStatus_Rejected;
  15707. }
  15708. }
  15709. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15710. {
  15711. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15712. {
  15713. check_ascii = value[0];
  15714. if( (check_ascii < 48) || (check_ascii > 57) )
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. else
  15719. {
  15720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15721. isSuccess = ConfigurationStatus_Accepted;
  15722. }
  15723. }
  15724. else
  15725. {
  15726. isSuccess = ConfigurationStatus_Rejected;
  15727. }
  15728. }
  15729. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15730. {
  15731. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15732. {
  15733. strcpy(str, (const char*)value);
  15734. for(int i = 0; str[i]; i++)
  15735. {
  15736. str[i] = tolower(str[i]);
  15737. }
  15738. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15740. isSuccess = ConfigurationStatus_Accepted;
  15741. }
  15742. else
  15743. {
  15744. isSuccess = ConfigurationStatus_Rejected;
  15745. }
  15746. }
  15747. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15748. {
  15749. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15750. {
  15751. strcpy(str, (const char*)value);
  15752. for(int i = 0; str[i]; i++)
  15753. {
  15754. str[i] = tolower(str[i]);
  15755. }
  15756. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15758. isSuccess = ConfigurationStatus_Accepted;
  15759. }
  15760. else
  15761. {
  15762. isSuccess = ConfigurationStatus_Rejected;
  15763. }
  15764. }
  15765. if(strcmp(key, "StopTxnAlignedData") == 0)
  15766. {
  15767. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15768. {
  15769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15770. isSuccess = ConfigurationStatus_Accepted;
  15771. }
  15772. else
  15773. {
  15774. isSuccess = ConfigurationStatus_Rejected;
  15775. }
  15776. }
  15777. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15778. {
  15779. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15780. {
  15781. check_ascii = value[0];
  15782. if( (check_ascii < 48) || (check_ascii > 57) )
  15783. {
  15784. isSuccess = ConfigurationStatus_Rejected;
  15785. }
  15786. else
  15787. {
  15788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15789. isSuccess = ConfigurationStatus_Accepted;
  15790. }
  15791. }
  15792. else
  15793. {
  15794. isSuccess = ConfigurationStatus_Rejected;
  15795. }
  15796. }
  15797. if(strcmp(key, "StopTxnSampledData") == 0)
  15798. {
  15799. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15800. {
  15801. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15802. isSuccess = ConfigurationStatus_Accepted;
  15803. }
  15804. else
  15805. {
  15806. isSuccess = ConfigurationStatus_Rejected;
  15807. }
  15808. }
  15809. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15810. {
  15811. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15812. {
  15813. check_ascii = value[0];
  15814. if( (check_ascii < 48) || (check_ascii > 57) )
  15815. {
  15816. isSuccess = ConfigurationStatus_Rejected;
  15817. }
  15818. else
  15819. {
  15820. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15821. isSuccess = ConfigurationStatus_Accepted;
  15822. }
  15823. }
  15824. else
  15825. {
  15826. isSuccess = ConfigurationStatus_Rejected;
  15827. }
  15828. }
  15829. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15830. {
  15831. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15832. {
  15833. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15834. isSuccess = ConfigurationStatus_Accepted;
  15835. }
  15836. else
  15837. {
  15838. isSuccess = ConfigurationStatus_Rejected;
  15839. }
  15840. }
  15841. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15842. {
  15843. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15844. {
  15845. check_ascii = value[0];
  15846. if( (check_ascii < 48) || (check_ascii > 57) )
  15847. {
  15848. isSuccess = ConfigurationStatus_Rejected;
  15849. }
  15850. else
  15851. {
  15852. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15853. isSuccess = ConfigurationStatus_Accepted;
  15854. }
  15855. }
  15856. else
  15857. {
  15858. isSuccess = ConfigurationStatus_Rejected;
  15859. }
  15860. }
  15861. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15862. {
  15863. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15864. {
  15865. check_ascii = value[0];
  15866. if( (check_ascii < 48) || (check_ascii > 57) )
  15867. {
  15868. isSuccess = ConfigurationStatus_Rejected;
  15869. }
  15870. else
  15871. {
  15872. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15873. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15874. TransactionMessageAttemptsValue = atoi(value);
  15875. isSuccess = ConfigurationStatus_Accepted;
  15876. }
  15877. }
  15878. else
  15879. {
  15880. isSuccess = ConfigurationStatus_Rejected;
  15881. }
  15882. }
  15883. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15884. {
  15885. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15886. {
  15887. check_ascii = value[0];
  15888. if( (check_ascii < 48) || (check_ascii > 57) )
  15889. {
  15890. isSuccess = ConfigurationStatus_Rejected;
  15891. }
  15892. else
  15893. {
  15894. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15895. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15896. TransactionMessageRetryIntervalValue = atoi(value);
  15897. isSuccess = ConfigurationStatus_Accepted;
  15898. }
  15899. }
  15900. else
  15901. {
  15902. isSuccess = ConfigurationStatus_Rejected;
  15903. }
  15904. }
  15905. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15906. {
  15907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15908. {
  15909. strcpy(str, (const char*)value);
  15910. for(int i = 0; str[i]; i++)
  15911. {
  15912. str[i] = tolower(str[i]);
  15913. }
  15914. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15915. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15916. isSuccess = ConfigurationStatus_Accepted;
  15917. }
  15918. else
  15919. {
  15920. isSuccess = ConfigurationStatus_Rejected;
  15921. }
  15922. }
  15923. if(strcmp(key, "WebSocketPingInterval") == 0)
  15924. {
  15925. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15926. {
  15927. check_ascii = value[0];
  15928. if( (check_ascii < 48) || (check_ascii > 57) )
  15929. {
  15930. isSuccess = ConfigurationStatus_Rejected;
  15931. }
  15932. else
  15933. {
  15934. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15935. isSuccess = ConfigurationStatus_Accepted;
  15936. if((atoi(value) == 0) || (atoi(value) >= 10))
  15937. {
  15938. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15939. isSuccess = ConfigurationStatus_Accepted;
  15940. }
  15941. else
  15942. isSuccess = ConfigurationStatus_Rejected;
  15943. }
  15944. }
  15945. else
  15946. {
  15947. isSuccess = ConfigurationStatus_Rejected;
  15948. }
  15949. }
  15950. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15951. {
  15952. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15953. {
  15954. strcpy(str, (const char*)value);
  15955. for(int i = 0; str[i]; i++)
  15956. {
  15957. str[i] = tolower(str[i]);
  15958. }
  15959. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15960. isSuccess = ConfigurationStatus_Accepted;
  15961. }
  15962. else
  15963. {
  15964. isSuccess = ConfigurationStatus_Rejected;
  15965. }
  15966. }
  15967. if(strcmp(key, "AuthorizationKey") == 0)
  15968. {
  15969. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15970. {
  15971. strcpy(str, (const char*)value);
  15972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15973. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15974. isSuccess = ConfigurationStatus_Accepted;
  15975. }
  15976. else
  15977. {
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. if(strcmp(key, "SecurityProfile") == 0)
  15982. {
  15983. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15984. {
  15985. check_ascii = value[0];
  15986. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15987. {
  15988. isSuccess = ConfigurationStatus_Rejected;
  15989. }
  15990. else if(check_ascii == 0x33)
  15991. {
  15992. isSuccess = NotSupported;
  15993. }
  15994. else
  15995. {
  15996. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15997. {
  15998. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15999. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16000. isSuccess = ConfigurationStatus_Accepted;
  16001. }
  16002. else
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. }
  16006. else
  16007. {
  16008. isSuccess = ConfigurationStatus_Rejected;
  16009. }
  16010. }
  16011. if(strcmp(key, "DefaultPrice") == 0)
  16012. {
  16013. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16014. {
  16015. strcpy(str, (const char*)value);
  16016. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16017. isSuccess = ConfigurationStatus_Accepted;
  16018. }
  16019. else
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. }
  16024. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16025. {
  16026. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16027. {
  16028. strcpy(str, (const char*)value);
  16029. for(int i = 0; str[i]; i++)
  16030. {
  16031. str[i] = tolower(str[i]);
  16032. }
  16033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16034. isSuccess = ConfigurationStatus_Accepted;
  16035. }
  16036. else
  16037. {
  16038. isSuccess = ConfigurationStatus_Rejected;
  16039. }
  16040. }
  16041. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16042. {
  16043. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16044. {
  16045. strcpy(str, (const char*)value);
  16046. for(int i = 0; str[i]; i++)
  16047. {
  16048. str[i] = tolower(str[i]);
  16049. }
  16050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16051. isSuccess = ConfigurationStatus_Accepted;
  16052. }
  16053. else
  16054. {
  16055. isSuccess = ConfigurationStatus_Rejected;
  16056. }
  16057. }
  16058. if(strcmp(key, "SystemUptimeSec") == 0)
  16059. {
  16060. isSuccess = NotSupported;
  16061. }
  16062. if(strcmp(key, "FreeVend") == 0)
  16063. {
  16064. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16065. {
  16066. strcpy(str, (const char*)value);
  16067. for(int i = 0; str[i]; i++)
  16068. {
  16069. str[i] = tolower(str[i]);
  16070. }
  16071. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16072. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16073. isSuccess = ConfigurationStatus_Accepted;
  16074. }
  16075. else
  16076. {
  16077. isSuccess = ConfigurationStatus_Rejected;
  16078. }
  16079. }
  16080. if(strcmp(key, "FreeVendIdtag") == 0)
  16081. {
  16082. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16083. {
  16084. strcpy(str, (const char*)value);
  16085. if(strlen(str) <= 20)
  16086. {
  16087. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16088. isSuccess = ConfigurationStatus_Accepted;
  16089. }
  16090. else
  16091. {
  16092. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16093. isSuccess = ConfigurationStatus_Rejected;
  16094. }
  16095. }
  16096. else
  16097. {
  16098. isSuccess = ConfigurationStatus_Rejected;
  16099. }
  16100. }
  16101. if(strcmp(key, "OcppServer") == 0)
  16102. {
  16103. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16104. {
  16105. strcpy(str, (const char*)value);
  16106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16107. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16108. isSuccess = ConfigurationStatus_Accepted;
  16109. }
  16110. else
  16111. {
  16112. isSuccess = ConfigurationStatus_Rejected;
  16113. }
  16114. }
  16115. if(strcmp(key, "MaintainServer") == 0)
  16116. {
  16117. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16118. {
  16119. strcpy(str, (const char*)value);
  16120. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16121. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16122. isSuccess = ConfigurationStatus_Accepted;
  16123. }
  16124. else
  16125. {
  16126. isSuccess = ConfigurationStatus_Rejected;
  16127. }
  16128. }
  16129. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16130. {
  16131. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16132. {
  16133. strcpy(str, (const char*)value);
  16134. for(int i = 0; str[i]; i++)
  16135. {
  16136. str[i] = tolower(str[i]);
  16137. }
  16138. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16139. isSuccess = ConfigurationStatus_Accepted;
  16140. }
  16141. else
  16142. {
  16143. isSuccess = ConfigurationStatus_Rejected;
  16144. }
  16145. }
  16146. if(strcmp(key, "StatusNotificationInterval") == 0)
  16147. {
  16148. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16149. {
  16150. check_ascii = value[0];
  16151. if( (check_ascii < 48) || (check_ascii > 57) )
  16152. {
  16153. isSuccess = ConfigurationStatus_Rejected;
  16154. }
  16155. else
  16156. {
  16157. if((atoi(value) == 0) || (atoi(value) >= 10))
  16158. {
  16159. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16160. isSuccess = ConfigurationStatus_Accepted;
  16161. }
  16162. else
  16163. isSuccess = ConfigurationStatus_Rejected;
  16164. }
  16165. }
  16166. else
  16167. {
  16168. isSuccess = ConfigurationStatus_Rejected;
  16169. }
  16170. }
  16171. #if 0
  16172. //For OCPP Test Case
  16173. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16174. {
  16175. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16176. {
  16177. strcpy(str, (const char*)value);
  16178. for(int i = 0; str[i]; i++)
  16179. {
  16180. str[i] = tolower(str[i]);
  16181. }
  16182. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16183. isSuccess = ConfigurationStatus_Accepted;
  16184. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16185. }
  16186. else
  16187. {
  16188. isSuccess = ConfigurationStatus_Rejected;
  16189. }
  16190. }
  16191. #endif
  16192. #if 1
  16193. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16194. {
  16195. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16196. {
  16197. strcpy(str, (const char*)value);
  16198. for(int i = 0; str[i]; i++)
  16199. {
  16200. str[i] = tolower(str[i]);
  16201. }
  16202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16203. isSuccess = ConfigurationStatus_Accepted;
  16204. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16205. }
  16206. else
  16207. {
  16208. isSuccess = ConfigurationStatus_Rejected;
  16209. }
  16210. }
  16211. #endif
  16212. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16213. {
  16214. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16215. {
  16216. check_ascii = value[0];
  16217. if( (check_ascii < 48) || (check_ascii > 57) )
  16218. {
  16219. isSuccess = ConfigurationStatus_Rejected;
  16220. }
  16221. else
  16222. {
  16223. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16224. isSuccess = ConfigurationStatus_Accepted;
  16225. }
  16226. }
  16227. else
  16228. {
  16229. isSuccess = ConfigurationStatus_Rejected;
  16230. }
  16231. }
  16232. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16233. {
  16234. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16235. {
  16236. check_ascii = value[0];
  16237. if( (check_ascii < 48) || (check_ascii > 57) )
  16238. {
  16239. isSuccess = ConfigurationStatus_Rejected;
  16240. }
  16241. else
  16242. {
  16243. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16244. isSuccess = ConfigurationStatus_Accepted;
  16245. }
  16246. }
  16247. else
  16248. {
  16249. isSuccess = ConfigurationStatus_Rejected;
  16250. }
  16251. }
  16252. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16253. {
  16254. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16255. {
  16256. strcpy(str, (const char*)value);
  16257. for(int i = 0; str[i]; i++)
  16258. {
  16259. str[i] = tolower(str[i]);
  16260. }
  16261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16262. isSuccess = ConfigurationStatus_Accepted;
  16263. }
  16264. else
  16265. {
  16266. isSuccess = ConfigurationStatus_Rejected;
  16267. }
  16268. }
  16269. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16270. {
  16271. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16272. {
  16273. check_ascii = value[0];
  16274. if( (check_ascii < 48) || (check_ascii > 57) )
  16275. {
  16276. isSuccess = ConfigurationStatus_Rejected;
  16277. }
  16278. else
  16279. {
  16280. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16281. isSuccess = ConfigurationStatus_Accepted;
  16282. }
  16283. }
  16284. else
  16285. {
  16286. isSuccess = ConfigurationStatus_Rejected;
  16287. }
  16288. }
  16289. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16290. {
  16291. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16292. {
  16293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16294. isSuccess = ConfigurationStatus_Accepted;
  16295. }
  16296. else
  16297. {
  16298. isSuccess = ConfigurationStatus_Rejected;
  16299. }
  16300. }
  16301. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16302. {
  16303. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16304. {
  16305. check_ascii = value[0];
  16306. if( (check_ascii < 48) || (check_ascii > 57) )
  16307. {
  16308. isSuccess = ConfigurationStatus_Rejected;
  16309. }
  16310. else
  16311. {
  16312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16313. isSuccess = ConfigurationStatus_Accepted;
  16314. }
  16315. }
  16316. else
  16317. {
  16318. isSuccess = ConfigurationStatus_Rejected;
  16319. }
  16320. }
  16321. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16322. {
  16323. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16324. {
  16325. strcpy(str, (const char*)value);
  16326. for(int i = 0; str[i]; i++)
  16327. {
  16328. str[i] = tolower(str[i]);
  16329. }
  16330. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16331. isSuccess = ConfigurationStatus_Accepted;
  16332. }
  16333. else
  16334. {
  16335. isSuccess = ConfigurationStatus_Rejected;
  16336. }
  16337. }
  16338. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16339. {
  16340. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16341. {
  16342. check_ascii = value[0];
  16343. if( (check_ascii < 48) || (check_ascii > 57) )
  16344. {
  16345. isSuccess = ConfigurationStatus_Rejected;
  16346. }
  16347. else
  16348. {
  16349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16350. isSuccess = ConfigurationStatus_Accepted;
  16351. }
  16352. }
  16353. else
  16354. {
  16355. isSuccess = ConfigurationStatus_Rejected;
  16356. }
  16357. }
  16358. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16359. return isSuccess;
  16360. }
  16361. int TransactionMessageAttemptsGet(void)
  16362. {
  16363. return TransactionMessageAttemptsValue;
  16364. }
  16365. int FirstHeartBeatResponse(void)
  16366. {
  16367. return FirstHeartBeat;
  16368. }
  16369. int TransactionMessageRetryIntervalGet(void)
  16370. {
  16371. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16372. }
  16373. int ReadHttpStatus(int sock)
  16374. {
  16375. //char c;
  16376. char buff[1024]="",*ptr=buff+1;
  16377. int bytes_received, status;
  16378. DEBUG_INFO("Begin Response ..\n");
  16379. while((bytes_received = recv(sock, ptr, 1, 0))){
  16380. if(bytes_received==-1){
  16381. perror("ReadHttpStatus");
  16382. exit(1);
  16383. }
  16384. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16385. ptr++;
  16386. }
  16387. *ptr=0;
  16388. ptr=buff+1;
  16389. sscanf(ptr,"%*s %d ", &status);
  16390. DEBUG_INFO("%s\n",ptr);
  16391. DEBUG_INFO("status=%d\n",status);
  16392. DEBUG_INFO("End Response ..\n");
  16393. return (bytes_received>0)?status:0;
  16394. }
  16395. //the only filed that it parsed is 'Content-Length'
  16396. int ParseHeader(int sock)
  16397. {
  16398. //char c;
  16399. char buff[1024]="",*ptr=buff+4;
  16400. int bytes_received;
  16401. DEBUG_INFO("Begin HEADER ..\n");
  16402. while((bytes_received = recv(sock, ptr, 1, 0))){
  16403. if(bytes_received==-1){
  16404. perror("Parse Header");
  16405. exit(1);
  16406. }
  16407. if(
  16408. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16409. (ptr[-1]=='\r') && (*ptr=='\n' )
  16410. ) break;
  16411. ptr++;
  16412. }
  16413. *ptr=0;
  16414. ptr=buff+4;
  16415. //printf("%s",ptr);
  16416. if(bytes_received){
  16417. ptr=strstr(ptr,"Content-Length:");
  16418. if(ptr){
  16419. sscanf(ptr,"%*s %d",&bytes_received);
  16420. }else
  16421. bytes_received=-1; //unknown size
  16422. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16423. }
  16424. DEBUG_INFO("End HEADER ..\n");
  16425. return bytes_received ;
  16426. }
  16427. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16428. {
  16429. int result = TRUE;
  16430. char rmFileCmd[100]={0};
  16431. char FilePath[100]={0};
  16432. char ftpbuf[200];
  16433. int systemresult;
  16434. sprintf(FilePath,"/mnt/%s",filename);
  16435. system("ping 8.8.8.8 &");
  16436. if((access(FilePath,F_OK))!=-1)
  16437. {
  16438. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16439. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16440. system(rmFileCmd);
  16441. }
  16442. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16443. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16444. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16445. systemresult = system(ftpbuf);
  16446. if(systemresult != 0)
  16447. {
  16448. DEBUG_INFO("http DownLoad error!\n");
  16449. result = FALSE;
  16450. }
  16451. system("pkill ping");
  16452. return result;
  16453. }
  16454. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16455. {
  16456. int result = TRUE;
  16457. char rmFileCmd[100]={0};
  16458. char FilePath[100]={0};
  16459. char ftpbuf[200];
  16460. int systemresult;
  16461. sprintf(FilePath,"/mnt/%s",filename);
  16462. system("ping 8.8.8.8 &");
  16463. if((access(FilePath,F_OK))!=-1)
  16464. {
  16465. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16466. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16467. system(rmFileCmd);
  16468. }
  16469. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16470. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16471. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16472. systemresult = system(ftpbuf);
  16473. if(systemresult != 0)
  16474. {
  16475. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16476. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16477. systemresult = system(ftpbuf);
  16478. if(systemresult != 0)
  16479. {
  16480. DEBUG_WARN("wget error!\n");
  16481. result = FALSE;
  16482. }
  16483. }
  16484. system("pkill ping");
  16485. return result;
  16486. }
  16487. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16488. {
  16489. char rmFileCmd[100]={0};
  16490. char FilePath[100]={0};
  16491. char buf[512];
  16492. int systemresult = 0;
  16493. //DEBUG_INFO("filename=%s\n",filename);
  16494. //DEBUG_INFO("url=%s\n",url);
  16495. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16496. if((access(FilePath,F_OK))!=-1)
  16497. {
  16498. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16499. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16500. system(rmFileCmd);
  16501. }
  16502. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16503. if(fp == NULL)
  16504. {
  16505. DEBUG_INFO("log is NULL\n");
  16506. return FALSE;
  16507. }
  16508. else
  16509. {
  16510. fprintf(fp, "%s\n", url);
  16511. fprintf(fp, "%s\n", filename);
  16512. fclose(fp);
  16513. }
  16514. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16515. if(phpFP == NULL)
  16516. {
  16517. DEBUG_INFO("PHP upload fail.\n");
  16518. return FALSE;
  16519. }
  16520. else
  16521. {
  16522. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16523. {
  16524. if(strstr(buf, "result") != NULL)
  16525. {
  16526. sscanf(buf, "result: %d", &systemresult);
  16527. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16528. }
  16529. }
  16530. pclose(phpFP);
  16531. }
  16532. if(systemresult != 1)
  16533. {
  16534. DEBUG_INFO("HTTP upload error!\n");
  16535. return FALSE;
  16536. }
  16537. return TRUE;
  16538. }
  16539. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16540. {
  16541. int result = FALSE;
  16542. char ftpbuf[200];
  16543. int systemresult;
  16544. /*
  16545. // Domaind name transfer to IP address
  16546. struct hostent* server;
  16547. char *IPbuffer;
  16548. server = gethostbyname(location);
  16549. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16550. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16551. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16552. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16553. systemresult = system(ftpbuf);
  16554. if(systemresult != 0)
  16555. {
  16556. DEBUG_INFO("ftpput error!\n");
  16557. }
  16558. else
  16559. {
  16560. result = TRUE;
  16561. DEBUG_INFO("ftpput OK!\n");
  16562. }
  16563. return result;
  16564. }
  16565. int GetOcppServerURL()
  16566. {
  16567. int result = FALSE;
  16568. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16569. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16570. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16571. struct yuarel url;
  16572. char urlStr[512];
  16573. // OCPPPH only
  16574. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16575. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16576. {
  16577. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16578. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16579. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16580. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16581. if(yuarel_parse(&url, urlStr) != -1)
  16582. {
  16583. sprintf(OcppProtocol, "%s", url.scheme);
  16584. sprintf(OcppHost, "%s", url.host);
  16585. if(url.path == NULL)
  16586. OcppTempPath[0] = '\0';
  16587. else
  16588. sprintf(OcppTempPath, "%s", url.path);
  16589. if(url.port == 0)
  16590. {
  16591. if(strcmp(OcppProtocol, "wss") == 0)
  16592. OcppPort = 443;
  16593. else
  16594. OcppPort = 80;
  16595. }
  16596. else
  16597. OcppPort = url.port;
  16598. result = TRUE;
  16599. }
  16600. }
  16601. else
  16602. {
  16603. strcpy(OcppHost,"");
  16604. }
  16605. return result;
  16606. }
  16607. int GetOcppPath()
  16608. {
  16609. int result = FALSE;
  16610. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16611. {
  16612. if(OcppTempPath == NULL)
  16613. {
  16614. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16615. }
  16616. else
  16617. {
  16618. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16619. }
  16620. result = TRUE;
  16621. goto End;
  16622. }
  16623. else
  16624. {
  16625. strcpy(OcppPath,"");
  16626. }
  16627. End:
  16628. return result;
  16629. }
  16630. int GetOcppPort()
  16631. {
  16632. return OcppPort;
  16633. }
  16634. int GetOcppConnStatus(void)
  16635. {
  16636. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16637. }
  16638. void SetOcppConnStatus(uint8_t status)
  16639. {
  16640. ShmOCPP16DataPH->OcppConnStatus = status;
  16641. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16642. }
  16643. int GetHeartBeatWithNOResponse(void)
  16644. {
  16645. return HeartBeatWithNOResponse;
  16646. }
  16647. void SetHeartBeatWithNOResponse(void)
  16648. {
  16649. HeartBeatWithNOResponse = 0;
  16650. }
  16651. void GetStartTransactionIdTag(int gun_index)
  16652. {
  16653. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16654. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16655. }
  16656. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16657. {
  16658. char ch;
  16659. FILE *fptr1;
  16660. int temptransactionId;
  16661. char str[100]={0};
  16662. temptransactionId = 0;
  16663. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16664. {
  16665. DEBUG_INFO("IdTag is empty.\n");
  16666. return temptransactionId;
  16667. }
  16668. /*------ Read the file ----------------*/
  16669. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16670. if (!fptr1)
  16671. {
  16672. DEBUG_INFO("QueueTransactionId file open error.\n");
  16673. //printf(" File not found or unable to open the input file!!\n");
  16674. return temptransactionId;
  16675. }
  16676. ch=fgetc(fptr1);
  16677. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16678. rewind(fptr1);
  16679. if(ch!=EOF)
  16680. {
  16681. // printf("%c",ch);
  16682. while (fgets(str, 100, fptr1) != NULL)
  16683. {
  16684. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16685. if(str[0]=='\0')
  16686. {
  16687. break;
  16688. }
  16689. char *revbuf[8] = {0}; // Variable store string split
  16690. int num = 0;// Quantity after string split
  16691. DEBUG_INFO("Transaction queue data= %s\n", str);
  16692. splitstring(str,",",revbuf,&num); // String split
  16693. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16694. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16695. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16696. DEBUG_INFO("------------------------------\n");
  16697. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16698. {
  16699. if(isStopTransaction)
  16700. {
  16701. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16702. {
  16703. temptransactionId = atoi(revbuf[2]);
  16704. //break;
  16705. }
  16706. }
  16707. else
  16708. {
  16709. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16710. {
  16711. temptransactionId = atoi(revbuf[2]);
  16712. //break;
  16713. }
  16714. }
  16715. }
  16716. }
  16717. }
  16718. else
  16719. DEBUG_INFO("EOF\n");
  16720. fclose(fptr1);
  16721. /*------- End of reading ---------------*/
  16722. return temptransactionId;
  16723. }
  16724. void SetTransactionIdZero(int transactionId)
  16725. {
  16726. char ch;
  16727. FILE *fptr1, *fptr2;
  16728. int temptransactionId = 0;
  16729. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16730. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16731. if (!fptr1)
  16732. {
  16733. //printf(" File not found or unable to open the input file!!\n");
  16734. return ;
  16735. }
  16736. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16737. if (!fptr2)
  16738. {
  16739. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16740. fclose(fptr1);
  16741. return ;
  16742. }
  16743. ch=fgetc(fptr1);
  16744. rewind(fptr1);
  16745. if(ch!=EOF)
  16746. {
  16747. // copy all contents to the temporary file except the specific line
  16748. while (fgets(str, 100, fptr1) != NULL)
  16749. {
  16750. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16751. if(str[0]=='\0')
  16752. {
  16753. break;
  16754. }
  16755. char *revbuf[8] = {0};
  16756. int num = 0;
  16757. strcpy(strtemp, str);
  16758. splitstring(str,",",revbuf,&num);
  16759. if(revbuf[2][0] != '\0')
  16760. {
  16761. temptransactionId = atoi(revbuf[2]);
  16762. if(transactionId != temptransactionId)
  16763. {
  16764. fprintf(fptr2, "%s\n", strtemp);
  16765. }
  16766. }
  16767. }
  16768. }
  16769. fclose(fptr1);
  16770. fclose(fptr2);
  16771. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16772. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16773. /*------ Read the file ----------------*/
  16774. }
  16775. int InternetDisconnect(void)
  16776. {
  16777. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16778. }
  16779. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16780. void storeTempStopTransaction(int gun_index)
  16781. {
  16782. char guid[37]={0};
  16783. int tempIndex = 0;
  16784. char TempStopTransaction[256];
  16785. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16786. DEBUG_INFO("storeTempStopTransaction...\n");
  16787. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16788. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16789. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16792. {
  16793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16794. {
  16795. tempIndex = ((gun_index==2) ? 1: 0);
  16796. }
  16797. else
  16798. {
  16799. tempIndex = gun_index;
  16800. }
  16801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16802. {
  16803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16804. {
  16805. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16806. }
  16807. }// END OF CHAdeMO_QUANTITY
  16808. }
  16809. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16810. {
  16811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16812. {
  16813. tempIndex = ((gun_index==2) ? 1: 0);
  16814. }
  16815. else
  16816. {
  16817. tempIndex = gun_index;
  16818. }
  16819. for (int index = 0; index < CCS_QUANTITY; index++)
  16820. {
  16821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16822. {
  16823. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16824. }
  16825. }// END OF CCS_QUANTITY
  16826. }
  16827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16828. {
  16829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16830. {
  16831. tempIndex = ((gun_index==2) ? 1: 0);
  16832. }
  16833. else
  16834. {
  16835. tempIndex = gun_index;
  16836. }
  16837. for (int index = 0; index < GB_QUANTITY; index++)
  16838. {
  16839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16840. {
  16841. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16842. }
  16843. }// END OF GB_QUANTITY
  16844. }
  16845. else if(gunType[gun_index] == GUN_TYPE_DO)
  16846. {
  16847. tempIndex = gun_index;
  16848. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16849. {
  16850. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16851. {
  16852. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16853. }
  16854. }
  16855. }
  16856. else
  16857. {
  16858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16859. {
  16860. tempIndex = 2;
  16861. }
  16862. else
  16863. {
  16864. tempIndex = gun_index;
  16865. }
  16866. for (int index = 0; index < AC_QUANTITY; index++)
  16867. {
  16868. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16869. {
  16870. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16871. }
  16872. }// END OF AC_QUANTITY
  16873. }
  16874. //Stop Transaction Time
  16875. struct timeval tmnow;
  16876. struct tm *tm;
  16877. char buf[28];//, usec_buf[6];
  16878. gettimeofday(&tmnow, NULL);
  16879. time_t t;
  16880. t = time(NULL);
  16881. /*UTC time and date*/
  16882. tm = gmtime(&t);
  16883. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16885. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16886. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16887. random_uuid(guid);
  16888. /***********************************transactionData******************************************************/
  16889. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16890. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16891. //=================================
  16892. //1. Transaction_Begin
  16893. //=================================
  16894. //============================== Energy.Active.Import.Interval ===========================================
  16895. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16896. {
  16897. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16898. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  16901. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16902. 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))
  16903. {
  16904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16905. }
  16906. else
  16907. {
  16908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16909. }
  16910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16911. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16912. }
  16913. //=================================
  16914. //2. Transaction_End
  16915. //=================================
  16916. //2.1====================================== Current.Import L1 ==============================================
  16917. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16918. {
  16919. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16920. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16921. {
  16922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16923. {
  16924. tempIndex = ((gun_index==2) ? 1: 0);
  16925. }
  16926. else
  16927. {
  16928. tempIndex = gun_index;
  16929. }
  16930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16931. {
  16932. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16933. {
  16934. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16935. }
  16936. }// End of for CHAdeMO_QUANTITY
  16937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16938. }
  16939. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16940. {
  16941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16942. {
  16943. tempIndex = ((gun_index==2) ? 1: 0);
  16944. }
  16945. else
  16946. {
  16947. tempIndex = gun_index;
  16948. }
  16949. for (int index = 0; index < CCS_QUANTITY; index++)
  16950. {
  16951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16952. {
  16953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16954. }
  16955. }// End of for CCS_QUANTITY
  16956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16957. }
  16958. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16959. {
  16960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16961. {
  16962. tempIndex = ((gun_index==2) ? 1: 0);
  16963. }
  16964. else
  16965. {
  16966. tempIndex = gun_index;
  16967. }
  16968. for (int index = 0; index < GB_QUANTITY; index++)
  16969. {
  16970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16971. {
  16972. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16973. }
  16974. }// End of for GB_QUANTITY
  16975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16976. }
  16977. else if(gunType[gun_index] == GUN_TYPE_DO)
  16978. {
  16979. tempIndex = gun_index;
  16980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16981. {
  16982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16983. {
  16984. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16985. }
  16986. }
  16987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16988. }
  16989. else
  16990. {
  16991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16992. {
  16993. tempIndex = 2;
  16994. }
  16995. else
  16996. {
  16997. tempIndex = gun_index;
  16998. }
  16999. for (int index = 0; index < AC_QUANTITY; index++)
  17000. {
  17001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17002. {
  17003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17004. }
  17005. }// End of for AC_QUANTITY
  17006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17007. }
  17008. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17009. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17010. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17011. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17012. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17014. }
  17015. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17016. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17017. {
  17018. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17019. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17020. {
  17021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17022. {
  17023. tempIndex = ((gun_index==2) ? 1: 0);
  17024. }
  17025. else
  17026. {
  17027. tempIndex = gun_index;
  17028. }
  17029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17030. {
  17031. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17032. {
  17033. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17034. }
  17035. }// END OF CHAdeMO_QUANTITY
  17036. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17037. }
  17038. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17039. {
  17040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17041. {
  17042. tempIndex = ((gun_index==2) ? 1: 0);
  17043. }
  17044. else
  17045. {
  17046. tempIndex = gun_index;
  17047. }
  17048. for (int index = 0; index < CCS_QUANTITY; index++)
  17049. {
  17050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17051. {
  17052. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17053. }
  17054. }// END OF CCS_QUANTITY
  17055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17056. }
  17057. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17058. {
  17059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17060. {
  17061. tempIndex = ((gun_index==2) ? 1: 0);
  17062. }
  17063. else
  17064. {
  17065. tempIndex = gun_index;
  17066. }
  17067. for (int index = 0; index < GB_QUANTITY; index++)
  17068. {
  17069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17070. {
  17071. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17072. }
  17073. }// END OF GB_QUANTITY
  17074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17075. }
  17076. else if(gunType[gun_index] == GUN_TYPE_DO)
  17077. {
  17078. tempIndex = gun_index;
  17079. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17080. {
  17081. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17082. {
  17083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17084. }
  17085. }
  17086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17087. }
  17088. else
  17089. {
  17090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17091. {
  17092. tempIndex = 2;
  17093. }
  17094. else
  17095. {
  17096. tempIndex = gun_index;
  17097. }
  17098. for (int index = 0; index < AC_QUANTITY; index++)
  17099. {
  17100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17101. {
  17102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17103. }
  17104. }// END OF AC_QUANTITY
  17105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17106. }
  17107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17109. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17110. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17113. }
  17114. //2.3====================================== Power.Active.Import =========================================
  17115. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17116. {
  17117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17119. {
  17120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17121. {
  17122. tempIndex = ((gun_index==2) ? 1: 0);
  17123. }
  17124. else
  17125. {
  17126. tempIndex = gun_index;
  17127. }
  17128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17129. {
  17130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17131. {
  17132. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17133. }
  17134. } // End for CHAdeMO_QUANTITY
  17135. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17136. }
  17137. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17138. {
  17139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17140. {
  17141. tempIndex = ((gun_index==2) ? 1: 0);
  17142. }
  17143. else
  17144. {
  17145. tempIndex = gun_index;
  17146. }
  17147. for (int index = 0; index < CCS_QUANTITY; index++)
  17148. {
  17149. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17150. {
  17151. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17152. }
  17153. } // END for CCS_QUANTITY
  17154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17155. }
  17156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17157. {
  17158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17159. {
  17160. tempIndex = ((gun_index==2) ? 1: 0);
  17161. }
  17162. else
  17163. {
  17164. tempIndex = gun_index;
  17165. }
  17166. for (int index = 0; index < GB_QUANTITY; index++)
  17167. {
  17168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17169. {
  17170. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17171. }
  17172. }// END for GB_QUANTITY
  17173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17174. }
  17175. else if(gunType[gun_index] == GUN_TYPE_DO)
  17176. {
  17177. tempIndex = gun_index;
  17178. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17179. {
  17180. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17181. {
  17182. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17183. }
  17184. }
  17185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17186. }
  17187. else
  17188. {
  17189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17190. {
  17191. tempIndex = 2;
  17192. }
  17193. else
  17194. {
  17195. tempIndex = gun_index;
  17196. }
  17197. for (int index = 0; index < AC_QUANTITY; index++)
  17198. {
  17199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17200. {
  17201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17202. }
  17203. } // END for AC_QUANTITY
  17204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17205. }
  17206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17209. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17212. }
  17213. //2.4====================================== Voltage L1 ====================================================
  17214. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17215. {
  17216. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17217. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17218. {
  17219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17220. {
  17221. tempIndex = ((gun_index==2) ? 1: 0);
  17222. }
  17223. else
  17224. {
  17225. tempIndex = gun_index;
  17226. }
  17227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17228. {
  17229. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17230. {
  17231. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17232. }
  17233. } // END OF FOR CHAdeMO_QUANTITY
  17234. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17235. }
  17236. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17237. {
  17238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17239. {
  17240. tempIndex = ((gun_index==2) ? 1: 0);
  17241. }
  17242. else
  17243. {
  17244. tempIndex = gun_index;
  17245. }
  17246. for (int index = 0; index < CCS_QUANTITY; index++)
  17247. {
  17248. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17249. {
  17250. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17251. }
  17252. } // END OF FOR CCS_QUANTITY
  17253. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17254. }
  17255. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17256. {
  17257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17258. {
  17259. tempIndex = ((gun_index==2) ? 1: 0);
  17260. }
  17261. else
  17262. {
  17263. tempIndex = gun_index;
  17264. }
  17265. for (int index = 0; index < GB_QUANTITY; index++)
  17266. {
  17267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17268. {
  17269. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17270. }
  17271. } // END OF FOR GB_QUANTITY
  17272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17273. }
  17274. else if(gunType[gun_index] == GUN_TYPE_DO)
  17275. {
  17276. tempIndex = gun_index;
  17277. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17278. {
  17279. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17280. {
  17281. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17282. }
  17283. }
  17284. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17285. }
  17286. else
  17287. {
  17288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17289. {
  17290. tempIndex = 2;
  17291. }
  17292. else
  17293. {
  17294. tempIndex = gun_index;
  17295. }
  17296. for (int index = 0; index < AC_QUANTITY; index++)
  17297. {
  17298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17299. {
  17300. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17301. }
  17302. } // END OF FOR AC_QUANTITY
  17303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17304. }
  17305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17308. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17311. }
  17312. //2.5============================================== End SoC =========================================================
  17313. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17314. {
  17315. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17316. 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))
  17317. {
  17318. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17319. {
  17320. tempIndex = ((gun_index==2) ? 1: 0);
  17321. }
  17322. else
  17323. {
  17324. tempIndex = gun_index;
  17325. }
  17326. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17327. {
  17328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17329. {
  17330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17331. {
  17332. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17333. }
  17334. }
  17335. }
  17336. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17337. {
  17338. for (int index = 0; index < CCS_QUANTITY; index++)
  17339. {
  17340. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17341. {
  17342. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17343. }
  17344. }
  17345. }
  17346. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17347. {
  17348. for (int index = 0; index < GB_QUANTITY; index++)
  17349. {
  17350. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17351. {
  17352. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17353. }
  17354. }
  17355. }
  17356. else if(gunType[gun_index] == GUN_TYPE_DO)
  17357. {
  17358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17359. {
  17360. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17361. {
  17362. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17363. }
  17364. }
  17365. }
  17366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17368. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17370. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17372. } // END FOR DC CASE
  17373. }
  17374. //2.6====================================== Current.Import L2 ==============================================
  17375. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17376. {
  17377. // AC 3 phase L2 current
  17378. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17379. {
  17380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17381. {
  17382. tempIndex = 2;
  17383. }
  17384. else
  17385. {
  17386. tempIndex = gun_index;
  17387. }
  17388. for (int index = 0; index < AC_QUANTITY; index++)
  17389. {
  17390. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17391. {
  17392. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17393. }
  17394. }// End of for AC_QUANTITY
  17395. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17396. }
  17397. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17398. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17399. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17401. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17402. }
  17403. //2.7====================================== Current.Import L3 ==============================================
  17404. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17405. {
  17406. // AC 3 phase L3 current
  17407. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17408. {
  17409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17410. {
  17411. tempIndex = 2;
  17412. }
  17413. else
  17414. {
  17415. tempIndex = gun_index;
  17416. }
  17417. for (int index = 0; index < AC_QUANTITY; index++)
  17418. {
  17419. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17420. {
  17421. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17422. }
  17423. }// End of for AC_QUANTITY
  17424. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17425. }
  17426. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17427. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17430. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17431. }
  17432. //2.9====================================== Voltage L2 ====================================================
  17433. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17434. {
  17435. // AC 3 phase L2 volatge
  17436. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17437. {
  17438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17439. {
  17440. tempIndex = 2;
  17441. }
  17442. else
  17443. {
  17444. tempIndex = gun_index;
  17445. }
  17446. for (int index = 0; index < AC_QUANTITY; index++)
  17447. {
  17448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17449. {
  17450. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17451. }
  17452. } // END OF FOR AC_QUANTITY
  17453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17454. }
  17455. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17460. }
  17461. //2.10====================================== Voltage L3 ====================================================
  17462. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17463. {
  17464. // AC 3 phase L3 volatge
  17465. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17466. {
  17467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17468. {
  17469. tempIndex = 2;
  17470. }
  17471. else
  17472. {
  17473. tempIndex = gun_index;
  17474. }
  17475. for (int index = 0; index < AC_QUANTITY; index++)
  17476. {
  17477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17478. {
  17479. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17480. }
  17481. } // END OF FOR AC_QUANTITY
  17482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17483. }
  17484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17489. }
  17490. //====================== Start SoC ================================
  17491. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17492. {
  17493. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17494. 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))
  17495. {
  17496. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17497. {
  17498. tempIndex = ((gun_index==2) ? 1: 0);
  17499. }
  17500. else
  17501. {
  17502. tempIndex = gun_index;
  17503. }
  17504. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17505. {
  17506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17507. {
  17508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17509. {
  17510. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17511. }
  17512. }
  17513. }
  17514. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17515. {
  17516. for (int index = 0; index < CCS_QUANTITY; index++)
  17517. {
  17518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17519. {
  17520. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17521. }
  17522. }
  17523. }
  17524. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17525. {
  17526. for (int index = 0; index < GB_QUANTITY; index++)
  17527. {
  17528. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17529. {
  17530. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17531. }
  17532. }
  17533. }
  17534. else if(gunType[gun_index] == GUN_TYPE_DO)
  17535. {
  17536. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17537. {
  17538. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17539. {
  17540. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17541. }
  17542. }
  17543. }
  17544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17550. } // END FOR DC CASE
  17551. }
  17552. //======================================== Message create ==============================================
  17553. json_object *StopTransaction = json_object_new_object();
  17554. json_object *transactionDatas = json_object_new_array();
  17555. json_object *sampledValues = json_object_new_array();
  17556. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17557. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17558. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17559. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17560. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17561. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17562. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17563. {
  17564. json_object *transactionData = json_object_new_object();
  17565. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17566. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17567. {
  17568. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17569. {
  17570. json_object *sampledValue = json_object_new_object();
  17571. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17572. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17573. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17574. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17575. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17576. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17577. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17578. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17579. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17580. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17581. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17582. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17583. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17584. json_object_array_add(sampledValues, sampledValue);
  17585. }
  17586. }
  17587. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17588. json_object_array_add(transactionDatas, transactionData);
  17589. }
  17590. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17591. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17592. ,MESSAGE_TYPE_CALL
  17593. ,guid
  17594. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17595. json_object_put(StopTransaction);
  17596. // Check File "TempStopTransaction" Exist
  17597. if((access(TempStopTransaction,F_OK))!=-1)
  17598. {
  17599. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17600. fclose(fopen(TempStopTransaction, "w"));
  17601. }
  17602. else
  17603. {
  17604. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17605. FILE *log = fopen(TempStopTransaction, "w+");
  17606. if(log == NULL)
  17607. {
  17608. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17609. return ;
  17610. }
  17611. else
  17612. {
  17613. fclose(log);
  17614. }
  17615. }
  17616. //Add TempStopTransaction | Update TempStopTransaction
  17617. // open file for writing
  17618. FILE *outfile;
  17619. outfile = fopen (TempStopTransaction, "a");
  17620. //DEBUG_INFO("data = %s\n", queuedata);
  17621. fputs(queuedata, outfile);
  17622. fputs("\n", outfile);
  17623. fclose (outfile);
  17624. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17625. }
  17626. void checkTempStopTransaction(int gun_index)
  17627. {
  17628. FILE *fptr1;
  17629. char ch;
  17630. char str[QUEUE_MESSAGE_LENGTH]={0};
  17631. char guid[37]={0};
  17632. char tempdata[65]={0};
  17633. char connectorStr[2]={0};
  17634. char TempStopTransaction[256];
  17635. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17636. fptr1 = fopen(TempStopTransaction, "r");
  17637. //TempStopTransaction格式: 槍號,StopTransaction封包
  17638. if (!fptr1)
  17639. {
  17640. //printf(" File not found or unable to open the input file!!\n");
  17641. return ;
  17642. }
  17643. ch=fgetc(fptr1);
  17644. //printf(" Now the content of the file %s is : \n",fname);
  17645. rewind(fptr1);
  17646. if(ch!=EOF)
  17647. {
  17648. // copy all contents to the temporary file except the specific line
  17649. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17650. {
  17651. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17652. if(str[0]=='\0')
  17653. {
  17654. break;
  17655. }
  17656. //TempStopTransaction格式: 槍號,StopTransaction封包
  17657. strncpy(connectorStr, str, 1);
  17658. if(atoi(connectorStr) != (gun_index+1))
  17659. {
  17660. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17661. fclose(fptr1);
  17662. return ;
  17663. }
  17664. //random_uuid(guid);
  17665. strncpy(guid, str+6, 36); //copy guid
  17666. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17667. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17668. {
  17669. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17670. }
  17671. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17672. OCPP_insert_transaction_msg(NO, str);
  17673. memset(str,0,ARRAY_SIZE(str));
  17674. }
  17675. }
  17676. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17677. fclose(fptr1);
  17678. remove(TempStopTransaction); // remove the original file
  17679. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17680. }
  17681. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17682. {
  17683. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17684. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17685. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17686. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17687. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17688. }
  17689. int GetWebSocketPingInterval(void)
  17690. {
  17691. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17692. }
  17693. int GetServerSign(void)
  17694. {
  17695. return server_sign;
  17696. }
  17697. uint8_t GetOcppSecurityProfile()
  17698. {
  17699. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17700. }
  17701. void GetOcppChargerBoxId(uint8_t *data)
  17702. {
  17703. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17704. }
  17705. void GetOcppSecurityPassword(uint8_t *data)
  17706. {
  17707. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17708. }
  17709. void SetOcppVersion(uint8_t *version)
  17710. {
  17711. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17712. DEBUG_INFO("ocpp version: %s\n", version);
  17713. if(strstr((char*)version, "ocpp1.6") != NULL)
  17714. {
  17715. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17716. }
  17717. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17718. {
  17719. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17720. system("pkill OcppBackend");
  17721. }
  17722. }
  17723. void SetServerSign(int value)
  17724. {
  17725. server_sign = value;
  17726. }
  17727. int GetBootNotificationInterval(void)
  17728. {
  17729. return BootNotificationInterval;
  17730. }
  17731. int GetInternetConn(void)
  17732. {
  17733. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17734. }
  17735. int GetBackendConnectionTimeout(void)
  17736. {
  17737. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17738. }
  17739. int isConnectorInitMode(int gun_index)
  17740. {
  17741. int tempIndex = 0;
  17742. int result = TRUE;
  17743. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17744. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17745. {
  17746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17747. {
  17748. tempIndex = ((gun_index==2) ? 1: 0);
  17749. }
  17750. else
  17751. {
  17752. tempIndex = gun_index;
  17753. }
  17754. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17755. {
  17756. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17757. {
  17758. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17759. } //end of the same index
  17760. }//end of for CHAdeMO_QUANTITY
  17761. }
  17762. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17763. {
  17764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17765. {
  17766. tempIndex = ((gun_index==2) ? 1: 0);
  17767. }
  17768. else
  17769. {
  17770. tempIndex = gun_index;
  17771. }
  17772. for (int index = 0; index < CCS_QUANTITY; index++)
  17773. {
  17774. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17775. {
  17776. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17777. } //end of the same index
  17778. } // end of for CCS_QUANTITY
  17779. }
  17780. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17781. {
  17782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17783. {
  17784. tempIndex = ((gun_index==2) ? 1: 0);
  17785. }
  17786. else
  17787. {
  17788. tempIndex = gun_index;
  17789. }
  17790. for (int index = 0; index < GB_QUANTITY; index++)
  17791. {
  17792. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17793. {
  17794. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17795. } //end of the same index
  17796. } // end of for GB_QUANTITY
  17797. }
  17798. else if(gunType[gun_index] == GUN_TYPE_DO)
  17799. {
  17800. tempIndex = gun_index;
  17801. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17802. {
  17803. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17804. {
  17805. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17806. } //end of the same index
  17807. }
  17808. }
  17809. else
  17810. {
  17811. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17812. {
  17813. tempIndex = 2;
  17814. }
  17815. else
  17816. {
  17817. tempIndex = gun_index;
  17818. }
  17819. for (int index = 0; index < AC_QUANTITY; index++)
  17820. {
  17821. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17822. {
  17823. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17824. }//end of the same index
  17825. }//end of for AC_QUANTITY
  17826. }
  17827. return result;
  17828. }
  17829. void refreshProcDogTimer()
  17830. {
  17831. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17832. }
  17833. void InitialSystemValue(void)
  17834. {
  17835. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17836. locallistVersion=0;
  17837. BootNotificationInterval = 0;
  17838. authorizeRetryTimes = 0;
  17839. GunStatusInterval = 10;
  17840. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17841. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17842. //Hear Beat
  17843. HeartBeatWithNOResponse = 0;
  17844. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17845. FirstHeartBeat = 0;
  17846. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17847. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17848. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17849. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17850. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17851. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17852. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17853. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17854. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17855. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17856. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17857. //Status && ConnectorPlugIn Setting
  17858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17859. {
  17860. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17861. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17862. }
  17863. for (int index = 0; index < CCS_QUANTITY; index++)
  17864. {
  17865. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17866. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17867. }
  17868. for (int index = 0; index < GB_QUANTITY; index++)
  17869. {
  17870. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17871. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17872. }
  17873. for (int index = 0; index < AC_QUANTITY; index++)
  17874. {
  17875. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17876. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17877. }
  17878. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17879. {
  17880. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17881. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17882. }
  17883. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17884. {
  17885. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17886. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17887. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17888. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17889. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17890. }
  17891. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17892. refreshStartTimer(&clientTime.Heartbeat);
  17893. sleep(1);
  17894. }
  17895. void LWS_Send(char *str)
  17896. {
  17897. //=====================================================
  17898. // Check InternetConn 0: disconnected, 1: connected
  17899. //====================================================
  17900. if(GetOcppConnStatus() == 0)
  17901. {
  17902. DEBUG_INFO("offline now !!!\n");
  17903. return;
  17904. }
  17905. // Only disable isWebsocketSendable operation initiated by charger
  17906. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17907. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17908. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17909. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17910. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17911. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17912. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17913. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17914. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17915. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17916. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17917. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17918. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17919. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17920. {
  17921. isWebsocketSendable = 0;
  17922. }
  17923. pthread_mutex_lock(&lock_send);
  17924. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17925. sprintf((char *)SendBuffer, "%s", str);
  17926. SendBufLen = strlen(str);
  17927. pthread_mutex_unlock(&lock_send);
  17928. lws_callback_on_writable(wsi_client);
  17929. //lws_service(context, 0);
  17930. //sleep(1);
  17931. }
  17932. void LWS_SendNow(char *str)
  17933. {
  17934. //=====================================================
  17935. // Check InternetConn 0: disconnected, 1: connected
  17936. //====================================================
  17937. if(GetOcppConnStatus() == 0)
  17938. {
  17939. DEBUG_INFO("offline now !!!\n");
  17940. return;
  17941. }
  17942. // Only disable isWebsocketSendable operation initiated by charger
  17943. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17944. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17945. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17946. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17947. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17948. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17949. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17950. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17951. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17952. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17953. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17954. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17955. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17956. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17957. {
  17958. isWebsocketSendable = 0;
  17959. }
  17960. pthread_mutex_lock(&lock_send);
  17961. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17962. sprintf((char *)SendBuffer, "%s", str);
  17963. SendBufLen = strlen(str);
  17964. pthread_mutex_unlock(&lock_send);
  17965. lws_callback_on_writable(wsi_client);
  17966. lws_service(context, 0);
  17967. //sleep(1);
  17968. }