MessageHandler.c 946 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483
  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. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  118. }clientTime;
  119. typedef union
  120. {
  121. //Operations Initiated by Central System
  122. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  123. struct
  124. {
  125. //CsMsgValue[0]
  126. unsigned char StatusNotificationReq:1; //bit 0,
  127. unsigned char StatusNotificationConf:1; //bit 1,
  128. unsigned char TriggerMeterValue:1; //bit 2,
  129. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  130. unsigned char isOnCharging:1; //bit 4.
  131. unsigned char :3; //bit 5~7
  132. }bits[CONNECTOR_QUANTITY];
  133. }CpinitiateMsg;
  134. CpinitiateMsg cpinitateMsg;
  135. //GetConfiguration Array
  136. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  139. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  140. static char *ChargePointErrorCodeStr[] = {
  141. MACROSTR(ConnectorLockFailure),
  142. MACROSTR(EVCommunicationError),
  143. MACROSTR(GroundFailure),
  144. MACROSTR(HighTemperature),
  145. MACROSTR(InternalError),
  146. MACROSTR(LocalListConflict),
  147. MACROSTR(NoError),
  148. MACROSTR(OtherError),
  149. MACROSTR(OverCurrentFailure),
  150. MACROSTR(OverVoltage),
  151. MACROSTR(PowerMeterFailure),
  152. MACROSTR(PowerSwitchFailure),
  153. MACROSTR(ReaderFailure),
  154. MACROSTR(ResetFailure),
  155. MACROSTR(UnderVoltage),
  156. MACROSTR(WeakSignal)
  157. };
  158. static char * ChargePointStatusStr[] = {
  159. MACROSTR(Available),
  160. MACROSTR(Preparing),
  161. MACROSTR(Charging),
  162. MACROSTR(SuspendedEVSE),
  163. MACROSTR(SuspendedEV),
  164. MACROSTR(Finishing),
  165. MACROSTR(Reserved),
  166. MACROSTR(Unavailable),
  167. MACROSTR(Faulted)
  168. };
  169. static char *RegistrationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Pending),
  172. MACROSTR(Rejected)
  173. };
  174. static char *AvailabilityTypeStr[] = {
  175. MACROSTR(Inoperative),
  176. MACROSTR(Operative)
  177. };
  178. static char *AvailabilityStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(Scheduled)
  182. };
  183. static char *ConfigurationStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected),
  186. MACROSTR(RebootRequired),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearCacheStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Rejected)
  192. };
  193. static char *ChargingProfilePurposeTypeStr[] = {
  194. MACROSTR(ChargePointMaxProfile),
  195. MACROSTR(TxDefaultProfile),
  196. MACROSTR(TxProfile)
  197. };
  198. static char *ChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Rejected),
  201. MACROSTR(NotSupported)
  202. };
  203. static char *ClearChargingProfileStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Unknown)
  206. };
  207. static char *GetCompositeScheduleStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *UpdateTypeStr[] = {
  212. MACROSTR(Differential),
  213. MACROSTR(Full)
  214. };
  215. static char *UpdateStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Failed),
  218. MACROSTR(NotSupported),
  219. MACROSTR(VersionMismatch)
  220. };
  221. static char *RemoteStartStopStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Rejected)
  224. };
  225. static char *ReservationStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Faulted),
  228. MACROSTR(Occupied),
  229. MACROSTR(Rejected),
  230. MACROSTR(Unavailable)
  231. };
  232. static char *ResetTypeStr[] = {
  233. MACROSTR(Hard),
  234. MACROSTR(Soft)
  235. };
  236. static char *ResetStatusStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected)
  239. };
  240. static char * DiagnosticsStatusStr[] = {
  241. MACROSTR(Idle),
  242. MACROSTR(Uploaded),
  243. MACROSTR(UploadFailed),
  244. MACROSTR(Uploading)
  245. };
  246. static char * FirmwareStatusStr[] = {
  247. MACROSTR(Downloaded),
  248. MACROSTR(DownloadFailed),
  249. MACROSTR(Downloading),
  250. MACROSTR(Idle),
  251. MACROSTR(InstallationFailed),
  252. MACROSTR(Installing),
  253. MACROSTR(Installed)
  254. };
  255. static char * MessageTriggerStr[] = {
  256. MACROSTR(BootNotification),
  257. MACROSTR(DiagnosticsStatusNotification),
  258. MACROSTR(FirmwareStatusNotification),
  259. MACROSTR(Heartbeat),
  260. MACROSTR(MeterValues),
  261. MACROSTR(StatusNotification)
  262. };
  263. static char * TriggerMessageStatusStr[] = {
  264. MACROSTR(Accepted),
  265. MACROSTR(Rejected),
  266. MACROSTR(NotImplemented)
  267. };
  268. static char * UnlockStatusStr[] = {
  269. MACROSTR(Unlocked),
  270. MACROSTR(UnlockFailed),
  271. MACROSTR(NotSupported)
  272. };
  273. #if 0
  274. static char * StopTransactionReasonStr[] = {
  275. MACROSTR(EmergencyStop),
  276. MACROSTR(EVDisconnected),
  277. MACROSTR(HardReset),
  278. MACROSTR(Local),
  279. MACROSTR(Other),
  280. MACROSTR(PowerLoss),
  281. MACROSTR(Reboot),
  282. MACROSTR(Remote),
  283. MACROSTR(SoftReset),
  284. MACROSTR(UnlockCommand),
  285. MACROSTR(DeAuthorized)
  286. };
  287. #endif
  288. static char * CancelReservationStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Rejected)
  291. };
  292. static char * ReadingContextStr[] = {
  293. MACROSTR(Interruption.Begin),
  294. MACROSTR(Interruption.End),
  295. MACROSTR(Other),
  296. MACROSTR(Sample.Clock),
  297. MACROSTR(Sample.Periodic),
  298. MACROSTR(Transaction.Begin),
  299. MACROSTR(Transaction.End),
  300. MACROSTR(Trigger)
  301. };
  302. static char * ValueFormatStr[] = {
  303. MACROSTR(Raw),
  304. MACROSTR(SignedData)
  305. };
  306. static char * MeasurandStr[] = {
  307. MACROSTR(Current.Export),
  308. MACROSTR(Current.Import),
  309. MACROSTR(Current.Offered),
  310. MACROSTR(Energy.Active.Export.Register),
  311. MACROSTR(Energy.Active.Import.Register),
  312. MACROSTR(Energy.Reactive.Export.Register),
  313. MACROSTR(Energy.Reactive.Import.Register),
  314. MACROSTR(Energy.Active.Export.Interval),
  315. MACROSTR(Energy.Active.Import.Interval),
  316. MACROSTR(Energy.Reactive.Export.Interval),
  317. MACROSTR(Energy.Reactive.Import.Interval),
  318. MACROSTR(Frequency),
  319. MACROSTR(Power.Active.Export),
  320. MACROSTR(Power.Active.Import),
  321. MACROSTR(Power.Factor),
  322. MACROSTR(Power.Offered),
  323. MACROSTR(Power.Reactive.ExportMACROSTR),
  324. MACROSTR(Power.Reactive.Import),
  325. MACROSTR(RPM),
  326. MACROSTR(SoC),
  327. MACROSTR(Temperature),
  328. MACROSTR(Voltage)
  329. };
  330. static char * LocationStr[] = {
  331. MACROSTR(Body),
  332. MACROSTR(Cable),
  333. MACROSTR(EV),
  334. MACROSTR(Inlet),
  335. MACROSTR(Outlet)
  336. };
  337. static char * PhaseStr[] = {
  338. MACROSTR(L1),
  339. MACROSTR(L2),
  340. MACROSTR(L3),
  341. MACROSTR(N),
  342. MACROSTR(L1-N),
  343. MACROSTR(L2-N),
  344. MACROSTR(L3-N),
  345. MACROSTR(L1-L2),
  346. MACROSTR(L2-L3),
  347. MACROSTR(L3-L1)
  348. };
  349. static char * UnitOfMeasureStr[] = {
  350. MACROSTR(Wh),
  351. MACROSTR(kWh),
  352. MACROSTR(varh),
  353. MACROSTR(kvarh),
  354. MACROSTR(W),
  355. MACROSTR(kW),
  356. MACROSTR(VA),
  357. MACROSTR(kVA),
  358. MACROSTR(var),
  359. MACROSTR(kvar),
  360. MACROSTR(A),
  361. MACROSTR(V),
  362. MACROSTR(Celsius),
  363. MACROSTR(Fahrenheit),
  364. MACROSTR(K),
  365. MACROSTR(Percent)
  366. };
  367. //=========================================
  368. // Save configuration
  369. //=========================================
  370. int runShellCmd(const char*cmd)
  371. {
  372. int result = FAIL;
  373. char buf[256];
  374. FILE *fp;
  375. fp = popen(cmd, "r");
  376. if(fp != NULL)
  377. {
  378. while(fgets(buf, sizeof(buf), fp) != NULL)
  379. {
  380. DEBUG_INFO("%s\n", buf);
  381. }
  382. result = PASS;
  383. }
  384. pclose(fp);
  385. return result;
  386. }
  387. int StoreUsrConfigData(struct SysConfigData *UsrData)
  388. {
  389. int result = PASS;
  390. int fd,wrd;
  391. unsigned int i,Chk;
  392. unsigned char *ptr, *BufTmp;
  393. int MtdBlockSize = 0x300000;
  394. Chk=0;
  395. ptr=(unsigned char *)UsrData;
  396. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  397. {
  398. memset(BufTmp,0,MtdBlockSize);
  399. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  400. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  401. Chk+=*(BufTmp+i);
  402. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  403. // Output configuration to file.
  404. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  405. if (fd < 0)
  406. {
  407. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  408. free(BufTmp);
  409. return 0;
  410. }
  411. wrd=write(fd, BufTmp, MtdBlockSize);
  412. close(fd);
  413. if(wrd<MtdBlockSize)
  414. {
  415. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  416. free(BufTmp);
  417. return 0;
  418. }
  419. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  420. DEBUG_INFO("Erase /dev/mtd10.\n");
  421. runShellCmd("flash_erase /dev/mtd10 0 0");
  422. DEBUG_INFO("Write /dev/mtd10.\n");
  423. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  424. DEBUG_INFO("Erase /dev/mtd11.\n");
  425. runShellCmd("flash_erase /dev/mtd11 0 0");
  426. DEBUG_INFO("Write /dev/mtd11.\n");
  427. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  428. system("rm -f /mnt/EvseConfig.bin");
  429. DEBUG_INFO("EvseConfig write to flash OK\n");
  430. }
  431. else
  432. {
  433. DEBUG_ERROR("alloc BlockSize NG\r\n");
  434. result = FAIL;
  435. }
  436. if(BufTmp!=NULL)
  437. free(BufTmp);
  438. return result;
  439. }
  440. //=========================================
  441. // Sqlite3 related function
  442. //=========================================
  443. static int selectSqlCount = 0;
  444. static int callback(void *data, int argc, char **argv, char **azColName){
  445. int i;
  446. //printf("%s: ", (const char*)data);
  447. selectSqlCount = argc;
  448. for(i = 0; i<argc; i++){
  449. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  450. }
  451. //printf("\n");
  452. return 0;
  453. }
  454. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  455. //int i;
  456. //printf("%s:\n", (const char*)data);
  457. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  458. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  459. return 0;
  460. }
  461. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  462. //printf("%s:\n", (const char*)data);
  463. //idTag
  464. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  465. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  466. //parentIdTag
  467. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  468. //expir_date
  469. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  470. //status
  471. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  472. //version
  473. if(columenCount > 5)
  474. idTagQuery.listVersionInt = atoi(columnValue[5]);
  475. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  476. return 0;
  477. }
  478. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  479. {
  480. // localversion = argv[5] ? atoi(argv[5]) : 0;
  481. // printf("localversion=%d\n", localversion);
  482. return 0;
  483. }
  484. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  485. {
  486. for (int i = 0; i < n_columns; i++)
  487. {
  488. DEBUG_INFO("%s\t", col_values[i]);
  489. }
  490. DEBUG_INFO("\n");
  491. return 0;
  492. }
  493. int OCPP_cleanLocalCache()
  494. {
  495. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  496. char *errMsg = 0;
  497. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  498. if (SQLITE_OK != rc)
  499. {
  500. DEBUG_INFO("SQL error: %s\n",errMsg);
  501. return FALSE;
  502. }
  503. return TRUE;
  504. }
  505. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  506. {
  507. int isSuccess = TRUE;
  508. int ret = 0;
  509. //const char* data = "Callback function called";
  510. char sql[300];
  511. char zErrMsg[200];
  512. memset(sql, 0, 300);
  513. memset(zErrMsg, 0, 200);
  514. 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);
  515. //* Execute SQL statement */
  516. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  517. if( ret != SQLITE_OK )
  518. {
  519. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  520. isSuccess = FALSE;
  521. }
  522. return isSuccess;
  523. }
  524. void OCPP_getIdTagFromLocalCache(char idTag[])
  525. {
  526. int rc = 0;
  527. char sql[100];
  528. char zErrMsg[100];
  529. memset(sql, 0, 100);
  530. memset(zErrMsg, 0, 100);
  531. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  532. memset(&idTagQuery, 0, sizeof(idTagQuery));
  533. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  534. /* Execute SQL statement */
  535. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  536. if( rc != SQLITE_OK )
  537. {
  538. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  539. }
  540. }
  541. void OCPP_getListVerion()
  542. {
  543. int rc = 0;
  544. // const char* data = "Callback function called";
  545. char sql[100];
  546. char zErrMsg[100];
  547. memset(sql, 0, 100);
  548. memset(zErrMsg, 0, 100);
  549. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  550. /* Execute SQL statement */
  551. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  552. if( rc != SQLITE_OK )
  553. {
  554. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  555. }
  556. }
  557. void OCPP_get_TableAuthlocalAllData(void)
  558. {
  559. int rc = 0;
  560. char sql[100];
  561. char zErrMsg[100];
  562. memset(sql, 0, 100);
  563. memset(zErrMsg, 0, 100);
  564. sprintf(sql,"select * from ocpp_auth_local ");
  565. /* Execute SQL statement */
  566. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  567. if( rc != SQLITE_OK )
  568. {
  569. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  570. }
  571. //return ver;
  572. }
  573. int OCPP_cleanLocalList()
  574. {
  575. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  576. char *errMsg = 0;
  577. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  578. if (SQLITE_OK != rc)
  579. {
  580. DEBUG_INFO("%s\n",errMsg);
  581. return FALSE;
  582. }
  583. return TRUE;
  584. }
  585. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  586. {
  587. int isSuccess = FALSE;
  588. int ret = 0;
  589. //const char* data = "Callback function called";
  590. char sql[300];
  591. char zErrMsg[200];
  592. memset(sql, 0, 300);
  593. memset(zErrMsg, 0, 200);
  594. 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);
  595. //* Execute SQL statement */
  596. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  597. if( ret != SQLITE_OK )
  598. {
  599. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  600. return isSuccess;
  601. }
  602. memset(sql, 0, 300);
  603. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  604. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  605. if( ret != SQLITE_OK )
  606. {
  607. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  608. return isSuccess;
  609. }
  610. isSuccess = TRUE;
  611. return isSuccess;
  612. }
  613. void OCPP_getIdTagFromLocalList(char idTag[])
  614. {
  615. int rc = 0;
  616. // const char* data = "Callback function called";
  617. char sql[100];
  618. char zErrMsg[100];
  619. memset(sql, 0, 100);
  620. memset(zErrMsg, 0, 100);
  621. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  622. memset(&idTagQuery, 0, sizeof(idTagQuery));
  623. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  624. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  625. /* Execute SQL statement */
  626. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  627. if( rc != SQLITE_OK )
  628. {
  629. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  630. }
  631. //return ver;
  632. }
  633. void OCPP_deleteIdTagFromLocalList(char idTag[])
  634. {
  635. //int ver = 0;
  636. //int isSuccess = FALSE;
  637. int rc = 0;
  638. char sql[100];
  639. char zErrMsg[100];
  640. memset(sql, 0, 100);
  641. memset(zErrMsg, 0, 100);
  642. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  643. //* Execute SQL statement */
  644. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  645. if( rc != SQLITE_OK )
  646. {
  647. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  648. }
  649. }
  650. int getCurrentYear()
  651. {
  652. int result = 0;
  653. time_t CurrentTime;
  654. struct tm *tm;
  655. CurrentTime = time(NULL);
  656. tm=localtime(&CurrentTime);
  657. result = (tm->tm_year + 1900);
  658. return result;
  659. }
  660. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  661. {
  662. int result = PASS;
  663. char* errMsg = NULL;
  664. char sqlStr[8192];
  665. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  666. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  667. {
  668. result = FAIL;
  669. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  670. }
  671. 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));
  672. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  673. {
  674. result = FAIL;
  675. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  676. }
  677. return result;
  678. }
  679. 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)
  680. {
  681. int result = PASS;
  682. char* errMsg = NULL;
  683. char sqlStr[8192];
  684. sprintf(sqlStr, "insert or replace 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');",
  685. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  692. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  693. {
  694. result = FAIL;
  695. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  696. }
  697. return result;
  698. }
  699. int OCPP_update_deduct_info(int txId, char *creditNo)
  700. {
  701. int result = PASS;
  702. char* errMsg = NULL;
  703. char sqlStr[8192];
  704. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  705. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  706. {
  707. result = FAIL;
  708. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  709. }
  710. return result;
  711. }
  712. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  713. {
  714. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  715. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  716. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  717. atoi(columnValue[1]),
  718. columnValue[2],
  719. atoi(columnValue[3])==1?"true":"false",
  720. atoi(columnValue[4])==1?"true":"false",
  721. columnValue[5],
  722. columnValue[9]);
  723. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  724. return 0;
  725. }
  726. void OCPP_query_deduct_info()
  727. {
  728. int rc = 0;
  729. char sql[100];
  730. char zErrMsg[100];
  731. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  732. /* Execute SQL statement */
  733. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  734. if( rc != SQLITE_OK )
  735. {
  736. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  737. }
  738. }
  739. void reportReaderStatus(int gun_index)
  740. {
  741. struct timeval tmnow;
  742. struct tm *tm;
  743. char buf[28];//, usec_buf[6];
  744. gettimeofday(&tmnow, NULL);
  745. time_t t;
  746. t = time(NULL);
  747. /*UTC time and date*/
  748. tm = gmtime(&t);
  749. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  750. #if 0 // remove temporally
  751. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  752. strcat(buf,".");
  753. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  754. strcat(buf,usec_buf);
  755. #endif
  756. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  757. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  758. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  759. (gun_index+1),
  760. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  761. buf,
  762. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  763. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  764. ShmOCPP16DataPH->TcciCustomData.VEMData[gun_index]);
  765. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  766. }
  767. //==========================================
  768. // Check time passed since today
  769. //==========================================
  770. long long DiffTimebWithNow(struct timeb ST)
  771. {
  772. //return milli-second
  773. struct timeb ET;
  774. long long StartTime,StopTime;
  775. ftime(&ET);
  776. StartTime=(long long)ST.time;
  777. StopTime=(long long)ET.time;
  778. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  779. }
  780. int getTimePassSinceToday(uint8_t gun_index)
  781. {
  782. int result = -1;
  783. static time_t lastTime[4];
  784. time_t t;
  785. struct tm *tmStartToday;
  786. struct timeb tbStartToday;
  787. t=time(NULL);
  788. if(difftime(t, lastTime[gun_index])>0)
  789. {
  790. tmStartToday=localtime(&t);
  791. tmStartToday->tm_hour = 0;
  792. tmStartToday->tm_min = 0;
  793. tmStartToday->tm_sec = 0;
  794. tbStartToday.time = mktime(tmStartToday);
  795. tbStartToday.millitm = 0;
  796. result = DiffTimebWithNow(tbStartToday)/1000;
  797. lastTime[gun_index] = t;
  798. }
  799. return result;
  800. }
  801. void getNowDatetime(uint8_t *data)
  802. {
  803. time_t t = time(NULL);
  804. struct tm tm = *localtime(&t);
  805. 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);
  806. }
  807. int syncDateTimeRTC(uint8_t *data)
  808. {
  809. struct ParsingResult
  810. {
  811. int result;
  812. int scanedElement;
  813. int year;
  814. int month;
  815. int mday;
  816. int hour;
  817. int min;
  818. int sec;
  819. int tz_hour;
  820. int tz_min;
  821. float minSec;
  822. }result;
  823. struct tm tmOrg;
  824. struct tm *tmTarget;
  825. struct timeb tbTarget;
  826. char buf[128];
  827. memset(&result, 0x00, sizeof(struct ParsingResult));
  828. result.result = PASS;
  829. if(strstr((char*)data, ".") != NULL)
  830. {
  831. // Original data with mini second
  832. if(strstr((char*)data, "Z") != NULL)
  833. {
  834. // Original data with Z
  835. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  836. &result.year,
  837. &result.month,
  838. &result.mday,
  839. &result.hour,
  840. &result.min,
  841. &result.sec,
  842. &result.minSec);
  843. }
  844. else
  845. {
  846. // Original data without Z
  847. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  848. &result.year,
  849. &result.month,
  850. &result.mday,
  851. &result.hour,
  852. &result.min,
  853. &result.sec,
  854. &result.minSec,
  855. &result.tz_hour,
  856. &result.tz_min);
  857. }
  858. }
  859. else
  860. {
  861. // Original data without mini second
  862. if(strstr((char*)data, "Z") != NULL)
  863. {
  864. // Original data with Z
  865. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  866. &result.year,
  867. &result.month,
  868. &result.mday,
  869. &result.hour,
  870. &result.min,
  871. &result.sec);
  872. }
  873. else
  874. {
  875. // Original data without Z
  876. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  877. &result.year,
  878. &result.month,
  879. &result.mday,
  880. &result.hour,
  881. &result.min,
  882. &result.sec,
  883. &result.tz_hour,
  884. &result.tz_min);
  885. }
  886. }
  887. tmOrg.tm_year = result.year - 1900;
  888. tmOrg.tm_mon = result.month - 1;
  889. tmOrg.tm_mday = result.mday;
  890. tmOrg.tm_hour = result.hour;
  891. tmOrg.tm_min = result.min;
  892. tmOrg.tm_sec = result.sec;
  893. tmOrg.tm_gmtoff = 0;
  894. tbTarget.time = mktime(&tmOrg);
  895. tbTarget.timezone = 0;
  896. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  897. tmTarget = gmtime(&tbTarget.time);
  898. 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);
  899. //DEBUG_INFO(" org date time: %s\n", data);
  900. //DEBUG_INFO("parse date time: %s\n", buf);
  901. system(buf);
  902. system("/sbin/hwclock -w --systohc");
  903. if(result.scanedElement < 6)
  904. result.result = FAIL;
  905. return result.result;
  906. }
  907. //==========================================
  908. // GetCompositeSchedule logic related function
  909. //==========================================
  910. int DiffTimebSec(struct timeb ST, struct timeb ET)
  911. {
  912. //return milli-second
  913. unsigned int StartTime,StopTime;
  914. StartTime=(unsigned int)ST.time;
  915. StopTime=(unsigned int)ET.time;
  916. return (StopTime-StartTime);
  917. }
  918. int DiffTimebWithNowSec(struct timeb ST)
  919. {
  920. //return milli-second
  921. struct timeb ET;
  922. unsigned int StartTime,StopTime;
  923. ftime(&ET);
  924. StartTime=(unsigned int)ST.time;
  925. StopTime=(unsigned int)ET.time;
  926. return (StopTime-StartTime);
  927. }
  928. int getStartStop(uint8_t *start, uint8_t *stop)
  929. {
  930. struct ParsingResult
  931. {
  932. int result;
  933. int scanedElement;
  934. int year;
  935. int month;
  936. int mday;
  937. int hour;
  938. int min;
  939. int sec;
  940. int tz_hour;
  941. int tz_min;
  942. float minSec;
  943. };
  944. struct ParsingResult parseStart;
  945. struct ParsingResult parseStop;
  946. int result = -1;
  947. struct tm tmStart;
  948. struct timeb tbStart;
  949. struct tm tmStop;
  950. struct timeb tbStop;
  951. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  952. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  953. // Scan start & stop date time
  954. if(strstr((char*)start, ".") != NULL)
  955. {
  956. // Original data with mini second
  957. if(strstr((char*)start, "Z") != NULL)
  958. {
  959. // Original data with Z
  960. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  961. &parseStart.year,
  962. &parseStart.month,
  963. &parseStart.mday,
  964. &parseStart.hour,
  965. &parseStart.min,
  966. &parseStart.sec,
  967. &parseStart.minSec);
  968. }
  969. else
  970. {
  971. // Original data without Z
  972. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  973. &parseStart.year,
  974. &parseStart.month,
  975. &parseStart.mday,
  976. &parseStart.hour,
  977. &parseStart.min,
  978. &parseStart.sec,
  979. &parseStart.minSec,
  980. &parseStart.tz_hour,
  981. &parseStart.tz_min);
  982. }
  983. }
  984. else
  985. {
  986. // Original data without mini second
  987. if(strstr((char*)start, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  991. &parseStart.year,
  992. &parseStart.month,
  993. &parseStart.mday,
  994. &parseStart.hour,
  995. &parseStart.min,
  996. &parseStart.sec);
  997. }
  998. else
  999. {
  1000. // Original data without Z
  1001. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1002. &parseStart.year,
  1003. &parseStart.month,
  1004. &parseStart.mday,
  1005. &parseStart.hour,
  1006. &parseStart.min,
  1007. &parseStart.sec,
  1008. &parseStart.tz_hour,
  1009. &parseStart.tz_min);
  1010. }
  1011. }
  1012. if(strstr((char*)stop, ".") != NULL)
  1013. {
  1014. // Original data with mini second
  1015. if(strstr((char*)stop, "Z") != NULL)
  1016. {
  1017. // Original data with Z
  1018. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1019. &parseStop.year,
  1020. &parseStop.month,
  1021. &parseStop.mday,
  1022. &parseStop.hour,
  1023. &parseStop.min,
  1024. &parseStop.sec,
  1025. &parseStop.minSec);
  1026. }
  1027. else
  1028. {
  1029. // Original data without Z
  1030. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1031. &parseStop.year,
  1032. &parseStop.month,
  1033. &parseStop.mday,
  1034. &parseStop.hour,
  1035. &parseStop.min,
  1036. &parseStop.sec,
  1037. &parseStop.minSec,
  1038. &parseStop.tz_hour,
  1039. &parseStop.tz_min);
  1040. }
  1041. }
  1042. else
  1043. {
  1044. // Original data without mini second
  1045. if(strstr((char*)stop, "Z") != NULL)
  1046. {
  1047. // Original data with Z
  1048. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1049. &parseStop.year,
  1050. &parseStop.month,
  1051. &parseStop.mday,
  1052. &parseStop.hour,
  1053. &parseStop.min,
  1054. &parseStop.sec);
  1055. }
  1056. else
  1057. {
  1058. // Original data without Z
  1059. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1060. &parseStop.year,
  1061. &parseStop.month,
  1062. &parseStop.mday,
  1063. &parseStop.hour,
  1064. &parseStop.min,
  1065. &parseStop.sec,
  1066. &parseStop.tz_hour,
  1067. &parseStop.tz_min);
  1068. }
  1069. }
  1070. // Calculate date time difference
  1071. if((parseStart.scanedElement >=6) &&
  1072. (parseStop.scanedElement >=6))
  1073. {
  1074. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1075. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1076. tmStart.tm_year = parseStart.year - 1900;
  1077. tmStart.tm_mon = parseStart.month - 1;
  1078. tmStart.tm_mday = parseStart.mday;
  1079. tmStart.tm_hour = parseStart.hour;
  1080. tmStart.tm_min = parseStart.min;
  1081. tmStart.tm_sec = parseStart.sec;
  1082. tmStart.tm_gmtoff = 0;
  1083. tbStart.time = mktime(&tmStart);
  1084. tbStart.timezone = 0;
  1085. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1086. tmStop.tm_year = parseStop.year - 1900;
  1087. tmStop.tm_mon = parseStop.month - 1;
  1088. tmStop.tm_mday = parseStop.mday;
  1089. tmStop.tm_hour = parseStop.hour;
  1090. tmStop.tm_min = parseStop.min;
  1091. tmStop.tm_sec = parseStop.sec;
  1092. tmStop.tm_gmtoff = 0;
  1093. tbStop.time = mktime(&tmStop);
  1094. tbStop.timezone = 0;
  1095. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1096. result = DiffTimebSec(tbStart, tbStop);
  1097. //DEBUG_INFO("getStartStop(): %d\n", result);
  1098. }
  1099. else
  1100. {
  1101. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1102. }
  1103. return result;
  1104. }
  1105. int isOvertNow(uint8_t *start)
  1106. {
  1107. int result = NO;
  1108. struct ParsingResult
  1109. {
  1110. int result;
  1111. int scanedElement;
  1112. int year;
  1113. int month;
  1114. int mday;
  1115. int hour;
  1116. int min;
  1117. int sec;
  1118. int tz_hour;
  1119. int tz_min;
  1120. float minSec;
  1121. }parsingResult;
  1122. struct tm tmStart;
  1123. struct timeb tbStart;
  1124. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1125. if(strstr((char*)start, ".") != NULL)
  1126. {
  1127. // Original data with mini second
  1128. if(strstr((char*)start, "Z") != NULL)
  1129. {
  1130. // Original data with Z
  1131. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1132. &parsingResult.year,
  1133. &parsingResult.month,
  1134. &parsingResult.mday,
  1135. &parsingResult.hour,
  1136. &parsingResult.min,
  1137. &parsingResult.sec,
  1138. &parsingResult.minSec);
  1139. }
  1140. else
  1141. {
  1142. // Original data without Z
  1143. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1144. &parsingResult.year,
  1145. &parsingResult.month,
  1146. &parsingResult.mday,
  1147. &parsingResult.hour,
  1148. &parsingResult.min,
  1149. &parsingResult.sec,
  1150. &parsingResult.minSec,
  1151. &parsingResult.tz_hour,
  1152. &parsingResult.tz_min);
  1153. }
  1154. }
  1155. else
  1156. {
  1157. // Original data without mini second
  1158. if(strstr((char*)start, "Z") != NULL)
  1159. {
  1160. // Original data with Z
  1161. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1162. &parsingResult.year,
  1163. &parsingResult.month,
  1164. &parsingResult.mday,
  1165. &parsingResult.hour,
  1166. &parsingResult.min,
  1167. &parsingResult.sec);
  1168. }
  1169. else
  1170. {
  1171. // Original data without Z
  1172. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1173. &parsingResult.year,
  1174. &parsingResult.month,
  1175. &parsingResult.mday,
  1176. &parsingResult.hour,
  1177. &parsingResult.min,
  1178. &parsingResult.sec,
  1179. &parsingResult.tz_hour,
  1180. &parsingResult.tz_min);
  1181. }
  1182. }
  1183. if(parsingResult.scanedElement >= 6)
  1184. {
  1185. tmStart.tm_year = parsingResult.year - 1900;
  1186. tmStart.tm_mon = parsingResult.month - 1;
  1187. tmStart.tm_mday = parsingResult.mday;
  1188. tmStart.tm_hour = parsingResult.hour;
  1189. tmStart.tm_min = parsingResult.min;
  1190. tmStart.tm_sec = parsingResult.sec;
  1191. tmStart.tm_gmtoff = 0;
  1192. tbStart.time = mktime(&tmStart);
  1193. tbStart.timezone = 0;
  1194. tbStart.millitm = 0;
  1195. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1196. if(DiffTimebWithNowSec(tbStart) <= 0)
  1197. result = NO;
  1198. else
  1199. result = YES;
  1200. }
  1201. else
  1202. {
  1203. DEBUG_WARN("Start date parsing error.\n");
  1204. }
  1205. return result;
  1206. }
  1207. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1208. {
  1209. struct ParsingResult
  1210. {
  1211. int result;
  1212. int scanedElement;
  1213. int year;
  1214. int month;
  1215. int mday;
  1216. int hour;
  1217. int min;
  1218. int sec;
  1219. int tz_hour;
  1220. int tz_min;
  1221. float minSec;
  1222. };
  1223. struct ParsingResult parseStart;
  1224. struct ParsingResult parseStop;
  1225. int result = -1;
  1226. struct tm tmStart;
  1227. struct timeb tbStart;
  1228. struct tm tmStop;
  1229. struct timeb tbStop;
  1230. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1231. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1232. // Scan start & stop date time
  1233. if(strstr((char*)start, ".") != NULL)
  1234. {
  1235. // Original data with mini second
  1236. if(strstr((char*)start, "Z") != NULL)
  1237. {
  1238. // Original data with Z
  1239. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1240. &parseStart.year,
  1241. &parseStart.month,
  1242. &parseStart.mday,
  1243. &parseStart.hour,
  1244. &parseStart.min,
  1245. &parseStart.sec,
  1246. &parseStart.minSec);
  1247. }
  1248. else
  1249. {
  1250. // Original data without Z
  1251. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1252. &parseStart.year,
  1253. &parseStart.month,
  1254. &parseStart.mday,
  1255. &parseStart.hour,
  1256. &parseStart.min,
  1257. &parseStart.sec,
  1258. &parseStart.minSec,
  1259. &parseStart.tz_hour,
  1260. &parseStart.tz_min);
  1261. }
  1262. }
  1263. else
  1264. {
  1265. // Original data without mini second
  1266. if(strstr((char*)start, "Z") != NULL)
  1267. {
  1268. // Original data with Z
  1269. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1270. &parseStart.year,
  1271. &parseStart.month,
  1272. &parseStart.mday,
  1273. &parseStart.hour,
  1274. &parseStart.min,
  1275. &parseStart.sec);
  1276. }
  1277. else
  1278. {
  1279. // Original data without Z
  1280. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1281. &parseStart.year,
  1282. &parseStart.month,
  1283. &parseStart.mday,
  1284. &parseStart.hour,
  1285. &parseStart.min,
  1286. &parseStart.sec,
  1287. &parseStart.tz_hour,
  1288. &parseStart.tz_min);
  1289. }
  1290. }
  1291. if(strstr((char*)stop, ".") != NULL)
  1292. {
  1293. // Original data with mini second
  1294. if(strstr((char*)stop, "Z") != NULL)
  1295. {
  1296. // Original data with Z
  1297. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1298. &parseStop.year,
  1299. &parseStop.month,
  1300. &parseStop.mday,
  1301. &parseStop.hour,
  1302. &parseStop.min,
  1303. &parseStop.sec,
  1304. &parseStop.minSec);
  1305. }
  1306. else
  1307. {
  1308. // Original data without Z
  1309. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1310. &parseStop.year,
  1311. &parseStop.month,
  1312. &parseStop.mday,
  1313. &parseStop.hour,
  1314. &parseStop.min,
  1315. &parseStop.sec,
  1316. &parseStop.minSec,
  1317. &parseStop.tz_hour,
  1318. &parseStop.tz_min);
  1319. }
  1320. }
  1321. else
  1322. {
  1323. // Original data without mini second
  1324. if(strstr((char*)stop, "Z") != NULL)
  1325. {
  1326. // Original data with Z
  1327. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1328. &parseStop.year,
  1329. &parseStop.month,
  1330. &parseStop.mday,
  1331. &parseStop.hour,
  1332. &parseStop.min,
  1333. &parseStop.sec);
  1334. }
  1335. else
  1336. {
  1337. // Original data without Z
  1338. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1339. &parseStop.year,
  1340. &parseStop.month,
  1341. &parseStop.mday,
  1342. &parseStop.hour,
  1343. &parseStop.min,
  1344. &parseStop.sec,
  1345. &parseStop.tz_hour,
  1346. &parseStop.tz_min);
  1347. }
  1348. }
  1349. // Calculate date time difference
  1350. if((parseStart.scanedElement >=6) &&
  1351. (parseStop.scanedElement >=6))
  1352. {
  1353. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1354. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1355. tmStart.tm_year = parseStart.year - 1900;
  1356. tmStart.tm_mon = parseStart.month - 1;
  1357. tmStart.tm_mday = parseStart.mday;
  1358. tmStart.tm_hour = parseStart.hour;
  1359. tmStart.tm_min = parseStart.min;
  1360. tmStart.tm_sec = parseStart.sec;
  1361. tmStart.tm_gmtoff = 0;
  1362. tbStart.time = mktime(&tmStart);
  1363. tbStart.timezone = 0;
  1364. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1365. tmStop.tm_year = parseStop.year - 1900;
  1366. tmStop.tm_mon = parseStop.month - 1;
  1367. tmStop.tm_mday = parseStop.mday;
  1368. tmStop.tm_hour = parseStop.hour;
  1369. tmStop.tm_min = parseStop.min;
  1370. tmStop.tm_sec = parseStop.sec;
  1371. tmStop.tm_gmtoff = 0;
  1372. tbStop.time = mktime(&tmStop);
  1373. tbStop.timezone = 0;
  1374. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1375. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1376. //DEBUG_INFO("getStartStop(): %d\n", result);
  1377. }
  1378. else
  1379. {
  1380. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1381. }
  1382. return result;
  1383. }
  1384. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1385. {
  1386. FILE *fp;
  1387. char profileFileName[128];
  1388. char *line = NULL;
  1389. size_t len = 0;
  1390. time_t CurrentTime;
  1391. struct tm *tmComposite;
  1392. struct StructChargingProfile maxProfile;
  1393. struct StructChargingProfile compositeProfile;
  1394. uint8_t limitMax=0;
  1395. int compositePeriodIdx = 0;
  1396. //uint8_t isDurationNull = FALSE;
  1397. CurrentTime = time(NULL);
  1398. tmComposite=localtime(&CurrentTime);
  1399. 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);
  1400. if(isUnitA)
  1401. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1402. else
  1403. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1404. compositeProfile.ChargingSchedule.Duration = durationReq;
  1405. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1406. {
  1407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1408. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1409. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1410. }
  1411. compositeProfile.ChargingProfileId = 0;
  1412. compositeProfile.StackLevel = 99 ;
  1413. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1414. maxProfile.ChargingProfileId = -1;
  1415. maxProfile.ChargingSchedule.Duration = -1;
  1416. system("rm -f /tmp/*.json");
  1417. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1418. // Search max profile
  1419. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1420. if((access(profileFileName, F_OK))!=-1)
  1421. {
  1422. fp = fopen(profileFileName, "r");
  1423. while(getline(&line, &len, fp) != -1)
  1424. {
  1425. json_object *obj = NULL;
  1426. obj = json_tokener_parse(line);
  1427. if(is_error(obj))
  1428. {
  1429. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1430. }
  1431. else
  1432. {
  1433. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1434. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1435. )
  1436. {
  1437. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1438. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1439. )
  1440. {
  1441. struct tm tmFrom, tmTo;
  1442. struct timeb tbFrom, tbTo;
  1443. 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) &&
  1444. (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))
  1445. {
  1446. tmFrom.tm_year -= 1900;
  1447. tmFrom.tm_mon -= 1;
  1448. tbFrom.time = mktime(&tmFrom);
  1449. tmTo.tm_year -= 1900;
  1450. tmTo.tm_mon -= 1;
  1451. tbTo.time = mktime(&tmTo);
  1452. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1453. {
  1454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1455. {
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1457. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1458. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1459. }
  1460. if(maxProfile.ChargingProfileId == -1)
  1461. DEBUG_INFO("MaxProfile found.\n");
  1462. else
  1463. DEBUG_INFO("MaxProfile updated.\n");
  1464. // Required item
  1465. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1466. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1467. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1468. if(isUnitA)
  1469. {
  1470. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1471. 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++)
  1472. {
  1473. 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"));
  1474. 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?
  1475. 3:
  1476. 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")));
  1477. 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")));
  1478. }
  1479. }
  1480. else
  1481. {
  1482. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1483. 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++)
  1484. {
  1485. 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"));
  1486. 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?
  1487. 3:
  1488. 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")));
  1489. 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));
  1490. }
  1491. }
  1492. // Optional item
  1493. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1494. {
  1495. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1496. }
  1497. else
  1498. {
  1499. sprintf((char*)maxProfile.ValidFrom, " ");
  1500. }
  1501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1502. {
  1503. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1504. }
  1505. else
  1506. {
  1507. sprintf((char*)maxProfile.ValidTo, " ");
  1508. }
  1509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1510. {
  1511. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1512. }
  1513. else
  1514. {
  1515. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1516. }
  1517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1518. {
  1519. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1520. }
  1521. else
  1522. {
  1523. maxProfile.TransactionId = -1;
  1524. }
  1525. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1526. {
  1527. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1528. }
  1529. else
  1530. {
  1531. maxProfile.ChargingSchedule.Duration = 86400;
  1532. //isDurationNull = TRUE;
  1533. }
  1534. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1535. {
  1536. 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")));
  1537. }
  1538. else
  1539. {
  1540. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1541. }
  1542. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1543. {
  1544. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1545. }
  1546. else
  1547. {
  1548. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1549. }
  1550. }
  1551. }
  1552. }
  1553. else
  1554. {
  1555. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1556. {
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1559. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1560. }
  1561. if(maxProfile.ChargingProfileId == -1)
  1562. DEBUG_INFO("MaxProfile found.\n");
  1563. else
  1564. DEBUG_INFO("MaxProfile updated.\n");
  1565. // Required item
  1566. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1567. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1568. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1569. if(isUnitA)
  1570. {
  1571. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1572. 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++)
  1573. {
  1574. 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"));
  1575. 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?
  1576. 3:
  1577. 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")));
  1578. 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")));
  1579. }
  1580. }
  1581. else
  1582. {
  1583. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1584. 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++)
  1585. {
  1586. 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"));
  1587. 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?
  1588. 3:
  1589. 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")));
  1590. 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));
  1591. }
  1592. }
  1593. // Optional item
  1594. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1595. {
  1596. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1597. }
  1598. else
  1599. {
  1600. sprintf((char*)maxProfile.ValidFrom, " ");
  1601. }
  1602. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1603. {
  1604. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1605. }
  1606. else
  1607. {
  1608. sprintf((char*)maxProfile.ValidTo, " ");
  1609. }
  1610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1611. {
  1612. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1613. }
  1614. else
  1615. {
  1616. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1617. }
  1618. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1619. {
  1620. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1621. }
  1622. else
  1623. {
  1624. maxProfile.TransactionId = -1;
  1625. }
  1626. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1627. {
  1628. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1629. }
  1630. else
  1631. {
  1632. maxProfile.ChargingSchedule.Duration = 86400;
  1633. //isDurationNull = TRUE;
  1634. }
  1635. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1636. {
  1637. 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")));
  1638. }
  1639. else
  1640. {
  1641. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1642. }
  1643. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1644. {
  1645. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1646. }
  1647. else
  1648. {
  1649. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1650. }
  1651. }
  1652. }
  1653. }
  1654. json_object_put(obj);
  1655. }
  1656. fclose(fp);
  1657. /*
  1658. if(maxProfile.ChargingProfileId !=-1)
  1659. {
  1660. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1661. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1662. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1663. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1664. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1665. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1666. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1667. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1668. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1669. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1670. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1671. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1672. {
  1673. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1674. {
  1675. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1676. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1677. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1678. }
  1679. }
  1680. }
  1681. else
  1682. DEBUG_INFO("MaxProfile not found.\n");
  1683. DEBUG_INFO("------------------------------------\n");*/
  1684. }
  1685. if(maxProfile.ChargingProfileId != -1)
  1686. {
  1687. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1688. {
  1689. if(maxProfile.ChargingSchedule.Duration != -1)
  1690. {
  1691. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1692. 0:
  1693. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1694. }
  1695. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1696. {
  1697. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1698. {
  1699. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1700. 0:
  1701. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1702. if(idxPeriod > 0)
  1703. {
  1704. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1705. {
  1706. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1707. }
  1708. }
  1709. }
  1710. }
  1711. }
  1712. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1713. {
  1714. if(maxProfile.ChargingSchedule.Duration != -1)
  1715. {
  1716. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1717. }
  1718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1719. {
  1720. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1721. {
  1722. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1723. if(idxPeriod > 0)
  1724. {
  1725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1726. {
  1727. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1728. }
  1729. }
  1730. }
  1731. }
  1732. }
  1733. else
  1734. {
  1735. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1736. {
  1737. if(maxProfile.ChargingSchedule.Duration != -1)
  1738. {
  1739. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1740. 0:
  1741. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1742. }
  1743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1744. {
  1745. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1746. {
  1747. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1748. 0:
  1749. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1750. if(idxPeriod > 0)
  1751. {
  1752. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1753. {
  1754. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. else
  1761. {
  1762. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  1763. {
  1764. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1765. 0:
  1766. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1767. }
  1768. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1769. {
  1770. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1771. {
  1772. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1773. 0:
  1774. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1775. if(idxPeriod > 0)
  1776. {
  1777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1778. {
  1779. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. }
  1786. /*
  1787. DEBUG_INFO("MaxProfile after align.\n");
  1788. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1789. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1790. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1791. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1792. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1793. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1794. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1795. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1796. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1797. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1798. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1800. {
  1801. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1802. {
  1803. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1804. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1805. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1806. }
  1807. }
  1808. DEBUG_INFO("------------------------------------\n");*/
  1809. }
  1810. // Find each profile period quantity
  1811. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1812. {
  1813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1814. limitMax = idx+1;
  1815. }
  1816. if(maxProfile.ChargingProfileId != -1)
  1817. {
  1818. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1819. {
  1820. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1821. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1822. (maxProfile.ChargingSchedule.Duration > 0))
  1823. {
  1824. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1825. {
  1826. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. compositePeriodIdx++;
  1828. }
  1829. else
  1830. {
  1831. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1832. }
  1833. }
  1834. }
  1835. }
  1836. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1837. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1838. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1839. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1841. {
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1843. {
  1844. compositeProfile.ChargingProfileId = 1;
  1845. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1846. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1847. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1848. }
  1849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1850. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1851. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1852. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1853. }
  1854. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1855. if(line)
  1856. free(line);
  1857. }
  1858. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1859. {
  1860. FILE *fp;
  1861. char profileFileName[128];
  1862. char *line = NULL;
  1863. size_t len = 0;
  1864. time_t CurrentTime;
  1865. struct tm *tmComposite;
  1866. struct StructChargingProfile maxProfile;
  1867. struct StructChargingProfile defaultTxProfile;
  1868. struct StructChargingProfile txProfile;
  1869. struct StructChargingProfile compositeProfile;
  1870. struct StructChargingSchedulePeriod tmpPeriod;
  1871. uint8_t limitMax=0;
  1872. uint8_t limitDef=0;
  1873. uint8_t limitTx=0;
  1874. int compositePeriodIdx = 0;
  1875. CurrentTime = time(NULL);
  1876. tmComposite=localtime(&CurrentTime);
  1877. 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);
  1878. if(isUnitA)
  1879. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1880. else
  1881. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1882. compositeProfile.ChargingSchedule.Duration = durationReq;
  1883. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1884. {
  1885. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1886. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1887. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1888. }
  1889. compositeProfile.ChargingProfileId = 0;
  1890. compositeProfile.StackLevel = 99 ;
  1891. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1892. maxProfile.ChargingProfileId = -1;
  1893. defaultTxProfile.ChargingProfileId = -1;
  1894. txProfile.ChargingProfileId = -1;
  1895. maxProfile.ChargingSchedule.Duration = -1;
  1896. defaultTxProfile.ChargingSchedule.Duration = -1;
  1897. txProfile.ChargingSchedule.Duration = -1;
  1898. system("rm -f /tmp/*.json");
  1899. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1900. /*
  1901. * Search valid charging profile
  1902. */
  1903. //DEBUG_INFO("====================================\n");
  1904. // Search tx profile
  1905. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1906. if((access(profileFileName, F_OK))!=-1)
  1907. {
  1908. fp = fopen(profileFileName, "r");
  1909. while(getline(&line, &len, fp) != -1)
  1910. {
  1911. json_object *obj = NULL;
  1912. obj = json_tokener_parse(line);
  1913. if(is_error(obj))
  1914. {
  1915. DEBUG_ERROR("Parse txProfile from file error.\n");
  1916. }
  1917. else
  1918. {
  1919. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1920. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1921. )
  1922. {
  1923. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1924. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1925. )
  1926. {
  1927. struct tm tmFrom, tmTo;
  1928. struct timeb tbFrom, tbTo;
  1929. 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) &&
  1930. (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))
  1931. {
  1932. tmFrom.tm_year -= 1900;
  1933. tmFrom.tm_mon -= 1;
  1934. tbFrom.time = mktime(&tmFrom);
  1935. tmTo.tm_year -= 1900;
  1936. tmTo.tm_mon -= 1;
  1937. tbTo.time = mktime(&tmTo);
  1938. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1939. {
  1940. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1941. {
  1942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1943. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1944. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1945. }
  1946. if(txProfile.ChargingProfileId == -1)
  1947. DEBUG_INFO("TxProfile found.\n");
  1948. else
  1949. DEBUG_INFO("TxProfile updated.\n");
  1950. // Required item
  1951. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1952. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1953. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1954. if(isUnitA)
  1955. {
  1956. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1957. 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++)
  1958. {
  1959. 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"));
  1960. 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?
  1961. 3:
  1962. 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")));
  1963. 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")));
  1964. }
  1965. }
  1966. else
  1967. {
  1968. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1969. 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++)
  1970. {
  1971. 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"));
  1972. 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?
  1973. 3:
  1974. 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")));
  1975. 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));
  1976. }
  1977. }
  1978. // Optional item
  1979. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1980. {
  1981. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1982. }
  1983. else
  1984. {
  1985. sprintf((char*)txProfile.ValidFrom, " ");
  1986. }
  1987. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1988. {
  1989. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1990. }
  1991. else
  1992. {
  1993. sprintf((char*)txProfile.ValidTo, " ");
  1994. }
  1995. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1996. {
  1997. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1998. }
  1999. else
  2000. {
  2001. sprintf((char*)txProfile.RecurrencyKind, " ");
  2002. }
  2003. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2004. {
  2005. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2006. }
  2007. else
  2008. {
  2009. txProfile.TransactionId = -1;
  2010. }
  2011. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2012. {
  2013. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2014. }
  2015. else
  2016. {
  2017. txProfile.ChargingSchedule.Duration = 86400;
  2018. }
  2019. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2020. {
  2021. 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")));
  2022. }
  2023. else
  2024. {
  2025. 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));
  2026. }
  2027. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2028. {
  2029. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2030. }
  2031. else
  2032. {
  2033. txProfile.ChargingSchedule.MinChargingRate = -1;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. else
  2039. {
  2040. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2041. {
  2042. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2043. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2044. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2045. }
  2046. if(txProfile.ChargingProfileId == -1)
  2047. DEBUG_INFO("TxProfile found.\n");
  2048. else
  2049. DEBUG_INFO("TxProfile updated.\n");
  2050. // Required item
  2051. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2052. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2053. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2054. if(isUnitA)
  2055. {
  2056. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2057. 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++)
  2058. {
  2059. 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"));
  2060. 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?
  2061. 3:
  2062. 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")));
  2063. 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")));
  2064. }
  2065. }
  2066. else
  2067. {
  2068. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2069. 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++)
  2070. {
  2071. 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"));
  2072. 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?
  2073. 3:
  2074. 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")));
  2075. 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));
  2076. }
  2077. }
  2078. // Optional item
  2079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2080. {
  2081. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2082. }
  2083. else
  2084. {
  2085. sprintf((char*)txProfile.ValidFrom, " ");
  2086. }
  2087. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2088. {
  2089. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2090. }
  2091. else
  2092. {
  2093. sprintf((char*)txProfile.ValidTo, " ");
  2094. }
  2095. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2096. {
  2097. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2098. }
  2099. else
  2100. {
  2101. sprintf((char*)txProfile.RecurrencyKind, " ");
  2102. }
  2103. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2104. {
  2105. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2106. }
  2107. else
  2108. {
  2109. txProfile.TransactionId = -1;
  2110. }
  2111. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2112. {
  2113. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2114. }
  2115. else
  2116. {
  2117. txProfile.ChargingSchedule.Duration = 86400;
  2118. }
  2119. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2120. {
  2121. 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")));
  2122. }
  2123. else
  2124. {
  2125. 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));
  2126. }
  2127. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2128. {
  2129. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2130. }
  2131. else
  2132. {
  2133. txProfile.ChargingSchedule.MinChargingRate = -1;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. json_object_put(obj);
  2139. }
  2140. fclose(fp);
  2141. /*
  2142. if(txProfile.ChargingProfileId != -1)
  2143. {
  2144. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2145. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2146. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2147. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2148. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2149. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2150. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2151. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2152. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2153. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2154. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2155. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2156. {
  2157. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2158. {
  2159. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2160. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2161. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2162. }
  2163. }
  2164. }
  2165. else
  2166. DEBUG_INFO("TxProfile not found.\n");*/
  2167. }
  2168. // Search default tx profile
  2169. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2170. if((access(profileFileName, F_OK))==-1)
  2171. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2172. if((access(profileFileName, F_OK))!=-1)
  2173. {
  2174. fp = fopen(profileFileName, "r");
  2175. while(getline(&line, &len, fp) != -1)
  2176. {
  2177. json_object *obj = NULL;
  2178. obj = json_tokener_parse(line);
  2179. if(is_error(obj))
  2180. {
  2181. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2182. }
  2183. else
  2184. {
  2185. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2186. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2187. )
  2188. {
  2189. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2190. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2191. )
  2192. {
  2193. struct tm tmFrom, tmTo;
  2194. struct timeb tbFrom, tbTo;
  2195. 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) &&
  2196. (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))
  2197. {
  2198. tmFrom.tm_year -= 1900;
  2199. tmFrom.tm_mon -= 1;
  2200. tbFrom.time = mktime(&tmFrom);
  2201. tmTo.tm_year -= 1900;
  2202. tmTo.tm_mon -= 1;
  2203. tbTo.time = mktime(&tmTo);
  2204. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2205. {
  2206. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2207. {
  2208. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2209. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2210. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2211. }
  2212. if(defaultTxProfile.ChargingProfileId == -1)
  2213. DEBUG_INFO("TxDefaultProfile found.\n");
  2214. else
  2215. DEBUG_INFO("TxDefaultProfile updated.\n");
  2216. // Required item
  2217. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2218. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2219. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2220. if(isUnitA)
  2221. {
  2222. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2223. 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++)
  2224. {
  2225. 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"));
  2226. 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?
  2227. 3:
  2228. 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")));
  2229. 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")));
  2230. }
  2231. }
  2232. else
  2233. {
  2234. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2235. 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++)
  2236. {
  2237. 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"));
  2238. 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?
  2239. 3:
  2240. 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")));
  2241. 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));
  2242. }
  2243. }
  2244. // Optional item
  2245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2246. {
  2247. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2248. }
  2249. else
  2250. {
  2251. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2252. }
  2253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2254. {
  2255. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2256. }
  2257. else
  2258. {
  2259. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2260. }
  2261. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2262. {
  2263. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2264. }
  2265. else
  2266. {
  2267. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2268. }
  2269. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2270. {
  2271. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2272. }
  2273. else
  2274. {
  2275. defaultTxProfile.TransactionId = -1;
  2276. }
  2277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2278. {
  2279. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2280. }
  2281. else
  2282. {
  2283. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2284. }
  2285. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2286. {
  2287. 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")));
  2288. }
  2289. else
  2290. {
  2291. 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));
  2292. }
  2293. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2294. {
  2295. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2296. }
  2297. else
  2298. {
  2299. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2300. }
  2301. }
  2302. }
  2303. }
  2304. else
  2305. {
  2306. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2307. {
  2308. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2309. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2310. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2311. }
  2312. if(defaultTxProfile.ChargingProfileId == -1)
  2313. DEBUG_INFO("TxDefaultProfile found.\n");
  2314. else
  2315. DEBUG_INFO("TxDefaultProfile updated.\n");
  2316. // Required item
  2317. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2318. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2319. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2320. if(isUnitA)
  2321. {
  2322. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2323. 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++)
  2324. {
  2325. 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"));
  2326. 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?
  2327. 3:
  2328. 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")));
  2329. 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")));
  2330. }
  2331. }
  2332. else
  2333. {
  2334. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2335. 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++)
  2336. {
  2337. 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"));
  2338. 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?
  2339. 3:
  2340. 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")));
  2341. 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));
  2342. }
  2343. }
  2344. // Optional item
  2345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2346. {
  2347. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2348. }
  2349. else
  2350. {
  2351. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2352. }
  2353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2354. {
  2355. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2360. }
  2361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2362. {
  2363. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2364. }
  2365. else
  2366. {
  2367. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2368. }
  2369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2370. {
  2371. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2372. }
  2373. else
  2374. {
  2375. defaultTxProfile.TransactionId = -1;
  2376. }
  2377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2378. {
  2379. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2380. }
  2381. else
  2382. {
  2383. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2384. }
  2385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2386. {
  2387. 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")));
  2388. }
  2389. else
  2390. {
  2391. 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));
  2392. }
  2393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2394. {
  2395. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2396. }
  2397. else
  2398. {
  2399. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. json_object_put(obj);
  2405. }
  2406. fclose(fp);
  2407. /*
  2408. if(defaultTxProfile.ChargingProfileId != -1)
  2409. {
  2410. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2411. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2412. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2413. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2414. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2415. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2416. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2417. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2418. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2419. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2420. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2422. {
  2423. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2424. {
  2425. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2426. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2427. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2428. }
  2429. }
  2430. }
  2431. else
  2432. DEBUG_INFO("TxDefaultProfile not found.\n");
  2433. DEBUG_INFO("------------------------------------\n");*/
  2434. }
  2435. // Search max profile
  2436. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2437. if((access(profileFileName, F_OK))!=-1)
  2438. {
  2439. fp = fopen(profileFileName, "r");
  2440. while(getline(&line, &len, fp) != -1)
  2441. {
  2442. json_object *obj = NULL;
  2443. obj = json_tokener_parse(line);
  2444. if(is_error(obj))
  2445. {
  2446. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2447. }
  2448. else
  2449. {
  2450. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2451. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2452. )
  2453. {
  2454. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2455. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2456. )
  2457. {
  2458. struct tm tmFrom, tmTo;
  2459. struct timeb tbFrom, tbTo;
  2460. 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) &&
  2461. (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))
  2462. {
  2463. tmFrom.tm_year -= 1900;
  2464. tmFrom.tm_mon -= 1;
  2465. tbFrom.time = mktime(&tmFrom);
  2466. tmTo.tm_year -= 1900;
  2467. tmTo.tm_mon -= 1;
  2468. tbTo.time = mktime(&tmTo);
  2469. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2470. {
  2471. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2472. {
  2473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2474. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2475. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2476. }
  2477. if(maxProfile.ChargingProfileId == -1)
  2478. DEBUG_INFO("MaxProfile found.\n");
  2479. else
  2480. DEBUG_INFO("MaxProfile updated.\n");
  2481. // Required item
  2482. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2483. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2484. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2485. if(isUnitA)
  2486. {
  2487. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2488. 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++)
  2489. {
  2490. 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"));
  2491. 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?
  2492. 3:
  2493. 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")));
  2494. 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")));
  2495. }
  2496. }
  2497. else
  2498. {
  2499. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2500. 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++)
  2501. {
  2502. 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"));
  2503. 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?
  2504. 3:
  2505. 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")));
  2506. 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));
  2507. }
  2508. }
  2509. // Optional item
  2510. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2511. {
  2512. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2513. }
  2514. else
  2515. {
  2516. sprintf((char*)maxProfile.ValidFrom, " ");
  2517. }
  2518. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2519. {
  2520. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2521. }
  2522. else
  2523. {
  2524. sprintf((char*)maxProfile.ValidTo, " ");
  2525. }
  2526. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2527. {
  2528. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2529. }
  2530. else
  2531. {
  2532. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2533. }
  2534. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2535. {
  2536. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2537. }
  2538. else
  2539. {
  2540. maxProfile.TransactionId = -1;
  2541. }
  2542. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2543. {
  2544. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2545. }
  2546. else
  2547. {
  2548. maxProfile.ChargingSchedule.Duration = 86400;
  2549. }
  2550. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2551. {
  2552. 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")));
  2553. }
  2554. else
  2555. {
  2556. 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));
  2557. }
  2558. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2559. {
  2560. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2561. }
  2562. else
  2563. {
  2564. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. else
  2570. {
  2571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2572. {
  2573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2576. }
  2577. if(maxProfile.ChargingProfileId == -1)
  2578. DEBUG_INFO("MaxProfile found.\n");
  2579. else
  2580. DEBUG_INFO("MaxProfile updated.\n");
  2581. // Required item
  2582. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2583. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2584. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2585. if(isUnitA)
  2586. {
  2587. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2588. 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++)
  2589. {
  2590. 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"));
  2591. 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?
  2592. 3:
  2593. 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")));
  2594. 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")));
  2595. }
  2596. }
  2597. else
  2598. {
  2599. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2600. 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++)
  2601. {
  2602. 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"));
  2603. 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?
  2604. 3:
  2605. 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")));
  2606. 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));
  2607. }
  2608. }
  2609. // Optional item
  2610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2611. {
  2612. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2613. }
  2614. else
  2615. {
  2616. sprintf((char*)maxProfile.ValidFrom, " ");
  2617. }
  2618. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2619. {
  2620. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2621. }
  2622. else
  2623. {
  2624. sprintf((char*)maxProfile.ValidTo, " ");
  2625. }
  2626. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2627. {
  2628. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2629. }
  2630. else
  2631. {
  2632. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2633. }
  2634. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2635. {
  2636. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2637. }
  2638. else
  2639. {
  2640. maxProfile.TransactionId = -1;
  2641. }
  2642. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2643. {
  2644. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2645. }
  2646. else
  2647. {
  2648. maxProfile.ChargingSchedule.Duration = 86400;
  2649. }
  2650. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2651. {
  2652. 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")));
  2653. }
  2654. else
  2655. {
  2656. 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));
  2657. }
  2658. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2659. {
  2660. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2661. }
  2662. else
  2663. {
  2664. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2665. }
  2666. }
  2667. }
  2668. }
  2669. json_object_put(obj);
  2670. }
  2671. fclose(fp);
  2672. /*
  2673. if(maxProfile.ChargingProfileId !=-1)
  2674. {
  2675. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2676. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2677. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2678. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2679. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2680. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2681. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2682. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2683. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2684. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2685. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2686. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2687. {
  2688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2689. {
  2690. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2691. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2692. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2693. }
  2694. }
  2695. }
  2696. else
  2697. DEBUG_INFO("MaxProfile not found.\n");
  2698. DEBUG_INFO("------------------------------------\n");*/
  2699. }
  2700. /*
  2701. * Align found profile start schedule & periods
  2702. */
  2703. //DEBUG_INFO("====================================\n");
  2704. /*
  2705. // For local test usage, force modify found profile start schedule info
  2706. 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);
  2707. 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);
  2708. 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);
  2709. */
  2710. if(txProfile.ChargingProfileId != -1)
  2711. {
  2712. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2713. {
  2714. if(txProfile.ChargingSchedule.Duration != -1)
  2715. {
  2716. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2717. 0:
  2718. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2719. }
  2720. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2721. {
  2722. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2723. {
  2724. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2725. 0:
  2726. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2727. if(idxPeriod > 0)
  2728. {
  2729. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2730. {
  2731. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2732. }
  2733. }
  2734. }
  2735. }
  2736. }
  2737. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2738. {
  2739. if(txProfile.ChargingSchedule.Duration != -1)
  2740. {
  2741. 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?
  2742. 0:
  2743. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2744. }
  2745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2746. {
  2747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2748. {
  2749. 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?
  2750. 0:
  2751. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2752. if(idxPeriod > 0)
  2753. {
  2754. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2755. {
  2756. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2757. }
  2758. }
  2759. }
  2760. }
  2761. }
  2762. else
  2763. {
  2764. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2765. {
  2766. if(txProfile.ChargingSchedule.Duration != -1)
  2767. {
  2768. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2769. 0:
  2770. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2771. }
  2772. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2773. {
  2774. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2775. {
  2776. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2777. 0:
  2778. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2779. if(idxPeriod > 0)
  2780. {
  2781. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2782. {
  2783. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2784. }
  2785. }
  2786. }
  2787. }
  2788. }
  2789. else
  2790. {
  2791. if(txProfile.ChargingSchedule.Duration != -1)
  2792. {
  2793. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2794. 0:
  2795. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2796. }
  2797. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2798. {
  2799. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2800. {
  2801. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2802. 0:
  2803. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2804. if(idxPeriod > 0)
  2805. {
  2806. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2807. {
  2808. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. }
  2815. /*
  2816. DEBUG_INFO("txProfile after align.\n");
  2817. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2818. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2819. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2820. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2821. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2822. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2823. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2824. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2825. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2826. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2827. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2829. {
  2830. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2831. {
  2832. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2833. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2834. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2835. }
  2836. }*/
  2837. }
  2838. if(defaultTxProfile.ChargingProfileId != -1)
  2839. {
  2840. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2841. {
  2842. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2843. {
  2844. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2845. 0:
  2846. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2847. }
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2851. {
  2852. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2853. 0:
  2854. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2855. if(idxPeriod > 0)
  2856. {
  2857. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2858. {
  2859. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2866. {
  2867. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2868. {
  2869. 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?
  2870. 0:
  2871. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2872. }
  2873. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2874. {
  2875. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2876. {
  2877. 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?
  2878. 0:
  2879. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2880. if(idxPeriod > 0)
  2881. {
  2882. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2883. {
  2884. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. }
  2890. else
  2891. {
  2892. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2893. {
  2894. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2895. {
  2896. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2897. 0:
  2898. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2899. }
  2900. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2901. {
  2902. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2903. {
  2904. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2905. 0:
  2906. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2907. if(idxPeriod > 0)
  2908. {
  2909. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2910. {
  2911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. else
  2918. {
  2919. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2920. {
  2921. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2922. 0:
  2923. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2924. }
  2925. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2926. {
  2927. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2928. {
  2929. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2930. 0:
  2931. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2932. if(idxPeriod > 0)
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2935. {
  2936. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2937. }
  2938. }
  2939. }
  2940. }
  2941. }
  2942. }
  2943. /*
  2944. DEBUG_INFO("defaultTxProfile after align.\n");
  2945. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2946. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2947. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2948. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2949. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2950. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2951. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2952. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2953. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2954. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2955. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2956. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2957. {
  2958. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2959. {
  2960. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2961. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2962. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2963. }
  2964. }
  2965. DEBUG_INFO("------------------------------------\n");*/
  2966. }
  2967. if(maxProfile.ChargingProfileId != -1)
  2968. {
  2969. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2970. {
  2971. if(maxProfile.ChargingSchedule.Duration != -1)
  2972. {
  2973. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2974. 0:
  2975. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2976. }
  2977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2978. {
  2979. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2980. {
  2981. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2982. 0:
  2983. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2984. if(idxPeriod > 0)
  2985. {
  2986. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2987. {
  2988. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2995. {
  2996. if(maxProfile.ChargingSchedule.Duration != -1)
  2997. {
  2998. 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?
  2999. 0:
  3000. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3001. }
  3002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3003. {
  3004. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3005. {
  3006. 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?
  3007. 0:
  3008. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3009. if(idxPeriod > 0)
  3010. {
  3011. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3012. {
  3013. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3014. }
  3015. }
  3016. }
  3017. }
  3018. }
  3019. else
  3020. {
  3021. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3022. {
  3023. if(maxProfile.ChargingSchedule.Duration != -1)
  3024. {
  3025. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3026. 0:
  3027. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3028. }
  3029. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3030. {
  3031. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3032. {
  3033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3034. 0:
  3035. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3036. if(idxPeriod > 0)
  3037. {
  3038. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3039. {
  3040. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3041. }
  3042. }
  3043. }
  3044. }
  3045. }
  3046. else
  3047. {
  3048. if(maxProfile.ChargingSchedule.Duration != -1)
  3049. {
  3050. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3051. 0:
  3052. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3053. }
  3054. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3055. {
  3056. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3057. {
  3058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3059. 0:
  3060. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3061. if(idxPeriod > 0)
  3062. {
  3063. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3064. {
  3065. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. }
  3072. /*
  3073. DEBUG_INFO("MaxProfile after align.\n");
  3074. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3075. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3076. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3077. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3078. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3079. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3080. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3081. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3082. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3083. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3084. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3085. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3086. {
  3087. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3088. {
  3089. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3090. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3091. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3092. }
  3093. }
  3094. DEBUG_INFO("------------------------------------\n");*/
  3095. }
  3096. /*
  3097. * Merge to conposite schedule
  3098. */
  3099. //DEBUG_INFO("====================================\n");
  3100. // Find each profile period quantity
  3101. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3102. {
  3103. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3104. limitMax = idx+1;
  3105. }
  3106. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3107. {
  3108. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3109. limitDef = idx+1;
  3110. }
  3111. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3112. {
  3113. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3114. limitTx = idx+1;
  3115. }
  3116. // TxProfile found, composite schedule based on it
  3117. if(txProfile.ChargingProfileId != -1)
  3118. {
  3119. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3120. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3121. {
  3122. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3123. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3124. (txProfile.ChargingSchedule.Duration > 0))
  3125. {
  3126. if(maxProfile.ChargingProfileId != -1)
  3127. {
  3128. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3129. {
  3130. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3131. {
  3132. if((maxProfile.ChargingSchedule.Duration > 0))
  3133. {
  3134. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3135. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3136. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3137. }
  3138. else
  3139. {
  3140. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3141. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3142. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3143. }
  3144. }
  3145. if(idxMaxPeriod == (limitMax-1))
  3146. {
  3147. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3148. {
  3149. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3150. {
  3151. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3152. compositePeriodIdx++;
  3153. }
  3154. else
  3155. {
  3156. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }
  3162. else
  3163. {
  3164. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3165. {
  3166. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3167. compositePeriodIdx++;
  3168. }
  3169. else
  3170. {
  3171. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3172. }
  3173. }
  3174. }
  3175. if(idxTxPeriod == (limitTx-1))
  3176. {
  3177. if(defaultTxProfile.ChargingProfileId != -1)
  3178. {
  3179. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3180. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3181. {
  3182. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3183. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3184. (defaultTxProfile.ChargingSchedule.Duration>0))
  3185. {
  3186. if(maxProfile.ChargingProfileId != -1)
  3187. {
  3188. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3189. {
  3190. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3191. {
  3192. if((maxProfile.ChargingSchedule.Duration > 0))
  3193. {
  3194. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3195. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3196. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3197. }
  3198. else
  3199. {
  3200. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3201. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3202. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3203. }
  3204. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3205. {
  3206. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3207. {
  3208. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3209. compositePeriodIdx++;
  3210. }
  3211. else
  3212. {
  3213. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3214. }
  3215. }
  3216. // Delete duplicate period
  3217. if(compositePeriodIdx > 1)
  3218. {
  3219. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3220. {
  3221. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3222. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3223. compositePeriodIdx -= 1;
  3224. }
  3225. }
  3226. }
  3227. else
  3228. {
  3229. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3230. {
  3231. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3232. compositePeriodIdx++;
  3233. }
  3234. else
  3235. {
  3236. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3237. }
  3238. break;
  3239. }
  3240. }
  3241. }
  3242. else
  3243. {
  3244. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3245. {
  3246. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3247. compositePeriodIdx++;
  3248. }
  3249. else
  3250. {
  3251. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3252. }
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. }
  3259. }
  3260. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3261. else if(defaultTxProfile.ChargingProfileId != -1)
  3262. {
  3263. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3264. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3265. {
  3266. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3267. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3268. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3269. {
  3270. if(maxProfile.ChargingProfileId != -1)
  3271. {
  3272. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3273. {
  3274. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3275. {
  3276. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3277. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3278. if((maxProfile.ChargingSchedule.Duration > 0))
  3279. {
  3280. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3281. }
  3282. else
  3283. {
  3284. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3285. }
  3286. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3287. {
  3288. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3289. {
  3290. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3291. compositePeriodIdx++;
  3292. }
  3293. else
  3294. {
  3295. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3296. }
  3297. }
  3298. // Delete duplicate period
  3299. if(compositePeriodIdx > 1)
  3300. {
  3301. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3302. {
  3303. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3304. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3305. compositePeriodIdx -= 1;
  3306. }
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3312. {
  3313. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3314. compositePeriodIdx++;
  3315. }
  3316. else
  3317. {
  3318. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3319. }
  3320. break;
  3321. }
  3322. }
  3323. }
  3324. else
  3325. {
  3326. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3327. {
  3328. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3329. compositePeriodIdx++;
  3330. }
  3331. else
  3332. {
  3333. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3334. }
  3335. }
  3336. }
  3337. }
  3338. }
  3339. // Fill other period by MaxProfile
  3340. if(maxProfile.ChargingProfileId != -1)
  3341. {
  3342. if(compositePeriodIdx==0)
  3343. {
  3344. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3345. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3346. {
  3347. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3348. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3349. (maxProfile.ChargingSchedule.Duration > 0))
  3350. {
  3351. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3352. {
  3353. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3354. compositePeriodIdx++;
  3355. }
  3356. else
  3357. {
  3358. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3359. }
  3360. }
  3361. }
  3362. }
  3363. else
  3364. {
  3365. int lastCompositePeriodIdx = compositePeriodIdx;
  3366. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3367. {
  3368. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3369. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3370. (maxProfile.ChargingSchedule.Duration > 0))
  3371. {
  3372. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3373. {
  3374. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3375. {
  3376. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3377. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3378. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3379. }
  3380. else
  3381. {
  3382. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3383. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3384. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3385. }
  3386. }
  3387. if(tmpPeriod.Limit != -1)
  3388. {
  3389. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3390. {
  3391. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3392. {
  3393. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3394. compositePeriodIdx++;
  3395. }
  3396. else
  3397. {
  3398. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3399. }
  3400. }
  3401. // Delete duplicate period
  3402. if(compositePeriodIdx > 1)
  3403. {
  3404. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3405. {
  3406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3408. compositePeriodIdx -= 1;
  3409. }
  3410. }
  3411. }
  3412. }
  3413. }
  3414. }
  3415. }
  3416. compositeProfile.ChargingSchedule.Duration = durationReq;
  3417. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3418. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3419. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3420. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3422. {
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3424. {
  3425. compositeProfile.ChargingProfileId = 1;
  3426. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3427. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3428. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3429. }
  3430. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3431. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3432. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3433. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3434. }
  3435. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3436. if(line)
  3437. free(line);
  3438. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3439. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3440. }
  3441. //==========================================
  3442. // Init all share memory
  3443. //==========================================
  3444. int InitShareMemory()
  3445. {
  3446. int result = PASS;
  3447. int MeterSMId;
  3448. //creat ShmSysConfigAndInfo
  3449. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3450. {
  3451. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3452. result = FAIL;
  3453. }
  3454. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3455. {
  3456. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3457. result = FAIL;
  3458. }
  3459. else
  3460. {}
  3461. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3462. {
  3463. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3464. result = FAIL;
  3465. }
  3466. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3467. {
  3468. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3469. result = FAIL;
  3470. }
  3471. else
  3472. {}
  3473. //creat ShmPsuData
  3474. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3475. {
  3476. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3477. result = FAIL;
  3478. }
  3479. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3480. {
  3481. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3482. result = FAIL;
  3483. }
  3484. else
  3485. {}
  3486. //link ShmOCPP16Data
  3487. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3488. {
  3489. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3490. result = FAIL;
  3491. }
  3492. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3493. {
  3494. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3495. result = FAIL;
  3496. }
  3497. else
  3498. {}
  3499. //creat ShmOCPP16DataPH
  3500. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3501. {
  3502. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3503. result = FAIL;
  3504. }
  3505. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3506. {
  3507. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3508. result = FAIL;
  3509. }
  3510. else
  3511. {}
  3512. /****************************** For Initial Settings************************************************/
  3513. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3514. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3515. // allocate Configuration memory address
  3516. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3517. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3518. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3519. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3520. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3521. //offline MeterValue Interval
  3522. TempMeterValueInterval = 0;
  3523. return result;
  3524. }
  3525. int ProcessShareMemory()
  3526. {
  3527. int result = PASS;
  3528. if(InitShareMemory() == FAIL)
  3529. {
  3530. DEBUG_ERROR("InitShareMemory NG\n");
  3531. if(ShmStatusCodeData!=NULL)
  3532. {
  3533. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3534. }
  3535. result = FAIL;
  3536. }
  3537. // Model name parsing
  3538. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3539. {
  3540. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3541. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3542. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3543. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3544. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  3545. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  3546. ) // 'D' means DC
  3547. {
  3548. // DO series
  3549. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3550. {
  3551. gunTotalNumber += 1;
  3552. gunType[gun_index] = GUN_TYPE_DO;
  3553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3554. {
  3555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3556. {
  3557. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3558. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3559. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3560. }
  3561. }
  3562. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3563. {
  3564. case Gun_Type_Chademo:
  3565. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3566. break;
  3567. case Gun_Type_CCS_2:
  3568. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3569. break;
  3570. case Gun_Type_GB:
  3571. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3572. break;
  3573. case Gun_Type_AC:
  3574. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3575. break;
  3576. default:
  3577. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3578. break;
  3579. }
  3580. }
  3581. }
  3582. else
  3583. {
  3584. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3585. {
  3586. gunTotalNumber += 1;
  3587. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3588. {
  3589. case Gun_Type_Chademo:
  3590. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3591. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3592. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3593. {
  3594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3595. {
  3596. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3597. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3598. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3599. }
  3600. }
  3601. break;
  3602. case Gun_Type_CCS_2:
  3603. gunType[gun_index] = GUN_TYPE_CCS;
  3604. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3605. for (int index = 0; index < CCS_QUANTITY; index++)
  3606. {
  3607. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3608. {
  3609. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3610. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3611. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3612. }
  3613. }
  3614. break;
  3615. case Gun_Type_GB:
  3616. gunType[gun_index] = GUN_TYPE_GBT;
  3617. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3618. for (int index = 0; index < GB_QUANTITY; index++)
  3619. {
  3620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3621. {
  3622. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3623. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3624. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3625. }
  3626. }
  3627. break;
  3628. case Gun_Type_AC:
  3629. gunType[gun_index] = GUN_TYPE_AC;
  3630. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3631. for (int index = 0; index < AC_QUANTITY; index++)
  3632. {
  3633. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3634. {
  3635. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3636. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3637. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3638. }
  3639. }
  3640. break;
  3641. default:
  3642. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3643. break;
  3644. }
  3645. }
  3646. }
  3647. }
  3648. else
  3649. {
  3650. DEBUG_ERROR("Model name parsing fail.\n");
  3651. result = FAIL;
  3652. }
  3653. if(result != PASS)sleep(5);
  3654. return result;
  3655. }
  3656. void checkRemoteStart(uint8_t connectorIdInt)
  3657. {
  3658. uint8_t tempIndex;
  3659. int result = PASS;
  3660. char cmdBuf[512];
  3661. //check Transaction active
  3662. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3667. }
  3668. else
  3669. {
  3670. tempIndex = connectorIdInt -1;
  3671. }
  3672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3673. {
  3674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3675. {
  3676. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3678. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3679. {
  3680. //Reserved
  3681. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3682. }
  3683. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3684. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3685. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3686. {
  3687. //Reserved
  3688. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3689. result = FAIL;
  3690. goto end;
  3691. }
  3692. else
  3693. {
  3694. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3697. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3698. {
  3699. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3700. result = FAIL;
  3701. goto end;
  3702. }
  3703. }//END FOR ELSE
  3704. }
  3705. }// END FOR CHAdeMO_QUANTITY
  3706. }
  3707. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3708. {
  3709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3710. {
  3711. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3712. }
  3713. else
  3714. {
  3715. tempIndex = connectorIdInt -1;
  3716. }
  3717. for (int index = 0; index < CCS_QUANTITY; index++)
  3718. {
  3719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3720. {
  3721. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3722. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3723. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3724. {
  3725. //Reserved
  3726. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3727. }
  3728. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3729. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3730. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3731. {
  3732. //Reserved
  3733. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3734. result = FAIL;
  3735. goto end;
  3736. }
  3737. else
  3738. {
  3739. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3740. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3741. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3742. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3743. {
  3744. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3745. result = FAIL;
  3746. goto end;
  3747. }
  3748. }// END FOR ELSE
  3749. }
  3750. }// END FOR CCS_QUANTITY
  3751. }
  3752. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3753. {
  3754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3755. {
  3756. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3757. }
  3758. else
  3759. {
  3760. tempIndex = connectorIdInt -1;
  3761. }
  3762. for (int index = 0; index < GB_QUANTITY; index++)
  3763. {
  3764. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3765. {
  3766. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3767. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3768. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3769. {
  3770. //Reserved
  3771. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3772. }
  3773. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3774. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3775. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3776. {
  3777. //Reserved
  3778. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3779. result = FAIL;
  3780. goto end;
  3781. }
  3782. else
  3783. {
  3784. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3786. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3787. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3788. {
  3789. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3790. result = FAIL;
  3791. goto end;
  3792. }
  3793. }// END FOR ELSE
  3794. }
  3795. } // END FOR GB_QUANTITY
  3796. }
  3797. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3798. {
  3799. tempIndex = connectorIdInt -1;
  3800. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3801. {
  3802. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3803. {
  3804. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3805. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3806. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3807. {
  3808. //Reserved
  3809. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3810. }
  3811. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3812. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3813. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3814. {
  3815. //Reserved
  3816. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3817. result = FAIL;
  3818. goto end;
  3819. }
  3820. else
  3821. {
  3822. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3823. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3824. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3825. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3826. {
  3827. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3828. result = FAIL;
  3829. goto end;
  3830. }
  3831. }// END FOR ELSE
  3832. }
  3833. } // END FOR GB_QUANTITY
  3834. }
  3835. else
  3836. {
  3837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3838. {
  3839. tempIndex = 2;
  3840. }
  3841. else
  3842. {
  3843. tempIndex = connectorIdInt -1;
  3844. }
  3845. for (int index = 0; index < AC_QUANTITY; index++)
  3846. {
  3847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3848. {
  3849. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3850. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3851. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3852. {
  3853. //Reserved
  3854. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3855. }
  3856. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3857. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3858. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3859. {
  3860. //Reserved
  3861. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3862. result = FAIL;
  3863. goto end;
  3864. }
  3865. else
  3866. {
  3867. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3869. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3870. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3871. {
  3872. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3873. result = FAIL;
  3874. goto end;
  3875. }
  3876. }//END FOR ELSE
  3877. }
  3878. }// END FOR AC_QUANTITY
  3879. }
  3880. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3881. {
  3882. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3883. {
  3884. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3885. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3886. {
  3887. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3888. system(cmdBuf);
  3889. }
  3890. }
  3891. else
  3892. {
  3893. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3894. result = FAIL;
  3895. }
  3896. }
  3897. end:
  3898. if(result == PASS)
  3899. {
  3900. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3901. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3902. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3903. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3905. }
  3906. }
  3907. void CheckSystemValue(void)
  3908. {
  3909. char filenmae[100]={0};
  3910. char str[100]={0};
  3911. int tempIndex = 0;
  3912. //===============================
  3913. // send Heartbeat
  3914. //===============================
  3915. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3916. {
  3917. //parameter for test
  3918. sendHeartbeatRequest(0);
  3919. //==============================================
  3920. // Reset Waiting Time
  3921. //==============================================
  3922. HeartBeatWithNOResponse += 2;
  3923. }
  3924. //===============================
  3925. // Credit deduct report
  3926. //===============================
  3927. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3928. {
  3929. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3930. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3931. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3932. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3933. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3934. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3935. }
  3936. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3937. {
  3938. OCPP_query_deduct_info();
  3939. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3940. }
  3941. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3942. {
  3943. // ClockAlign MeterValue
  3944. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3945. {
  3946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3947. {
  3948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3949. {
  3950. tempIndex = ((gun_index==2) ? 1: 0);
  3951. }
  3952. else
  3953. {
  3954. tempIndex = gun_index;
  3955. }
  3956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3957. {
  3958. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3959. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3960. {
  3961. reqClockAlignMeter[gun_index] = 1;
  3962. }
  3963. }// End for CHAdeMO
  3964. }
  3965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3966. {
  3967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3968. {
  3969. tempIndex = ((gun_index==2) ? 1: 0);
  3970. }
  3971. else
  3972. {
  3973. tempIndex = gun_index;
  3974. }
  3975. for (int index = 0; index < CCS_QUANTITY; index++)
  3976. {
  3977. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3979. {
  3980. reqClockAlignMeter[gun_index] = 1;
  3981. }
  3982. } // End for CCS
  3983. }
  3984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3985. {
  3986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3987. {
  3988. tempIndex = ((gun_index==2) ? 1: 0);
  3989. }
  3990. else
  3991. {
  3992. tempIndex = gun_index;
  3993. }
  3994. for (int index = 0; index < GB_QUANTITY; index++)
  3995. {
  3996. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3997. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3998. {
  3999. reqClockAlignMeter[gun_index] = 1;
  4000. }
  4001. }// End for GB
  4002. }
  4003. else if(gunType[gun_index] == GUN_TYPE_DO)
  4004. {
  4005. tempIndex = gun_index;
  4006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4007. {
  4008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4009. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4010. {
  4011. reqClockAlignMeter[gun_index] = 1;
  4012. }
  4013. }
  4014. }
  4015. else
  4016. {
  4017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4018. {
  4019. tempIndex = 2;
  4020. }
  4021. else
  4022. {
  4023. tempIndex = gun_index;
  4024. }
  4025. for (int index = 0; index < AC_QUANTITY; index++)
  4026. {
  4027. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4028. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4029. {
  4030. reqClockAlignMeter[gun_index] = 1;
  4031. }
  4032. }//End for AC
  4033. }
  4034. }
  4035. }
  4036. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4037. {
  4038. //==========================================
  4039. // Check remote start without connector id
  4040. //==========================================
  4041. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4042. {
  4043. int connectorIdInt = -1;
  4044. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4045. {
  4046. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4047. {
  4048. connectorIdInt = (gun_index+1);
  4049. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4050. checkRemoteStart(connectorIdInt);
  4051. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4052. break;
  4053. }
  4054. }
  4055. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4056. {
  4057. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4058. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4059. }
  4060. }
  4061. //==========================================
  4062. // csu trigger DataTransferReq
  4063. //==========================================
  4064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4065. {
  4066. sendDataTransferRequest(gun_index);
  4067. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4068. }
  4069. //===============================
  4070. // CSU Trigger Authorize Request
  4071. //===============================
  4072. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4073. {
  4074. sendAuthorizeRequest(0);
  4075. authorizeRetryTimes = authorizeRetryTimes + 1;
  4076. if(authorizeRetryTimes < 3)
  4077. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4078. }
  4079. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4080. {
  4081. authorizeRetryTimes = 0;
  4082. SetOcppConnStatus(FALSE);
  4083. server_sign = FALSE;
  4084. }
  4085. 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))
  4086. {
  4087. sendAuthorizeRequest(0);
  4088. }
  4089. //==============================================
  4090. // Charger start transaction
  4091. //==============================================
  4092. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4093. {
  4094. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4095. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4096. sendStartTransactionRequest(gun_index);
  4097. refreshStartTimer(&clientTime.StartTransaction);
  4098. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4099. //storeTempStopTransaction(gun_index);
  4100. }
  4101. //==============================================
  4102. // Charger stop transaction
  4103. //==============================================
  4104. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4105. {
  4106. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4107. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4108. sendStopTransactionRequest(gun_index);
  4109. refreshStartTimer(&clientTime.StopTransaction);
  4110. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4111. }
  4112. //==============================================
  4113. // Charger status report
  4114. //==============================================
  4115. //--- Check Mode Change ---//
  4116. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4117. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4118. {
  4119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4120. {
  4121. tempIndex = ((gun_index==2) ? 1: 0);
  4122. }
  4123. else
  4124. {
  4125. tempIndex = gun_index;
  4126. }
  4127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4128. {
  4129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4130. {
  4131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4132. {
  4133. // Sent unplug message for California pricing logic
  4134. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4135. {
  4136. uint8_t ts[36];
  4137. getNowDatetime(ts);
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4139. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4140. if(strcmp((char*)dmsVersion, "2.0")==0)
  4141. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4142. else
  4143. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4144. sendUnplugByDataTransferRequest(gun_index);
  4145. interLock.isSentUnplug[gun_index] = 1;
  4146. }
  4147. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4148. {
  4149. interLock.isSentUnplug[gun_index] = 0;
  4150. }
  4151. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4152. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4153. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4154. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4155. {
  4156. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4157. if((access(filenmae,F_OK))!=-1)
  4158. {
  4159. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4160. sprintf(str,"rm -f %s",filenmae);
  4161. system(str);
  4162. }
  4163. }
  4164. }
  4165. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4166. #if 1 // for TempStopTransaction
  4167. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4168. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4169. {
  4170. checkTempStopTransaction(gun_index);
  4171. }
  4172. #endif
  4173. }
  4174. }
  4175. }
  4176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4177. {
  4178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4179. {
  4180. tempIndex = ((gun_index==2) ? 1: 0);
  4181. }
  4182. else
  4183. {
  4184. tempIndex = gun_index;
  4185. }
  4186. for (int index = 0; index < CCS_QUANTITY; index++)
  4187. {
  4188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4189. {
  4190. if((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]*/ )
  4191. {
  4192. // Sent unplug message for California pricing logic
  4193. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4194. {
  4195. uint8_t ts[36];
  4196. getNowDatetime(ts);
  4197. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4198. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4199. if(strcmp((char*)dmsVersion, "2.0")==0)
  4200. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4201. else
  4202. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4203. sendUnplugByDataTransferRequest(gun_index);
  4204. interLock.isSentUnplug[gun_index] = 1;
  4205. }
  4206. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4207. {
  4208. interLock.isSentUnplug[gun_index] = 0;
  4209. }
  4210. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4211. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4213. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4214. {
  4215. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4216. if((access(filenmae,F_OK))!=-1)
  4217. {
  4218. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4219. sprintf(str,"rm -f %s",filenmae);
  4220. system(str);
  4221. }
  4222. }
  4223. }
  4224. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4225. #if 1 // for TempStopTransaction
  4226. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4227. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4228. {
  4229. checkTempStopTransaction(gun_index);
  4230. }
  4231. #endif
  4232. }
  4233. }
  4234. }
  4235. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4236. {
  4237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4238. {
  4239. tempIndex = ((gun_index==2) ? 1: 0);
  4240. }
  4241. else
  4242. {
  4243. tempIndex = gun_index;
  4244. }
  4245. for (int index = 0; index < GB_QUANTITY; index++)
  4246. {
  4247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4248. {
  4249. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4250. {
  4251. // Sent unplug message for California pricing logic
  4252. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4253. {
  4254. uint8_t ts[36];
  4255. getNowDatetime(ts);
  4256. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4257. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4258. if(strcmp((char*)dmsVersion, "2.0")==0)
  4259. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4260. else
  4261. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4262. sendUnplugByDataTransferRequest(gun_index);
  4263. interLock.isSentUnplug[gun_index] = 1;
  4264. }
  4265. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4266. {
  4267. interLock.isSentUnplug[gun_index] = 0;
  4268. }
  4269. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4270. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4271. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4272. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4273. {
  4274. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4275. if((access(filenmae,F_OK))!=-1)
  4276. {
  4277. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4278. sprintf(str,"rm -f %s",filenmae);
  4279. system(str);
  4280. }
  4281. }
  4282. }
  4283. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4284. #if 1 // for TempStopTransaction
  4285. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4286. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4287. {
  4288. checkTempStopTransaction(gun_index);
  4289. }
  4290. #endif
  4291. }
  4292. }
  4293. }
  4294. else if(gunType[gun_index] == GUN_TYPE_DO)
  4295. {
  4296. tempIndex = gun_index;
  4297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4298. {
  4299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4300. {
  4301. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4302. {
  4303. // Sent unplug message for California pricing logic
  4304. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4305. {
  4306. uint8_t ts[36];
  4307. getNowDatetime(ts);
  4308. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4309. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4310. if(strcmp((char*)dmsVersion, "2.0")==0)
  4311. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4312. else
  4313. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4314. sendUnplugByDataTransferRequest(gun_index);
  4315. interLock.isSentUnplug[gun_index] = 1;
  4316. }
  4317. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4318. {
  4319. interLock.isSentUnplug[gun_index] = 0;
  4320. }
  4321. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4322. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4323. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4324. 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
  4325. {
  4326. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4327. if((access(filenmae,F_OK))!=-1)
  4328. {
  4329. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4330. sprintf(str,"rm -f %s",filenmae);
  4331. system(str);
  4332. }
  4333. }
  4334. }
  4335. 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);
  4336. #if 1 // for TempStopTransaction
  4337. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4338. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4339. {
  4340. checkTempStopTransaction(gun_index);
  4341. }
  4342. #endif
  4343. }
  4344. }
  4345. }
  4346. else
  4347. {
  4348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4349. {
  4350. tempIndex = 2;
  4351. }
  4352. else
  4353. {
  4354. tempIndex = gun_index;
  4355. }
  4356. for (int index = 0; index < AC_QUANTITY; index++)
  4357. {
  4358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4359. {
  4360. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4361. {
  4362. // Sent unplug message for California pricing logic
  4363. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4364. {
  4365. uint8_t ts[36];
  4366. getNowDatetime(ts);
  4367. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4368. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4369. if(strcmp((char*)dmsVersion, "2.0")==0)
  4370. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4371. else
  4372. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4373. sendUnplugByDataTransferRequest(gun_index);
  4374. interLock.isSentUnplug[gun_index] = 1;
  4375. }
  4376. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4377. {
  4378. interLock.isSentUnplug[gun_index] = 0;
  4379. }
  4380. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4381. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4382. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4383. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4384. {
  4385. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4386. if((access(filenmae,F_OK))!=-1)
  4387. {
  4388. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4389. sprintf(str,"rm -f %s",filenmae);
  4390. system(str);
  4391. }
  4392. }
  4393. }
  4394. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4395. #if 1 // for TempStopTransaction
  4396. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4397. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4398. {
  4399. checkTempStopTransaction(gun_index);
  4400. }
  4401. #endif
  4402. }
  4403. }// END
  4404. }
  4405. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4406. (
  4407. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4408. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4409. )
  4410. )
  4411. {
  4412. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4413. sendStatusNotificationRequest(gun_index);
  4414. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4415. }
  4416. //==============================================
  4417. // TCCI reader status report
  4418. //==============================================
  4419. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4420. {
  4421. reportReaderStatus(gun_index);
  4422. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4423. }
  4424. //==============================================
  4425. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4426. //==============================================
  4427. if((ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4428. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4429. {
  4430. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4431. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4432. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4433. }
  4434. //==============================================
  4435. // Meter report
  4436. //==============================================
  4437. // Trigger MeterValue
  4438. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4439. {
  4440. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4441. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4442. }
  4443. // Clock-aligned Meter value
  4444. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4445. {
  4446. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4447. reqClockAlignMeter[gun_index] = 0;
  4448. }
  4449. // Sample period MeterValue
  4450. 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))))
  4451. {
  4452. //check Transaction active
  4453. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4454. {
  4455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4456. {
  4457. tempIndex = ((gun_index==2) ? 1: 0);
  4458. }
  4459. else
  4460. {
  4461. tempIndex = gun_index;
  4462. }
  4463. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4464. {
  4465. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4466. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4467. {
  4468. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4469. {
  4470. reqSampleMeter[gun_index] = 1;
  4471. }
  4472. }
  4473. }// End for CHAdeMO
  4474. }
  4475. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4476. {
  4477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4478. {
  4479. tempIndex = ((gun_index==2) ? 1: 0);
  4480. }
  4481. else
  4482. {
  4483. tempIndex = gun_index;
  4484. }
  4485. for (int index = 0; index < CCS_QUANTITY; index++)
  4486. {
  4487. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4488. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4489. {
  4490. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4491. {
  4492. reqSampleMeter[gun_index] = 1;
  4493. }
  4494. }
  4495. } // End for CCS
  4496. }
  4497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4498. {
  4499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4500. {
  4501. tempIndex = ((gun_index==2) ? 1: 0);
  4502. }
  4503. else
  4504. {
  4505. tempIndex = gun_index;
  4506. }
  4507. for (int index = 0; index < GB_QUANTITY; index++)
  4508. {
  4509. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4511. {
  4512. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4513. {
  4514. reqSampleMeter[gun_index] = 1;
  4515. }
  4516. }
  4517. }// End for GB
  4518. }
  4519. else if(gunType[gun_index] == GUN_TYPE_DO)
  4520. {
  4521. tempIndex = gun_index;
  4522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4523. {
  4524. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4525. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4526. {
  4527. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4528. {
  4529. reqSampleMeter[gun_index] = 1;
  4530. }
  4531. }
  4532. }
  4533. }
  4534. else
  4535. {
  4536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4537. {
  4538. tempIndex = 2;
  4539. }
  4540. else
  4541. {
  4542. tempIndex = gun_index;
  4543. }
  4544. for (int index = 0; index < AC_QUANTITY; index++)
  4545. {
  4546. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4547. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4548. {
  4549. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4550. {
  4551. reqSampleMeter[gun_index] = 1;
  4552. }
  4553. }
  4554. }//End for AC
  4555. }
  4556. if(reqSampleMeter[gun_index] == 1)
  4557. {
  4558. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4559. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4560. //storeTempStopTransaction(gun_index);
  4561. reqSampleMeter[gun_index] = 0;
  4562. }
  4563. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4564. }
  4565. //==============================================
  4566. // Check Connector reserved
  4567. //==============================================
  4568. //===============================
  4569. // Check if Reserve is expired
  4570. //===============================
  4571. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4572. {
  4573. double diff_t;
  4574. struct tm tp;
  4575. // current time
  4576. time_t t = time(NULL);
  4577. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4578. tp.tm_isdst = -1;
  4579. time_t utc = mktime(&tp);
  4580. diff_t = difftime(utc, t);
  4581. if(diff_t <= 0)
  4582. {
  4583. DEBUG_INFO("reserve expired.\n");
  4584. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4585. }
  4586. }//END OF Check if Reserve is expired
  4587. //==========================================
  4588. // csu trigger FirmwareStatusNotificationReq
  4589. //==========================================
  4590. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4591. {
  4592. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4593. }
  4594. //==========================================
  4595. // csu trigger DiagnosticsStatusNotificationReq
  4596. //==========================================
  4597. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4598. {
  4599. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4600. }
  4601. //==========================================
  4602. // csu trigger CancelReservationConf
  4603. //==========================================
  4604. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4605. {
  4606. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4607. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4608. }
  4609. //==========================================
  4610. // csu trigger ChangeAvailabilityConf
  4611. //==========================================
  4612. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4613. {
  4614. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4615. }
  4616. //==========================================
  4617. // csu trigger UnlockConnectorConf
  4618. //==========================================
  4619. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4620. {
  4621. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4622. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4623. }
  4624. //==========================================
  4625. // csu trigger ReserveNowConf
  4626. //==========================================
  4627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4628. {
  4629. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4630. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4631. }
  4632. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4633. {
  4634. sendSignCertificateRequest();
  4635. }
  4636. }
  4637. }
  4638. //==========================================
  4639. // send request routine
  4640. //==========================================
  4641. int sendAuthorizeRequest(int gun_index)
  4642. {
  4643. mtrace();
  4644. int result = FAIL;
  4645. char message[100]={0};
  4646. char guid[37];
  4647. char tempdata[65]={0};
  4648. DEBUG_INFO("sendAuthorizeRequest...\n");
  4649. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4650. //Local Authorize
  4651. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4652. {
  4653. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4654. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4655. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4656. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4657. result = PASS;
  4658. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4659. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4660. authorizeRetryTimes = 0;
  4661. return result;
  4662. }
  4663. 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))||
  4664. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4665. {
  4666. // Query from cache
  4667. DEBUG_INFO("Authorize from cache.\n");
  4668. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4669. // Query from list
  4670. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4671. {
  4672. DEBUG_INFO("Authorize from list.\n");
  4673. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4674. }
  4675. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4676. {
  4677. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4678. {
  4679. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4680. }
  4681. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4682. {
  4683. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4684. }
  4685. if(!GetOcppConnStatus())
  4686. {
  4687. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4688. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4689. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4690. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4691. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4692. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4693. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4694. authorizeRetryTimes = 0;
  4695. return result;
  4696. }
  4697. }
  4698. else
  4699. {
  4700. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4701. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4702. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4703. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4704. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4705. else
  4706. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4707. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4708. result = PASS;
  4709. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4710. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4711. authorizeRetryTimes = 0;
  4712. return result;
  4713. }
  4714. }
  4715. //initialize struct Authorize
  4716. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4717. //get data from shared memory
  4718. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4719. random_uuid(guid);
  4720. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4721. LWS_Send(message);
  4722. sprintf(tempdata, "Authorize,%d", gun_index);
  4723. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4724. {
  4725. result = PASS;
  4726. DEBUG_INFO("Authorize mapItem pass\n");
  4727. }
  4728. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4729. return result;
  4730. }
  4731. int sendBootNotificationRequest(void)
  4732. {
  4733. mtrace();
  4734. int result = FAIL;
  4735. char message[500]={0}, payload[700]={0};
  4736. char guid[37]={0};
  4737. char tempdata[65]={0};
  4738. // Fill BootNotification fields
  4739. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4740. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4741. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4742. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4743. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4744. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4745. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4746. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4747. ShmOCPP16DataPH->ChargeBoxId
  4748. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4749. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4750. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4751. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4752. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4753. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4754. random_uuid(guid);
  4755. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4756. LWS_Send(message);
  4757. sprintf(tempdata, "BootNotification,0");
  4758. 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*/)
  4759. {
  4760. result = PASS;
  4761. }
  4762. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4763. strcpy(queuedata,message);
  4764. return result;
  4765. }
  4766. int sendDataTransferRequest(int gun_index)
  4767. {
  4768. mtrace();
  4769. char message[10240]={0};
  4770. char guid[37]={0};
  4771. char tempdata[65]={0};
  4772. int result = FAIL;
  4773. json_object *DataTransfer = json_object_new_object();
  4774. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId));
  4775. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId));
  4776. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data));
  4777. random_uuid(guid);
  4778. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  4779. guid,
  4780. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  4781. json_object_put(DataTransfer);
  4782. LWS_Send(message);
  4783. sprintf(tempdata, "DataTransfer,%d", gun_index);
  4784. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4785. {
  4786. result = PASS;
  4787. DEBUG_INFO("DataTransfer mapItem pass\n");
  4788. }
  4789. return result;
  4790. }
  4791. int sendUnplugByDataTransferRequest(int gun_index)
  4792. {
  4793. mtrace();
  4794. char message[10752]={0};
  4795. char guid[37]={0};
  4796. char tempdata[65]={0};
  4797. int result = FAIL;
  4798. random_uuid(guid);
  4799. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4800. (gun_index+1),
  4801. MESSAGE_TYPE_CALL,
  4802. guid,
  4803. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4804. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4805. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4806. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4807. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4808. {
  4809. result = PASS;
  4810. DEBUG_INFO("DataTransfer mapItem pass\n");
  4811. }
  4812. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4813. return result;
  4814. }
  4815. int sendDiagnosticsStatusNotificationRequest(char *status)
  4816. {
  4817. mtrace();
  4818. int result = FAIL;
  4819. char message[110]={0};
  4820. char guid[37]={0};
  4821. char tempdata[65]={0};
  4822. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4823. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4824. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4825. random_uuid(guid);
  4826. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4827. LWS_SendNow(message);
  4828. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4829. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4830. {
  4831. result = PASS;
  4832. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4833. }
  4834. //#ifdef SystemLogMessage
  4835. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4836. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4837. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4838. //#endif
  4839. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4840. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4841. //record status
  4842. if(strcmp(status,"Idle")==0)
  4843. {
  4844. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4845. }
  4846. else if(strcmp(status,"Uploaded")==0)
  4847. {
  4848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4849. }
  4850. else if(strcmp(status,"UploadFailed")==0)
  4851. {
  4852. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4853. }
  4854. else if(strcmp(status,"Uploading")==0)
  4855. {
  4856. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4857. }
  4858. return result;
  4859. }
  4860. int sendFirmwareStatusNotificationRequest(char *status)
  4861. {
  4862. mtrace();
  4863. int result = FAIL;
  4864. char message[110]={0};
  4865. char guid[37]={0};
  4866. char tempdata[65]={0};
  4867. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4868. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4869. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4870. random_uuid(guid);
  4871. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4872. LWS_SendNow(message);
  4873. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4874. 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*/)
  4875. {
  4876. result = PASS;
  4877. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4878. }
  4879. //#ifdef SystemLogMessage
  4880. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4881. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4882. //#endif
  4883. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4884. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4885. //record status
  4886. if(strcmp(status,"Downloaded")==0)
  4887. {
  4888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4889. }
  4890. else if(strcmp(status,"DownloadFailed")==0)
  4891. {
  4892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4893. }
  4894. else if(strcmp(status,"Downloading")==0)
  4895. {
  4896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4897. }
  4898. else if(strcmp(status,"Idle")==0)
  4899. {
  4900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4901. }
  4902. else if(strcmp(status,"InstallationFailed")==0)
  4903. {
  4904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4905. }
  4906. else if(strcmp(status,"Installing")==0)
  4907. {
  4908. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4909. }
  4910. else if(strcmp(status,"Installed")==0)
  4911. {
  4912. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4913. }
  4914. return result;
  4915. }
  4916. int sendHeartbeatRequest(int gun_index)
  4917. {
  4918. mtrace();
  4919. int result = FAIL;
  4920. char message[80]={0};
  4921. char guid[37]={0};
  4922. char tempdata[65]={0};
  4923. random_uuid(guid);
  4924. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4925. , MESSAGE_TYPE_CALL
  4926. , guid );
  4927. LWS_Send(message);
  4928. sprintf(tempdata, "Heartbeat,%d", 0);
  4929. 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*/)
  4930. {
  4931. result = PASS;
  4932. }
  4933. return result;
  4934. }
  4935. int sendStartTransactionRequest(int gun_index)
  4936. {
  4937. mtrace();
  4938. int result = FAIL;
  4939. char message[250]={0};
  4940. char guid[37]={0};
  4941. struct timeval tmnow;
  4942. struct tm *tm;
  4943. char buf[28];//, usec_buf[6];
  4944. char tempdata[65]={0};
  4945. int tempIndex = 0;
  4946. DEBUG_INFO("sendStartTransactionRequest...\n");
  4947. gettimeofday(&tmnow, NULL);
  4948. time_t t;
  4949. t = time(NULL);
  4950. /*UTC time and date*/
  4951. tm = gmtime(&t);
  4952. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4953. #if 0 // remove temporally
  4954. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4955. strcat(buf,".");
  4956. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4957. strcat(buf,usec_buf);
  4958. #endif
  4959. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4960. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4961. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4962. // clear StartTransaction Response
  4963. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4964. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4965. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4966. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4967. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4970. {
  4971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4972. {
  4973. tempIndex = ((gun_index==2) ? 1: 0);
  4974. }
  4975. else
  4976. {
  4977. tempIndex = gun_index;
  4978. }
  4979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4980. {
  4981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4982. {
  4983. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4984. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4985. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4986. }
  4987. }
  4988. }
  4989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4990. {
  4991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4992. {
  4993. tempIndex = ((gun_index==2) ? 1: 0);
  4994. }
  4995. else
  4996. {
  4997. tempIndex = gun_index;
  4998. }
  4999. for (int index = 0; index < CCS_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5002. {
  5003. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5004. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5005. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5006. }
  5007. }
  5008. }
  5009. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5010. {
  5011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5012. {
  5013. tempIndex = ((gun_index==2) ? 1: 0);
  5014. }
  5015. else
  5016. {
  5017. tempIndex = gun_index;
  5018. }
  5019. for (int index = 0; index < GB_QUANTITY; index++)
  5020. {
  5021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5022. {
  5023. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5024. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5025. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5026. }
  5027. }
  5028. }
  5029. else if(gunType[gun_index] == GUN_TYPE_DO)
  5030. {
  5031. tempIndex = gun_index;
  5032. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5033. {
  5034. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5035. {
  5036. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5037. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5038. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5039. }
  5040. }
  5041. }
  5042. else
  5043. {
  5044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5045. {
  5046. tempIndex = 2;
  5047. }
  5048. else
  5049. {
  5050. tempIndex = gun_index;
  5051. }
  5052. for (int index = 0; index < AC_QUANTITY; index++)
  5053. {
  5054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5055. {
  5056. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5057. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5058. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5059. }
  5060. }
  5061. }
  5062. random_uuid(guid);
  5063. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5064. {
  5065. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5066. , gun_index +1
  5067. , MESSAGE_TYPE_CALL
  5068. , guid
  5069. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5070. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5071. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5072. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5073. }
  5074. else
  5075. {
  5076. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5077. , gun_index +1
  5078. , MESSAGE_TYPE_CALL
  5079. , guid
  5080. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5081. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5082. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5083. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5084. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5085. }
  5086. #if 1
  5087. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5088. 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*/)
  5089. {
  5090. result = PASS;
  5091. }
  5092. #endif
  5093. strcpy(queuedata, message);
  5094. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5095. OCPP_insert_transaction_msg(YES, queuedata);
  5096. return result;
  5097. }
  5098. int sendStatusNotificationRequest(int gun_index)
  5099. {
  5100. mtrace();
  5101. int result = FAIL;
  5102. char message[600]={0};
  5103. char guid[37];
  5104. int currentStatus = 0;
  5105. struct timeval tmnow;
  5106. struct tm *tm;
  5107. char buf[28];//, usec_buf[6];
  5108. char tempdata[65]={0};
  5109. int tempIndex = 0;
  5110. uint8_t isStateChanged = TRUE;
  5111. uint8_t isContentIllegal = TRUE;
  5112. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5113. gettimeofday(&tmnow, NULL);
  5114. time_t t;
  5115. t = time(NULL);
  5116. /*UTC time and date*/
  5117. tm = gmtime(&t);
  5118. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5119. #if 0 // remove temporally
  5120. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5121. strcat(buf,".");
  5122. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5123. strcat(buf,usec_buf);
  5124. #endif
  5125. //printf("%s",buf);
  5126. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5127. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5128. // it's option
  5129. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5130. /*
  5131. enum _SYSTEM_STATUS
  5132. {
  5133. S_BOOTING = 0,
  5134. S_IDLE, = 1
  5135. S_AUTHORIZING, =2
  5136. S_REASSIGN_CHECK, =3
  5137. S_REASSIGN, =4
  5138. S_PRECHARGE, =5
  5139. S_PREPARING_FOR_EV, =6
  5140. S_PREPARING_FOR_EVSE, =7
  5141. S_CHARGING, =8
  5142. S_TERMINATING, =9
  5143. S_COMPLETE, =10
  5144. S_ALARM, =11
  5145. S_FAULT =12
  5146. }
  5147. */
  5148. //check Transaction active
  5149. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5150. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5151. {
  5152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5153. {
  5154. tempIndex = ((gun_index==2) ? 1: 0);
  5155. }
  5156. else
  5157. {
  5158. tempIndex = gun_index;
  5159. }
  5160. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5161. {
  5162. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5163. {
  5164. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5165. {
  5166. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5167. {
  5168. currentStatus = Preparing; //OCPP Status: Preparing
  5169. }
  5170. else
  5171. {
  5172. currentStatus = Available; //OCPP Status: Available
  5173. }
  5174. }
  5175. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5176. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5177. ) //S_PRECHARGE
  5178. {
  5179. currentStatus = Preparing; //OCPP Status: Preparing
  5180. }
  5181. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5182. {
  5183. currentStatus = Charging; //OCPP Status: Charging
  5184. }
  5185. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5186. {
  5187. currentStatus = Finishing; //OCPP Status: Finishing
  5188. }
  5189. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5190. {
  5191. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5192. }
  5193. 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
  5194. {
  5195. currentStatus = Unavailable; //OCPP Status: Unavailable
  5196. }
  5197. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5198. {
  5199. currentStatus = Faulted; //OCPP Status: Faulted
  5200. }
  5201. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5202. {
  5203. currentStatus = Reserved; //OCPP Status: Reserved
  5204. }
  5205. } //end of the same index
  5206. }//end of for CHAdeMO_QUANTITY
  5207. }
  5208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5209. {
  5210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5211. {
  5212. tempIndex = ((gun_index==2) ? 1: 0);
  5213. }
  5214. else
  5215. {
  5216. tempIndex = gun_index;
  5217. }
  5218. for (int index = 0; index < CCS_QUANTITY; index++)
  5219. {
  5220. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5223. {
  5224. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5225. {
  5226. currentStatus = Preparing; //OCPP Status: Preparing
  5227. }
  5228. else
  5229. {
  5230. currentStatus = Available; //OCPP Status: Available
  5231. }
  5232. }
  5233. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5234. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5235. ) //S_PRECHARGE
  5236. {
  5237. currentStatus = Preparing; //OCPP Status: Preparing
  5238. }
  5239. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5240. {
  5241. currentStatus = Charging; //OCPP Status: Charging
  5242. }
  5243. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5244. {
  5245. currentStatus = Finishing; //OCPP Status: Finishing
  5246. }
  5247. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5248. {
  5249. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5250. }
  5251. 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
  5252. {
  5253. currentStatus = Unavailable; //OCPP Status : Unavailable
  5254. }
  5255. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5256. {
  5257. currentStatus = Faulted; //OCPP Status: Faulted
  5258. }
  5259. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5260. {
  5261. currentStatus = Reserved; //OCPP Status: Reserved
  5262. }
  5263. } //end of the same index
  5264. } // end of for CCS_QUANTITY
  5265. }
  5266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5267. {
  5268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5269. {
  5270. tempIndex = ((gun_index==2) ? 1: 0);
  5271. }
  5272. else
  5273. {
  5274. tempIndex = gun_index;
  5275. }
  5276. for (int index = 0; index < GB_QUANTITY; index++)
  5277. {
  5278. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5279. {
  5280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5281. {
  5282. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5283. {
  5284. currentStatus = Preparing; //OCPP Status: Preparing
  5285. }
  5286. else
  5287. {
  5288. currentStatus = Available; //OCPP Status: Available
  5289. }
  5290. }
  5291. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5292. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5293. ) //S_PRECHARGE
  5294. {
  5295. currentStatus = Preparing; //OCPP Status: Preparing
  5296. }
  5297. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5298. {
  5299. currentStatus = Charging; //OCPP Status: Charging
  5300. }
  5301. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5302. {
  5303. currentStatus = Finishing; //OCPP Status: Finishing
  5304. }
  5305. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5306. {
  5307. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5308. }
  5309. 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
  5310. {
  5311. currentStatus = Unavailable; //OCPP Status: Unavailable
  5312. }
  5313. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5314. {
  5315. currentStatus = Faulted; //OCPP Status: Faulted
  5316. }
  5317. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5318. {
  5319. currentStatus = Reserved; //OCPP Status: Reserved
  5320. }
  5321. } //end of the same index
  5322. } // end of for GB_QUANTITY
  5323. }
  5324. else if(gunType[gun_index] == GUN_TYPE_DO)
  5325. {
  5326. tempIndex = gun_index;
  5327. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5328. {
  5329. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5330. {
  5331. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5332. {
  5333. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5334. {
  5335. currentStatus = Preparing; //OCPP Status: Preparing
  5336. }
  5337. else
  5338. {
  5339. currentStatus = Available; //OCPP Status: Available
  5340. }
  5341. }
  5342. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5343. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5344. ) //S_PRECHARGE
  5345. {
  5346. currentStatus = Preparing; //OCPP Status: Preparing
  5347. }
  5348. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5349. {
  5350. currentStatus = Charging; //OCPP Status: Charging
  5351. }
  5352. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5353. {
  5354. currentStatus = Finishing; //OCPP Status: Finishing
  5355. }
  5356. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5357. {
  5358. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5359. }
  5360. 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
  5361. {
  5362. currentStatus = Unavailable; //OCPP Status: Unavailable
  5363. }
  5364. 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
  5365. {
  5366. currentStatus = Faulted; //OCPP Status: Faulted
  5367. }
  5368. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5369. {
  5370. currentStatus = Reserved; //OCPP Status: Reserved
  5371. }
  5372. } //end of the same index
  5373. }
  5374. }
  5375. else
  5376. {
  5377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5378. {
  5379. tempIndex = 2;
  5380. }
  5381. else
  5382. {
  5383. tempIndex = gun_index;
  5384. }
  5385. for (int index = 0; index < AC_QUANTITY; index++)
  5386. {
  5387. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5388. {
  5389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5390. {
  5391. 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))
  5392. {
  5393. currentStatus = Preparing; //OCPP Status: Preparing
  5394. }
  5395. else
  5396. {
  5397. currentStatus = Available; //OCPP Status: Available
  5398. }
  5399. }
  5400. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5401. {
  5402. currentStatus = Preparing; //OCPP Status: Preparing
  5403. }
  5404. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5405. {
  5406. currentStatus = Charging; //OCPP Status: Charging
  5407. }
  5408. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5409. {
  5410. currentStatus = Finishing; //OCPP Status: Finishing
  5411. }
  5412. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5413. {
  5414. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5415. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5416. else
  5417. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5418. }
  5419. 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
  5420. {
  5421. currentStatus = Unavailable; //OCPP Status: Unavailable
  5422. }
  5423. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5424. {
  5425. currentStatus = Faulted; //OCPP Status: Faulted
  5426. }
  5427. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5428. {
  5429. currentStatus = Reserved; //OCPP Status: Reserved
  5430. }
  5431. }//end of the same index
  5432. }//end of for AC_QUANTITY
  5433. }
  5434. //it's option
  5435. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5436. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5437. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5438. {
  5439. isStateChanged = FALSE;
  5440. }
  5441. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5442. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5443. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5444. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5445. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5446. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5447. isContentIllegal = TRUE;
  5448. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5449. {
  5450. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5451. {
  5452. isContentIllegal = FALSE;
  5453. break;
  5454. }
  5455. }
  5456. if(isContentIllegal)
  5457. {
  5458. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5459. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5460. }
  5461. random_uuid(guid);
  5462. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5463. , MESSAGE_TYPE_CALL
  5464. , guid
  5465. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5466. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5467. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5468. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5469. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5470. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5471. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5472. if((server_sign == TRUE) && isStateChanged)
  5473. {
  5474. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5475. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5476. LWS_Send(message);
  5477. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5478. 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*/)
  5479. {
  5480. //DEBUG_ERROR("statusNotification mapitem pass");
  5481. result = PASS;
  5482. }
  5483. }
  5484. else
  5485. {
  5486. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5487. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5488. result = PASS;
  5489. }
  5490. return result;
  5491. }
  5492. int sendStopTransactionRequest(int gun_index)
  5493. {
  5494. mtrace();
  5495. int result = FAIL;
  5496. //char message[1500]={0};
  5497. char guid[37]={0};
  5498. char tempdata[65]={0};
  5499. int tempIndex = 0;
  5500. char TempStopTransaction[256];
  5501. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5502. //int idx_sample=0;
  5503. DEBUG_INFO("sendStopTransactionRequest \n");
  5504. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5505. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5506. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5508. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5509. {
  5510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5511. {
  5512. tempIndex = ((gun_index==2) ? 1: 0);
  5513. }
  5514. else
  5515. {
  5516. tempIndex = gun_index;
  5517. }
  5518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5519. {
  5520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5521. {
  5522. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5523. }
  5524. }// END OF CHAdeMO_QUANTITY
  5525. }
  5526. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5527. {
  5528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5529. {
  5530. tempIndex = ((gun_index==2) ? 1: 0);
  5531. }
  5532. else
  5533. {
  5534. tempIndex = gun_index;
  5535. }
  5536. for (int index = 0; index < CCS_QUANTITY; index++)
  5537. {
  5538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5539. {
  5540. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5541. }
  5542. }// END OF CCS_QUANTITY
  5543. }
  5544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5545. {
  5546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5547. {
  5548. tempIndex = ((gun_index==2) ? 1: 0);
  5549. }
  5550. else
  5551. {
  5552. tempIndex = gun_index;
  5553. }
  5554. for (int index = 0; index < GB_QUANTITY; index++)
  5555. {
  5556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5557. {
  5558. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5559. }
  5560. }// END OF GB_QUANTITY
  5561. }
  5562. else if(gunType[gun_index] == GUN_TYPE_DO)
  5563. {
  5564. tempIndex = gun_index;
  5565. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5566. {
  5567. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5568. {
  5569. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5570. }
  5571. }// END OF GB_QUANTITY
  5572. }
  5573. else
  5574. {
  5575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5576. {
  5577. tempIndex = 2;
  5578. }
  5579. else
  5580. {
  5581. tempIndex = gun_index;
  5582. }
  5583. for (int index = 0; index < AC_QUANTITY; index++)
  5584. {
  5585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5586. {
  5587. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5588. }
  5589. }// END OF AC_QUANTITY
  5590. }
  5591. //====================================== Stop Transaction Time =====================================================
  5592. struct timeval tmnow;
  5593. struct tm *tm;
  5594. char buf[28];//, usec_buf[6];
  5595. gettimeofday(&tmnow, NULL);
  5596. time_t t;
  5597. t = time(NULL);
  5598. /*UTC time and date*/
  5599. tm = gmtime(&t);
  5600. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5602. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5603. random_uuid(guid);
  5604. /***********************************transactionData******************************************************/
  5605. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5607. //=================================
  5608. // Transaction_Begin
  5609. //=================================
  5610. //=================================
  5611. // Transaction_End
  5612. //=================================
  5613. // ================================= Current.Import L1 ===============================================
  5614. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5615. {
  5616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5618. {
  5619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5620. {
  5621. tempIndex = ((gun_index==2) ? 1: 0);
  5622. }
  5623. else
  5624. {
  5625. tempIndex = gun_index;
  5626. }
  5627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5628. {
  5629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5630. {
  5631. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5632. }
  5633. }// End of for CHAdeMO_QUANTITY
  5634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5635. }
  5636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5637. {
  5638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5639. {
  5640. tempIndex = ((gun_index==2) ? 1: 0);
  5641. }
  5642. else
  5643. {
  5644. tempIndex = gun_index;
  5645. }
  5646. for (int index = 0; index < CCS_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5649. {
  5650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5651. }
  5652. }// End of for CCS_QUANTITY
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5654. }
  5655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5656. {
  5657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5658. {
  5659. tempIndex = ((gun_index==2) ? 1: 0);
  5660. }
  5661. else
  5662. {
  5663. tempIndex = gun_index;
  5664. }
  5665. for (int index = 0; index < GB_QUANTITY; index++)
  5666. {
  5667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5668. {
  5669. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5670. }
  5671. }// End of for GB_QUANTITY
  5672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5673. }
  5674. else if(gunType[gun_index] == GUN_TYPE_DO)
  5675. {
  5676. tempIndex = gun_index;
  5677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5678. {
  5679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5680. {
  5681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5682. }
  5683. }
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5685. }
  5686. else
  5687. {
  5688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5689. {
  5690. tempIndex = 2;
  5691. }
  5692. else
  5693. {
  5694. tempIndex = gun_index;
  5695. }
  5696. for (int index = 0; index < AC_QUANTITY; index++)
  5697. {
  5698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5699. {
  5700. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5701. }
  5702. }// End of for AC_QUANTITY
  5703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5704. }
  5705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5710. }
  5711. // ================================= Energy.Active.Import.Interval ==============================================
  5712. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5713. {
  5714. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5715. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5716. {
  5717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5718. {
  5719. tempIndex = ((gun_index==2) ? 1: 0);
  5720. }
  5721. else
  5722. {
  5723. tempIndex = gun_index;
  5724. }
  5725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5726. {
  5727. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5728. {
  5729. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5730. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5731. }
  5732. }// END OF CHAdeMO_QUANTITY
  5733. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5734. }
  5735. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5736. {
  5737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5738. {
  5739. tempIndex = ((gun_index==2) ? 1: 0);
  5740. }
  5741. else
  5742. {
  5743. tempIndex = gun_index;
  5744. }
  5745. for (int index = 0; index < CCS_QUANTITY; index++)
  5746. {
  5747. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5748. {
  5749. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5750. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5751. }
  5752. }// END OF CCS_QUANTITY
  5753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5754. }
  5755. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5756. {
  5757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5758. {
  5759. tempIndex = ((gun_index==2) ? 1: 0);
  5760. }
  5761. else
  5762. {
  5763. tempIndex = gun_index;
  5764. }
  5765. for (int index = 0; index < GB_QUANTITY; index++)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5768. {
  5769. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5770. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5771. }
  5772. }// END OF GB_QUANTITY
  5773. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5774. }
  5775. else if(gunType[gun_index] == GUN_TYPE_DO)
  5776. {
  5777. tempIndex = gun_index;
  5778. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5779. {
  5780. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5781. {
  5782. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5783. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5784. }
  5785. }
  5786. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5787. }
  5788. else
  5789. {
  5790. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5791. {
  5792. tempIndex = 2;
  5793. }
  5794. else
  5795. {
  5796. tempIndex = gun_index;
  5797. }
  5798. for (int index = 0; index < AC_QUANTITY; index++)
  5799. {
  5800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5801. {
  5802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5803. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5804. }
  5805. }// END OF AC_QUANTITY
  5806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5807. }
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5810. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5813. }
  5814. //=================================== Power.Active.Import ==================================================
  5815. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5816. {
  5817. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5818. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5819. {
  5820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5821. {
  5822. tempIndex = ((gun_index==2) ? 1: 0);
  5823. }
  5824. else
  5825. {
  5826. tempIndex = gun_index;
  5827. }
  5828. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5829. {
  5830. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5831. {
  5832. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5833. }
  5834. } // End for CHAdeMO_QUANTITY
  5835. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5836. }
  5837. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5838. {
  5839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5840. {
  5841. tempIndex = ((gun_index==2) ? 1: 0);
  5842. }
  5843. else
  5844. {
  5845. tempIndex = gun_index;
  5846. }
  5847. for (int index = 0; index < CCS_QUANTITY; index++)
  5848. {
  5849. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5850. {
  5851. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5852. }
  5853. } // END for CCS_QUANTITY
  5854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5855. }
  5856. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5857. {
  5858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5859. {
  5860. tempIndex = ((gun_index==2) ? 1: 0);
  5861. }
  5862. else
  5863. {
  5864. tempIndex = gun_index;
  5865. }
  5866. for (int index = 0; index < GB_QUANTITY; index++)
  5867. {
  5868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5869. {
  5870. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5871. }
  5872. }// END for GB_QUANTITY
  5873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5874. }
  5875. else if(gunType[gun_index] == GUN_TYPE_DO)
  5876. {
  5877. tempIndex = gun_index;
  5878. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5879. {
  5880. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5881. {
  5882. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5883. }
  5884. }
  5885. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5886. }
  5887. else
  5888. {
  5889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5890. {
  5891. tempIndex = 2;
  5892. }
  5893. else
  5894. {
  5895. tempIndex = gun_index;
  5896. }
  5897. for (int index = 0; index < AC_QUANTITY; index++)
  5898. {
  5899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5900. {
  5901. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5902. }
  5903. } // END for AC_QUANTITY
  5904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5905. }
  5906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5909. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5911. }
  5912. //============================ Voltage L1 ====================================
  5913. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5914. {
  5915. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5916. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5917. {
  5918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5919. {
  5920. tempIndex = ((gun_index==2) ? 1: 0);
  5921. }
  5922. else
  5923. {
  5924. tempIndex = gun_index;
  5925. }
  5926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5927. {
  5928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5929. {
  5930. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5931. }
  5932. } // END OF FOR CHAdeMO_QUANTITY
  5933. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5934. }
  5935. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5936. {
  5937. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5938. {
  5939. tempIndex = ((gun_index==2) ? 1: 0);
  5940. }
  5941. else
  5942. {
  5943. tempIndex = gun_index;
  5944. }
  5945. for (int index = 0; index < CCS_QUANTITY; index++)
  5946. {
  5947. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5948. {
  5949. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5950. }
  5951. } // END OF FOR CCS_QUANTITY
  5952. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5953. }
  5954. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5955. {
  5956. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5957. {
  5958. tempIndex = ((gun_index==2) ? 1: 0);
  5959. }
  5960. else
  5961. {
  5962. tempIndex = gun_index;
  5963. }
  5964. for (int index = 0; index < GB_QUANTITY; index++)
  5965. {
  5966. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5967. {
  5968. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5969. }
  5970. } // END OF FOR GB_QUANTITY
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5972. }
  5973. else if(gunType[gun_index] == GUN_TYPE_DO)
  5974. {
  5975. tempIndex = gun_index;
  5976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5979. {
  5980. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5981. }
  5982. }
  5983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5984. }
  5985. else
  5986. {
  5987. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5988. {
  5989. tempIndex = 2;
  5990. }
  5991. else
  5992. {
  5993. tempIndex = gun_index;
  5994. }
  5995. for (int index = 0; index < AC_QUANTITY; index++)
  5996. {
  5997. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5998. {
  5999. 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
  6000. }
  6001. } // END OF FOR AC_QUANTITY
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6003. }
  6004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6007. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6008. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6009. }
  6010. //====================== End SoC ================================
  6011. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6012. {
  6013. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6014. 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))
  6015. {
  6016. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6017. {
  6018. tempIndex = ((gun_index==2) ? 1: 0);
  6019. }
  6020. else
  6021. {
  6022. tempIndex = gun_index;
  6023. }
  6024. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6025. {
  6026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6027. {
  6028. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6029. {
  6030. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6031. }
  6032. }
  6033. }
  6034. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6035. {
  6036. for (int index = 0; index < CCS_QUANTITY; index++)
  6037. {
  6038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6039. {
  6040. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6041. }
  6042. }
  6043. }
  6044. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6045. {
  6046. for (int index = 0; index < GB_QUANTITY; index++)
  6047. {
  6048. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6049. {
  6050. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6051. }
  6052. }
  6053. }
  6054. else if(gunType[gun_index] == GUN_TYPE_DO)
  6055. {
  6056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6057. {
  6058. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6059. {
  6060. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6061. }
  6062. }
  6063. }
  6064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6066. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6067. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6069. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6070. } // END FOR DC CASE
  6071. }
  6072. // ================================= Current.Import L2 ===============================================
  6073. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6074. {
  6075. // AC 3 phse L2 current
  6076. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6077. {
  6078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6079. {
  6080. tempIndex = 2;
  6081. }
  6082. else
  6083. {
  6084. tempIndex = gun_index;
  6085. }
  6086. for (int index = 0; index < AC_QUANTITY; index++)
  6087. {
  6088. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6089. {
  6090. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6091. }
  6092. }// End of for AC_QUANTITY
  6093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6094. }
  6095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6096. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6099. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6100. }
  6101. // ================================= Current.Import L3 ===============================================
  6102. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6103. {
  6104. // AC 3 phse L3 current
  6105. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6106. {
  6107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6108. {
  6109. tempIndex = 2;
  6110. }
  6111. else
  6112. {
  6113. tempIndex = gun_index;
  6114. }
  6115. for (int index = 0; index < AC_QUANTITY; index++)
  6116. {
  6117. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6118. {
  6119. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6120. }
  6121. }// End of for AC_QUANTITY
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6123. }
  6124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6125. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6127. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6129. }
  6130. //============================ Voltage L2 ====================================
  6131. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6132. {
  6133. // AC 3 phse L2 voltage
  6134. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6135. {
  6136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6137. {
  6138. tempIndex = 2;
  6139. }
  6140. else
  6141. {
  6142. tempIndex = gun_index;
  6143. }
  6144. for (int index = 0; index < AC_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6147. {
  6148. 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
  6149. }
  6150. } // END OF FOR AC_QUANTITY
  6151. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6152. }
  6153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6158. }
  6159. //============================ Voltage L3 ====================================
  6160. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6161. {
  6162. // AC 3 phse L3 voltage
  6163. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6164. {
  6165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6166. {
  6167. tempIndex = 2;
  6168. }
  6169. else
  6170. {
  6171. tempIndex = gun_index;
  6172. }
  6173. for (int index = 0; index < AC_QUANTITY; index++)
  6174. {
  6175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6176. {
  6177. 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
  6178. }
  6179. } // END OF FOR AC_QUANTITY
  6180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6181. }
  6182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6187. }
  6188. //====================== Start SoC ================================
  6189. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6190. {
  6191. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6192. 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))
  6193. {
  6194. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6195. {
  6196. tempIndex = ((gun_index==2) ? 1: 0);
  6197. }
  6198. else
  6199. {
  6200. tempIndex = gun_index;
  6201. }
  6202. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6203. {
  6204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6205. {
  6206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6207. {
  6208. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6209. }
  6210. }
  6211. }
  6212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6213. {
  6214. for (int index = 0; index < CCS_QUANTITY; index++)
  6215. {
  6216. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6217. {
  6218. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6219. }
  6220. }
  6221. }
  6222. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6223. {
  6224. for (int index = 0; index < GB_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6227. {
  6228. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6229. }
  6230. }
  6231. }
  6232. else if(gunType[gun_index] == GUN_TYPE_DO)
  6233. {
  6234. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6235. {
  6236. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6237. {
  6238. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6239. }
  6240. }
  6241. }
  6242. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6246. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6247. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6248. } // END FOR DC CASE
  6249. }
  6250. //================================================ Message create ====================================================
  6251. json_object *StopTransaction = json_object_new_object();
  6252. json_object *transactionDatas = json_object_new_array();
  6253. json_object *sampledValues = json_object_new_array();
  6254. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6255. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6256. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6257. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6258. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6259. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6260. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6261. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6262. {
  6263. json_object *transactionData = json_object_new_object();
  6264. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6265. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6266. {
  6267. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6268. {
  6269. json_object *sampledValue = json_object_new_object();
  6270. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6271. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6272. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6273. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6274. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6275. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6276. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6277. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6278. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6279. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6280. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6281. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6282. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6283. json_object_array_add(sampledValues, sampledValue);
  6284. }
  6285. }
  6286. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6287. json_object_array_add(transactionDatas, transactionData);
  6288. }
  6289. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6290. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6291. ,MESSAGE_TYPE_CALL
  6292. ,guid
  6293. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6294. json_object_put(StopTransaction);
  6295. #if 1 // for TempStopTransaction
  6296. //Delete TempStopTransaction
  6297. if((access(TempStopTransaction,F_OK))!=-1)
  6298. {
  6299. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6300. }
  6301. #endif
  6302. #if 1
  6303. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6304. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6305. {
  6306. result = PASS;
  6307. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6308. }
  6309. #endif
  6310. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6311. OCPP_insert_transaction_msg(NO, queuedata);
  6312. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6313. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6314. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6315. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6316. {
  6317. //SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6318. }
  6319. //for test
  6320. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6321. return result;
  6322. }
  6323. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6324. {
  6325. mtrace();
  6326. int result = FAIL;
  6327. char guid[37]={0};
  6328. char tempdata[65]={0};
  6329. int tempIndex = 0;
  6330. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6331. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6332. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6333. //set value
  6334. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6335. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6336. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6337. -1);
  6338. random_uuid(guid);
  6339. //UTC Date time
  6340. struct timeval tmnow;
  6341. struct tm *tm;
  6342. char buf[28];//, usec_buf[6];
  6343. gettimeofday(&tmnow, NULL);
  6344. time_t t;
  6345. t = time(NULL);
  6346. /*UTC time and date*/
  6347. tm = gmtime(&t);
  6348. if(dataType == ReadingContext_Sample_Clock)
  6349. {
  6350. struct tm *tmTarget;
  6351. struct timeb tbTarget;
  6352. tbTarget.time = mktime(tm);
  6353. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6354. tmTarget = gmtime(&tbTarget.time);
  6355. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6356. }
  6357. else
  6358. {
  6359. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6360. }
  6361. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6362. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6363. //********************************(1)Current.Import L1************************************************/
  6364. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6365. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6366. (dataType == ReadingContext_Trigger))
  6367. {
  6368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6369. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6370. {
  6371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6372. {
  6373. tempIndex = ((gun_index==2) ? 1: 0);
  6374. }
  6375. else
  6376. {
  6377. tempIndex = gun_index;
  6378. }
  6379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6384. }
  6385. }
  6386. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6387. }
  6388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < CCS_QUANTITY; index++)
  6399. {
  6400. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6401. {
  6402. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6403. }
  6404. }
  6405. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6406. }
  6407. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6408. {
  6409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6410. {
  6411. tempIndex = ((gun_index==2) ? 1: 0);
  6412. }
  6413. else
  6414. {
  6415. tempIndex = gun_index;
  6416. }
  6417. for (int index = 0; index < GB_QUANTITY; index++)
  6418. {
  6419. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6420. {
  6421. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6422. }
  6423. }
  6424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6425. }
  6426. else if(gunType[gun_index] == GUN_TYPE_DO)
  6427. {
  6428. tempIndex = gun_index;
  6429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6430. {
  6431. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6432. {
  6433. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6434. }
  6435. }
  6436. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6437. }
  6438. else
  6439. {
  6440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6441. {
  6442. tempIndex = 2;
  6443. }
  6444. else
  6445. {
  6446. tempIndex = gun_index;
  6447. }
  6448. for (int index = 0; index < AC_QUANTITY; index++)
  6449. {
  6450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6451. {
  6452. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6453. }
  6454. }
  6455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6456. }
  6457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6459. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6460. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6461. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6462. }
  6463. //********************************(2)Energy.Active.Import.Register ************************************************/
  6464. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6465. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6466. (dataType == ReadingContext_Trigger))
  6467. {
  6468. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6469. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6470. {
  6471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6472. {
  6473. tempIndex = ((gun_index==2) ? 1: 0);
  6474. }
  6475. else
  6476. {
  6477. tempIndex = gun_index;
  6478. }
  6479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6480. {
  6481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6482. {
  6483. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6484. }
  6485. }
  6486. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6487. }
  6488. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6489. {
  6490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6491. {
  6492. tempIndex = ((gun_index==2) ? 1: 0);
  6493. }
  6494. else
  6495. {
  6496. tempIndex = gun_index;
  6497. }
  6498. for (int index = 0; index < CCS_QUANTITY; index++)
  6499. {
  6500. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6501. {
  6502. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6503. }
  6504. }
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6506. }
  6507. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6508. {
  6509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6510. {
  6511. tempIndex = ((gun_index==2) ? 1: 0);
  6512. }
  6513. else
  6514. {
  6515. tempIndex = gun_index;
  6516. }
  6517. for (int index = 0; index < GB_QUANTITY; index++)
  6518. {
  6519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6520. {
  6521. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6522. }
  6523. }
  6524. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6525. }
  6526. else if(gunType[gun_index] == GUN_TYPE_DO)
  6527. {
  6528. tempIndex = gun_index;
  6529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6532. {
  6533. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6534. }
  6535. }
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6537. }
  6538. else
  6539. {
  6540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6541. {
  6542. tempIndex = 2;
  6543. }
  6544. else
  6545. {
  6546. tempIndex = gun_index;
  6547. }
  6548. for (int index = 0; index < AC_QUANTITY; index++)
  6549. {
  6550. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6551. {
  6552. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6553. }
  6554. }
  6555. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6556. }
  6557. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6558. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6559. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6560. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6562. }
  6563. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6564. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6565. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6566. (dataType == ReadingContext_Trigger))
  6567. {
  6568. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6569. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6570. {
  6571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6572. {
  6573. tempIndex = ((gun_index==2) ? 1: 0);
  6574. }
  6575. else
  6576. {
  6577. tempIndex = gun_index;
  6578. }
  6579. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6580. {
  6581. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6582. {
  6583. if(dataType == ReadingContext_Sample_Clock)
  6584. {
  6585. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6586. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6587. }
  6588. else if(dataType == ReadingContext_Sample_Periodic)
  6589. {
  6590. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6591. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6592. }
  6593. else
  6594. {
  6595. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6596. }
  6597. }
  6598. } // END OF FOR CHAdeMO_QUANTITY
  6599. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6600. }
  6601. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6602. {
  6603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6604. {
  6605. tempIndex = ((gun_index==2) ? 1: 0);
  6606. }
  6607. else
  6608. {
  6609. tempIndex = gun_index;
  6610. }
  6611. for (int index = 0; index < CCS_QUANTITY; index++)
  6612. {
  6613. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6614. {
  6615. if(dataType == ReadingContext_Sample_Clock)
  6616. {
  6617. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6618. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6619. }
  6620. else if(dataType == ReadingContext_Sample_Periodic)
  6621. {
  6622. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6623. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6624. }
  6625. else
  6626. {
  6627. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6628. }
  6629. }
  6630. } // END OF CCS_QUANTITY
  6631. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6632. }
  6633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6634. {
  6635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6636. {
  6637. tempIndex = ((gun_index==2) ? 1: 0);
  6638. }
  6639. else
  6640. {
  6641. tempIndex = gun_index;
  6642. }
  6643. for (int index = 0; index < GB_QUANTITY; index++)
  6644. {
  6645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6646. {
  6647. if(dataType == ReadingContext_Sample_Clock)
  6648. {
  6649. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6650. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6651. }
  6652. else if(dataType == ReadingContext_Sample_Periodic)
  6653. {
  6654. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6655. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6656. }
  6657. else
  6658. {
  6659. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6660. }
  6661. }
  6662. } // END OF GB_QUANTITY
  6663. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_DO)
  6666. {
  6667. tempIndex = gun_index;
  6668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6671. {
  6672. if(dataType == ReadingContext_Sample_Clock)
  6673. {
  6674. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6675. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6676. }
  6677. else if(dataType == ReadingContext_Sample_Periodic)
  6678. {
  6679. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6680. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6681. }
  6682. else
  6683. {
  6684. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6685. }
  6686. }
  6687. }
  6688. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6689. }
  6690. else
  6691. {
  6692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6693. {
  6694. tempIndex = 2;
  6695. }
  6696. else
  6697. {
  6698. tempIndex = gun_index;
  6699. }
  6700. for (int index = 0; index < AC_QUANTITY; index++)
  6701. {
  6702. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6703. {
  6704. if(dataType == ReadingContext_Sample_Clock)
  6705. {
  6706. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6707. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6708. }
  6709. else if(dataType == ReadingContext_Sample_Periodic)
  6710. {
  6711. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6712. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6713. }
  6714. else
  6715. {
  6716. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6717. }
  6718. }
  6719. }
  6720. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6721. }
  6722. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6723. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6724. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6725. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6726. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6727. }
  6728. //********************************(4)Power.Active.Import************************************************/
  6729. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6730. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6731. (dataType == ReadingContext_Trigger))
  6732. {
  6733. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6734. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6735. {
  6736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6737. {
  6738. tempIndex = ((gun_index==2) ? 1: 0);
  6739. }
  6740. else
  6741. {
  6742. tempIndex = gun_index;
  6743. }
  6744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6745. {
  6746. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6747. {
  6748. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6749. }
  6750. } // END OF FOR
  6751. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6752. }
  6753. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6754. {
  6755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6756. {
  6757. tempIndex = ((gun_index==2) ? 1: 0);
  6758. }
  6759. else
  6760. {
  6761. tempIndex = gun_index;
  6762. }
  6763. for (int index = 0; index < CCS_QUANTITY; index++)
  6764. {
  6765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6766. {
  6767. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6768. }
  6769. }
  6770. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6771. }
  6772. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6785. {
  6786. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6787. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6788. }
  6789. }
  6790. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6791. }
  6792. else if(gunType[gun_index] == GUN_TYPE_DO)
  6793. {
  6794. tempIndex = gun_index;
  6795. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6798. {
  6799. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6800. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6801. }
  6802. }
  6803. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6804. }
  6805. else
  6806. {
  6807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6808. {
  6809. tempIndex = 2;
  6810. }
  6811. else
  6812. {
  6813. tempIndex = gun_index;
  6814. }
  6815. for (int index = 0; index < AC_QUANTITY; index++)
  6816. {
  6817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6818. {
  6819. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6820. }
  6821. }
  6822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6823. }
  6824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6825. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6826. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6827. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6828. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6829. }
  6830. //***********************************************(5)VOLTAGE L1******************************************************/
  6831. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6832. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6833. (dataType == ReadingContext_Trigger))
  6834. {
  6835. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6836. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6837. {
  6838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6839. {
  6840. tempIndex = ((gun_index==2) ? 1: 0);
  6841. }
  6842. else
  6843. {
  6844. tempIndex = gun_index;
  6845. }
  6846. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6847. {
  6848. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6849. {
  6850. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6851. }
  6852. }
  6853. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6854. }
  6855. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6856. {
  6857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6858. {
  6859. tempIndex = ((gun_index==2) ? 1: 0);
  6860. }
  6861. else
  6862. {
  6863. tempIndex = gun_index;
  6864. }
  6865. for (int index = 0; index < CCS_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6868. {
  6869. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6870. }
  6871. }
  6872. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6873. }
  6874. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6875. {
  6876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6877. {
  6878. tempIndex = ((gun_index==2) ? 1: 0);
  6879. }
  6880. else
  6881. {
  6882. tempIndex = gun_index;
  6883. }
  6884. for (int index = 0; index < GB_QUANTITY; index++)
  6885. {
  6886. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6887. {
  6888. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6889. }
  6890. }
  6891. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6892. }
  6893. else if(gunType[gun_index] == GUN_TYPE_DO)
  6894. {
  6895. tempIndex = gun_index;
  6896. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6899. {
  6900. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6901. }
  6902. }
  6903. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6904. }
  6905. else
  6906. {
  6907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6908. {
  6909. tempIndex = 2;
  6910. }
  6911. else
  6912. {
  6913. tempIndex = gun_index;
  6914. }
  6915. for (int index = 0; index < AC_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6918. {
  6919. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6920. }
  6921. }
  6922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6923. }
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6929. }
  6930. //***********************************************(6)SOC******************************************************/
  6931. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6932. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6933. (dataType == ReadingContext_Trigger))
  6934. {
  6935. 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))
  6936. {
  6937. //idx_sample=5;
  6938. //sampledValue = NULL;
  6939. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6940. {
  6941. tempIndex = ((gun_index==2) ? 1: 0);
  6942. }
  6943. else
  6944. {
  6945. tempIndex = gun_index;
  6946. }
  6947. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6948. {
  6949. //tempIndex = ((gun_index==2) ? 1: 0);
  6950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6951. {
  6952. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6953. {
  6954. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6955. }
  6956. }
  6957. }
  6958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6959. {
  6960. //tempIndex = ((gun_index==2) ? 1: 0);
  6961. for (int index = 0; index < CCS_QUANTITY; index++)
  6962. {
  6963. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6964. {
  6965. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6966. }
  6967. }
  6968. }
  6969. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6970. {
  6971. //tempIndex = ((gun_index==2) ? 1: 0);
  6972. for (int index = 0; index < GB_QUANTITY; index++)
  6973. {
  6974. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6975. {
  6976. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6977. }
  6978. }
  6979. }
  6980. else if(gunType[gun_index] == GUN_TYPE_DO)
  6981. {
  6982. //tempIndex = ((gun_index==2) ? 1: 0);
  6983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6984. {
  6985. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6986. {
  6987. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6988. }
  6989. }
  6990. }
  6991. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6992. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6993. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6995. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6996. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6997. }
  6998. }
  6999. //********************************(7)Current.Import L2************************************************/
  7000. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7001. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7002. (dataType == ReadingContext_Trigger))
  7003. {
  7004. // Only for AC 3 phase
  7005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7006. {
  7007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7008. {
  7009. tempIndex = 2;
  7010. }
  7011. else
  7012. {
  7013. tempIndex = gun_index;
  7014. }
  7015. for (int index = 0; index < AC_QUANTITY; index++)
  7016. {
  7017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7018. {
  7019. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7020. }
  7021. }
  7022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7023. }
  7024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7026. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7027. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7028. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7029. }
  7030. //********************************(8)Current.Import L3************************************************/
  7031. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7032. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7033. (dataType == ReadingContext_Trigger))
  7034. {
  7035. // Only for AC 3 phase
  7036. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7037. {
  7038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7039. {
  7040. tempIndex = 2;
  7041. }
  7042. else
  7043. {
  7044. tempIndex = gun_index;
  7045. }
  7046. for (int index = 0; index < AC_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7049. {
  7050. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7051. }
  7052. }
  7053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7054. }
  7055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7057. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7058. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7059. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7060. }
  7061. //***********************************************(9)VOLTAGE L2******************************************************/
  7062. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7063. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7064. (dataType == ReadingContext_Trigger))
  7065. {
  7066. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7069. {
  7070. tempIndex = 2;
  7071. }
  7072. else
  7073. {
  7074. tempIndex = gun_index;
  7075. }
  7076. for (int index = 0; index < AC_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7079. {
  7080. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7081. }
  7082. }
  7083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7084. }
  7085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7086. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7087. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7088. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7089. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7090. }
  7091. //***********************************************(10)VOLTAGE L3******************************************************/
  7092. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7093. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7094. (dataType == ReadingContext_Trigger))
  7095. {
  7096. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7097. {
  7098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7099. {
  7100. tempIndex = 2;
  7101. }
  7102. else
  7103. {
  7104. tempIndex = gun_index;
  7105. }
  7106. for (int index = 0; index < AC_QUANTITY; index++)
  7107. {
  7108. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7109. {
  7110. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7111. }
  7112. }
  7113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7114. }
  7115. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7117. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7120. }
  7121. //***********************************************(11)Current.Offered******************************************************/
  7122. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7123. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7124. (dataType == ReadingContext_Trigger))
  7125. {
  7126. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7127. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7128. {
  7129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7130. {
  7131. tempIndex = ((gun_index==2) ? 1: 0);
  7132. }
  7133. else
  7134. {
  7135. tempIndex = gun_index;
  7136. }
  7137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7138. {
  7139. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7140. {
  7141. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7142. }
  7143. } // END OF FOR CHAdeMO_QUANTITY
  7144. }
  7145. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7146. {
  7147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7148. {
  7149. tempIndex = ((gun_index==2) ? 1: 0);
  7150. }
  7151. else
  7152. {
  7153. tempIndex = gun_index;
  7154. }
  7155. for (int index = 0; index < CCS_QUANTITY; index++)
  7156. {
  7157. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7158. {
  7159. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7160. }
  7161. } // END OF CCS_QUANTITY
  7162. }
  7163. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7164. {
  7165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7166. {
  7167. tempIndex = ((gun_index==2) ? 1: 0);
  7168. }
  7169. else
  7170. {
  7171. tempIndex = gun_index;
  7172. }
  7173. for (int index = 0; index < GB_QUANTITY; index++)
  7174. {
  7175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7176. {
  7177. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7178. }
  7179. } // END OF GB_QUANTITY
  7180. }
  7181. else if(gunType[gun_index] == GUN_TYPE_DO)
  7182. {
  7183. tempIndex = gun_index;
  7184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7187. {
  7188. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7189. }
  7190. }
  7191. }
  7192. else
  7193. {
  7194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7195. {
  7196. tempIndex = 2;
  7197. }
  7198. else
  7199. {
  7200. tempIndex = gun_index;
  7201. }
  7202. for (int index = 0; index < AC_QUANTITY; index++)
  7203. {
  7204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7205. {
  7206. uint16_t currentOffer;
  7207. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7208. {
  7209. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7210. }
  7211. else
  7212. {
  7213. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7214. }
  7215. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7216. }
  7217. }
  7218. }
  7219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7223. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7224. }
  7225. //***********************************************(12)Power.Offered******************************************************/
  7226. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7227. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7228. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7229. {
  7230. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7231. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7232. {
  7233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7234. {
  7235. tempIndex = ((gun_index==2) ? 1: 0);
  7236. }
  7237. else
  7238. {
  7239. tempIndex = gun_index;
  7240. }
  7241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7244. {
  7245. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7246. }
  7247. } // END OF FOR CHAdeMO_QUANTITY
  7248. }
  7249. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7250. {
  7251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7252. {
  7253. tempIndex = ((gun_index==2) ? 1: 0);
  7254. }
  7255. else
  7256. {
  7257. tempIndex = gun_index;
  7258. }
  7259. for (int index = 0; index < CCS_QUANTITY; index++)
  7260. {
  7261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7262. {
  7263. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7264. }
  7265. } // END OF CCS_QUANTITY
  7266. }
  7267. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7268. {
  7269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7270. {
  7271. tempIndex = ((gun_index==2) ? 1: 0);
  7272. }
  7273. else
  7274. {
  7275. tempIndex = gun_index;
  7276. }
  7277. for (int index = 0; index < GB_QUANTITY; index++)
  7278. {
  7279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7280. {
  7281. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7282. }
  7283. } // END OF GB_QUANTITY
  7284. }
  7285. else if(gunType[gun_index] == GUN_TYPE_DO)
  7286. {
  7287. tempIndex = gun_index;
  7288. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7289. {
  7290. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7291. {
  7292. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7293. }
  7294. }
  7295. }
  7296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7297. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7298. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7300. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7301. }
  7302. // Message create ====================================================================================================
  7303. if(TRUE)
  7304. {
  7305. json_object *MeterValueReq = json_object_new_object();
  7306. json_object *MeterValues = json_object_new_array();
  7307. json_object *sampledValues = json_object_new_array();
  7308. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7309. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7310. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7311. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7312. {
  7313. json_object *MeterValue = json_object_new_object();
  7314. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7315. {
  7316. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7317. {
  7318. json_object *sampledValue = json_object_new_object();
  7319. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7320. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7321. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7322. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7323. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7324. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7325. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7326. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7327. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7328. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7329. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7330. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7331. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7332. json_object_array_add(sampledValues, sampledValue);
  7333. }
  7334. }
  7335. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7336. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7337. json_object_array_add(MeterValues, MeterValue);
  7338. }
  7339. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7340. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7341. ,gun_index + 1
  7342. ,MESSAGE_TYPE_CALL
  7343. ,guid
  7344. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7345. json_object_put(MeterValueReq);
  7346. }
  7347. // Put request guid to hash map
  7348. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7349. 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*/)
  7350. {
  7351. result = PASS;
  7352. //DEBUG_INFO("MeterValues mapitem pass\n");
  7353. }
  7354. if((dataType != ReadingContext_Trigger) &&
  7355. (dataType != ReadingContext_Sample_Clock) &&
  7356. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7357. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7358. else
  7359. {
  7360. if(FirstHeartBeat)
  7361. LWS_Send(queuedata +2);
  7362. }
  7363. return result;
  7364. }
  7365. int sendLogStatusNotificationRequest(char *status)
  7366. {
  7367. mtrace();
  7368. int result = PASS;
  7369. char message[4096]={0};
  7370. char guid[37]={0};
  7371. char tempdata[128]={0};
  7372. json_object *LogStatusNotification = json_object_new_object();
  7373. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7374. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7375. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7376. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7377. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7378. random_uuid(guid);
  7379. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7380. json_object_put(LogStatusNotification);
  7381. LWS_Send(message);
  7382. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7383. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7384. {
  7385. result = PASS;
  7386. }
  7387. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7388. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7389. return result;
  7390. }
  7391. int sendSecurityEventNotificationRequest()
  7392. {
  7393. mtrace();
  7394. int result = PASS;
  7395. char message[4096]={0};
  7396. char guid[37]={0};
  7397. char tempdata[128]={0};
  7398. json_object *SecurityEventNotification = json_object_new_object();
  7399. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7400. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7401. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7402. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7403. random_uuid(guid);
  7404. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7405. json_object_put(SecurityEventNotification);
  7406. LWS_Send(message);
  7407. sprintf(tempdata, "SecurityEventNotification,0");
  7408. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7409. {
  7410. result = PASS;
  7411. }
  7412. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7413. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7414. return result;
  7415. }
  7416. int sendSignCertificateRequest()
  7417. {
  7418. mtrace();
  7419. int result = PASS;
  7420. char message[4096]={0};
  7421. char guid[37]={0};
  7422. char tempdata[128]={0};
  7423. json_object *SignCertificate = json_object_new_object();
  7424. DEBUG_INFO("sendSignCertificateRequest...\n");
  7425. // Read csr file content
  7426. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7427. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7428. char *line = NULL;
  7429. size_t len = 0;
  7430. while(getline(&line, &len, fp) != -1)
  7431. {
  7432. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7433. {
  7434. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7435. }
  7436. }
  7437. fclose(fp);
  7438. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7439. random_uuid(guid);
  7440. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7441. json_object_put(SignCertificate);
  7442. LWS_Send(message);
  7443. sprintf(tempdata, "SignCertificate,0");
  7444. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7445. {
  7446. result = PASS;
  7447. }
  7448. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7449. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7450. return result;
  7451. }
  7452. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7453. {
  7454. mtrace();
  7455. int result = PASS;
  7456. char message[110]={0};
  7457. char guid[37]={0};
  7458. char tempdata[65]={0};
  7459. json_object *FirmwareStatusNotification = json_object_new_object();
  7460. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7461. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7462. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7463. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7464. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7465. random_uuid(guid);
  7466. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7467. json_object_put(FirmwareStatusNotification);
  7468. LWS_Send(message);
  7469. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7470. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7471. {
  7472. result = PASS;
  7473. }
  7474. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7475. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7476. return result;
  7477. }
  7478. //==========================================
  7479. // send confirm routine
  7480. //==========================================
  7481. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7482. {
  7483. mtrace();
  7484. int result = FAIL;
  7485. char message[100]={0};
  7486. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7487. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7488. LWS_Send(message);
  7489. result = TRUE;
  7490. return result;
  7491. }
  7492. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7493. {
  7494. mtrace();
  7495. int result = FAIL;
  7496. char message[100]={0};
  7497. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7498. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7499. LWS_Send(message);
  7500. result = TRUE;
  7501. return result;
  7502. }
  7503. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7504. {
  7505. mtrace();
  7506. int result = FAIL;
  7507. char message[100]={0};
  7508. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7509. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7510. LWS_Send(message);
  7511. result = TRUE;
  7512. return result;
  7513. }
  7514. int sendClearCacheConfirmation(char *uuid,char *payload)
  7515. {
  7516. mtrace();
  7517. int result = FAIL;
  7518. char message[500]={0};
  7519. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7520. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7521. LWS_Send(message);
  7522. return result;
  7523. }
  7524. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7525. {
  7526. mtrace();
  7527. int result = FAIL;
  7528. char message[500]={0};
  7529. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7530. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7531. LWS_Send(message);
  7532. return result;
  7533. }
  7534. int sendDataTransferConfirmation(char *uuid,char *payload)
  7535. {
  7536. mtrace();
  7537. char statusStr[20]={0};
  7538. char dataStr[10]={0};
  7539. char sstr[20]={0};
  7540. int c = 0;
  7541. char *loc;
  7542. int result = FAIL;
  7543. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7544. /**********************status**************************/
  7545. loc = strstr(payload, "status");
  7546. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7547. c = 0;
  7548. while (loc[3+strlen("status")+c] != '\"')
  7549. {
  7550. sstr[c] = loc[3+strlen("status")+c];
  7551. c++;
  7552. }
  7553. sstr[c] = '\0';
  7554. strcpy(statusStr, sstr);
  7555. /**********************data**************************/
  7556. loc = strstr(payload, "data");
  7557. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7558. c = 0;
  7559. while (loc[3+strlen("data")+c] != '\"')
  7560. {
  7561. sstr[c] = loc[3+strlen("data")+c];
  7562. c++;
  7563. }
  7564. sstr[c] = '\0';
  7565. strcpy(dataStr, sstr);
  7566. return result;
  7567. }
  7568. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7569. {
  7570. mtrace();
  7571. int result = FAIL;
  7572. char message[1000]={0};
  7573. int CompositeScheduleIndex = 0;
  7574. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7575. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7576. if(nPeriod == 0)
  7577. {
  7578. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7579. {
  7580. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7581. ,MESSAGE_TYPE_CALLRESULT
  7582. ,uuid
  7583. ,payload
  7584. ,connectorIdInt);
  7585. }
  7586. else
  7587. {
  7588. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7589. ,MESSAGE_TYPE_CALLRESULT
  7590. ,uuid
  7591. ,payload
  7592. ,connectorIdInt
  7593. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7594. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7595. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7596. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7597. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7598. }
  7599. }
  7600. else
  7601. {
  7602. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7603. ,MESSAGE_TYPE_CALLRESULT
  7604. ,uuid
  7605. ,payload
  7606. ,connectorIdInt
  7607. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7608. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7609. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7610. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7611. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7612. {
  7613. if (idx_sample == 0)
  7614. {
  7615. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7616. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7617. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7618. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7619. }
  7620. else
  7621. {
  7622. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7623. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7624. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7625. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7626. }
  7627. }
  7628. sprintf(message + strlen(message), "]}}]");
  7629. }
  7630. LWS_Send(message);
  7631. result = TRUE;
  7632. return result;
  7633. }
  7634. int sendGetConfigurationConfirmation(char *uuid)
  7635. {
  7636. mtrace();
  7637. int result = FAIL;
  7638. int MaxKeySupported = 0;
  7639. int sentConfigurationNumber= 0;
  7640. int sentunConfigurationNumber= 0;
  7641. char message[1024*10]={0};
  7642. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7643. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7644. //configuration key
  7645. json_object *GetConfiguration = json_object_new_object();
  7646. json_object *configurationKey = json_object_new_array();
  7647. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7648. {
  7649. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7650. {
  7651. json_object *keyValue = json_object_new_object();
  7652. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  7653. json_object_object_add(keyValue, "readonly", atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1?json_object_new_boolean(1):json_object_new_boolean(0));
  7654. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  7655. json_object_array_add(configurationKey, keyValue);
  7656. sentConfigurationNumber = sentConfigurationNumber + 1;
  7657. }
  7658. }
  7659. json_object *unknownKey = json_object_new_array();
  7660. if(UnknownKeynum != 0)
  7661. {
  7662. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7663. {
  7664. DEBUG_INFO("unknown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7665. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  7666. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7667. }
  7668. }
  7669. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  7670. {
  7671. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  7672. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  7673. }
  7674. else if(sentConfigurationNumber>0)
  7675. {
  7676. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  7677. json_object_put(unknownKey);
  7678. }
  7679. else
  7680. {
  7681. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  7682. json_object_put(configurationKey);
  7683. }
  7684. sprintf(message,"[%d,\"%s\",%s]"
  7685. ,MESSAGE_TYPE_CALLRESULT
  7686. ,uuid
  7687. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  7688. json_object_put(GetConfiguration);
  7689. LWS_Send(message);
  7690. return result;
  7691. }
  7692. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7693. {
  7694. mtrace();
  7695. int result = FAIL;
  7696. char message[400]={0};
  7697. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7698. if(strcmp(payload,"")==0)
  7699. {
  7700. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7701. }
  7702. else
  7703. {
  7704. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7705. }
  7706. LWS_Send(message);
  7707. result = TRUE;
  7708. return result;
  7709. }
  7710. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7711. {
  7712. mtrace();
  7713. int result = FAIL;
  7714. char message[80]={0};
  7715. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7716. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7717. LWS_Send(message);
  7718. result = TRUE;
  7719. return result;
  7720. }
  7721. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7722. {
  7723. mtrace();
  7724. int result = FAIL;
  7725. char message[80]={0};
  7726. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7727. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7728. LWS_Send(message);
  7729. result = TRUE;
  7730. return result;
  7731. }
  7732. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7733. {
  7734. mtrace();
  7735. int result = FAIL;
  7736. char message[80]={0};
  7737. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7738. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7739. LWS_Send(message);
  7740. result = TRUE;
  7741. return result;
  7742. }
  7743. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7744. {
  7745. mtrace();
  7746. int result = FAIL;
  7747. char message[80]={0};
  7748. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7749. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7750. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7751. LWS_Send(message);
  7752. result = TRUE;
  7753. return result;
  7754. }
  7755. int sendResetConfirmation(char *uuid,char *payload)
  7756. {
  7757. mtrace();
  7758. int result = FAIL;
  7759. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7760. char message[80]={0};
  7761. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7762. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7763. LWS_Send(message);
  7764. result = TRUE;
  7765. return result;
  7766. }
  7767. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7768. {
  7769. mtrace();
  7770. int result = FAIL;
  7771. char message[500]={0};
  7772. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7773. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7774. LWS_Send(message);
  7775. result = TRUE;
  7776. return result;
  7777. }
  7778. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7779. {
  7780. mtrace();
  7781. int result = FAIL;
  7782. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7783. char message[80]={0};
  7784. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7785. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7786. LWS_Send(message);
  7787. result = TRUE;
  7788. return result;
  7789. }
  7790. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7791. {
  7792. mtrace();
  7793. int result = FAIL;
  7794. char message[80]={0};
  7795. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7796. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7797. LWS_Send(message);
  7798. result = TRUE;
  7799. return result;
  7800. }
  7801. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7802. {
  7803. mtrace();
  7804. int result = FAIL;
  7805. char message[80]={0};
  7806. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7807. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7808. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7809. LWS_Send(message);
  7810. result = TRUE;
  7811. return result;
  7812. }
  7813. int sendUpdateFirmwareConfirmation(char *uuid)
  7814. {
  7815. mtrace();
  7816. int result = FAIL;
  7817. char message[60]={0};
  7818. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7819. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7820. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7821. LWS_Send(message);
  7822. result = TRUE;
  7823. return result;
  7824. }
  7825. int sendCertificateSignedConfirmation(char *uuid)
  7826. {
  7827. mtrace();
  7828. int result = PASS;
  7829. char message[4096]={0};
  7830. json_object *CertificateSigned = json_object_new_object();
  7831. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7832. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7833. sprintf(message,"[%d,\"%s\",%s]"
  7834. ,MESSAGE_TYPE_CALLRESULT
  7835. ,uuid
  7836. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7837. json_object_put(CertificateSigned);
  7838. LWS_Send(message);
  7839. return result;
  7840. }
  7841. int sendDeleteCertificateConfirmation(char *uuid)
  7842. {
  7843. mtrace();
  7844. int result = PASS;
  7845. char message[4096]={0};
  7846. json_object *DeleteCertificate = json_object_new_object();
  7847. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7848. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7849. sprintf(message,"[%d,\"%s\",%s]"
  7850. ,MESSAGE_TYPE_CALLRESULT
  7851. ,uuid
  7852. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7853. json_object_put(DeleteCertificate);
  7854. LWS_Send(message);
  7855. return result;
  7856. }
  7857. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7858. {
  7859. mtrace();
  7860. int result = PASS;
  7861. char message[4096]={0};
  7862. json_object *ExtendedTriggerMessage = json_object_new_object();
  7863. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7864. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7865. sprintf(message,"[%d,\"%s\",%s]"
  7866. ,MESSAGE_TYPE_CALLRESULT
  7867. ,uuid
  7868. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7869. json_object_put(ExtendedTriggerMessage);
  7870. LWS_Send(message);
  7871. return result;
  7872. }
  7873. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7874. {
  7875. mtrace();
  7876. int result = PASS;
  7877. char message[4096]={0};
  7878. json_object *GetInstalledCertificateIds = json_object_new_object();
  7879. json_object *certificateHashDataDatas = json_object_new_array();
  7880. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7881. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7882. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7883. {
  7884. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7885. {
  7886. json_object *certificateHashData = json_object_new_object();
  7887. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7888. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7889. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7890. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7891. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7892. }
  7893. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7894. }
  7895. else
  7896. {
  7897. json_object_put(certificateHashDataDatas);
  7898. }
  7899. sprintf(message,"[%d,\"%s\",%s]"
  7900. ,MESSAGE_TYPE_CALLRESULT
  7901. ,uuid
  7902. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7903. json_object_put(GetInstalledCertificateIds);
  7904. LWS_Send(message);
  7905. return result;
  7906. }
  7907. int sendGetLogConfirmation(char *uuid)
  7908. {
  7909. mtrace();
  7910. int result = PASS;
  7911. char message[4096]={0};
  7912. json_object *GetLog = json_object_new_object();
  7913. DEBUG_INFO("sendGetLogConfirmation...\n");
  7914. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7915. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7916. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7917. sprintf(message,"[%d,\"%s\",%s]"
  7918. ,MESSAGE_TYPE_CALLRESULT
  7919. ,uuid
  7920. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7921. json_object_put(GetLog);
  7922. LWS_Send(message);
  7923. return result;
  7924. }
  7925. int sendInstallCertificateConfirmation(char *uuid)
  7926. {
  7927. mtrace();
  7928. int result = PASS;
  7929. char message[4096]={0};
  7930. json_object *InstallCertificate = json_object_new_object();
  7931. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7932. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7933. sprintf(message,"[%d,\"%s\",%s]"
  7934. ,MESSAGE_TYPE_CALLRESULT
  7935. ,uuid
  7936. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7937. json_object_put(InstallCertificate);
  7938. LWS_Send(message);
  7939. return result;
  7940. }
  7941. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7942. {
  7943. mtrace();
  7944. int result = PASS;
  7945. char message[4096]={0};
  7946. json_object *SignedUpdateFirmware = json_object_new_object();
  7947. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7948. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7949. sprintf(message,"[%d,\"%s\",%s]"
  7950. ,MESSAGE_TYPE_CALLRESULT
  7951. ,uuid
  7952. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7953. json_object_put(SignedUpdateFirmware);
  7954. LWS_Send(message);
  7955. return result;
  7956. }
  7957. int sendUnknownConfirmation(char *uuid)
  7958. {
  7959. mtrace();
  7960. int result = PASS;
  7961. char message[256]={0};
  7962. DEBUG_INFO("sendUnknownConfirmation...\n");
  7963. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7964. LWS_Send(message);
  7965. return result;
  7966. }
  7967. //==========================================
  7968. // Handle server request routine Start
  7969. //==========================================
  7970. int handleCancelReservationRequest(char *uuid, char *payload)
  7971. {
  7972. mtrace();
  7973. int result = FAIL;
  7974. int gunNO = 0;
  7975. int reservationIdInt = -1;
  7976. char comfirmstr[20];
  7977. DEBUG_INFO("handleCancelReservationRequest...\n");
  7978. json_object *CancelReservation;
  7979. CancelReservation = json_tokener_parse(payload);
  7980. if(!is_error(CancelReservation))
  7981. {
  7982. // Required data
  7983. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7984. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7985. }
  7986. json_object_put(CancelReservation);
  7987. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7988. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7989. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7990. if(reservationIdInt != -1)
  7991. {
  7992. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7993. //check Transaction active
  7994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7995. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7996. {
  7997. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7998. {
  7999. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8000. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8001. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8002. {
  8003. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8004. }
  8005. else
  8006. {
  8007. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8008. }
  8009. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8010. goto end;
  8011. }
  8012. }
  8013. for (int index = 0; index < CCS_QUANTITY; index++)
  8014. {
  8015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8016. {
  8017. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8018. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8019. if(gunType[2] == GUN_TYPE_CCS)
  8020. {
  8021. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8022. }
  8023. else
  8024. {
  8025. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8026. }
  8027. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8028. goto end;
  8029. }
  8030. }
  8031. for (int index = 0; index < GB_QUANTITY; index++)
  8032. {
  8033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8034. {
  8035. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8036. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8037. if(gunType[2] == GUN_TYPE_GBT)
  8038. {
  8039. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8040. }
  8041. else
  8042. {
  8043. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8044. }
  8045. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8046. goto end;
  8047. }
  8048. }
  8049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8050. {
  8051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8052. {
  8053. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8054. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8055. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8056. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8057. goto end;
  8058. }
  8059. }
  8060. for (int index = 0; index < AC_QUANTITY; index++)
  8061. {
  8062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8063. {
  8064. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8065. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8067. {
  8068. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8069. }
  8070. else
  8071. {
  8072. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8073. }
  8074. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8075. goto end;
  8076. }
  8077. }
  8078. }
  8079. //The reservationId does NOT match the reservationId
  8080. sendCancelReservationConfirmation(uuid, comfirmstr);
  8081. end:
  8082. // Fill in ocpp packet uuid
  8083. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8084. return result;
  8085. }
  8086. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8087. {
  8088. mtrace();
  8089. int result = FAIL;
  8090. int gunIndex = -1;
  8091. char typeStr[16]={0};
  8092. char comfirmstr[20];
  8093. int specificId = FALSE;
  8094. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8095. json_object *ChangeAvailability;
  8096. ChangeAvailability = json_tokener_parse(payload);
  8097. if(!is_error(ChangeAvailability))
  8098. {
  8099. // Required data
  8100. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8101. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8102. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8103. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8104. }
  8105. json_object_put(ChangeAvailability);
  8106. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8107. {
  8108. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8109. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8110. }
  8111. else if(gunIndex == 0)
  8112. {
  8113. for(int i=0; i < gunTotalNumber; i++)
  8114. {
  8115. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8116. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8117. }
  8118. }
  8119. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8120. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8121. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8122. {
  8123. specificId = TRUE;
  8124. }
  8125. if(specificId == FALSE)
  8126. goto end;
  8127. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8128. {
  8129. //----------------------gunIndex is 0 ------------------------------------------------//
  8130. if(gunIndex == 0)
  8131. {
  8132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8133. {
  8134. for(int i=0; i < gunTotalNumber; i++)
  8135. {
  8136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8137. {
  8138. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8139. {
  8140. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8141. {
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8143. goto end;
  8144. }
  8145. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8146. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8147. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8148. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8149. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8150. {
  8151. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8152. goto end;
  8153. }
  8154. }
  8155. }//END FOR CHAdeMO_QUANTITY
  8156. for (int index = 0; index < CCS_QUANTITY; index++)
  8157. {
  8158. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8159. {
  8160. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8163. goto end;
  8164. }
  8165. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8170. {
  8171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8172. goto end;
  8173. }
  8174. }
  8175. }//END FOR CCS_QUANTITY
  8176. for (int index = 0; index < GB_QUANTITY; index++)
  8177. {
  8178. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8179. {
  8180. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8181. {
  8182. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8183. goto end;
  8184. }
  8185. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8190. {
  8191. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8192. goto end;
  8193. }
  8194. }
  8195. }// END FOR GB_QUANTITY
  8196. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8197. {
  8198. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8199. {
  8200. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8201. {
  8202. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8203. goto end;
  8204. }
  8205. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8208. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8209. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8210. {
  8211. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8212. goto end;
  8213. }
  8214. }
  8215. }// END FOR GENERAL_GUN_QUANTITY
  8216. for (int index = 0; index < AC_QUANTITY; index++)
  8217. {
  8218. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8219. {
  8220. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8221. {
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8223. goto end;
  8224. }
  8225. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8226. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8227. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8228. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8229. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8230. {
  8231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8232. goto end;
  8233. }
  8234. }
  8235. }//END FOR AC_QUANTITY
  8236. }// END FOR gunTotalNumber
  8237. }
  8238. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8239. {
  8240. for(int i=0; i < gunTotalNumber; i++)
  8241. {
  8242. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8243. {
  8244. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8245. goto end;
  8246. }
  8247. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8248. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8249. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8250. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8251. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8252. {
  8253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8254. goto end;
  8255. }
  8256. }
  8257. }
  8258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8259. goto end;
  8260. }
  8261. //----------------------gunIndex is not 0 ------------------------------------------------//
  8262. //check Transaction active
  8263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8264. {
  8265. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8266. {
  8267. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8268. {
  8269. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8270. goto end;
  8271. }
  8272. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8273. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8275. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8276. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8277. {
  8278. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8279. goto end;
  8280. }
  8281. else
  8282. {
  8283. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8285. goto end;
  8286. }
  8287. }
  8288. }//END FOR CHAdeMO_QUANTITY
  8289. for (int index = 0; index < CCS_QUANTITY; index++)
  8290. {
  8291. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8292. {
  8293. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8294. {
  8295. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8296. goto end;
  8297. }
  8298. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8303. {
  8304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8305. goto end;
  8306. }
  8307. else
  8308. {
  8309. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8311. goto end;
  8312. }
  8313. }
  8314. }//END FOR CCS_QUANTITY
  8315. for (int index = 0; index < GB_QUANTITY; index++)
  8316. {
  8317. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8318. {
  8319. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8320. {
  8321. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8322. goto end;
  8323. }
  8324. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8325. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8327. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8328. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8329. {
  8330. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8331. goto end;
  8332. }
  8333. else
  8334. {
  8335. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8337. goto end;
  8338. }
  8339. }
  8340. }// END FOR GB_QUANTITY
  8341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8342. {
  8343. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8344. {
  8345. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8346. {
  8347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8348. goto end;
  8349. }
  8350. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8351. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8352. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8353. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8354. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8355. {
  8356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8357. goto end;
  8358. }
  8359. else
  8360. {
  8361. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8362. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8363. goto end;
  8364. }
  8365. }
  8366. }// END FOR GENERAL_GUN_QUANTITY
  8367. for (int index = 0; index < AC_QUANTITY; index++)
  8368. {
  8369. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8370. {
  8371. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8372. {
  8373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8374. goto end;
  8375. }
  8376. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8377. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8379. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8380. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8381. {
  8382. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8383. goto end;
  8384. }
  8385. else
  8386. {
  8387. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8389. goto end;
  8390. }
  8391. }
  8392. }//END FOR AC_QUANTITY
  8393. }//END FOR AvailabilityTypeStr[Inoperative]
  8394. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8395. {
  8396. //----------------------gunIndex is 0 ------------------------------------------------//
  8397. if(gunIndex == 0)
  8398. {
  8399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8400. {
  8401. for(int i=0; i < gunTotalNumber; i++)
  8402. {
  8403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8404. {
  8405. 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
  8406. {
  8407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8408. goto end;
  8409. }
  8410. }//END FOR CHAdeMO_QUANTITY
  8411. for (int index = 0; index < CCS_QUANTITY; index++)
  8412. {
  8413. 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
  8414. {
  8415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8416. goto end;
  8417. }
  8418. }//END FOR CCS_QUANTITY
  8419. for (int index = 0; index < GB_QUANTITY; index++)
  8420. {
  8421. 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
  8422. {
  8423. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8425. goto end;
  8426. }
  8427. }// END FOR GB_QUANTITY
  8428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8429. {
  8430. 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
  8431. {
  8432. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8434. goto end;
  8435. }
  8436. }// END FOR GENERAL_GUN_QUANTITY
  8437. for (int index = 0; index < AC_QUANTITY; index++)
  8438. {
  8439. 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
  8440. {
  8441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8442. goto end;
  8443. }
  8444. }//END FOR CHAdeMO_QUANTITY
  8445. }// END FOR gunTotalNumber
  8446. }
  8447. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8448. {
  8449. for(int i=0; i < gunTotalNumber; i++)
  8450. {
  8451. for (int index = 0; index < AC_QUANTITY; index++)
  8452. {
  8453. 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
  8454. {
  8455. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8456. goto end;
  8457. }
  8458. }//END FOR CHAdeMO_QUANTITY
  8459. } // END FOR gunTotalNumber
  8460. }
  8461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8462. goto end;
  8463. }
  8464. //----------------------gunIndex is not 0 ------------------------------------------------//
  8465. //check Transaction active
  8466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8467. {
  8468. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8469. {
  8470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8471. goto end;
  8472. }
  8473. }//END FOR CHAdeMO_QUANTITY
  8474. for (int index = 0; index < CCS_QUANTITY; index++)
  8475. {
  8476. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8477. {
  8478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8479. goto end;
  8480. }
  8481. }//END FOR CCS_QUANTITY
  8482. for (int index = 0; index < GB_QUANTITY; index++)
  8483. {
  8484. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8485. {
  8486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8487. goto end;
  8488. }
  8489. }// END FOR GB_QUANTITY
  8490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8491. {
  8492. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8493. {
  8494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8495. goto end;
  8496. }
  8497. }// END FOR GENERAL_GUN_QUANTITY
  8498. for (int index = 0; index < AC_QUANTITY; index++)
  8499. {
  8500. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8501. {
  8502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8503. goto end;
  8504. }
  8505. }//END FOR AC_QUANTITY
  8506. }//END FOR AvailabilityTypeStr[Operative]
  8507. end:
  8508. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8509. {
  8510. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8511. }
  8512. else
  8513. {
  8514. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8515. }
  8516. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8517. {
  8518. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8519. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8520. }
  8521. else if(gunIndex == 0)
  8522. {
  8523. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8524. {
  8525. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8526. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8527. }
  8528. }
  8529. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8530. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8531. return result;
  8532. }
  8533. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8534. {
  8535. mtrace();
  8536. int valueInvalid = NO;
  8537. int result = FAIL;
  8538. char keystr[40]={0};
  8539. char valuestr[501]={0}; //value should be limited in 500 bytes
  8540. char comfirmstr[20]={0};
  8541. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8542. json_object *ChangeConfiguration;
  8543. ChangeConfiguration = json_tokener_parse(payload);
  8544. if(!is_error(ChangeConfiguration))
  8545. {
  8546. // Required data
  8547. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8548. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8549. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8550. {
  8551. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8552. }
  8553. else
  8554. {
  8555. valueInvalid = YES;
  8556. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8557. }
  8558. }
  8559. json_object_put(ChangeConfiguration);
  8560. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8561. {
  8562. DEBUG_ERROR("Payload is null or not accepted.\n");
  8563. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8564. }
  8565. else
  8566. {
  8567. int status = setKeyValue(keystr, valuestr);
  8568. switch(status)
  8569. {
  8570. case ConfigurationStatus_Accepted:
  8571. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8572. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8573. StoreConfigurationTable();
  8574. break;
  8575. case RebootRequired:
  8576. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8577. StoreConfigurationTable();
  8578. break;
  8579. case NotSupported:
  8580. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8581. break;
  8582. case ConfigurationStatus_Rejected:
  8583. default:
  8584. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8585. break;
  8586. }
  8587. }
  8588. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8589. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8590. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8591. {
  8592. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8593. SetOcppConnStatus(FALSE);
  8594. }
  8595. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8596. {
  8597. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8598. }
  8599. return result;
  8600. }
  8601. int handleClearCacheRequest(char *uuid, char *payload)
  8602. {
  8603. mtrace();
  8604. int result = FAIL;
  8605. char comfirmstr[20];
  8606. char rmFileCmd[100]={0};
  8607. struct stat stats;
  8608. DEBUG_INFO("handleClearCacheRequest...\n");
  8609. stat("/Storage/OCPP_PH", &stats);
  8610. // Check for directory existence
  8611. if (S_ISDIR(stats.st_mode) == 1)
  8612. {}
  8613. else
  8614. {
  8615. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8616. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8617. system(rmFileCmd);
  8618. }
  8619. if(OCPP_cleanLocalCache())
  8620. {
  8621. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8622. }
  8623. else
  8624. {
  8625. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8626. }
  8627. sendClearCacheConfirmation(uuid, comfirmstr);
  8628. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8629. return result;
  8630. }
  8631. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8632. {
  8633. mtrace();
  8634. int result = FAIL;
  8635. int resultRename;
  8636. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8637. char chargingProfilePurposeStr[26]={0};
  8638. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8639. char tempchargingProfilePurposeStr[26]={0};
  8640. char str[100]={0};
  8641. char fname[200]={0};
  8642. char comfirmstr[20]={0};
  8643. char word[1600]={0};
  8644. int clearflag = FALSE;
  8645. int chargingProfileIdIsNULL = FALSE;
  8646. int connectorIsNULL = FALSE;
  8647. int chargingProfilePurposeIsNULL = FALSE;
  8648. int stackLevelIsNULL = FALSE;
  8649. //int GotoEnd = FALSE;
  8650. FILE *fptr1, *fptr2;
  8651. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8652. int n_chargingProfile=0;
  8653. int isEmptyFile = FALSE;
  8654. char sLineWord[1600]={0};
  8655. char chargingProfiles[10][100]={0};
  8656. int ChargeProfileCount = 0;
  8657. int ch;
  8658. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8659. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8660. json_object *ClearChargingProfile;
  8661. ClearChargingProfile = json_tokener_parse(payload);
  8662. if(!is_error(ClearChargingProfile))
  8663. {
  8664. // Optional data
  8665. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8666. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8667. else
  8668. chargingProfileIdIsNULL = TRUE;
  8669. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8670. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8671. else
  8672. connectorIsNULL = TRUE;
  8673. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8674. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8675. else
  8676. chargingProfilePurposeIsNULL = TRUE;
  8677. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8678. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8679. else
  8680. stackLevelIsNULL = TRUE;
  8681. }
  8682. json_object_put(ClearChargingProfile);
  8683. if(connectorIdInt > 0)
  8684. {
  8685. if(chargingProfilePurposeIsNULL == TRUE)
  8686. {
  8687. int m = 0;
  8688. memset(fname, 0, ARRAY_SIZE(fname));
  8689. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8690. if((access(fname,F_OK))!=-1)
  8691. {
  8692. strcpy(chargingProfiles[m], fname);
  8693. m = m + 1;
  8694. }
  8695. memset(fname, 0, ARRAY_SIZE(fname));
  8696. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8697. if((access(fname,F_OK))!=-1)
  8698. {
  8699. strcpy(chargingProfiles[m], fname);
  8700. m = m + 1;
  8701. }
  8702. ChargeProfileCount = m;
  8703. }
  8704. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8705. {
  8706. //strcpy(fname, TxDefaultProfile_1_JSON);
  8707. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8708. if((access(fname,F_OK))!=-1)
  8709. {
  8710. strcpy(chargingProfiles[0], fname);
  8711. ChargeProfileCount = 1;
  8712. }
  8713. }
  8714. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8715. {
  8716. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8717. if((access(fname,F_OK))!=-1)
  8718. {
  8719. strcpy(chargingProfiles[0], fname);
  8720. ChargeProfileCount = 1;
  8721. }
  8722. //strcpy(fname, TxProfile_1_JSON);
  8723. }
  8724. }
  8725. else // Check all Charging Profiles
  8726. {
  8727. int i = 0;
  8728. char fnametemp[200]={0};
  8729. ChargeProfileCount = 0;
  8730. //Check ChargePointMaxProfile.json exit
  8731. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8732. {
  8733. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8734. i = i + 1;
  8735. }
  8736. //Check TxDefaultProfile_0.json exit
  8737. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8738. {
  8739. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8740. i = i + 1;
  8741. }
  8742. //Check TxDefaultProfile_%d.json
  8743. for(int j=1; j <= gunTotalNumber; j++)
  8744. {
  8745. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8746. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8747. if((access(fnametemp,F_OK))!=-1)
  8748. {
  8749. strcpy(chargingProfiles[i], fnametemp);
  8750. i = i + 1;
  8751. }
  8752. }
  8753. //Check TxProfile_%d.json
  8754. for(int j=1; j <= gunTotalNumber; j++)
  8755. {
  8756. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8757. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8758. if((access(fnametemp,F_OK))!=-1)
  8759. {
  8760. strcpy(chargingProfiles[i], fnametemp);
  8761. i = i + 1;
  8762. }
  8763. }
  8764. ChargeProfileCount = i;
  8765. }// End connectorIsNULL is TRUE
  8766. if(ChargeProfileCount == 0)
  8767. {
  8768. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8769. goto end;
  8770. }
  8771. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8772. {
  8773. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8774. goto end;
  8775. }
  8776. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8777. {
  8778. memset(str, 0, ARRAY_SIZE(str));
  8779. // clear temp file
  8780. sprintf(str,"rm -f %s",temp);
  8781. system(str);
  8782. for(int k=0; k < ChargeProfileCount; k++)
  8783. {
  8784. memset(str, 0, ARRAY_SIZE(str));
  8785. //clear file in C
  8786. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8787. system(str);
  8788. }
  8789. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8790. goto end;
  8791. }
  8792. else if(connectorIsNULL == TRUE)
  8793. {
  8794. for(int k=0; k < ChargeProfileCount; k++)
  8795. {
  8796. fptr1 = fopen(chargingProfiles[k], "r");
  8797. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8798. //Check Charging Profile Count
  8799. while(fscanf(fptr1, "%s", word) != EOF)
  8800. {
  8801. //DEBUG_INFO("word=%s\n",word);
  8802. if(strstr(word, "chargingProfileId")!= NULL)
  8803. {
  8804. //DEBUG_INFO("test chargingProfileId \n");
  8805. n_chargingProfile = n_chargingProfile + 1;
  8806. //DEBUG_INFO("chargingProfileId Found\n");
  8807. }
  8808. }
  8809. rewind(fptr1);
  8810. //search Charging Profile Element
  8811. //int i= 0;
  8812. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8813. {
  8814. json_object *tmpProfilee;
  8815. tmpProfilee = json_tokener_parse(sLineWord);
  8816. if(!is_error(tmpProfilee))
  8817. {
  8818. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8819. {
  8820. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8821. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8822. }
  8823. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8824. {
  8825. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8826. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8827. }
  8828. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8829. {
  8830. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8831. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8832. }
  8833. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8834. {
  8835. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8836. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8837. }
  8838. }
  8839. json_object_put(tmpProfilee);
  8840. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8841. {
  8842. //------- not write to fptr2-------//
  8843. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8844. //clearflag = TRUE;
  8845. }
  8846. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8847. {
  8848. //------- not write to fptr2-------//
  8849. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8850. }
  8851. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8852. {
  8853. //------- not write to fptr2-------//
  8854. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8855. }
  8856. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8857. {
  8858. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8859. }
  8860. else
  8861. {
  8862. fprintf(fptr2, sLineWord);//writing data into file
  8863. }
  8864. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8865. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8866. if(clearflag == TRUE)
  8867. {
  8868. fclose(fptr1);
  8869. fclose(fptr2);
  8870. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8871. system(str);
  8872. // clear temp file
  8873. sprintf(str,"rm -f %s",temp);
  8874. system(str);
  8875. }
  8876. else
  8877. {
  8878. fclose(fptr1);
  8879. fclose(fptr2);
  8880. memset(str, 0, ARRAY_SIZE(str));
  8881. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8882. system(str);
  8883. resultRename = rename(temp, chargingProfiles[k]);
  8884. if(resultRename == 0)
  8885. {
  8886. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8887. }
  8888. else
  8889. {
  8890. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8891. }
  8892. if(comfirmstr[0]== 0)
  8893. {
  8894. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8895. }
  8896. //Check chargingProfile is empty file
  8897. /*------ Read the file ----------------*/
  8898. fptr1=fopen(chargingProfiles[k],"r");
  8899. ch=fgetc(fptr1);
  8900. rewind(fptr1);
  8901. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8902. if(ch!=EOF)
  8903. {
  8904. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8905. {
  8906. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8907. if(sLineWord[0]=='\0')
  8908. {
  8909. isEmptyFile = TRUE;
  8910. break;
  8911. }
  8912. else
  8913. {
  8914. isEmptyFile = FALSE;
  8915. break;
  8916. }
  8917. }
  8918. }
  8919. else
  8920. isEmptyFile = TRUE;
  8921. fclose(fptr1);
  8922. if(isEmptyFile == TRUE)
  8923. {
  8924. memset(str, 0, ARRAY_SIZE(str));
  8925. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8926. system(str);
  8927. }
  8928. }
  8929. }// End of while(int k=0; k < ChargePointCount; k++)
  8930. }
  8931. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8932. {
  8933. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8934. for(int k=0; k < ChargeProfileCount; k++)
  8935. {
  8936. fptr1 = fopen(chargingProfiles[k], "r");
  8937. fptr2 = fopen(temp, "w+");
  8938. //Check Charging Profile Count
  8939. while(fscanf(fptr1, "%s", word) != EOF)
  8940. {
  8941. //DEBUG_INFO("word=%s\n",word);
  8942. if(strstr(word, "chargingProfileId")!= NULL)
  8943. {
  8944. n_chargingProfile = n_chargingProfile + 1;
  8945. }
  8946. }
  8947. rewind(fptr1);
  8948. //search Charging Profile Element
  8949. //int i= 0;
  8950. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8951. {
  8952. json_object *tmpProfilee;
  8953. tmpProfilee = json_tokener_parse(sLineWord);
  8954. if(!is_error(tmpProfilee))
  8955. {
  8956. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8957. {
  8958. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8959. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8960. }
  8961. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8962. {
  8963. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8964. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8965. }
  8966. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8967. {
  8968. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8969. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8970. }
  8971. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8972. {
  8973. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8974. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8975. }
  8976. }
  8977. json_object_put(tmpProfilee);
  8978. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8979. {
  8980. //------- not write to fptr2-------//
  8981. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8982. //clearflag = TRUE;
  8983. }
  8984. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8985. {
  8986. //------- not write to fptr2-------//
  8987. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8988. }
  8989. else if(stackLevelIsNULL == TRUE)
  8990. {
  8991. //Clear Whole File
  8992. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8993. clearflag = TRUE;
  8994. break;
  8995. }
  8996. else
  8997. {
  8998. fprintf(fptr2, sLineWord);//writing data into file
  8999. }
  9000. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9001. }
  9002. if(clearflag == TRUE)
  9003. {
  9004. fclose(fptr1);
  9005. fclose(fptr2);
  9006. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9007. system(str);
  9008. // clear temp file
  9009. sprintf(str,"rm -f %s",temp);
  9010. system(str);
  9011. }
  9012. else
  9013. {
  9014. fclose(fptr1);
  9015. fclose(fptr2);
  9016. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9017. system(str);
  9018. resultRename = rename(temp, chargingProfiles[k]);
  9019. if(resultRename == 0)
  9020. {
  9021. DEBUG_INFO("File ChargingProfile renamed successfully");
  9022. }
  9023. else
  9024. {
  9025. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9026. }
  9027. if(comfirmstr[0]== 0)
  9028. {
  9029. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9030. }
  9031. //Check chargingProfile is empty file
  9032. /*------ Read the file ----------------*/
  9033. fptr1=fopen(chargingProfiles[k],"r");
  9034. ch=fgetc(fptr1);
  9035. rewind(fptr1);
  9036. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9037. if(ch!=EOF)
  9038. {
  9039. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9040. {
  9041. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9042. if(sLineWord[0]=='\0')
  9043. {
  9044. isEmptyFile = TRUE;
  9045. break;
  9046. }
  9047. else
  9048. {
  9049. isEmptyFile = FALSE;
  9050. break;
  9051. }
  9052. }
  9053. }
  9054. else
  9055. isEmptyFile = TRUE;
  9056. fclose(fptr1);
  9057. if(isEmptyFile == TRUE)
  9058. {
  9059. memset(str, 0, ARRAY_SIZE(str));
  9060. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9061. system(str);
  9062. }
  9063. /*------- End of reading ---------------*/
  9064. }
  9065. } // while(int k=0; k < ChargeProfileCount; k++)
  9066. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9067. end:
  9068. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9069. {
  9070. if(connectorIdInt == 0)
  9071. {
  9072. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9073. {
  9074. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9075. }
  9076. }
  9077. else
  9078. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9079. }
  9080. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9081. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9082. return result;
  9083. }
  9084. void createFirmwareVersionByDataTransfer(void)
  9085. {
  9086. json_object *FirmwareDataTransfer = json_object_new_object();
  9087. // AC & DC model
  9088. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9089. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9090. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9091. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9092. // DC model
  9093. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9094. {
  9095. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9096. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9097. (gunType[3] != GUN_TYPE_UNKNOWN))
  9098. {
  9099. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9100. }
  9101. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9102. {
  9103. // DS DM DW
  9104. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9105. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9106. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9107. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9108. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9109. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9110. }
  9111. else
  9112. {
  9113. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9114. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9115. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9116. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9117. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9118. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9119. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9120. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9121. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9122. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9123. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9124. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9125. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9126. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9127. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9128. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9129. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9130. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9131. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9132. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9133. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9134. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9135. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9136. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9137. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9138. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9139. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9140. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9141. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9142. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9143. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9144. }
  9145. }
  9146. // 4G model
  9147. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9148. {
  9149. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9150. }
  9151. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9152. json_object_put(FirmwareDataTransfer);
  9153. }
  9154. int handleDataTransferRequest(char *uuid, char *payload)
  9155. {
  9156. mtrace();
  9157. json_object *response = json_object_new_object();
  9158. int result = FAIL;
  9159. char tempvendorId[255]={0};
  9160. char tempmessageId[50]={0};
  9161. char tempdata[1024]={0};
  9162. char message[2048]={0};
  9163. DEBUG_INFO("handleDataTransferRequest...\n");
  9164. if((uuid != NULL) && (payload != NULL))
  9165. {
  9166. json_object *DataTransfer;
  9167. DataTransfer = json_tokener_parse(payload);
  9168. if(!is_error(DataTransfer))
  9169. {
  9170. // Required data
  9171. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9172. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9173. // Optional data
  9174. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9175. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9176. if(json_object_object_get(DataTransfer, "data") != NULL)
  9177. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9178. result = PASS;
  9179. }
  9180. json_object_put(DataTransfer);
  9181. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9182. {
  9183. // Send all moudle firmware version on EVSE
  9184. createFirmwareVersionByDataTransfer();
  9185. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9186. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9187. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9188. json_object_put(response);
  9189. }
  9190. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9191. {
  9192. system("/usr/bin/run_tmate_restart.sh &");
  9193. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9194. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9195. json_object_put(response);
  9196. }
  9197. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9198. {
  9199. json_object *data;
  9200. data = json_tokener_parse(tempdata);
  9201. if(!is_error(data))
  9202. {
  9203. 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))
  9204. {
  9205. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9206. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9207. if(json_object_object_get(data, "SOC") != NULL)
  9208. {
  9209. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9210. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9211. }
  9212. if(json_object_object_get(data, "Energy") != NULL)
  9213. {
  9214. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9215. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9216. }
  9217. if(json_object_object_get(data, "Duration") != NULL)
  9218. {
  9219. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9220. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9221. }
  9222. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9223. }
  9224. else
  9225. {
  9226. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9227. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9228. }
  9229. }
  9230. else
  9231. {
  9232. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9233. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9234. }
  9235. json_object_put(data);
  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, "SetLEDBar") != NULL)
  9240. {
  9241. json_object *data;
  9242. data = json_tokener_parse(tempdata);
  9243. if(!is_error(data))
  9244. {
  9245. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9246. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9247. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9248. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9249. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9250. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9251. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9252. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9253. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9254. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9255. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9256. }
  9257. else
  9258. {
  9259. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9260. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9261. }
  9262. json_object_put(data);
  9263. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9264. json_object_put(response);
  9265. }
  9266. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9267. {
  9268. json_object *data;
  9269. data = json_tokener_parse(tempdata);
  9270. if(!is_error(data))
  9271. {
  9272. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9273. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9274. if(json_object_object_get(data, "idToken") != NULL)
  9275. {
  9276. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9277. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9278. }
  9279. else
  9280. {
  9281. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9282. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9283. }
  9284. if(json_object_object_get(data, "price") != NULL) //v1.0
  9285. {
  9286. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9287. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9288. }
  9289. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9290. {
  9291. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9292. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9293. }
  9294. else
  9295. {
  9296. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9297. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9298. }
  9299. }
  9300. else
  9301. {
  9302. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9303. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9304. }
  9305. json_object_put(data);
  9306. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9307. json_object_put(response);
  9308. }
  9309. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9310. {
  9311. json_object *data;
  9312. data = json_tokener_parse(tempdata);
  9313. if(!is_error(data))
  9314. {
  9315. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9316. if(json_object_object_get(data, "txId") != NULL)
  9317. {
  9318. // California pricing V1.0
  9319. DEBUG_INFO("California pricing V1.0\n");
  9320. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9321. sprintf((char*)dmsVersion, "1.0");
  9322. for(int idx = 0;idx<gunTotalNumber;idx++)
  9323. {
  9324. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9325. {
  9326. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9327. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9328. if(json_object_object_get(data, "description") != NULL)
  9329. {
  9330. // California pricing V1.0
  9331. DEBUG_INFO("California pricing V1.0\n");
  9332. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9333. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9334. }
  9335. }
  9336. }
  9337. }
  9338. else if(json_object_object_get(data, "transactionId") != NULL)
  9339. {
  9340. // California pricing V2.0
  9341. DEBUG_INFO("California pricing V2.0\n");
  9342. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9343. sprintf((char*)dmsVersion, "2.0");
  9344. for(int idx=0;idx<gunTotalNumber;idx++)
  9345. {
  9346. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9347. {
  9348. if(json_object_object_get(data, "timestamp") != NULL)
  9349. {
  9350. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9351. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9352. }
  9353. else
  9354. {
  9355. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9356. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9357. }
  9358. if(json_object_object_get(data, "meterValue") != NULL)
  9359. {
  9360. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9361. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9362. }
  9363. else
  9364. {
  9365. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9366. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9367. }
  9368. if(json_object_object_get(data, "cost") != NULL)
  9369. {
  9370. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9371. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9372. }
  9373. else
  9374. {
  9375. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9376. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9377. }
  9378. if(json_object_object_get(data, "state") != NULL)
  9379. {
  9380. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9381. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9382. }
  9383. else
  9384. {
  9385. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9386. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9387. }
  9388. if(json_object_object_get(data, "chargingPrice") != NULL)
  9389. {
  9390. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9391. {
  9392. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9393. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9394. }
  9395. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9396. {
  9397. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9398. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9399. }
  9400. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9401. {
  9402. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9403. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9404. }
  9405. }
  9406. else
  9407. {
  9408. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9409. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9410. }
  9411. if(json_object_object_get(data, "idlePrice") != NULL)
  9412. {
  9413. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9414. {
  9415. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9416. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9417. }
  9418. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9419. {
  9420. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9421. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9422. }
  9423. }
  9424. if(json_object_object_get(data, "nextPeriod") != NULL)
  9425. {
  9426. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9427. {
  9428. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9429. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9430. }
  9431. else
  9432. {
  9433. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9434. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9435. }
  9436. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9437. {
  9438. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9439. {
  9440. 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")));
  9441. 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"));
  9442. }
  9443. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9444. {
  9445. 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")));
  9446. 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"));
  9447. }
  9448. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9449. {
  9450. 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")));
  9451. 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"));
  9452. }
  9453. }
  9454. else
  9455. {
  9456. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9457. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9458. }
  9459. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9460. {
  9461. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9462. {
  9463. 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")));
  9464. 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"));
  9465. }
  9466. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9467. {
  9468. 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")));
  9469. 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"));
  9470. }
  9471. }
  9472. }
  9473. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9474. {
  9475. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9476. {
  9477. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9478. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9479. }
  9480. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9481. {
  9482. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9483. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9484. }
  9485. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9486. {
  9487. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9488. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9489. }
  9490. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9491. {
  9492. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9493. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9494. }
  9495. }
  9496. }
  9497. }
  9498. }
  9499. else
  9500. {
  9501. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9502. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9503. }
  9504. }
  9505. else
  9506. {
  9507. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9508. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9509. }
  9510. json_object_put(data);
  9511. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9512. json_object_put(response);
  9513. }
  9514. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9515. {
  9516. json_object *data;
  9517. data = json_tokener_parse(tempdata);
  9518. if(!is_error(data))
  9519. {
  9520. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9521. if(json_object_object_get(data, "txId") != NULL)
  9522. {
  9523. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9524. for(int idx = 0;idx<gunTotalNumber;idx++)
  9525. {
  9526. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9527. {
  9528. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9529. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9530. if(json_object_object_get(data, "description") != NULL)
  9531. {
  9532. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9533. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9534. }
  9535. else
  9536. {
  9537. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9538. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9539. }
  9540. }
  9541. }
  9542. }
  9543. else if(json_object_object_get(data, "transactionId") != NULL)
  9544. {
  9545. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9546. for(int idx = 0;idx<gunTotalNumber;idx++)
  9547. {
  9548. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9549. {
  9550. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9551. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9552. if(json_object_object_get(data, "cost") != NULL)
  9553. {
  9554. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9555. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9556. }
  9557. else
  9558. {
  9559. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9560. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9561. }
  9562. if(json_object_object_get(data, "priceText") != NULL)
  9563. {
  9564. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9565. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9566. }
  9567. else
  9568. {
  9569. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9570. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9571. }
  9572. if(json_object_object_get(data, "qrCodeText") != NULL)
  9573. {
  9574. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9575. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9576. }
  9577. }
  9578. }
  9579. }
  9580. else
  9581. {
  9582. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9583. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9584. }
  9585. }
  9586. else
  9587. {
  9588. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9589. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9590. }
  9591. json_object_put(data);
  9592. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9593. json_object_put(response);
  9594. }
  9595. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9596. {
  9597. json_object *data;
  9598. data = json_tokener_parse(tempdata);
  9599. if(!is_error(data))
  9600. {
  9601. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9602. if(json_object_object_get(data, "Content_Type") != NULL)
  9603. {
  9604. 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))
  9605. {
  9606. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9607. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9608. {
  9609. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9610. }
  9611. }
  9612. else
  9613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9614. }
  9615. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9616. }
  9617. else
  9618. {
  9619. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9620. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9621. }
  9622. json_object_put(data);
  9623. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9624. json_object_put(response);
  9625. }
  9626. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9627. {
  9628. json_object *data;
  9629. data = json_tokener_parse(tempdata);
  9630. if(!is_error(data))
  9631. {
  9632. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9633. if(json_object_object_get(data, "ConnectorId") != NULL)
  9634. {
  9635. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9636. }
  9637. if(json_object_object_get(data, "SerialNo") != NULL)
  9638. {
  9639. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9640. }
  9641. if(json_object_object_get(data, "Page_Index") != NULL)
  9642. {
  9643. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9644. }
  9645. if(json_object_object_get(data, "Duration") != NULL)
  9646. {
  9647. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9648. }
  9649. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9650. }
  9651. else
  9652. {
  9653. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9654. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9655. }
  9656. json_object_put(data);
  9657. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9658. json_object_put(response);
  9659. }
  9660. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9661. {
  9662. json_object *data;
  9663. data = json_tokener_parse(tempdata);
  9664. if(!is_error(data))
  9665. {
  9666. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9667. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9668. {
  9669. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9670. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9671. else
  9672. {
  9673. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9674. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9675. }
  9676. }
  9677. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9678. {
  9679. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9680. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9681. else
  9682. {
  9683. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9684. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9685. }
  9686. }
  9687. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9688. {
  9689. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9690. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9691. else
  9692. {
  9693. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9694. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9695. }
  9696. }
  9697. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9698. {
  9699. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9700. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9701. else
  9702. {
  9703. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9704. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9705. }
  9706. }
  9707. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9708. {
  9709. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9710. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9711. else
  9712. {
  9713. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9714. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9715. }
  9716. }
  9717. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9718. {
  9719. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9720. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9721. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9722. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9723. else
  9724. {
  9725. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9726. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9727. }
  9728. }
  9729. if(json_object_object_get(data, "isAuthentication") != NULL)
  9730. {
  9731. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9732. {
  9733. case 0:
  9734. case 1:
  9735. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9736. break;
  9737. default:
  9738. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9739. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9740. break;
  9741. }
  9742. }
  9743. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9744. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9745. }
  9746. else
  9747. {
  9748. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9749. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9750. }
  9751. json_object_put(data);
  9752. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9753. json_object_put(response);
  9754. }
  9755. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9756. {
  9757. json_object *data;
  9758. data = json_tokener_parse(tempdata);
  9759. if(!is_error(data))
  9760. {
  9761. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9762. if(json_object_object_get(data, "stationName") != NULL)
  9763. {
  9764. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9765. }
  9766. else
  9767. {
  9768. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9769. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9770. }
  9771. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9772. {
  9773. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9774. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9775. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9776. }
  9777. }
  9778. else
  9779. {
  9780. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9781. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9782. }
  9783. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9784. json_object_put(response);
  9785. }
  9786. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9787. {
  9788. json_object *data;
  9789. data = json_tokener_parse(tempdata);
  9790. if(!is_error(data))
  9791. {
  9792. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9793. if(json_object_object_get(data, "weatherId") != NULL)
  9794. {
  9795. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9796. }
  9797. else
  9798. {
  9799. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9800. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9801. }
  9802. if(json_object_object_get(data, "Temperature") != NULL)
  9803. {
  9804. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9805. }
  9806. else
  9807. {
  9808. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9809. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9810. }
  9811. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9812. {
  9813. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9814. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9815. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9816. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9817. }
  9818. }
  9819. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9820. {
  9821. json_object *data;
  9822. data = json_tokener_parse(tempdata);
  9823. if(!is_error(data))
  9824. {
  9825. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9826. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9827. {
  9828. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9829. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9830. }
  9831. else
  9832. {
  9833. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9834. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9835. }
  9836. }
  9837. else
  9838. {
  9839. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9840. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9841. }
  9842. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9843. json_object_put(response);
  9844. }
  9845. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9846. {
  9847. json_object *data;
  9848. data = json_tokener_parse(tempdata);
  9849. if(!is_error(data))
  9850. {
  9851. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9852. {
  9853. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9854. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9855. if(gun_index < gunTotalNumber)
  9856. {
  9857. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9858. {
  9859. json_object *responsedata = json_object_new_object();
  9860. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9861. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9862. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9863. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9864. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.VEMData[gun_index]));
  9865. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9866. }
  9867. else
  9868. {
  9869. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9870. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9871. }
  9872. }
  9873. else
  9874. {
  9875. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9876. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9877. }
  9878. }
  9879. else
  9880. {
  9881. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9882. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9883. }
  9884. }
  9885. else
  9886. {
  9887. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9888. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9889. }
  9890. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9891. json_object_put(response);
  9892. }
  9893. else
  9894. {
  9895. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9896. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9897. }
  9898. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9899. json_object_put(response);
  9900. }
  9901. else
  9902. {
  9903. // Can not find valid message id
  9904. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9905. }
  9906. }
  9907. else
  9908. {
  9909. // Payload is null
  9910. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9911. }
  9912. LWS_Send(message);
  9913. return result;
  9914. }
  9915. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9916. {
  9917. mtrace();
  9918. int result = FAIL;
  9919. int connectorIdInt, durationInt;
  9920. char chargingRateUnitStr[4]={0};
  9921. char comfirmstr[20];
  9922. int confirmPeriods = 0;
  9923. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9924. json_object *GetCompositeSchedule;
  9925. GetCompositeSchedule = json_tokener_parse(payload);
  9926. if(!is_error(GetCompositeSchedule))
  9927. {
  9928. // Required data
  9929. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9930. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9931. else
  9932. connectorIdInt = -1;
  9933. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9934. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9935. else
  9936. durationInt = 86400;
  9937. // Optional data
  9938. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9939. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9940. }
  9941. json_object_put(GetCompositeSchedule);
  9942. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9943. if((connectorIdInt == 0) ||
  9944. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9945. {
  9946. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9947. struct StructChargingProfile tmpProfile[1];
  9948. if(strstr(chargingRateUnitStr, "W") != NULL)
  9949. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9950. else
  9951. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9952. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9953. {
  9954. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9955. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9956. }
  9957. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9958. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9959. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9960. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9961. {
  9962. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9963. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9964. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9965. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9966. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9967. {
  9968. confirmPeriods = idx;
  9969. break;
  9970. }
  9971. }
  9972. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9973. {
  9974. confirmPeriods += 1;
  9975. }
  9976. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9977. }
  9978. else
  9979. {
  9980. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9981. }
  9982. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9983. return result;
  9984. }
  9985. int handleGetConfigurationRequest(char *uuid, char *payload)
  9986. {
  9987. mtrace();
  9988. int result = FAIL;
  9989. int MaxKeySupported = 0;
  9990. int n_keys = 0;
  9991. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9992. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9993. json_object *GetConfiguration;
  9994. GetConfiguration = json_tokener_parse(payload);
  9995. if(!is_error(GetConfiguration))
  9996. {
  9997. // Optional data
  9998. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9999. {
  10000. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10001. {
  10002. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10003. n_keys = idx + 1;
  10004. }
  10005. }
  10006. }
  10007. json_object_put(GetConfiguration);
  10008. UnknownKeynum = 0;
  10009. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10010. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10011. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10012. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10013. if(n_keys != 0)
  10014. {
  10015. for(int i=0;i<n_keys;i++)
  10016. {
  10017. getKeyValue(requestKey[i]);
  10018. }
  10019. }
  10020. else
  10021. {
  10022. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10023. getKeyValue("");
  10024. }
  10025. processUnkownKey();
  10026. sendGetConfigurationConfirmation(uuid);
  10027. return result;
  10028. }
  10029. static char fnamePlusPath[100]={0};
  10030. static char fnamePWithNoPath[60]={0};
  10031. void checkUploadLog(void)
  10032. {
  10033. FILE *fp;
  10034. /* Open the command for reading. */
  10035. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10036. if (fp == NULL) {
  10037. DEBUG_WARN("Failed to run command\n" );
  10038. exit(1);
  10039. }
  10040. int ftppathlen = 0;
  10041. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10042. int i = 0;
  10043. /* Read the output a line at a time - output it. */
  10044. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10045. if(i==0)
  10046. {
  10047. ftppathlen = strlen(fnamePlusPath);
  10048. DEBUG_INFO("%s\n", fnamePlusPath);
  10049. fnamePlusPath[ftppathlen]='\0';
  10050. break;
  10051. }
  10052. i= i+1;
  10053. }
  10054. /* close */
  10055. pclose(fp);
  10056. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10057. {
  10058. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10059. {
  10060. fnamePlusPath[k]='\0';
  10061. }
  10062. }
  10063. i=1;
  10064. //char fname[60]={0};
  10065. while(i < ftppathlen)
  10066. {
  10067. int len=ftppathlen-i;
  10068. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10069. {
  10070. DEBUG_INFO("compare '/' all right\n");
  10071. break;
  10072. }
  10073. i=i+1;
  10074. }
  10075. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10076. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10077. fnamePWithNoPath[i+1] = '\0';
  10078. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10079. {
  10080. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10081. {
  10082. fnamePWithNoPath[j]='\0';
  10083. }
  10084. }
  10085. FILE* fp1 = fopen(fnamePlusPath, "r");
  10086. if (fp1)
  10087. {
  10088. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10089. // file exists
  10090. fclose(fp1);
  10091. }
  10092. else
  10093. {
  10094. // file doesn't exist
  10095. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10096. }
  10097. }
  10098. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10099. {
  10100. mtrace();
  10101. int result = FAIL;
  10102. time_t CurrentTime;
  10103. struct tm *tm;
  10104. pthread_t th_Status;
  10105. CurrentTime = time(NULL);
  10106. tm = localtime(&CurrentTime);
  10107. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10108. 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);
  10109. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10110. if(!interLock.isGetDiagnosticGoing)
  10111. {
  10112. interLock.isGetDiagnosticGoing = 1;
  10113. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10114. sleep(1);
  10115. }
  10116. else
  10117. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10118. return result;
  10119. }
  10120. void* GetDiagnosticsProcess(void* data)
  10121. {
  10122. pthread_detach(pthread_self());
  10123. mtrace();
  10124. int retriesInt=0, retryIntervalInt=0;
  10125. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10126. 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};
  10127. int port=0;
  10128. int isSuccess = FALSE;
  10129. char ftpbuf[200]={0};
  10130. char cmdBuf[2048];
  10131. struct tm *tmNow;
  10132. time_t CurrentTime;
  10133. struct tm tmStart;
  10134. struct tm tmStop;
  10135. CurrentTime = time(NULL);
  10136. tmNow=localtime(&CurrentTime);
  10137. uint16_t targetYear, targetMonth;
  10138. json_object *GetDiagnostics;
  10139. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10140. GetDiagnostics = json_tokener_parse(data);
  10141. if(!is_error(GetDiagnostics))
  10142. {
  10143. // Required data
  10144. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10145. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10146. // Optional data
  10147. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10148. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10149. else
  10150. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10151. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10152. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10153. else
  10154. retryIntervalInt = 30;
  10155. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10156. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10157. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10158. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10159. }
  10160. json_object_put(GetDiagnostics);
  10161. // Notify CSU to get log of dispensers.
  10162. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  10163. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  10164. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  10165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  10166. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  10167. )
  10168. {
  10169. sprintf((char *)ShmOCPP16DataPH->GetDiagnostics.StartTime,"%s",startTimestr);
  10170. sprintf((char *)ShmOCPP16DataPH->GetDiagnostics.StopTime,"%s",stopTimestr);
  10171. ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq = TRUE;
  10172. struct timespec timerGetDiagnostics;
  10173. refreshStartTimer(&timerGetDiagnostics);
  10174. while(ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq != FALSE)
  10175. {
  10176. if(getDiffSecNow(timerGetDiagnostics)>=180)
  10177. {
  10178. ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq = FALSE;
  10179. DEBUG_INFO("Waiting log of dispenser timeout.");
  10180. }
  10181. }
  10182. }
  10183. // Pack log to compress file
  10184. 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) &&
  10185. (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))
  10186. {
  10187. // Pack system log
  10188. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10189. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10190. targetYear = tmStart.tm_year;
  10191. targetMonth = tmStart.tm_mon;
  10192. do
  10193. {
  10194. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10195. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10196. if(targetMonth+1>=13)
  10197. {
  10198. targetYear += 1;
  10199. targetMonth = 1;
  10200. }
  10201. else
  10202. {
  10203. targetMonth += 1;
  10204. }
  10205. }while((targetYear < (tmNow->tm_year+1900)) ||
  10206. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10207. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10208. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10209. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  10210. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  10211. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  10212. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  10213. system(cmdBuf);
  10214. // Pack charging & event log
  10215. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10216. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10217. targetYear = tmStart.tm_year;
  10218. targetMonth = tmStart.tm_mon;
  10219. do
  10220. {
  10221. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10222. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  10223. if(targetMonth+1>=13)
  10224. {
  10225. targetYear += 1;
  10226. targetMonth = 1;
  10227. }
  10228. else
  10229. {
  10230. targetMonth += 1;
  10231. }
  10232. }while((targetYear < (tmNow->tm_year+1900)) ||
  10233. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10234. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10235. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10236. system(cmdBuf);
  10237. // Combine log file
  10238. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10239. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10240. }
  10241. else
  10242. {
  10243. system("exec /root/logPackTools 'log' 6");
  10244. }
  10245. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10246. system(cmdBuf);
  10247. checkUploadLog();
  10248. //****************location*******************/
  10249. if(strcmp(locationstr,"")==0)
  10250. {
  10251. DEBUG_INFO("location is <Empty>!\n");
  10252. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10253. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10254. goto end;
  10255. }
  10256. memset(protocol, 0, ARRAY_SIZE(protocol));
  10257. memset(user, 0, ARRAY_SIZE(user) );
  10258. memset(password, 0, ARRAY_SIZE(password));
  10259. memset(host, 0, ARRAY_SIZE(host));
  10260. memset(path, 0, ARRAY_SIZE(path));
  10261. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10262. memset(host1, 0, ARRAY_SIZE(host1));
  10263. memset(path1, 0, ARRAY_SIZE(path1));
  10264. /*location: ftp://user:password@host:port/path*/
  10265. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10266. if((access(fnamePlusPath,F_OK))!=-1)
  10267. {
  10268. DEBUG_INFO("fnamePlusPath exist.\n");
  10269. }
  10270. else
  10271. {
  10272. DEBUG_INFO("fnamePlusPath not exist!\n");
  10273. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10274. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10275. goto end;
  10276. }
  10277. if(strchr(locationstr,'@')==NULL)
  10278. {
  10279. sscanf(locationstr,
  10280. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10281. protocol, host, &port, path);
  10282. strcpy(user,"anonymous");
  10283. strcpy(password,"");
  10284. }
  10285. else
  10286. {
  10287. //DEBUG_INFO("pch=%s\n", pch);
  10288. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10289. protocol, user, password, host, &port, path);
  10290. }
  10291. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10292. {
  10293. DEBUG_INFO("protocol is not ftp/http ! \n");
  10294. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10295. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10296. goto end;
  10297. }
  10298. if(strncmp(locationstr,"http", 4) == 0)
  10299. {
  10300. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10301. sprintf(ftppath,"/%s", path);
  10302. do
  10303. {
  10304. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10305. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10306. sleep(3);
  10307. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10308. if(!isSuccess)
  10309. {
  10310. DEBUG_INFO("Diagnostics fail.\n");
  10311. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10312. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10313. sleep(retryIntervalInt);
  10314. }
  10315. else
  10316. {
  10317. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10318. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10319. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10320. }
  10321. retriesInt--;
  10322. }while((isSuccess == 0)&&(retriesInt >= 0));
  10323. }
  10324. else
  10325. {
  10326. sscanf(host,"%[^/]%s",host1, path1);
  10327. if(strlen(path) > 0)
  10328. sprintf(ftppath,"/%s", path);
  10329. else
  10330. sprintf(ftppath,"/%s", path1);
  10331. int ftppathlen=strlen(ftppath);
  10332. int i=1;
  10333. char filenametemp[50];
  10334. while(i < ftppathlen)
  10335. {
  10336. int len=ftppathlen-i;
  10337. if(ftppath[len]== 47) // '/' ascll code: 47
  10338. {
  10339. DEBUG_INFO("find '/' all right\n");
  10340. break;
  10341. }
  10342. i=i+1;
  10343. }
  10344. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10345. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10346. filenametemp[i+1] = 0;
  10347. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10348. if(port == 0)
  10349. port = 21;
  10350. do
  10351. {
  10352. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10353. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10354. sleep(3);
  10355. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10356. if(!isSuccess)
  10357. {
  10358. DEBUG_INFO("Diagnostics fail.\n");
  10359. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10360. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10361. sleep(retryIntervalInt);
  10362. }
  10363. else
  10364. {
  10365. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10366. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10367. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10368. }
  10369. retriesInt--;
  10370. }while((!isSuccess)&&(retriesInt >= 0));
  10371. }
  10372. end:
  10373. system("rm -f /mnt/*");
  10374. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  10375. sleep(5);
  10376. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10377. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10378. interLock.isGetDiagnosticGoing = 0;
  10379. pthread_exit(NULL);
  10380. }
  10381. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10382. {
  10383. mtrace();
  10384. int result = FAIL;
  10385. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10386. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10387. {
  10388. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10389. locallistVersion = -1;
  10390. }
  10391. else
  10392. {
  10393. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10394. locallistVersion = 0;
  10395. OCPP_getListVerion();
  10396. }
  10397. //from db.OCPP_getListVerion
  10398. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10399. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10400. sendGetLocalListVersionConfirmation(uuid,"");
  10401. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10402. return result;
  10403. }
  10404. int handleRemoteStartRequest(char *uuid, char *payload)
  10405. {
  10406. mtrace();
  10407. int result = PASS;
  10408. int connectorIdInt=-1;
  10409. int tempIndex = 0;
  10410. char comfirmstr[20]={0};
  10411. char cmdBuf[512];
  10412. json_object *RemoteStartTransaction;
  10413. FILE *fp;
  10414. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10415. if(server_pending == TRUE)
  10416. {
  10417. result = FAIL;
  10418. }
  10419. RemoteStartTransaction = json_tokener_parse(payload);
  10420. if(!is_error(RemoteStartTransaction))
  10421. {
  10422. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10423. {
  10424. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10425. }
  10426. else
  10427. {
  10428. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10429. {
  10430. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10431. {
  10432. connectorIdInt = (gun_index+1);
  10433. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10434. break;
  10435. }
  10436. }
  10437. }
  10438. if(connectorIdInt == 0)
  10439. {
  10440. DEBUG_WARN("Connector id shall not equal 0.\n");
  10441. result = FAIL;
  10442. }
  10443. else if(connectorIdInt == -1)
  10444. {
  10445. DEBUG_INFO("Connector id does not specific.\n");
  10446. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10447. {
  10448. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10449. // Required data
  10450. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10451. // Optional data
  10452. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10453. {
  10454. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10455. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10456. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10457. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10458. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10459. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10460. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10461. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10462. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10463. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10464. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10465. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10466. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10467. {
  10468. 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")));
  10469. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10470. 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"));
  10471. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10472. 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"));
  10473. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10474. 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")));
  10475. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10476. {
  10477. 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++)
  10478. {
  10479. 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"));
  10480. 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"));
  10481. 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)
  10482. 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"));
  10483. }
  10484. }
  10485. }
  10486. }
  10487. else
  10488. {
  10489. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10490. }
  10491. }
  10492. }
  10493. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10494. {
  10495. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10496. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10497. // Required data
  10498. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10499. // Optional data
  10500. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10501. {
  10502. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10503. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10504. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10505. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10506. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10507. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10508. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10509. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10510. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10511. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10512. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10513. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10514. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10515. {
  10516. 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")));
  10517. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10518. 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"));
  10519. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10520. 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"));
  10521. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10522. 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")));
  10523. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10524. {
  10525. 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++)
  10526. {
  10527. 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"));
  10528. 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"));
  10529. 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)
  10530. 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"));
  10531. }
  10532. }
  10533. }
  10534. }
  10535. else
  10536. {
  10537. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10538. }
  10539. }
  10540. else
  10541. {
  10542. DEBUG_WARN("Connector id is over maximun value.\n");
  10543. result = FAIL;
  10544. }
  10545. }
  10546. if(result == PASS)
  10547. {
  10548. if(connectorIdInt > 0)
  10549. {
  10550. //check Transaction active
  10551. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10552. {
  10553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10554. {
  10555. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10556. }
  10557. else
  10558. {
  10559. tempIndex = connectorIdInt -1;
  10560. }
  10561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10562. {
  10563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10564. {
  10565. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10566. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10567. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10568. {
  10569. //Reserved
  10570. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10571. }
  10572. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10573. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10574. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10575. {
  10576. //Reserved
  10577. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10578. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10579. goto end;
  10580. }
  10581. else
  10582. {
  10583. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10584. {
  10585. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10586. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10587. goto end;
  10588. }
  10589. }//END FOR ELSE
  10590. }
  10591. }// END FOR CHAdeMO_QUANTITY
  10592. }
  10593. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10594. {
  10595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10596. {
  10597. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10598. }
  10599. else
  10600. {
  10601. tempIndex = connectorIdInt -1;
  10602. }
  10603. for (int index = 0; index < CCS_QUANTITY; index++)
  10604. {
  10605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10606. {
  10607. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10608. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10609. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10610. {
  10611. //Reserved
  10612. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10613. }
  10614. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10615. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10616. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10617. {
  10618. //Reserved
  10619. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10620. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10621. goto end;
  10622. }
  10623. else
  10624. {
  10625. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10626. {
  10627. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10628. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10629. goto end;
  10630. }
  10631. }// END FOR ELSE
  10632. }
  10633. }// END FOR CCS_QUANTITY
  10634. }
  10635. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10636. {
  10637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10638. {
  10639. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10640. }
  10641. else
  10642. {
  10643. tempIndex = connectorIdInt -1;
  10644. }
  10645. for (int index = 0; index < GB_QUANTITY; index++)
  10646. {
  10647. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10648. {
  10649. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10650. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10651. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10652. {
  10653. //Reserved
  10654. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10655. }
  10656. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10657. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10658. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10659. {
  10660. //Reserved
  10661. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10662. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10663. goto end;
  10664. }
  10665. else
  10666. {
  10667. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10668. {
  10669. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10670. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10671. goto end;
  10672. }
  10673. }// END FOR ELSE
  10674. }
  10675. } // END FOR GB_QUANTITY
  10676. }
  10677. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10678. {
  10679. tempIndex = connectorIdInt -1;
  10680. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10681. {
  10682. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10683. {
  10684. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10685. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10686. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10687. {
  10688. //Reserved
  10689. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10690. }
  10691. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10692. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10693. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10694. {
  10695. //Reserved
  10696. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10697. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10698. goto end;
  10699. }
  10700. else
  10701. {
  10702. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10703. {
  10704. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10705. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10706. goto end;
  10707. }
  10708. }// END FOR ELSE
  10709. }
  10710. } // END FOR GB_QUANTITY
  10711. }
  10712. else
  10713. {
  10714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10715. {
  10716. tempIndex = 2;
  10717. }
  10718. else
  10719. {
  10720. tempIndex = connectorIdInt -1;
  10721. }
  10722. for (int index = 0; index < AC_QUANTITY; index++)
  10723. {
  10724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10725. {
  10726. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10727. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10728. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10729. {
  10730. //Reserved
  10731. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10732. }
  10733. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10734. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10735. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10736. {
  10737. //Reserved
  10738. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10739. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10740. goto end;
  10741. }
  10742. else
  10743. {
  10744. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10745. {
  10746. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10748. goto end;
  10749. }
  10750. }//END FOR ELSE
  10751. }
  10752. }// END FOR AC_QUANTITY
  10753. }
  10754. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10755. {
  10756. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10757. {
  10758. // Save profile to file
  10759. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10760. system(cmdBuf);
  10761. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10762. fp = fopen(cmdBuf, "w");
  10763. 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));
  10764. fclose(fp);
  10765. }
  10766. else
  10767. {
  10768. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10770. goto end;
  10771. }
  10772. }
  10773. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10774. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10775. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10776. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10777. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10779. }
  10780. else
  10781. {
  10782. uint8_t isHasIdleConnector = FALSE;
  10783. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10784. {
  10785. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10786. {
  10787. isHasIdleConnector = TRUE;
  10788. break;
  10789. }
  10790. }
  10791. if((isHasIdleConnector == TRUE) && !ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10792. {
  10793. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10794. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10795. {
  10796. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10797. {
  10798. // Save profile to file
  10799. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10800. system(cmdBuf);
  10801. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10802. fp = fopen(cmdBuf, "w");
  10803. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10804. fclose(fp);
  10805. refreshStartTimer(&clientTime.RemoteStartWait);
  10806. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10807. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10808. }
  10809. else
  10810. {
  10811. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10812. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10813. }
  10814. }
  10815. else
  10816. {
  10817. refreshStartTimer(&clientTime.RemoteStartWait);
  10818. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10819. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10820. }
  10821. }
  10822. else
  10823. {
  10824. DEBUG_INFO("There is not any connector is idle.\n");
  10825. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10826. }
  10827. }
  10828. }
  10829. else
  10830. {
  10831. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10832. }
  10833. end:
  10834. json_object_put(RemoteStartTransaction);
  10835. sendRemoteStartConfirmation(uuid, comfirmstr);
  10836. return result;
  10837. }
  10838. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10839. {
  10840. mtrace();
  10841. int result = FAIL;
  10842. int match = FALSE;
  10843. int GunNO = 0;
  10844. int tempIndex = 0;
  10845. int transactionIdInt=0;
  10846. int transactionIdIsNULL= TRUE;
  10847. char comfirmstr[20];
  10848. json_object *RemoteStopTransaction;
  10849. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10850. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10851. if(server_pending == TRUE)
  10852. {
  10853. return 0;
  10854. }
  10855. RemoteStopTransaction = json_tokener_parse(payload);
  10856. if(!is_error(RemoteStopTransaction))
  10857. {
  10858. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10859. {
  10860. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10861. transactionIdIsNULL = FALSE;
  10862. }
  10863. }
  10864. json_object_put(RemoteStopTransaction);
  10865. if(transactionIdIsNULL == FALSE)
  10866. {
  10867. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10868. {
  10869. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10870. {
  10871. //check Transaction active
  10872. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10873. {
  10874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10875. {
  10876. tempIndex = ((gun_index==2) ? 1: 0);
  10877. }
  10878. else
  10879. {
  10880. tempIndex = gun_index;
  10881. }
  10882. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10883. {
  10884. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10885. {
  10886. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10887. {
  10888. match = TRUE;
  10889. GunNO = gun_index;
  10890. }
  10891. }
  10892. }// END FOR CHAdeMO_QUANTITY
  10893. }
  10894. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10895. {
  10896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10897. {
  10898. tempIndex = ((gun_index==2) ? 1: 0);
  10899. }
  10900. else
  10901. {
  10902. tempIndex = gun_index;
  10903. }
  10904. for (int index = 0; index < CCS_QUANTITY; index++)
  10905. {
  10906. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10907. {
  10908. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10909. {
  10910. match = TRUE;
  10911. GunNO = gun_index;
  10912. }
  10913. }
  10914. }// END FOR CCS_QUANTITY
  10915. }
  10916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10917. {
  10918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10919. {
  10920. tempIndex = ((gun_index==2) ? 1: 0);
  10921. }
  10922. else
  10923. {
  10924. tempIndex = gun_index;
  10925. }
  10926. for (int index = 0; index < GB_QUANTITY; index++)
  10927. {
  10928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10929. {
  10930. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10931. {
  10932. match = TRUE;
  10933. GunNO = gun_index;
  10934. }
  10935. }
  10936. }// END FOR GB_QUANTITY
  10937. }
  10938. else if(gunType[gun_index] == GUN_TYPE_DO)
  10939. {
  10940. tempIndex = gun_index;
  10941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10942. {
  10943. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10944. {
  10945. 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
  10946. {
  10947. match = TRUE;
  10948. GunNO = gun_index;
  10949. }
  10950. }
  10951. }// END FOR GB_QUANTITY
  10952. }
  10953. else
  10954. {
  10955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10956. {
  10957. tempIndex = 2;
  10958. }
  10959. else
  10960. {
  10961. tempIndex = gun_index;
  10962. }
  10963. for (int index = 0; index < AC_QUANTITY; index++)
  10964. {
  10965. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10966. {
  10967. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10968. {
  10969. match = TRUE;
  10970. GunNO = gun_index;
  10971. }
  10972. }
  10973. }// END FOR CHAdeMO_QUANTITY
  10974. } // END FOR AC ELSE
  10975. }// CHECK IF ResponseTransactionId == transactionIdInt
  10976. }//END FOR
  10977. if( match == TRUE)
  10978. {
  10979. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10981. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10982. }
  10983. else
  10984. {
  10985. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10986. }
  10987. }
  10988. else
  10989. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10990. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10991. return result;
  10992. }
  10993. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10994. {
  10995. mtrace();
  10996. int result = FAIL;
  10997. int connectorIdInt=0, reservationIdInt=0;
  10998. int tempIndex = 0;
  10999. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11000. char comfirmstr[20]={0};
  11001. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11002. int c = 0;
  11003. char *loc;
  11004. //char *ptr;
  11005. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11006. strcpy(sstrtemp, stringtrimspace(payload));
  11007. //***(1)connectorId ****/
  11008. c=0;
  11009. loc = strstr(sstrtemp, "connectorId");
  11010. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11011. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11012. {
  11013. sstr[c] = loc[strlen("connectorId")+2+c];
  11014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11015. c++;
  11016. }
  11017. sstr[c] = '\0';
  11018. connectorIdInt = atoi(sstr);
  11019. //***(2)expiryDate ****/
  11020. loc = strstr(sstrtemp, "expiryDate");
  11021. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11022. c = 0;
  11023. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11024. {
  11025. sstr[c] = loc[3+strlen("expiryDate")+c];
  11026. c++;
  11027. }
  11028. sstr[c] = '\0';
  11029. strcpy(expiryDatestr, sstr);
  11030. //***(3)idTag ****/
  11031. loc = strstr(sstrtemp, "idTag");
  11032. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11033. c = 0;
  11034. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11035. {
  11036. sstr[c] = loc[3+strlen("idTag")+c];
  11037. c++;
  11038. }
  11039. sstr[c] = '\0';
  11040. strcpy(idTagstr, sstr);
  11041. //***(4)parentIdTag ****/
  11042. loc = strstr(sstrtemp, "parentIdTag");
  11043. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11044. c = 0;
  11045. if(loc == NULL)
  11046. {
  11047. strcpy(parentIdTagstr, "");
  11048. }
  11049. else
  11050. {
  11051. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11052. {
  11053. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11054. c++;
  11055. }
  11056. sstr[c] = '\0';
  11057. strcpy(parentIdTagstr, sstr);
  11058. }
  11059. //***(5)reservationId ****/
  11060. c=0;
  11061. loc = strstr(sstrtemp, "reservationId");
  11062. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11063. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11064. {
  11065. sstr[c] = loc[strlen("reservationId")+2+c];
  11066. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11067. c++;
  11068. }
  11069. sstr[c] = '\0';
  11070. reservationIdInt = atoi(sstr);
  11071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11072. /*
  11073. enum SYSTEM_STATUS
  11074. {
  11075. SYS_MODE_BOOTING = 0,
  11076. SYS_MODE_IDLE = 1,
  11077. SYS_MODE_AUTHORIZING = 2,
  11078. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11079. SYS_MODE_REASSIGN = 4,
  11080. SYS_MODE_PREPARING = 5,
  11081. SYS_MODE_PREPARE_FOR_EV = 6,
  11082. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11083. SYS_MODE_CHARGING = 8,
  11084. SYS_MODE_TERMINATING = 9,
  11085. SYS_MODE_COMPLETE = 10,
  11086. SYS_MODE_ALARM = 11,
  11087. SYS_MODE_FAULT = 12,
  11088. SYS_MODE_RESERVATION = 13,
  11089. SYS_MODE_BOOKING = 14,
  11090. SYS_MODE_MAINTAIN = 15,
  11091. SYS_MODE_DEBUG = 16,
  11092. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11093. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11094. SYS_MODE_UPDATE = 19
  11095. };
  11096. */
  11097. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11098. {
  11099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11100. goto end;
  11101. }
  11102. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11103. {
  11104. //check Transaction active
  11105. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11106. {
  11107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11108. {
  11109. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11110. }
  11111. else
  11112. {
  11113. tempIndex = connectorIdInt -1;
  11114. }
  11115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11116. {
  11117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11118. {
  11119. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11120. {
  11121. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11122. {
  11123. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11124. {
  11125. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11126. {
  11127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11128. }
  11129. else
  11130. {
  11131. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11133. }
  11134. }
  11135. 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'))
  11136. {
  11137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11138. }
  11139. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11140. {
  11141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11142. }
  11143. else
  11144. {
  11145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11146. }
  11147. }
  11148. 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
  11149. {
  11150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11151. }
  11152. }
  11153. else
  11154. {
  11155. //replace reservation
  11156. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11158. }
  11159. }
  11160. } // END FOR CHAdeMO_QUANTITY
  11161. }
  11162. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11163. {
  11164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11165. {
  11166. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11167. }
  11168. else
  11169. {
  11170. tempIndex = connectorIdInt -1;
  11171. }
  11172. for (int index = 0; index < CCS_QUANTITY; index++)
  11173. {
  11174. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11175. {
  11176. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11177. {
  11178. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11179. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11180. {
  11181. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11182. {
  11183. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11184. {
  11185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11186. }
  11187. else
  11188. {
  11189. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11191. }
  11192. }
  11193. 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'))
  11194. {
  11195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11196. }
  11197. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11198. {
  11199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11200. }
  11201. else
  11202. {
  11203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11204. }
  11205. }
  11206. 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
  11207. {
  11208. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11209. }
  11210. }
  11211. else
  11212. {
  11213. //replace reservation
  11214. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11216. }
  11217. }
  11218. } // END FOR CCS_QUANTITY
  11219. }
  11220. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11221. {
  11222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11223. {
  11224. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11225. }
  11226. else
  11227. {
  11228. tempIndex = connectorIdInt -1;
  11229. }
  11230. for (int index = 0; index < GB_QUANTITY; index++)
  11231. {
  11232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11233. {
  11234. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11235. {
  11236. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11237. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11238. {
  11239. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11240. {
  11241. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11242. {
  11243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11244. }
  11245. else
  11246. {
  11247. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11248. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11249. }
  11250. }
  11251. 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'))
  11252. {
  11253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11254. }
  11255. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11256. {
  11257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11258. }
  11259. else
  11260. {
  11261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11262. }
  11263. }
  11264. 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
  11265. {
  11266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11267. }
  11268. }
  11269. else
  11270. {
  11271. //replace reservation
  11272. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11274. }
  11275. }
  11276. }// END FOR GB_QUANTITY
  11277. }
  11278. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11279. {
  11280. tempIndex = connectorIdInt -1;
  11281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11282. {
  11283. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11284. {
  11285. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11286. {
  11287. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11288. 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
  11289. {
  11290. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11291. {
  11292. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11293. {
  11294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11295. }
  11296. else
  11297. {
  11298. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11299. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11300. }
  11301. }
  11302. 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'))
  11303. {
  11304. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11305. }
  11306. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11307. {
  11308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11309. }
  11310. else
  11311. {
  11312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11313. }
  11314. }
  11315. 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
  11316. {
  11317. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11318. }
  11319. }
  11320. else
  11321. {
  11322. //replace reservation
  11323. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11325. }
  11326. }
  11327. }// END FOR GB_QUANTITY
  11328. }
  11329. else
  11330. {
  11331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11332. {
  11333. tempIndex = 2;
  11334. }
  11335. else
  11336. {
  11337. tempIndex = (connectorIdInt -1);
  11338. }
  11339. for (int index = 0; index < AC_QUANTITY; index++)
  11340. {
  11341. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11342. {
  11343. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11344. {
  11345. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11346. {
  11347. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11348. {
  11349. 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))
  11350. {
  11351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11352. }
  11353. else
  11354. {
  11355. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11356. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11357. }
  11358. }
  11359. 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'))
  11360. {
  11361. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11362. }
  11363. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11364. {
  11365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11366. }
  11367. else
  11368. {
  11369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11370. }
  11371. }
  11372. 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
  11373. {
  11374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11375. }
  11376. }
  11377. else
  11378. {
  11379. //replace reservation
  11380. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11381. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11382. }
  11383. }
  11384. } // END FOR AC_QUANTITY
  11385. }
  11386. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11387. }
  11388. else if(connectorIdInt == 0)
  11389. {
  11390. //check Transaction active
  11391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11392. {
  11393. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11394. {
  11395. 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'))
  11396. {
  11397. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11398. goto end;
  11399. }
  11400. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11401. {
  11402. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11403. goto end;
  11404. }
  11405. 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
  11406. {
  11407. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11408. goto end;
  11409. }
  11410. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11411. {
  11412. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11413. goto end;
  11414. }
  11415. }
  11416. }// END FOR CHAdeMO_QUANTITY
  11417. for (int index = 0; index < CCS_QUANTITY; index++)
  11418. {
  11419. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11420. {
  11421. 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'))
  11422. {
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11424. goto end;
  11425. }
  11426. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11427. {
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11429. goto end;
  11430. }
  11431. 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
  11432. {
  11433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11434. goto end;
  11435. }
  11436. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11437. {
  11438. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11439. goto end;
  11440. }
  11441. }
  11442. } // END FOR CCS_QUANTITY
  11443. for (int index = 0; index < GB_QUANTITY; index++)
  11444. {
  11445. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11446. {
  11447. 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'))
  11448. {
  11449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11450. goto end;
  11451. }
  11452. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11453. {
  11454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11455. goto end;
  11456. }
  11457. 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
  11458. {
  11459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11460. goto end;
  11461. }
  11462. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11463. {
  11464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11465. goto end;
  11466. }
  11467. }
  11468. } // END FOR GB_QUANTITY
  11469. for (int index = 0; index < AC_QUANTITY; index++)
  11470. {
  11471. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11472. {
  11473. 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'))
  11474. {
  11475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11476. goto end;
  11477. }
  11478. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11479. {
  11480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11481. goto end;
  11482. }
  11483. 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
  11484. {
  11485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11486. goto end;
  11487. }
  11488. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11489. {
  11490. 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))
  11491. {
  11492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11493. goto end;
  11494. }
  11495. }
  11496. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11497. {
  11498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11499. goto end;
  11500. }
  11501. }
  11502. }// END FOR AC_QUANTITY
  11503. //The connectorId is 0
  11504. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11506. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11507. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11508. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11509. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11510. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11511. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11512. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11513. result = TRUE;
  11514. return result;
  11515. }
  11516. else
  11517. {
  11518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11519. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11520. }
  11521. if(strcmp(comfirmstr,"Accepted") == 0)
  11522. {
  11523. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11524. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11525. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11526. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11527. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11528. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11529. result = TRUE;
  11530. return result;
  11531. }
  11532. end:
  11533. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11534. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11535. return result;
  11536. }
  11537. int handleResetRequest(char *uuid, char *payload)
  11538. {
  11539. mtrace();
  11540. int result = FAIL;
  11541. char sstr[10]={0},sstrtemp[30]={ 0 };
  11542. char typestr[10]={0};
  11543. char comfirmstr[20]={0};
  11544. int c = 0;
  11545. char *loc;
  11546. DEBUG_INFO("handleResetRequest...\n");
  11547. strcpy(sstrtemp, stringtrimspace(payload));
  11548. loc = strstr(sstrtemp, "type");
  11549. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11550. c = 0;
  11551. while (loc[3+strlen("type")+c] != '\"')
  11552. {
  11553. sstr[c] = loc[3+strlen("type")+c];
  11554. c++;
  11555. }
  11556. sstr[c] = '\0';
  11557. strcpy(typestr,sstr);
  11558. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11559. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11560. {
  11561. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11562. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11563. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11564. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11565. }
  11566. else
  11567. {
  11568. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11569. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11570. result = PASS;
  11571. }
  11572. sendResetConfirmation(uuid, comfirmstr);
  11573. return result;
  11574. }
  11575. int handleSendLocalListRequest(char *uuid, char *payload)
  11576. {
  11577. mtrace();
  11578. int result = FAIL;
  11579. char comfirmstr[20];
  11580. int checkState_Faulted = FALSE;
  11581. json_object *SendLocalList;
  11582. DEBUG_INFO("handleSendLocalListRequest...\n");
  11583. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11584. {
  11585. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11586. goto end;
  11587. }
  11588. //check Charge Point state
  11589. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11590. {
  11591. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11592. {
  11593. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11594. }
  11595. }
  11596. for (int index = 0; index < CCS_QUANTITY; index++)
  11597. {
  11598. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11599. {
  11600. checkState_Faulted = TRUE; //OCPP Status
  11601. }
  11602. }
  11603. for (int index = 0; index < GB_QUANTITY; index++)
  11604. {
  11605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11606. {
  11607. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11608. }
  11609. }
  11610. //check Charge Point state
  11611. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11612. {
  11613. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11614. {
  11615. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11616. }
  11617. }
  11618. //check Charge Point state
  11619. for (int index = 0; index < AC_QUANTITY; index++)
  11620. {
  11621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11622. {
  11623. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11624. }
  11625. }
  11626. if(checkState_Faulted == TRUE)
  11627. {
  11628. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11629. goto end;
  11630. }
  11631. // Parsing payload
  11632. SendLocalList = json_tokener_parse(payload);
  11633. if(!is_error(SendLocalList))
  11634. {
  11635. // Required data
  11636. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11637. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11638. // Optional data
  11639. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11640. {
  11641. //Check UpdateType
  11642. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11643. {
  11644. //Local list full update
  11645. DEBUG_INFO("Local list full update.\n");
  11646. locallistVersion = 0;
  11647. OCPP_getListVerion();
  11648. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11649. {
  11650. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11651. goto end;
  11652. }*/
  11653. OCPP_cleanLocalList();
  11654. }
  11655. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11656. {
  11657. //Local list different update
  11658. DEBUG_INFO("Local list different update.\n");
  11659. locallistVersion = 0;
  11660. OCPP_getListVerion();
  11661. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11662. {
  11663. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11664. goto end;
  11665. }
  11666. }
  11667. else
  11668. {
  11669. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11670. goto end;
  11671. }
  11672. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  11673. {
  11674. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  11675. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11676. goto end;
  11677. }
  11678. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11679. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11680. {
  11681. 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")));
  11682. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11683. {
  11684. 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")));
  11685. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11686. 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")));
  11687. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11688. 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")));
  11689. }
  11690. // Add to db
  11691. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11692. {
  11693. //Local list full update
  11694. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11695. idx,
  11696. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11697. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11698. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11699. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11700. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11701. // update list
  11702. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11703. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11704. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11705. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11706. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11707. }
  11708. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11709. {
  11710. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11711. idx,
  11712. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11713. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11714. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11715. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11716. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11717. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11718. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11719. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11720. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11721. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11722. }
  11723. }
  11724. }
  11725. else
  11726. {
  11727. //Check UpdateType
  11728. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11729. {
  11730. //Local list full update
  11731. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11732. OCPP_cleanLocalList();
  11733. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11734. goto end;
  11735. }
  11736. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11737. {
  11738. //Local list different update
  11739. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11740. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11741. goto end;
  11742. }
  11743. }
  11744. result = PASS;
  11745. }
  11746. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11747. end:
  11748. json_object_put(SendLocalList);
  11749. sendSendLocalListConfirmation(uuid, comfirmstr);
  11750. return result;
  11751. }
  11752. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11753. {
  11754. mtrace();
  11755. int result = FAIL;
  11756. struct StructSetChargingProfile SetProfileReq = {0};
  11757. int tempchargingProfileIdInt;
  11758. int tempstackLevelInt;
  11759. int chargingSchedulePeriodCount = 0;
  11760. char comfirmstr[20]={0};
  11761. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11762. char rmFileCmd[128]={0};
  11763. int profileQuantity = 0;
  11764. int replaceableProfileCnt = 0;
  11765. json_object *SetChargingProfile;
  11766. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11767. SetChargingProfile = json_tokener_parse(payload);
  11768. if(!is_error(SetChargingProfile))
  11769. {
  11770. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11771. {
  11772. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11773. }
  11774. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11775. {
  11776. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11777. {
  11778. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11779. }
  11780. else
  11781. {
  11782. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11783. DEBUG_WARN("Cannot find chargingProfileId field.");
  11784. goto end;
  11785. }
  11786. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11787. {
  11788. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11789. }
  11790. else
  11791. {
  11792. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11793. DEBUG_WARN("Cannot find stackLevel field.");
  11794. goto end;
  11795. }
  11796. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11797. {
  11798. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11799. }
  11800. else
  11801. {
  11802. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11803. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  11804. goto end;
  11805. }
  11806. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11807. {
  11808. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11809. }
  11810. else
  11811. {
  11812. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11813. DEBUG_WARN("Cannot find chargingProfileKind field.");
  11814. goto end;
  11815. }
  11816. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11817. {
  11818. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11819. }
  11820. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11821. {
  11822. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11823. }
  11824. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11825. {
  11826. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11827. }
  11828. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11829. {
  11830. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11831. }
  11832. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11833. {
  11834. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11835. {
  11836. 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")));
  11837. }
  11838. else
  11839. {
  11840. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11841. DEBUG_WARN("Cannot find chargingRateUnit field.");
  11842. goto end;
  11843. }
  11844. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11845. {
  11846. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11847. }
  11848. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11849. {
  11850. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11851. }
  11852. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11853. {
  11854. 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")));
  11855. }
  11856. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11857. {
  11858. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11859. if(chargingSchedulePeriodCount <= 10)
  11860. {
  11861. 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++)
  11862. {
  11863. 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)
  11864. {
  11865. 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"));
  11866. }
  11867. else
  11868. {
  11869. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11870. DEBUG_WARN("Cannot find startPeriod field.");
  11871. goto end;
  11872. }
  11873. 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)
  11874. {
  11875. 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"));
  11876. }
  11877. else
  11878. {
  11879. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11880. DEBUG_WARN("Cannot find limit field.");
  11881. goto end;
  11882. }
  11883. 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)
  11884. {
  11885. 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"));
  11886. }
  11887. }
  11888. }
  11889. }
  11890. else
  11891. {
  11892. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11893. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  11894. goto end;
  11895. }
  11896. }
  11897. else
  11898. {
  11899. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11900. DEBUG_WARN("Cannot find chargingSchedule field.");
  11901. goto end;
  11902. }
  11903. }
  11904. }
  11905. // Profile periods quantity check
  11906. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11907. {
  11908. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11909. goto end;
  11910. }
  11911. // Check invalid limit
  11912. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  11913. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  11914. {
  11915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11916. {
  11917. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11918. {
  11919. 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)))) ||
  11920. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11921. {
  11922. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11923. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11924. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11925. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11926. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11927. goto end;
  11928. }
  11929. }
  11930. }
  11931. else
  11932. {
  11933. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11934. {
  11935. 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) ||
  11936. (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*0.01)))
  11937. {
  11938. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11939. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11940. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11941. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11942. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11943. goto end;
  11944. }
  11945. }
  11946. }
  11947. }
  11948. // Profile purpose info check
  11949. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11950. {
  11951. FILE *fp;
  11952. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11953. if(SetProfileReq.ConnectorId != 0)
  11954. {
  11955. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11956. goto end;
  11957. }
  11958. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11959. if (!fp)
  11960. {
  11961. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11962. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11963. }
  11964. else
  11965. {
  11966. char *line = NULL;
  11967. size_t len = 0;
  11968. while(getline(&line, &len, fp) != -1)
  11969. {
  11970. json_object *obj = NULL;
  11971. obj = json_tokener_parse(line);
  11972. if(is_error(obj))
  11973. {
  11974. DEBUG_ERROR("Parse txProfile from file error.\n");
  11975. }
  11976. else
  11977. {
  11978. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11979. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11980. {
  11981. profileQuantity += 1;
  11982. }
  11983. else
  11984. replaceableProfileCnt += 1;
  11985. }
  11986. }
  11987. }
  11988. fclose(fp);
  11989. }
  11990. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11991. {
  11992. FILE *fp;
  11993. char filename[128]={0};
  11994. int tmpProfileQuantity;
  11995. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11996. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11997. {
  11998. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11999. goto end;
  12000. }
  12001. if(SetProfileReq.ConnectorId == 0)
  12002. {
  12003. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12004. {
  12005. tmpProfileQuantity = 0;
  12006. memset(filename, 0, ARRAY_SIZE(filename));
  12007. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12008. fp = fopen(filename, "r");
  12009. if (!fp)
  12010. {
  12011. DEBUG_INFO("%s does not create.\n", filename);
  12012. fp = fopen(filename, "w+");
  12013. }
  12014. else
  12015. {
  12016. char *line = NULL;
  12017. size_t len = 0;
  12018. while(getline(&line, &len, fp) != -1)
  12019. {
  12020. json_object *obj = NULL;
  12021. obj = json_tokener_parse(line);
  12022. if(is_error(obj))
  12023. {
  12024. DEBUG_ERROR("Parse txProfile from file error.\n");
  12025. }
  12026. else
  12027. {
  12028. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12029. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12030. {
  12031. tmpProfileQuantity += 1;
  12032. }
  12033. else
  12034. replaceableProfileCnt += 1;
  12035. }
  12036. }
  12037. }
  12038. fclose(fp);
  12039. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12040. }
  12041. }
  12042. else
  12043. {
  12044. memset(filename, 0, ARRAY_SIZE(filename));
  12045. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12046. fp = fopen(filename, "r");
  12047. if (!fp)
  12048. {
  12049. DEBUG_INFO("%s does not create.\n", filename);
  12050. fp = fopen(filename, "w+");
  12051. }
  12052. else
  12053. {
  12054. char *line = NULL;
  12055. size_t len = 0;
  12056. while(getline(&line, &len, fp) != -1)
  12057. {
  12058. json_object *obj = NULL;
  12059. obj = json_tokener_parse(line);
  12060. if(is_error(obj))
  12061. {
  12062. DEBUG_ERROR("Parse txProfile from file error.\n");
  12063. }
  12064. else
  12065. {
  12066. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12067. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12068. {
  12069. profileQuantity += 1;
  12070. }
  12071. else
  12072. replaceableProfileCnt += 1;
  12073. }
  12074. }
  12075. }
  12076. fclose(fp);
  12077. }
  12078. }
  12079. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12080. {
  12081. int isMatchTransactiodId= FALSE;
  12082. FILE *fp;
  12083. char filename[128]={0};
  12084. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12085. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12086. if(SetProfileReq.ConnectorId == 0)
  12087. {
  12088. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12089. goto end;
  12090. }
  12091. int tempIndex = 0;
  12092. //check Transaction active
  12093. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12094. {
  12095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12096. {
  12097. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12098. }
  12099. else
  12100. {
  12101. tempIndex = SetProfileReq.ConnectorId -1;
  12102. }
  12103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12104. {
  12105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12106. {
  12107. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12108. {
  12109. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12110. {
  12111. isMatchTransactiodId = TRUE;
  12112. break;
  12113. }
  12114. }
  12115. }
  12116. }
  12117. }
  12118. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12119. {
  12120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12121. {
  12122. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12123. }
  12124. else
  12125. {
  12126. tempIndex = SetProfileReq.ConnectorId -1;
  12127. }
  12128. for (int index = 0; index < CCS_QUANTITY; index++)
  12129. {
  12130. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12131. {
  12132. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12133. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12134. {
  12135. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12136. {
  12137. isMatchTransactiodId = TRUE;
  12138. break;
  12139. }
  12140. }
  12141. }
  12142. }
  12143. }
  12144. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12145. {
  12146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12147. {
  12148. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12149. }
  12150. else
  12151. {
  12152. tempIndex = SetProfileReq.ConnectorId -1;
  12153. }
  12154. for (int index = 0; index < GB_QUANTITY; index++)
  12155. {
  12156. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12157. {
  12158. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12159. {
  12160. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12161. {
  12162. isMatchTransactiodId = TRUE;
  12163. break;
  12164. }
  12165. }
  12166. }
  12167. }
  12168. }
  12169. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12170. {
  12171. tempIndex = SetProfileReq.ConnectorId -1;
  12172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12173. {
  12174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12175. {
  12176. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12177. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12178. {
  12179. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12180. {
  12181. isMatchTransactiodId = TRUE;
  12182. break;
  12183. }
  12184. }
  12185. }
  12186. }
  12187. }
  12188. else
  12189. {
  12190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12191. {
  12192. tempIndex = 2;
  12193. }
  12194. else
  12195. {
  12196. tempIndex = (SetProfileReq.ConnectorId -1);
  12197. }
  12198. for (int index = 0; index < AC_QUANTITY; index++)
  12199. {
  12200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12201. {
  12202. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12203. {
  12204. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12205. {
  12206. isMatchTransactiodId = TRUE;
  12207. break;
  12208. }
  12209. }
  12210. }
  12211. }
  12212. }
  12213. //check Transaction active
  12214. if(isMatchTransactiodId == FALSE)
  12215. {
  12216. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12217. goto end;
  12218. }
  12219. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12220. {
  12221. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12222. goto end;
  12223. }
  12224. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12225. fp = fopen(filename, "r");
  12226. if (!fp)
  12227. {
  12228. DEBUG_INFO("%s does not create.\n", filename);
  12229. fp = fopen(filename, "w+");
  12230. }
  12231. else
  12232. {
  12233. char *line = NULL;
  12234. size_t len = 0;
  12235. while(getline(&line, &len, fp) != -1)
  12236. {
  12237. json_object *obj = NULL;
  12238. obj = json_tokener_parse(line);
  12239. if(is_error(obj))
  12240. {
  12241. DEBUG_ERROR("Parse txProfile from file error.\n");
  12242. }
  12243. else
  12244. {
  12245. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12246. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12247. {
  12248. profileQuantity += 1;
  12249. }
  12250. else
  12251. replaceableProfileCnt += 1;
  12252. }
  12253. }
  12254. }
  12255. fclose(fp);
  12256. }
  12257. // Check ChargeProfileMaxStackLevel
  12258. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12259. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12260. {
  12261. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12262. goto end;
  12263. }
  12264. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12265. {
  12266. FILE *fp;
  12267. char dataLine[4096]={0};
  12268. char fnametemp[128]={0};
  12269. int tmpProfileQuantity;
  12270. //Check ChargePointMaxProfile.json exit
  12271. profileQuantity = 0;
  12272. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12273. {
  12274. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12275. //Check Charging Profile Count
  12276. tmpProfileQuantity = 0;
  12277. while(fscanf(fp, "%s", dataLine) != EOF)
  12278. {
  12279. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12280. {
  12281. profileQuantity += 1;
  12282. tmpProfileQuantity += 1;
  12283. }
  12284. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12285. }
  12286. fclose(fp);
  12287. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12288. }
  12289. //Check TxDefaultProfile_%d.json
  12290. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12291. {
  12292. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12293. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12294. if((access(fnametemp,F_OK))!=-1)
  12295. {
  12296. fp = fopen(fnametemp, "r");
  12297. //Check Charging Profile Count
  12298. tmpProfileQuantity = 0;
  12299. while(fscanf(fp, "%s", dataLine) != EOF)
  12300. {
  12301. //DEBUG_INFO("word=%s\n",word);
  12302. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12303. {
  12304. profileQuantity += 1;
  12305. tmpProfileQuantity += 1;
  12306. }
  12307. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12308. }
  12309. fclose(fp);
  12310. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12311. }
  12312. }
  12313. //Check TxProfile_%d.json
  12314. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12315. {
  12316. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12317. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12318. if((access(fnametemp,F_OK))!=-1)
  12319. {
  12320. fp = fopen(fnametemp, "r");
  12321. //Check Charging Profile Count
  12322. tmpProfileQuantity = 0;
  12323. while(fscanf(fp, "%s", dataLine) != EOF)
  12324. {
  12325. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12326. {
  12327. profileQuantity += 1;
  12328. tmpProfileQuantity += 1;
  12329. }
  12330. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12331. }
  12332. fclose(fp);
  12333. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12334. }
  12335. }
  12336. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12337. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12338. // To check total Profile quantity
  12339. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12340. {
  12341. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12342. {
  12343. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12344. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12345. goto end;
  12346. }
  12347. }
  12348. else
  12349. {
  12350. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12351. {
  12352. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12353. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12354. goto end;
  12355. }
  12356. }
  12357. }
  12358. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12359. //**********************************Write to File********************************************************/
  12360. {
  12361. FILE *infile;
  12362. FILE *outfile;
  12363. char dataLine[4096]={0};
  12364. char filename[128]={0};
  12365. int chkChar=0;
  12366. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12367. {
  12368. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12369. {
  12370. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12371. }
  12372. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12373. {
  12374. if(SetProfileReq.ConnectorId==0)
  12375. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12376. else
  12377. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12378. }
  12379. else
  12380. {
  12381. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12382. }
  12383. infile = fopen (filename, "r");
  12384. outfile = fopen (tempfile, "w");
  12385. chkChar = fgetc(infile);
  12386. rewind(infile);
  12387. if(chkChar == EOF)
  12388. {
  12389. // Profile is empty
  12390. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12391. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12392. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12393. fclose(infile);
  12394. fclose(outfile);
  12395. sprintf(rmFileCmd,"rm -f %s",filename);
  12396. system(rmFileCmd);
  12397. rename(tempfile, filename);
  12398. }
  12399. else
  12400. {
  12401. // Profile is not empty
  12402. int ChargingProfileAdded = FALSE;
  12403. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12404. {
  12405. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12406. json_object *tmpChargingProfile;
  12407. tmpChargingProfile = json_tokener_parse(dataLine);
  12408. if(!is_error(SetChargingProfile))
  12409. {
  12410. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12411. {
  12412. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12413. {
  12414. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12415. }
  12416. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12417. {
  12418. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12419. }
  12420. }
  12421. }
  12422. json_object_put(tmpChargingProfile);
  12423. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12424. {
  12425. if(ChargingProfileAdded == FALSE)
  12426. {
  12427. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12428. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12429. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12430. ChargingProfileAdded = TRUE;
  12431. }
  12432. }
  12433. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12434. {
  12435. if(ChargingProfileAdded == FALSE)
  12436. {
  12437. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12438. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12439. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12440. ChargingProfileAdded = TRUE;
  12441. }
  12442. }
  12443. else
  12444. {
  12445. fprintf(outfile,"%s\n",dataLine);
  12446. if(ChargingProfileAdded == FALSE)
  12447. {
  12448. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12449. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12450. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12451. ChargingProfileAdded = TRUE;
  12452. }
  12453. }
  12454. } // end of while loop
  12455. fclose(infile);
  12456. fclose(outfile);
  12457. sprintf(rmFileCmd,"rm -f %s",filename);
  12458. system(rmFileCmd);
  12459. rename(tempfile, filename);
  12460. }
  12461. }
  12462. sleep(1);
  12463. result = TRUE;
  12464. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12465. }
  12466. end:
  12467. json_object_put(SetChargingProfile);
  12468. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12469. {
  12470. if(SetProfileReq.ConnectorId == 0)
  12471. {
  12472. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12473. {
  12474. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12475. }
  12476. }
  12477. else
  12478. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12479. }
  12480. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12481. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12482. return result;
  12483. }
  12484. int handleTriggerMessageRequest(char *uuid, char *payload)
  12485. {
  12486. mtrace();
  12487. int result = FAIL;
  12488. int connectorIdIsNULL = FALSE;
  12489. int connectorIdInt =0;
  12490. char sstr[40]={0},sstrtemp[100]={ 0 };
  12491. char requestedMessagestr[40]={0};
  12492. char comfirmstr[20]={0};
  12493. int c = 0;
  12494. char *loc;
  12495. DEBUG_INFO("handleTriggerMessageRequest\n");
  12496. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12497. strcpy(sstrtemp, stringtrimspace(payload));
  12498. c = 0;
  12499. loc = strstr(sstrtemp, "requestedMessage");
  12500. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12501. {
  12502. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12503. c++;
  12504. }
  12505. sstr[c] = '\0';
  12506. strcpy(requestedMessagestr, sstr);
  12507. c = 0;
  12508. loc = strstr(sstrtemp, "connectorId");
  12509. if(loc == NULL)
  12510. {
  12511. connectorIdIsNULL = TRUE;
  12512. }
  12513. else
  12514. {
  12515. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12516. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12517. {
  12518. sstr[c] = loc[strlen("connectorId")+2+c];
  12519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12520. c++;
  12521. }
  12522. sstr[c] = '\0';
  12523. connectorIdInt = atoi(sstr);
  12524. }
  12525. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12526. {
  12527. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12528. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12529. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12530. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12531. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12532. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12533. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12534. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12535. {
  12536. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12537. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12538. return TRUE;
  12539. }
  12540. else
  12541. {
  12542. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12543. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12544. }
  12545. }
  12546. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12547. {
  12548. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12549. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12550. return TRUE;
  12551. }
  12552. //==========================
  12553. // Trigger message
  12554. //==========================
  12555. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12556. {
  12557. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12558. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12559. {
  12560. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12561. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12562. }
  12563. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12564. }
  12565. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12566. {
  12567. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12568. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12569. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12570. }
  12571. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12572. {
  12573. //sendBootNotificationRequest();
  12574. server_sign = FALSE;
  12575. }
  12576. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12577. {
  12578. refreshStartTimer(&clientTime.Heartbeat);
  12579. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12580. }
  12581. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12582. {
  12583. if(connectorIdIsNULL == FALSE)
  12584. {
  12585. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12586. {
  12587. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12588. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12589. }
  12590. }
  12591. else
  12592. {
  12593. for(int idx=0;idx< gunTotalNumber;idx++)
  12594. {
  12595. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12596. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12597. }
  12598. }
  12599. }
  12600. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12601. {
  12602. if(connectorIdIsNULL == FALSE)
  12603. {
  12604. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12605. {
  12606. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12607. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12608. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12609. }
  12610. }
  12611. else
  12612. {
  12613. for(int idx=0;idx< gunTotalNumber;idx++)
  12614. {
  12615. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12616. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12617. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12618. }
  12619. }
  12620. }
  12621. return result;
  12622. }
  12623. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12624. {
  12625. mtrace();
  12626. int result = FAIL;
  12627. int connectorIdInt =0;
  12628. char comfirmstr[20]={0};
  12629. int tempIndex = 0;
  12630. json_object *UnlockConnector;
  12631. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12632. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12633. UnlockConnector = json_tokener_parse(payload);
  12634. if(!is_error(UnlockConnector))
  12635. {
  12636. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12637. {
  12638. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12639. }
  12640. }
  12641. json_object_put(UnlockConnector);
  12642. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12643. if(gunTotalNumber == 0)
  12644. {
  12645. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12646. goto end;
  12647. }
  12648. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12649. {
  12650. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12651. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12652. goto end;
  12653. }
  12654. else
  12655. {
  12656. //check Transaction active
  12657. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12658. {
  12659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12660. {
  12661. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12662. }
  12663. else
  12664. {
  12665. tempIndex = connectorIdInt -1;
  12666. }
  12667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12668. {
  12669. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12670. {
  12671. //stop Transaction
  12672. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12673. }
  12674. }
  12675. }
  12676. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12677. {
  12678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12679. {
  12680. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12681. }
  12682. else
  12683. {
  12684. tempIndex = connectorIdInt -1;
  12685. }
  12686. for (int index = 0; index < CCS_QUANTITY; index++)
  12687. {
  12688. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12689. {
  12690. //stop Transaction
  12691. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12692. }
  12693. }
  12694. }
  12695. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12696. {
  12697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12698. {
  12699. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12700. }
  12701. else
  12702. {
  12703. tempIndex = connectorIdInt -1;
  12704. }
  12705. for (int index = 0; index < GB_QUANTITY; index++)
  12706. {
  12707. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12708. {
  12709. //stop Transaction
  12710. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12711. }
  12712. }
  12713. }
  12714. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12715. {
  12716. tempIndex = connectorIdInt -1;
  12717. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12718. {
  12719. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12720. {
  12721. //stop Transaction
  12722. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12723. }
  12724. }
  12725. }
  12726. else
  12727. {
  12728. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12729. {
  12730. tempIndex = 2;
  12731. }
  12732. else
  12733. {
  12734. tempIndex = connectorIdInt-1;
  12735. }
  12736. for (int index = 0; index < AC_QUANTITY; index++)
  12737. {
  12738. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12739. {
  12740. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12741. }
  12742. }
  12743. }
  12744. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12745. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12746. result = TRUE;
  12747. return result;
  12748. }
  12749. end:
  12750. //json_object_put(obj); --- remove temporally
  12751. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12752. return result;
  12753. }
  12754. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12755. {
  12756. mtrace();
  12757. int result = FAIL;
  12758. pthread_t t;
  12759. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12760. sendUpdateFirmwareConfirmation(uuid);
  12761. if(!interLock.isUpdateFirmwareGoing)
  12762. {
  12763. interLock.isUpdateFirmwareGoing = 1;
  12764. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  12765. sleep(1);
  12766. }
  12767. else
  12768. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12769. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12770. return result;
  12771. }
  12772. void *UpdateFirmwareProcess(void *data)
  12773. {
  12774. pthread_detach(pthread_self());
  12775. mtrace();
  12776. int retriesInt =0, retryIntervalInt=0;
  12777. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  12778. int port=0;
  12779. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  12780. int isSuccess = 0;
  12781. char ftpbuf[2048];
  12782. char temp[2048];
  12783. char filenametemp[256];
  12784. char * pch;
  12785. json_object *UpdateFirmware;
  12786. UpdateFirmware = json_tokener_parse(data);
  12787. if(!is_error(UpdateFirmware))
  12788. {
  12789. // Required data
  12790. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12791. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12792. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12793. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12794. // Optional data
  12795. if(json_object_object_get(UpdateFirmware, "retries"))
  12796. {
  12797. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12798. }
  12799. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12800. {
  12801. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12802. }
  12803. }
  12804. json_object_put(UpdateFirmware);
  12805. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12806. memset(path, 0, ARRAY_SIZE(path));
  12807. // Wait retrieveData
  12808. if(strlen(retrieveDatestr) > 10)
  12809. {
  12810. do
  12811. {
  12812. sleep(1);
  12813. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12814. }
  12815. // Ready to download
  12816. system("rm -f /mnt/*");
  12817. if(strncmp(locationstr,"http", 4) == 0)
  12818. {
  12819. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12820. sprintf(ftppath,"/%s", path);
  12821. DEBUG_INFO("locationstr: %s\n", locationstr);
  12822. DEBUG_INFO("protocol: %s\n",protocol);
  12823. DEBUG_INFO("host: %s\n",host);
  12824. DEBUG_INFO("path: %s\n",path);
  12825. DEBUG_INFO("ftppath: %s\n",ftppath);
  12826. int ftppathlen=strlen(ftppath);
  12827. int i=1;
  12828. while(i < ftppathlen)
  12829. {
  12830. int len=ftppathlen-i;
  12831. if(ftppath[len]== 47) // '/' ascll code: 47
  12832. {
  12833. DEBUG_INFO("compare '/' all right\n");
  12834. break;
  12835. }
  12836. i=i+1;
  12837. }
  12838. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12839. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12840. filenametemp[i+1] = 0;
  12841. do
  12842. {
  12843. sleep(1);
  12844. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12845. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12846. sleep(1);
  12847. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12848. if(!isSuccess)
  12849. {
  12850. sleep(1);
  12851. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12852. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12853. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  12854. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12855. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12856. }
  12857. else
  12858. {
  12859. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12860. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12861. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12862. }
  12863. retriesInt--;
  12864. }while((isSuccess == 0)&&(retriesInt >= 0));
  12865. }
  12866. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  12867. {
  12868. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12869. memset(temp, 0, ARRAY_SIZE(temp));
  12870. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12871. strcpy(ftpbuf, locationstr);
  12872. int ftppathlen=strlen(ftpbuf);
  12873. int i=1;
  12874. while(i < ftppathlen)
  12875. {
  12876. int len=ftppathlen-i;
  12877. if(ftpbuf[len]== 47) // '/' ascii code: 47
  12878. {
  12879. DEBUG_INFO(" compare '/' all right\n");
  12880. break;
  12881. }
  12882. i=i+1;
  12883. }
  12884. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12885. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12886. filenametemp[i+1] = 0;
  12887. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12888. pch=strchr(temp,'@');
  12889. if(pch==NULL)
  12890. {
  12891. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12892. protocol, host, &port, path);
  12893. strcpy(user,"anonymous");
  12894. strcpy(password,"");
  12895. }
  12896. else
  12897. {
  12898. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  12899. protocol, user, host, &port, path);
  12900. }
  12901. sscanf(host,"%[^/]%s",host1, path1);
  12902. sprintf(ftppath,"%s:/%s", host,path);
  12903. if(port == 0)
  12904. {
  12905. port = 21;
  12906. }
  12907. do
  12908. {
  12909. sleep(1);
  12910. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12911. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12912. sleep(1);
  12913. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  12914. if(!isSuccess)
  12915. {
  12916. //BulldogUtil.sleepMs(interval*1000);
  12917. DEBUG_INFO("Update firmware request and download file fail.\n");
  12918. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12919. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12920. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  12921. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12922. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12923. }
  12924. else
  12925. {
  12926. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12927. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12928. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12929. }
  12930. retriesInt--;
  12931. }while((!isSuccess)&&(retriesInt >= 0));
  12932. }
  12933. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  12934. {
  12935. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12936. memset(temp, 0, ARRAY_SIZE(temp));
  12937. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12938. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12939. int ftppathlen=strlen(ftpbuf);
  12940. int i=1;
  12941. while(i < ftppathlen)
  12942. {
  12943. int len=ftppathlen-i;
  12944. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12945. {
  12946. DEBUG_INFO(" compare '/' all right\n");
  12947. break;
  12948. }
  12949. i=i+1;
  12950. }
  12951. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12952. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12953. filenametemp[i+1] = 0;
  12954. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12955. pch=strchr(temp,'@');
  12956. if(pch==NULL)
  12957. {
  12958. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12959. protocol, host, &port, path);
  12960. strcpy(user,"anonymous");
  12961. strcpy(password,"");
  12962. }
  12963. else
  12964. {
  12965. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12966. protocol, user, password, host, &port, path);
  12967. }
  12968. sscanf(host,"%[^/]%s",host1, path1);
  12969. sprintf(ftppath,"%s", path1);
  12970. //DEBUG_INFO("protocol =%s\n",protocol);
  12971. //DEBUG_INFO("user =%s\n",user);
  12972. //DEBUG_INFO("password =%s\n",password);
  12973. //DEBUG_INFO("host1 =%s\n",host1);
  12974. //DEBUG_INFO("port =%d\n",port);
  12975. //DEBUG_INFO("path1 =%s\n",path1);
  12976. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12977. //ftpFile(host, user, password, port, ftppath, fname);
  12978. //download firmware pthred
  12979. if(port == 0)
  12980. {
  12981. port = 21;
  12982. }
  12983. do
  12984. {
  12985. sleep(1);
  12986. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12987. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12988. sleep(1);
  12989. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12990. if(!isSuccess)
  12991. {
  12992. //BulldogUtil.sleepMs(interval*1000);
  12993. DEBUG_INFO("Update firmware request and download file fail.\n");
  12994. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12995. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12996. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  12997. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12998. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12999. }
  13000. else
  13001. {
  13002. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13003. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13004. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13005. }
  13006. retriesInt--;
  13007. }while((!isSuccess)&&(retriesInt >= 0));
  13008. }
  13009. else
  13010. {
  13011. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13012. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13013. sleep(1);
  13014. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13015. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13016. }
  13017. // OCPPPH only, must announce CSU upgrade firmware
  13018. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13019. {
  13020. sleep(3);
  13021. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13022. }
  13023. interLock.isUpdateFirmwareGoing = 0;
  13024. pthread_exit(NULL);
  13025. }
  13026. int handleCertificateSignedRequest(char *uuid, char *payload)
  13027. {
  13028. mtrace();
  13029. int result = PASS;
  13030. json_object *CertificateSigned;
  13031. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13032. CertificateSigned = json_tokener_parse(payload);
  13033. if(!is_error(CertificateSigned))
  13034. {
  13035. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13036. }
  13037. json_object_put(CertificateSigned);
  13038. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13039. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13040. fclose(fp);
  13041. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13042. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13043. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13044. sendCertificateSignedConfirmation(uuid);
  13045. return result;
  13046. }
  13047. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13048. {
  13049. mtrace();
  13050. int result = PASS;
  13051. json_object *DeleteCertificate;
  13052. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13053. DeleteCertificate = json_tokener_parse(payload);
  13054. if(!is_error(DeleteCertificate))
  13055. {
  13056. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13057. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13058. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13059. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13060. }
  13061. json_object_put(DeleteCertificate);
  13062. /*
  13063. * TODO: Delete certificateSigned process
  13064. */
  13065. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13066. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13067. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13068. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13069. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13070. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13071. sendDeleteCertificateConfirmation(uuid);
  13072. return result;
  13073. }
  13074. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13075. {
  13076. mtrace();
  13077. int result = PASS;
  13078. json_object *ExtendedTriggerMessage;
  13079. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13080. ExtendedTriggerMessage = json_tokener_parse(payload);
  13081. if(!is_error(ExtendedTriggerMessage))
  13082. {
  13083. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13084. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13085. {
  13086. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13087. }
  13088. else
  13089. {
  13090. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13091. }
  13092. }
  13093. json_object_put(ExtendedTriggerMessage);
  13094. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13095. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13096. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13097. {
  13098. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13099. }
  13100. else
  13101. {
  13102. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13103. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13104. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13105. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13106. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13107. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13108. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13109. {
  13110. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13111. }
  13112. else
  13113. {
  13114. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13115. }
  13116. }
  13117. sendExtendedTriggerMessageConfirmation(uuid);
  13118. //==========================
  13119. // Trigger message
  13120. //==========================
  13121. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13122. {
  13123. //sendBootNotificationRequest();
  13124. server_sign = FALSE;
  13125. }
  13126. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13127. {
  13128. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13129. }
  13130. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13131. {
  13132. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13133. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13134. {
  13135. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13136. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13137. }
  13138. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13139. }
  13140. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13141. {
  13142. refreshStartTimer(&clientTime.Heartbeat);
  13143. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13144. }
  13145. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13146. {
  13147. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13148. {
  13149. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13150. }
  13151. else
  13152. {
  13153. for(int idx=0;idx< gunTotalNumber;idx++)
  13154. {
  13155. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13156. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13157. }
  13158. }
  13159. }
  13160. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13161. {
  13162. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13163. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13164. {
  13165. 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\" &");
  13166. }
  13167. }
  13168. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13169. {
  13170. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13171. {
  13172. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13173. }
  13174. else
  13175. {
  13176. for(int idx=0;idx< gunTotalNumber;idx++)
  13177. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13178. }
  13179. }
  13180. return result;
  13181. }
  13182. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13183. {
  13184. mtrace();
  13185. int result = PASS;
  13186. json_object *GetInstalledCertificateIds;
  13187. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13188. GetInstalledCertificateIds = json_tokener_parse(payload);
  13189. if(!is_error(GetInstalledCertificateIds))
  13190. {
  13191. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13192. }
  13193. json_object_put(GetInstalledCertificateIds);
  13194. /*
  13195. * TODO: Return installed certificate process
  13196. */
  13197. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13198. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13199. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13200. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13201. sendGetInstalledCertificateIdsConfirmation(uuid);
  13202. return result;
  13203. }
  13204. int handleGetLogRequest(char *uuid, char *payload)
  13205. {
  13206. mtrace();
  13207. int result = PASS;
  13208. json_object *GetLog;
  13209. DEBUG_INFO("handleGetLogRequest...\n");
  13210. GetLog = json_tokener_parse(payload);
  13211. if(!is_error(GetLog))
  13212. {
  13213. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13214. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13215. if(json_object_object_get(GetLog, "retries") != NULL)
  13216. {
  13217. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13218. }
  13219. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13220. {
  13221. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13222. }
  13223. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13224. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13225. {
  13226. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13227. }
  13228. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13229. {
  13230. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13231. }
  13232. }
  13233. json_object_put(GetLog);
  13234. /*
  13235. * TODO: Upload log process
  13236. */
  13237. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13238. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13239. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13240. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13241. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13242. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13243. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13244. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13245. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13246. sendGetLogConfirmation(uuid);
  13247. return result;
  13248. }
  13249. int handleInstallCertificateRequest(char *uuid, char *payload)
  13250. {
  13251. mtrace();
  13252. int result = PASS;
  13253. json_object *InstallCertificate;
  13254. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13255. InstallCertificate = json_tokener_parse(payload);
  13256. if(!is_error(InstallCertificate))
  13257. {
  13258. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13259. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13260. /*
  13261. * TODO: Install certificate process
  13262. */
  13263. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13264. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13265. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13266. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13267. sendInstallCertificateConfirmation(uuid);
  13268. }
  13269. json_object_put(InstallCertificate);
  13270. return result;
  13271. }
  13272. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13273. {
  13274. mtrace();
  13275. int result = PASS;
  13276. json_object *SignedUpdateFirmware;
  13277. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13278. SignedUpdateFirmware = json_tokener_parse(payload);
  13279. if(!is_error(SignedUpdateFirmware))
  13280. {
  13281. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13282. {
  13283. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13284. }
  13285. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13286. {
  13287. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13288. }
  13289. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13290. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13291. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13292. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13293. {
  13294. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13295. }
  13296. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13297. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13298. }
  13299. json_object_put(SignedUpdateFirmware);
  13300. /*
  13301. * TODO: Upgrade firmware process
  13302. */
  13303. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13304. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13305. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13306. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13307. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13308. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13309. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13310. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13311. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13312. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13313. sendInstallCertificateConfirmation(uuid);
  13314. return result;
  13315. }
  13316. int handleUnknownRequest(char *uuid, char *payload)
  13317. {
  13318. mtrace();
  13319. int result = PASS;
  13320. DEBUG_INFO("handleUnknownRequest...\n");
  13321. sendUnknownConfirmation(uuid);
  13322. result = PASS;
  13323. return result;
  13324. }
  13325. //==========================================
  13326. // Handle server response routine
  13327. //==========================================
  13328. void handleAuthorizeResponse(char *payload, int gun_index)
  13329. {
  13330. mtrace();
  13331. char expiryDatestr[36]={0};
  13332. char parentIdTagstr[21]={0};
  13333. char statusstr[20]={0};
  13334. int expiryDateISNULL=FALSE;
  13335. int parentIdTagISNULL=FALSE;
  13336. DEBUG_INFO("handleAuthorizeResponse...\n");
  13337. json_object *Authorize;
  13338. Authorize = json_tokener_parse(payload);
  13339. if(!is_error(Authorize))
  13340. {
  13341. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13342. {
  13343. // Required data
  13344. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13345. // Optional data
  13346. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13347. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13348. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13349. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13350. }
  13351. }
  13352. json_object_put(Authorize);
  13353. if(expiryDateISNULL == FALSE)
  13354. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13355. if(parentIdTagISNULL == FALSE)
  13356. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13357. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13358. //Update idTag information to authorization cache if supproted
  13359. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13360. {
  13361. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13362. }
  13363. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13364. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13365. authorizeRetryTimes = 0;
  13366. }
  13367. void handleBootNotificationResponse(char *payload, int gun_index)
  13368. {
  13369. mtrace();
  13370. char statusStr[12]={0};
  13371. char currentTimeStr[30]={0};
  13372. int intervalInt = 0;
  13373. DEBUG_INFO("handleBootNotificationResponse...\n");
  13374. json_object *BootNotification;
  13375. BootNotification = json_tokener_parse(payload);
  13376. if(!is_error(BootNotification))
  13377. {
  13378. // Required data
  13379. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13380. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13381. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13382. }
  13383. json_object_put(BootNotification);
  13384. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13385. BootNotificationInterval = intervalInt;
  13386. //write back to ShmOCPP16DataPH->BootNotification
  13387. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13388. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13389. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13390. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13391. {
  13392. BootNotificationInterval = 0;
  13393. if((intervalInt == 0) || (intervalInt >= 10))
  13394. {
  13395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13396. HeartBeatWaitTime = intervalInt;
  13397. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13398. }
  13399. server_sign = TRUE;
  13400. server_pending =FALSE;
  13401. }
  13402. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13403. {
  13404. server_pending = TRUE;
  13405. }
  13406. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13407. srand(time(NULL));
  13408. refreshStartTimer(&clientTime.Heartbeat);
  13409. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13410. SetOcppConnStatus(TRUE);
  13411. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13412. }
  13413. void handleDataTransferResponse(char *payload, int gun_index)
  13414. {
  13415. json_object *DataTransfer = json_tokener_parse(payload);
  13416. if(!is_error(DataTransfer))
  13417. {
  13418. // Required data
  13419. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13420. // Optional data
  13421. if(json_object_object_get(DataTransfer, "data") != NULL)
  13422. {
  13423. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13424. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13425. if(!is_error(Data))
  13426. {
  13427. if(json_object_object_get(Data, "msgId") != NULL)
  13428. {
  13429. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13430. {
  13431. 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")));
  13432. }
  13433. }
  13434. }
  13435. json_object_put(Data);
  13436. }
  13437. }
  13438. json_object_put(DataTransfer);
  13439. }
  13440. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13441. {
  13442. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13443. //struct json_object *obj;
  13444. // obj = json_tokener_parse(payload);
  13445. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13446. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13447. //No fields are defined.
  13448. }
  13449. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13450. {
  13451. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13452. //struct json_object *obj;
  13453. // obj = json_tokener_parse(payload);
  13454. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13455. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13456. //No fields are defined.
  13457. }
  13458. void handleHeartbeatResponse(char *payload, int gun_index)
  13459. {
  13460. mtrace();
  13461. DEBUG_INFO("handleHeartbeatResponse...\n");
  13462. json_object *Heartbeat;
  13463. Heartbeat = json_tokener_parse(payload);
  13464. if(!is_error(Heartbeat))
  13465. {
  13466. // Required data
  13467. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13468. }
  13469. json_object_put(Heartbeat);
  13470. if(FirstHeartBeat == 0)
  13471. {
  13472. FirstHeartBeat = 1;
  13473. DEBUG_INFO("FirstHeartBeat \n");
  13474. }
  13475. HeartBeatWithNOResponse = 0;
  13476. refreshStartTimer(&clientTime.Heartbeat);
  13477. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13478. }
  13479. void handleMeterValuesResponse(char *payload, int gun_index)
  13480. {
  13481. mtrace();
  13482. DEBUG_INFO("handleMeterValuesResponse...\n");
  13483. isQueueSendable = 1;
  13484. }
  13485. void handleStartTransactionResponse(char *payload, int gun_index)
  13486. {
  13487. mtrace();
  13488. //int transactionIdInt = 0;
  13489. FILE *outfile;
  13490. char data[100]={0};
  13491. DEBUG_INFO("handleStartTransactionResponse...\n");
  13492. json_object *StartTransaction;
  13493. StartTransaction = json_tokener_parse(payload);
  13494. if(!is_error(StartTransaction))
  13495. {
  13496. // Required data
  13497. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13498. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13499. // Optional data
  13500. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13501. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13502. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13503. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13504. }
  13505. json_object_put(StartTransaction);
  13506. isQueueSendable = 1;
  13507. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13508. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13509. //-----------Start : write to the Queue TransactionId file -----------------//
  13510. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13511. {}
  13512. else
  13513. {
  13514. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13515. if(log == NULL)
  13516. {
  13517. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13518. return ;
  13519. }
  13520. else
  13521. {
  13522. fclose(log);
  13523. }
  13524. }
  13525. // open file for writing
  13526. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13527. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13528. {
  13529. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13530. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13531. fputs(data, outfile);
  13532. fclose (outfile);
  13533. }
  13534. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13535. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13536. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13537. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13538. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13539. }
  13540. void handleStatusNotificationResponse(char *payload, int gun_index)
  13541. {
  13542. mtrace();
  13543. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13544. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13545. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13546. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13547. }
  13548. void handleStopTransactionnResponse(char *payload, int gun_index)
  13549. {
  13550. mtrace();
  13551. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13552. json_object *StopTransaction;
  13553. StopTransaction = json_tokener_parse(payload);
  13554. if(!is_error(StopTransaction))
  13555. {
  13556. // Optional data
  13557. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13558. {
  13559. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13560. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13562. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13563. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13564. }
  13565. }
  13566. json_object_put(StopTransaction);
  13567. isQueueSendable = 1;
  13568. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13569. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13570. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13571. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13572. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13573. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13574. }
  13575. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13576. {
  13577. mtrace();
  13578. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13579. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13580. }
  13581. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13582. {
  13583. mtrace();
  13584. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13585. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13586. }
  13587. void handleSignCertificateResponse(char *payload, int gun_index)
  13588. {
  13589. mtrace();
  13590. DEBUG_INFO("handleSignCertificateResponse...\n");
  13591. json_object *SignCertificate;
  13592. SignCertificate = json_tokener_parse(payload);
  13593. if(!is_error(SignCertificate))
  13594. {
  13595. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13596. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13597. }
  13598. json_object_put(SignCertificate);
  13599. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13600. }
  13601. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13602. {
  13603. mtrace();
  13604. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13605. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13606. }
  13607. //==========================================
  13608. // Handle Error routine
  13609. //==========================================
  13610. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13611. {
  13612. mtrace();
  13613. #ifdef SystemLogMessage
  13614. DEBUG_INFO("errorCode: %s\n", errorCode);
  13615. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13616. DEBUG_INFO("errorDetails: %s\n", payload);
  13617. #endif
  13618. }
  13619. //===============================================
  13620. // Common routine
  13621. //===============================================
  13622. int initialConfigurationTable(void)
  13623. {
  13624. //clock_t start_t, end_t, total_t;
  13625. FILE *fp;
  13626. FILE *outfile;
  13627. char str[512]={0};
  13628. int confVersion = 19;
  13629. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13630. //start_t = clock();
  13631. //printf("Starting of the program, start_t = %ld\n", start_t);
  13632. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13633. // Check configuration file size is correct
  13634. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13635. {
  13636. struct stat st;
  13637. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13638. if(st.st_size < 3100)
  13639. {
  13640. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13641. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13642. }
  13643. }
  13644. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13645. {
  13646. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13647. if(outfile == NULL)
  13648. {
  13649. DEBUG_INFO("Error opening file\n");
  13650. return FALSE;
  13651. }
  13652. /*Core Profile*/
  13653. //AllowOfflineTxForUnknownId
  13654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13658. //AuthorizationCacheEnabled
  13659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13663. //AuthorizeRemoteTxRequests
  13664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13668. //BlinkRepeat
  13669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13673. //ClockAlignedDataInterval
  13674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13678. //ConnectionTimeOut
  13679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13681. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13683. //GetConfigurationMaxKeys
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13686. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13688. // HeartbeatInterval
  13689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13691. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13693. // LightIntensity
  13694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13696. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13698. // LocalAuthorizeOffline
  13699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13701. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13703. // LocalPreAuthorize
  13704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13706. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13708. // MaxEnergyOnInvalidId
  13709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13711. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13713. // MeterValuesAlignedData
  13714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13717. 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" );
  13718. else
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13721. // MeterValuesAlignedDataMaxLength
  13722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13725. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13726. else
  13727. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13729. // MeterValuesSampledData
  13730. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13731. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13732. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13733. 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" );
  13734. else
  13735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13737. // MeterValuesSampledDataMaxLength
  13738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13742. else
  13743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13745. // MeterValueSampleInterval
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13750. // MinimumStatusDuration
  13751. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13754. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13756. // NumberOfConnectors
  13757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13760. {
  13761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13762. }
  13763. else
  13764. {
  13765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13766. }
  13767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13768. // ResetRetries
  13769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13773. // ConnectorPhaseRotation
  13774. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13776. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13778. // ConnectorPhaseRotationMaxLength
  13779. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13780. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13781. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13783. // StopTransactionOnEVSideDisconnect
  13784. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13786. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13788. // StopTransactionOnInvalidId
  13789. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13793. // StopTxnAlignedData
  13794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13798. // StopTxnAlignedDataMaxLength
  13799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13801. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13803. // StopTxnSampledData
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13808. else
  13809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13811. // StopTxnSampledDataMaxLength
  13812. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13815. {
  13816. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13817. }
  13818. else
  13819. {
  13820. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13821. }
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13823. // SupportedFeatureProfiles
  13824. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13828. // SupportedFeatureProfilesMaxLength
  13829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13833. // TransactionMessageAttempts
  13834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13837. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13839. // TransactionMessageRetryInterval
  13840. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13842. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13843. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13845. // UnlockConnectorOnEVSideDisconnect
  13846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13850. // WebSocketPingInterval
  13851. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13855. // QueueOffLineMeterValues
  13856. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13860. // AuthorizationKey
  13861. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13863. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13865. // SecurityProfile
  13866. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13868. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13870. // DefaultPrice
  13871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13875. // CustomDisplayCostAndPrice
  13876. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13880. // CustomIdleFeeAfterStop
  13881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13885. // SystemUptimeSec
  13886. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13890. // FreeVend
  13891. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13895. // FreeVendIdtag
  13896. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13900. // OcppServer
  13901. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13903. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13905. // MaintainServer
  13906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13908. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13910. // StatusNotificationPeriodically
  13911. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13915. // StatusNotificationInterval
  13916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13920. // isEnableLocalPowerSharing
  13921. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  13922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  13923. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  13925. // PowerSharingServerIP
  13926. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  13928. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  13930. // EVCCID_PREFIX
  13931. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  13935. // OffLineMaxChargingPower
  13936. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  13937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  13938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  13939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  13940. // Configuration Version
  13941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13943. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13945. // Charging profile refresh interval
  13946. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  13947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  13948. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  13949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  13950. // Ocpp Software certificated version
  13951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  13952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  13953. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  13954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  13955. // Check certificate of download link
  13956. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  13957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  13958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", "FALSE");
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  13960. //* Local Auth List Management Profile*/
  13961. #if 0
  13962. //For OCTT Test Case
  13963. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13966. #endif
  13967. #if 1
  13968. //LocalAuthListEnabled
  13969. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13973. #endif
  13974. //LocalAuthListMaxLength
  13975. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13979. //SendLocalListMaxLength
  13980. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  13983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13984. //ReserveConnectorZeroSupported
  13985. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13989. //* Smart Charging Profile */
  13990. //ChargeProfileMaxStackLevel
  13991. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  13994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13995. // ChargingScheduleAllowedChargingRateUnit
  13996. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14000. // ChargingScheduleMaxPeriods
  14001. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14003. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14005. // ConnectorSwitch3to1PhaseSupported
  14006. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14010. // MaxChargingProfilesInstalled
  14011. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14015. fclose(outfile);
  14016. }
  14017. else
  14018. {
  14019. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14020. char keystr[60]={0};
  14021. char readonlystr[10]={0};
  14022. char valuestr[256]={0};
  14023. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14024. if(fp == NULL) {
  14025. DEBUG_INFO("Error opening file");
  14026. return FALSE;
  14027. }
  14028. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14029. {
  14030. //DEBUG_INFO("Get Configuration \n");
  14031. if(strlen(str) > 0)
  14032. {
  14033. json_object *OCPPConfiguration;
  14034. OCPPConfiguration = json_tokener_parse(str);
  14035. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  14036. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  14037. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  14038. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  14039. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  14040. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  14041. json_object_put(OCPPConfiguration);
  14042. // DEBUG_INFO("keystr=%s\n",keystr);
  14043. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14044. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14045. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14046. {
  14047. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14048. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14049. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14050. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14051. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14052. }
  14053. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14054. {
  14055. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14057. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14058. }
  14059. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14060. {
  14061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14062. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14063. }
  14064. if(strcmp(keystr, "BlinkRepeat") == 0)
  14065. {
  14066. //Charger.BlinkRepeat = Integer.parseInt(value);
  14067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14068. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14069. }
  14070. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14071. {
  14072. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14074. }
  14075. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14076. {
  14077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14078. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14079. }
  14080. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14081. {
  14082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14083. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14084. }
  14085. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14086. {
  14087. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14088. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14089. HeartBeatWaitTime = atoi(valuestr);
  14090. }
  14091. if(strcmp(keystr, "LightIntensity") == 0)
  14092. {
  14093. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14094. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14095. }
  14096. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14097. {
  14098. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14099. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14100. }
  14101. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14102. {
  14103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14104. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14105. }
  14106. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14107. {
  14108. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14109. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14110. }
  14111. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14112. {
  14113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14114. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14115. }
  14116. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14117. {
  14118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14119. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14120. }
  14121. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14122. {
  14123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14124. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14125. }
  14126. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14127. {
  14128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14129. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14130. }
  14131. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14132. {
  14133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14134. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14135. }
  14136. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14137. {
  14138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14139. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14140. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14141. }
  14142. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14143. {
  14144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14145. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14146. }
  14147. if(strcmp(keystr, "ResetRetries") == 0)
  14148. {
  14149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14150. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14151. }
  14152. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14153. {
  14154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14156. }
  14157. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14158. {
  14159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14161. }
  14162. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14163. {
  14164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14165. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14166. }
  14167. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14168. {
  14169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14170. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14171. }
  14172. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14173. {
  14174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14176. }
  14177. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14178. {
  14179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14181. }
  14182. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14183. {
  14184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14185. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14186. }
  14187. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14188. {
  14189. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14190. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14191. }
  14192. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14193. {
  14194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14195. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14196. }
  14197. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14198. {
  14199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14201. }
  14202. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14203. {
  14204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14206. TransactionMessageAttemptsValue = atoi(valuestr);
  14207. }
  14208. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14209. {
  14210. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14212. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14213. }
  14214. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14215. {
  14216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14217. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14218. }
  14219. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14220. {
  14221. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14222. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14223. }
  14224. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14225. {
  14226. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14227. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14228. }
  14229. if(strcmp(keystr, "AuthorizationKey") == 0)
  14230. {
  14231. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14232. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14233. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14234. }
  14235. if(strcmp(keystr, "SecurityProfile") == 0)
  14236. {
  14237. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14239. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14240. }
  14241. if(strcmp(keystr, "DefaultPrice") == 0)
  14242. {
  14243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14244. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14245. }
  14246. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14247. {
  14248. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14249. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14250. }
  14251. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14252. {
  14253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14255. }
  14256. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14257. {
  14258. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14259. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14260. }
  14261. if(strcmp(keystr, "FreeVend") == 0)
  14262. {
  14263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14264. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14265. }
  14266. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14267. {
  14268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14269. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14270. }
  14271. if(strcmp(keystr, "OcppServer") == 0)
  14272. {
  14273. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14274. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14275. }
  14276. if(strcmp(keystr, "MaintainServer") == 0)
  14277. {
  14278. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14279. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14280. }
  14281. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14282. {
  14283. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14284. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14285. }
  14286. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14287. {
  14288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14289. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14290. }
  14291. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14292. {
  14293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14294. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14295. }
  14296. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14297. {
  14298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14299. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14300. }
  14301. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14302. {
  14303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14304. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14305. }
  14306. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14307. {
  14308. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14309. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14310. }
  14311. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14312. {
  14313. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14314. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14315. }
  14316. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  14317. {
  14318. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14319. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  14320. }
  14321. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  14322. {
  14323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14324. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  14325. }
  14326. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  14327. {
  14328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  14330. }
  14331. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14332. {
  14333. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14334. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14335. }
  14336. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14337. {
  14338. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14340. }
  14341. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14342. {
  14343. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14345. }
  14346. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14347. {
  14348. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14350. }
  14351. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14352. {
  14353. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14355. }
  14356. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14357. {
  14358. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14359. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14360. }
  14361. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14362. {
  14363. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14364. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14365. }
  14366. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14367. {
  14368. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14369. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14370. }
  14371. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14372. {
  14373. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14374. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14375. }
  14376. }
  14377. }
  14378. fclose(fp);
  14379. }
  14380. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14381. {
  14382. return PASS;
  14383. }
  14384. else
  14385. {
  14386. return FAIL;
  14387. }
  14388. }
  14389. void StoreConfigurationTable(void)
  14390. {
  14391. FILE *outfile;
  14392. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14393. if(outfile == NULL)
  14394. {
  14395. DEBUG_INFO("Error opening file");
  14396. return ;
  14397. }
  14398. /*Core Profile*/
  14399. //AllowOfflineTxForUnknownId
  14400. /*
  14401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14402. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14405. */
  14406. //DEBUG_INFO("data=%s\n",data);
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14408. //AuthorizationCacheEnabled
  14409. /*
  14410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14413. */
  14414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14415. //AuthorizeRemoteTxRequests
  14416. /*
  14417. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14420. */
  14421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14422. //BlinkRepeat
  14423. /*
  14424. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14427. */
  14428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14429. //ClockAlignedDataInterval
  14430. /*
  14431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14434. */
  14435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14436. //ConnectionTimeOut
  14437. /*
  14438. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14439. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14440. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14441. */
  14442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14443. //GetConfigurationMaxKeys
  14444. /*
  14445. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14446. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14448. */
  14449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14450. // HeartbeatInterval
  14451. /*
  14452. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14453. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14455. */
  14456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14457. // LightIntensity
  14458. /*
  14459. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14460. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14461. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14462. */
  14463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14464. // LocalAuthorizeOffline
  14465. /*
  14466. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14468. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14469. */
  14470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14471. // LocalPreAuthorize
  14472. /*
  14473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14474. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14475. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14476. */
  14477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14478. // MaxEnergyOnInvalidId
  14479. /*
  14480. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14481. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14483. */
  14484. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14486. // MeterValuesAlignedData
  14487. /*
  14488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14490. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14491. */
  14492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14493. // MeterValuesAlignedDataMaxLength
  14494. /*
  14495. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14496. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14497. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14498. */
  14499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14500. // MeterValuesSampledData
  14501. /*
  14502. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14505. */
  14506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14507. // MeterValuesSampledDataMaxLength
  14508. /*
  14509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14510. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14512. */
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14514. // MeterValueSampleInterval
  14515. /*
  14516. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14517. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14519. */
  14520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14521. // MinimumStatusDuration
  14522. /*
  14523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14524. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14525. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14526. */
  14527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14528. // NumberOfConnectors
  14529. /*
  14530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14531. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14533. {
  14534. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14535. }
  14536. else
  14537. {
  14538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14539. }
  14540. */
  14541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14542. // ResetRetries
  14543. /*
  14544. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14545. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14546. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14547. */
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14549. // ConnectorPhaseRotation
  14550. /*
  14551. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14552. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14553. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14554. */
  14555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14556. // ConnectorPhaseRotationMaxLength
  14557. /*
  14558. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14560. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14561. */
  14562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14563. // StopTransactionOnEVSideDisconnect
  14564. /*
  14565. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14566. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14567. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14568. */
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14570. // StopTransactionOnInvalidId
  14571. /*
  14572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14575. */
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14577. // StopTxnAlignedData
  14578. /*
  14579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14584. // StopTxnAlignedDataMaxLength
  14585. /*
  14586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14591. // StopTxnSampledData
  14592. /*
  14593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14596. */
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14598. // StopTxnSampledDataMaxLength
  14599. /*
  14600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14605. // SupportedFeatureProfiles
  14606. /*
  14607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14612. // SupportedFeatureProfilesMaxLength
  14613. /*
  14614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14617. */
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14619. // TransactionMessageAttempts
  14620. /*
  14621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14626. // TransactionMessageRetryInterval
  14627. /*
  14628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14631. */
  14632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14633. // UnlockConnectorOnEVSideDisconnect
  14634. /*
  14635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14638. */
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14640. // WebSocketPingInterval
  14641. /*
  14642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14645. */
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14647. // QueueOffLineMeterValues
  14648. /*
  14649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14652. */
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14654. // AuthorizationKey
  14655. /*
  14656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14659. */
  14660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14661. // SecurityProfile
  14662. /*
  14663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14666. */
  14667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14668. // DefaultPrice
  14669. /*
  14670. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14673. */
  14674. json_object *tmp;
  14675. tmp = json_tokener_parse((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14676. if(!is_error(tmp))
  14677. {
  14678. DEBUG_INFO("JSON string type\n");
  14679. json_object *target = json_object_new_object();
  14680. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  14681. json_object_object_add(target, "readonly", (ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  14682. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  14683. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  14684. json_object_put(target);
  14685. }
  14686. else
  14687. {
  14688. DEBUG_INFO("Normal string type\n");
  14689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14690. }
  14691. json_object_put(tmp);
  14692. // CustomDisplayCostAndPrice
  14693. /*
  14694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14696. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14697. */
  14698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14699. // CustomIdleFeeAfterStop
  14700. /*
  14701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14704. */
  14705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14706. // SystemUptimeSec
  14707. /*
  14708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14711. */
  14712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14713. // FreeVend
  14714. /*
  14715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14716. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14718. */
  14719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14720. // FreeVendIdtag
  14721. /*
  14722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14725. */
  14726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14727. // OcppServer
  14728. /*
  14729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14731. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14732. */
  14733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14734. // MaintainServer
  14735. /*
  14736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14739. */
  14740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14741. // StatusNotificationPeriodically
  14742. /*
  14743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14746. */
  14747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14748. // StatusNotificationInterval
  14749. /*
  14750. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14753. */
  14754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14755. // isEnableLocalPowerSharing
  14756. /*
  14757. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14760. */
  14761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14762. // PowerSharingServerIP
  14763. /*
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14767. */
  14768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14769. // EVCCID_PREFIX
  14770. /*
  14771. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14774. */
  14775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14776. // OffLineMaxChargingPower
  14777. /*
  14778. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  14781. */
  14782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14783. // ConfigurationVersion
  14784. /*
  14785. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14786. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14787. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14788. */
  14789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14790. // CharingProfileRefreshInterval
  14791. /*
  14792. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14793. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  14795. */
  14796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14797. // OcppSoftwareVersion
  14798. /*
  14799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  14800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  14801. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  14802. */
  14803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  14804. // AuthDownloadlinkCertificate
  14805. /*
  14806. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  14807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  14808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "" );
  14809. */
  14810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  14811. //* Local Auth List Management Profile*/
  14812. //LocalAuthListEnabled
  14813. /*
  14814. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14817. */
  14818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14819. //LocalAuthListMaxLength
  14820. /*
  14821. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14824. */
  14825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14826. //SendLocalListMaxLength
  14827. /*
  14828. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14831. */
  14832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14833. //ReserveConnectorZeroSupported
  14834. /*
  14835. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14838. */
  14839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14840. //* Smart Charging Profile */
  14841. //ChargeProfileMaxStackLevel
  14842. /*
  14843. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14846. */
  14847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14848. // ChargingScheduleAllowedChargingRateUnit
  14849. /*
  14850. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14853. */
  14854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14855. // ChargingScheduleMaxPeriods
  14856. /*
  14857. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14860. */
  14861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14862. // ConnectorSwitch3to1PhaseSupported
  14863. /*
  14864. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14867. */
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14869. // MaxChargingProfilesInstalled
  14870. /*
  14871. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14874. */
  14875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14876. fclose(outfile);
  14877. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14878. }
  14879. void getKeyValue(char *keyReq)
  14880. {
  14881. int isEmpty = FALSE;
  14882. int isKnowKey = FALSE;
  14883. DEBUG_INFO("keyReq = %s\n", keyReq);
  14884. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14885. isEmpty = TRUE;
  14886. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14887. {
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14890. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14891. {
  14892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14893. }
  14894. else
  14895. {
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14897. }
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14899. isKnowKey = TRUE;
  14900. }
  14901. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14902. {
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14905. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14906. {
  14907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14908. }
  14909. else
  14910. {
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14912. }
  14913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14914. isKnowKey = TRUE;
  14915. }
  14916. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14917. {
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14920. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14921. {
  14922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14923. }
  14924. else
  14925. {
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14927. }
  14928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14929. isKnowKey = TRUE;
  14930. }
  14931. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14932. {
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14935. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14936. {
  14937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14938. }
  14939. else
  14940. {
  14941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14942. }
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14944. isKnowKey = TRUE;
  14945. }
  14946. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14947. {
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14950. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14951. {
  14952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14953. }
  14954. else
  14955. {
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14957. }
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14959. isKnowKey = TRUE;
  14960. }
  14961. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14962. {
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14965. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14966. {
  14967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14968. }
  14969. else
  14970. {
  14971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14972. }
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14974. isKnowKey = TRUE;
  14975. }
  14976. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14977. {
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14980. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14981. {
  14982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14983. }
  14984. else
  14985. {
  14986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14987. }
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14989. isKnowKey = TRUE;
  14990. }
  14991. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14992. {
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14995. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14996. {
  14997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14998. }
  14999. else
  15000. {
  15001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15002. }
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15004. isKnowKey = TRUE;
  15005. }
  15006. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15007. {
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15010. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15011. {
  15012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15013. }
  15014. else
  15015. {
  15016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15017. }
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15019. isKnowKey = TRUE;
  15020. }
  15021. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15022. {
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15025. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15026. {
  15027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15028. }
  15029. else
  15030. {
  15031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15032. }
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15034. isKnowKey = TRUE;
  15035. }
  15036. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15037. {
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15040. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15041. {
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15043. }
  15044. else
  15045. {
  15046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15047. }
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15049. isKnowKey = TRUE;
  15050. }
  15051. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15052. {
  15053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15055. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15056. {
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15058. }
  15059. else
  15060. {
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15062. }
  15063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15064. isKnowKey = TRUE;
  15065. }
  15066. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15067. {
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15070. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15071. {
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15073. }
  15074. else
  15075. {
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15077. }
  15078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15079. isKnowKey = TRUE;
  15080. }
  15081. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15085. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15086. {
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15088. }
  15089. else
  15090. {
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15092. }
  15093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15094. isKnowKey = TRUE;
  15095. }
  15096. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15097. {
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15100. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15101. {
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15103. }
  15104. else
  15105. {
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15107. }
  15108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15109. isKnowKey = TRUE;
  15110. }
  15111. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15112. {
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15115. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15116. {
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15118. }
  15119. else
  15120. {
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15122. }
  15123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15124. isKnowKey = TRUE;
  15125. }
  15126. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15127. {
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15130. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15131. {
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15133. }
  15134. else
  15135. {
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15137. }
  15138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15139. isKnowKey = TRUE;
  15140. }
  15141. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15142. {
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15146. {
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15148. }
  15149. else
  15150. {
  15151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15152. }
  15153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15154. isKnowKey = TRUE;
  15155. }
  15156. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15157. {
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15160. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15161. {
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15163. }
  15164. else
  15165. {
  15166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15167. }
  15168. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15170. isKnowKey = TRUE;
  15171. }
  15172. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15173. {
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15176. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15177. {
  15178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15179. }
  15180. else
  15181. {
  15182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15183. }
  15184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15185. isKnowKey = TRUE;
  15186. }
  15187. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15188. {
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15191. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15192. {
  15193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15194. }
  15195. else
  15196. {
  15197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15198. }
  15199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15200. isKnowKey = TRUE;
  15201. }
  15202. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15203. {
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15206. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15207. {
  15208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15209. }
  15210. else
  15211. {
  15212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15213. }
  15214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15215. isKnowKey = TRUE;
  15216. }
  15217. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15218. {
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15221. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15222. {
  15223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15224. }
  15225. else
  15226. {
  15227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15228. }
  15229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15230. isKnowKey = TRUE;
  15231. }
  15232. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15233. {
  15234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15236. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15237. {
  15238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15239. }
  15240. else
  15241. {
  15242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15243. }
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15245. isKnowKey = TRUE;
  15246. }
  15247. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15248. {
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15251. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15252. {
  15253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15254. }
  15255. else
  15256. {
  15257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15258. }
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15260. isKnowKey = TRUE;
  15261. }
  15262. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15263. {
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15266. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15267. {
  15268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15269. }
  15270. else
  15271. {
  15272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15273. }
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15275. isKnowKey = TRUE;
  15276. }
  15277. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15278. {
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15281. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15282. {
  15283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15284. }
  15285. else
  15286. {
  15287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15288. }
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15290. isKnowKey = TRUE;
  15291. }
  15292. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15293. {
  15294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15296. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15297. {
  15298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15299. }
  15300. else
  15301. {
  15302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15303. }
  15304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15305. isKnowKey = TRUE;
  15306. }
  15307. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15308. {
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15311. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15312. {
  15313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15314. }
  15315. else
  15316. {
  15317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15318. }
  15319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15320. isKnowKey = TRUE;
  15321. }
  15322. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15323. {
  15324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15326. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15327. {
  15328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15329. }
  15330. else
  15331. {
  15332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15333. }
  15334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15335. isKnowKey = TRUE;
  15336. }
  15337. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15338. {
  15339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15341. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15342. {
  15343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15344. }
  15345. else
  15346. {
  15347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15348. }
  15349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15350. isKnowKey = TRUE;
  15351. }
  15352. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15353. {
  15354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15356. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15357. {
  15358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15359. }
  15360. else
  15361. {
  15362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15363. }
  15364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15365. isKnowKey = TRUE;
  15366. }
  15367. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15368. {
  15369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15372. {
  15373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15374. }
  15375. else
  15376. {
  15377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15378. }
  15379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15380. isKnowKey = TRUE;
  15381. }
  15382. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15383. {
  15384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15386. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15387. {
  15388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15389. }
  15390. else
  15391. {
  15392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15393. }
  15394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15395. isKnowKey = TRUE;
  15396. }
  15397. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15398. {
  15399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15401. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15402. {
  15403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15404. }
  15405. else
  15406. {
  15407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15408. }
  15409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15410. isKnowKey = TRUE;
  15411. }
  15412. /*
  15413. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15414. {
  15415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15418. {
  15419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15420. }
  15421. else
  15422. {
  15423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15424. }
  15425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15426. isKnowKey = TRUE;
  15427. }*/
  15428. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15429. {
  15430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15433. {
  15434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15435. }
  15436. else
  15437. {
  15438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15439. }
  15440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15441. isKnowKey = TRUE;
  15442. }
  15443. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15444. {
  15445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15447. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15448. {
  15449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15450. }
  15451. else
  15452. {
  15453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15454. }
  15455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15456. isKnowKey = TRUE;
  15457. }
  15458. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15459. {
  15460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15462. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15463. {
  15464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15465. }
  15466. else
  15467. {
  15468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15469. }
  15470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15471. isKnowKey = TRUE;
  15472. }
  15473. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15474. {
  15475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15477. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15478. {
  15479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15480. }
  15481. else
  15482. {
  15483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15484. }
  15485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15486. isKnowKey = TRUE;
  15487. }
  15488. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15489. {
  15490. struct sysinfo s_info;
  15491. int error = sysinfo(&s_info);
  15492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15494. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15495. {
  15496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15497. }
  15498. else
  15499. {
  15500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15501. }
  15502. if(error != 0)
  15503. {
  15504. DEBUG_WARN("System uptime get error: %d\n", error);
  15505. }
  15506. else
  15507. {
  15508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15509. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15510. }
  15511. isKnowKey = TRUE;
  15512. }
  15513. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15514. {
  15515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15517. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15518. {
  15519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15520. }
  15521. else
  15522. {
  15523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15524. }
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15526. isKnowKey = TRUE;
  15527. }
  15528. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15529. {
  15530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15532. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15533. {
  15534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15535. }
  15536. else
  15537. {
  15538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15539. }
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15541. isKnowKey = TRUE;
  15542. }
  15543. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15544. {
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15547. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15548. {
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15550. }
  15551. else
  15552. {
  15553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15554. }
  15555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15556. isKnowKey = TRUE;
  15557. }
  15558. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15559. {
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15562. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15563. {
  15564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15565. }
  15566. else
  15567. {
  15568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15569. }
  15570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15571. isKnowKey = TRUE;
  15572. }
  15573. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15574. {
  15575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15577. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15578. {
  15579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15580. }
  15581. else
  15582. {
  15583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15584. }
  15585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15586. isKnowKey = TRUE;
  15587. }
  15588. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15589. {
  15590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15592. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15593. {
  15594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15595. }
  15596. else
  15597. {
  15598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15599. }
  15600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15601. isKnowKey = TRUE;
  15602. }
  15603. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15604. {
  15605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15607. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15608. {
  15609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15610. }
  15611. else
  15612. {
  15613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15614. }
  15615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15616. isKnowKey = TRUE;
  15617. }
  15618. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15619. {
  15620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15622. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15623. {
  15624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15625. }
  15626. else
  15627. {
  15628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15629. }
  15630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15631. isKnowKey = TRUE;
  15632. }
  15633. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15634. {
  15635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15637. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15638. {
  15639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15640. }
  15641. else
  15642. {
  15643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15644. }
  15645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15646. isKnowKey = TRUE;
  15647. }
  15648. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  15649. {
  15650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  15651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  15652. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  15653. {
  15654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  15655. }
  15656. else
  15657. {
  15658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  15659. }
  15660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  15661. isKnowKey = TRUE;
  15662. }
  15663. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15664. {
  15665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15667. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15668. {
  15669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15670. }
  15671. else
  15672. {
  15673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15674. }
  15675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15676. isKnowKey = TRUE;
  15677. }
  15678. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  15679. {
  15680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  15681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  15682. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  15683. {
  15684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  15685. }
  15686. else
  15687. {
  15688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  15689. }
  15690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  15691. isKnowKey = TRUE;
  15692. }
  15693. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  15694. {
  15695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  15696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  15697. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  15698. {
  15699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  15700. }
  15701. else
  15702. {
  15703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  15704. }
  15705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  15706. isKnowKey = TRUE;
  15707. }
  15708. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  15709. {
  15710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  15711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  15712. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  15713. {
  15714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  15715. }
  15716. else
  15717. {
  15718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  15719. }
  15720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  15721. isKnowKey = TRUE;
  15722. }
  15723. #if 1
  15724. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15725. {
  15726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15728. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15729. {
  15730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15731. }
  15732. else
  15733. {
  15734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15735. }
  15736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15737. isKnowKey = TRUE;
  15738. }
  15739. #endif
  15740. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15741. {
  15742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15744. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15745. {
  15746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15747. }
  15748. else
  15749. {
  15750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15751. }
  15752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15753. isKnowKey = TRUE;
  15754. }
  15755. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15756. {
  15757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15759. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15760. {
  15761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15762. }
  15763. else
  15764. {
  15765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15766. }
  15767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15768. isKnowKey = TRUE;
  15769. }
  15770. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15771. {
  15772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15774. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15775. {
  15776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15777. }
  15778. else
  15779. {
  15780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15781. }
  15782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15783. isKnowKey = TRUE;
  15784. }
  15785. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15786. {
  15787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15789. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15790. {
  15791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15792. }
  15793. else
  15794. {
  15795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15796. }
  15797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15798. isKnowKey = TRUE;
  15799. }
  15800. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15801. {
  15802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15804. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15805. {
  15806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15807. }
  15808. else
  15809. {
  15810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15811. }
  15812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15813. isKnowKey = TRUE;
  15814. }
  15815. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15816. {
  15817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15819. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15820. {
  15821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15822. }
  15823. else
  15824. {
  15825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15826. }
  15827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15828. isKnowKey = TRUE;
  15829. }
  15830. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15831. {
  15832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15834. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15835. {
  15836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15837. }
  15838. else
  15839. {
  15840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15841. }
  15842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15843. isKnowKey = TRUE;
  15844. }
  15845. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15846. {
  15847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15849. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15850. {
  15851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15852. }
  15853. else
  15854. {
  15855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15856. }
  15857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15858. isKnowKey = TRUE;
  15859. }
  15860. //=========================================================
  15861. if(!isEmpty && !isKnowKey)
  15862. {
  15863. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15864. strcpy(unknownkey[UnknownKeynum], keyReq);
  15865. UnknownKeynum = UnknownKeynum + 1;
  15866. }
  15867. }
  15868. void processUnkownKey(void)
  15869. {
  15870. DEBUG_INFO("processUnkownKey...\n");
  15871. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15872. for(int index=0; index < UnknownKeynum; index++)
  15873. {
  15874. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15875. {
  15876. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15877. }
  15878. }
  15879. }
  15880. int setKeyValue(char *key, char *value)
  15881. {
  15882. int isSuccess = NotSupported;
  15883. int check_ascii=0;
  15884. char str[501]={0};
  15885. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15886. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15887. {
  15888. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15890. {
  15891. strcpy(str, (const char*)value);
  15892. for(int i = 0; str[i]; i++){
  15893. str[i] = tolower(str[i]);
  15894. }
  15895. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15896. isSuccess = ConfigurationStatus_Accepted;
  15897. }
  15898. else
  15899. {
  15900. isSuccess = ConfigurationStatus_Rejected;
  15901. }
  15902. }
  15903. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15904. {
  15905. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15906. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15907. {
  15908. strcpy(str, (const char*)value);
  15909. for(int i = 0; str[i]; i++){
  15910. str[i] = tolower(str[i]);
  15911. }
  15912. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15913. isSuccess = ConfigurationStatus_Accepted;
  15914. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15915. }
  15916. else
  15917. {
  15918. isSuccess = ConfigurationStatus_Rejected;
  15919. }
  15920. }
  15921. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15922. {
  15923. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15924. {
  15925. strcpy(str, (const char*)value);
  15926. for(int i = 0; str[i]; i++)
  15927. {
  15928. str[i] = tolower(str[i]);
  15929. }
  15930. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15931. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15932. isSuccess = ConfigurationStatus_Accepted;
  15933. }
  15934. else
  15935. {
  15936. isSuccess = ConfigurationStatus_Rejected;
  15937. }
  15938. }
  15939. if(strcmp(key, "BlinkRepeat") == 0)
  15940. {
  15941. //Charger.BlinkRepeat = Integer.parseInt(value);
  15942. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15943. {
  15944. check_ascii = value[0];
  15945. if( (check_ascii < 48) || (check_ascii > 57) )
  15946. {
  15947. isSuccess = ConfigurationStatus_Rejected;
  15948. }
  15949. else
  15950. {
  15951. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15952. isSuccess = ConfigurationStatus_Accepted;
  15953. }
  15954. }
  15955. else
  15956. {
  15957. isSuccess = ConfigurationStatus_Rejected;
  15958. }
  15959. }
  15960. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15961. {
  15962. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15963. {
  15964. check_ascii = value[0];
  15965. if( (check_ascii < 48) || (check_ascii > 57) )
  15966. {
  15967. isSuccess = ConfigurationStatus_Rejected;
  15968. }
  15969. else
  15970. {
  15971. if((atoi(value) == 0) || (atoi(value) >= 5))
  15972. {
  15973. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15974. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15975. isSuccess = ConfigurationStatus_Accepted;
  15976. }
  15977. else
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. else
  15982. {
  15983. isSuccess = ConfigurationStatus_Rejected;
  15984. }
  15985. }
  15986. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15987. {
  15988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15989. {
  15990. check_ascii = value[0];
  15991. if( (check_ascii < 48) || (check_ascii > 57) )
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. else
  15996. {
  15997. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15998. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15999. isSuccess = ConfigurationStatus_Accepted;
  16000. }
  16001. }
  16002. else
  16003. {
  16004. isSuccess = ConfigurationStatus_Rejected;
  16005. }
  16006. }
  16007. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16008. {
  16009. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16010. {
  16011. check_ascii = value[0];
  16012. if( (check_ascii < 48) || (check_ascii > 57) )
  16013. {
  16014. isSuccess = ConfigurationStatus_Rejected;
  16015. }
  16016. else
  16017. {
  16018. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16019. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16020. isSuccess = ConfigurationStatus_Accepted;
  16021. }
  16022. }
  16023. else
  16024. {
  16025. isSuccess = ConfigurationStatus_Rejected;
  16026. }
  16027. }
  16028. if(strcmp(key, "HeartbeatInterval") == 0)
  16029. {
  16030. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16031. {
  16032. check_ascii = value[0];
  16033. if( (check_ascii < 48) || (check_ascii > 57) )
  16034. {
  16035. isSuccess = ConfigurationStatus_Rejected;
  16036. }
  16037. else
  16038. {
  16039. if((atoi(value) == 0) || (atoi(value) >= 10))
  16040. {
  16041. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16043. HeartBeatWaitTime = atoi(value);
  16044. isSuccess = ConfigurationStatus_Accepted;
  16045. }
  16046. else
  16047. {
  16048. isSuccess = ConfigurationStatus_Rejected;
  16049. }
  16050. }
  16051. }
  16052. else
  16053. {
  16054. isSuccess = ConfigurationStatus_Rejected;
  16055. }
  16056. }
  16057. if(strcmp(key, "LightIntensity") == 0)
  16058. {
  16059. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16060. {
  16061. check_ascii = value[0];
  16062. if( (check_ascii < 48) || (check_ascii > 57) )
  16063. {
  16064. isSuccess = ConfigurationStatus_Rejected;
  16065. }
  16066. else
  16067. {
  16068. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16069. isSuccess = ConfigurationStatus_Accepted;
  16070. }
  16071. }
  16072. else
  16073. {
  16074. isSuccess = ConfigurationStatus_Rejected;
  16075. }
  16076. }
  16077. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16078. {
  16079. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16080. {
  16081. strcpy(str, (const char*)value);
  16082. for(int i = 0; str[i]; i++)
  16083. {
  16084. str[i] = tolower(str[i]);
  16085. }
  16086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16087. isSuccess = ConfigurationStatus_Accepted;
  16088. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16089. }
  16090. else
  16091. {
  16092. isSuccess = ConfigurationStatus_Rejected;
  16093. }
  16094. }
  16095. if(strcmp(key, "LocalPreAuthorize") == 0)
  16096. {
  16097. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16098. {
  16099. strcpy(str, (const char*)value);
  16100. for(int i = 0; str[i]; i++)
  16101. {
  16102. str[i] = tolower(str[i]);
  16103. }
  16104. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16105. isSuccess = ConfigurationStatus_Accepted;
  16106. }
  16107. else
  16108. {
  16109. isSuccess = ConfigurationStatus_Rejected;
  16110. }
  16111. }
  16112. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16113. {
  16114. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16115. {
  16116. check_ascii = value[0];
  16117. if( (check_ascii < 48) || (check_ascii > 57) )
  16118. {
  16119. isSuccess = ConfigurationStatus_Rejected;
  16120. }
  16121. else
  16122. {
  16123. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16124. isSuccess = ConfigurationStatus_Accepted;
  16125. }
  16126. }
  16127. else
  16128. {
  16129. isSuccess = ConfigurationStatus_Rejected;
  16130. }
  16131. }
  16132. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16133. {
  16134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16135. {
  16136. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16137. isSuccess = ConfigurationStatus_Accepted;
  16138. }
  16139. else
  16140. {
  16141. isSuccess = ConfigurationStatus_Rejected;
  16142. }
  16143. }
  16144. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16145. {
  16146. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16147. {
  16148. check_ascii = value[0];
  16149. if( (check_ascii < 48) || (check_ascii > 57) )
  16150. {
  16151. isSuccess = ConfigurationStatus_Rejected;
  16152. }
  16153. else
  16154. {
  16155. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16157. isSuccess = ConfigurationStatus_Accepted;
  16158. }
  16159. }
  16160. else
  16161. {
  16162. isSuccess = ConfigurationStatus_Rejected;
  16163. }
  16164. }
  16165. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16166. {
  16167. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16168. {
  16169. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16170. isSuccess = ConfigurationStatus_Accepted;
  16171. }
  16172. else
  16173. {
  16174. isSuccess = ConfigurationStatus_Rejected;
  16175. }
  16176. }
  16177. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16178. {
  16179. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16180. {
  16181. check_ascii = value[0];
  16182. if( (check_ascii < 48) || (check_ascii > 57) )
  16183. {
  16184. isSuccess = ConfigurationStatus_Rejected;
  16185. }
  16186. else
  16187. {
  16188. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16189. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16190. isSuccess = ConfigurationStatus_Accepted;
  16191. }
  16192. }
  16193. else
  16194. {
  16195. isSuccess = ConfigurationStatus_Rejected;
  16196. }
  16197. }
  16198. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16199. {
  16200. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16201. {
  16202. check_ascii = value[0];
  16203. if( (check_ascii < 48) || (check_ascii > 57) )
  16204. {
  16205. isSuccess = ConfigurationStatus_Rejected;
  16206. }
  16207. else
  16208. {
  16209. if((atoi(value) == 0) || (atoi(value) >= 3))
  16210. {
  16211. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16212. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16213. isSuccess = ConfigurationStatus_Accepted;
  16214. }
  16215. else
  16216. {
  16217. isSuccess = ConfigurationStatus_Rejected;
  16218. }
  16219. }
  16220. }
  16221. else
  16222. {
  16223. isSuccess = ConfigurationStatus_Rejected;
  16224. }
  16225. }
  16226. if(strcmp(key, "MinimumStatusDuration") == 0)
  16227. {
  16228. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16229. {
  16230. check_ascii = value[0];
  16231. if( (check_ascii < 48) || (check_ascii > 57) )
  16232. {
  16233. isSuccess = ConfigurationStatus_Rejected;
  16234. }
  16235. else
  16236. {
  16237. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16238. {
  16239. isSuccess = ConfigurationStatus_Rejected;
  16240. }
  16241. else
  16242. {
  16243. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16244. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16245. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16246. isSuccess = ConfigurationStatus_Accepted;
  16247. }
  16248. }
  16249. }
  16250. else
  16251. {
  16252. isSuccess = ConfigurationStatus_Rejected;
  16253. }
  16254. }
  16255. if(strcmp(key, "NumberOfConnectors") == 0)
  16256. {
  16257. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16258. {
  16259. check_ascii = value[0];
  16260. if( (check_ascii < 48) || (check_ascii > 57) )
  16261. {
  16262. isSuccess = ConfigurationStatus_Rejected;
  16263. }
  16264. else
  16265. {
  16266. //Charger.ResetRetries = Integer.parseInt(value);
  16267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16268. isSuccess = ConfigurationStatus_Accepted;
  16269. }
  16270. }
  16271. else
  16272. {
  16273. isSuccess = ConfigurationStatus_Rejected;
  16274. }
  16275. }
  16276. if(strcmp(key, "ResetRetries") == 0)
  16277. {
  16278. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16279. {
  16280. check_ascii = value[0];
  16281. if( (check_ascii < 48) || (check_ascii > 57) )
  16282. {
  16283. isSuccess = ConfigurationStatus_Rejected;
  16284. }
  16285. else
  16286. {
  16287. //Charger.ResetRetries = Integer.parseInt(value);
  16288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16289. isSuccess = ConfigurationStatus_Accepted;
  16290. }
  16291. }
  16292. else
  16293. {
  16294. isSuccess = ConfigurationStatus_Rejected;
  16295. }
  16296. }
  16297. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16298. {
  16299. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16300. {
  16301. strcpy(str, (const char*)value);
  16302. for(int i = 0; str[i]; i++)
  16303. {
  16304. str[i] = tolower(str[i]);
  16305. }
  16306. if(strcmp(str, "notapplicable")== 0)
  16307. {
  16308. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16309. isSuccess = ConfigurationStatus_Accepted;
  16310. }
  16311. else if(strcmp(str, "unknown")== 0)
  16312. {
  16313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16314. isSuccess = ConfigurationStatus_Accepted;
  16315. }
  16316. else if(strcmp(str, "rst")== 0)
  16317. {
  16318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16319. isSuccess = ConfigurationStatus_Accepted;
  16320. }
  16321. else if(strcmp(str, "rts")== 0)
  16322. {
  16323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16324. isSuccess = ConfigurationStatus_Accepted;
  16325. }
  16326. else if(strcmp(str, "srt")== 0)
  16327. {
  16328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16329. isSuccess = ConfigurationStatus_Accepted;
  16330. }
  16331. else if(strcmp(str, "str")== 0)
  16332. {
  16333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16334. isSuccess = ConfigurationStatus_Accepted;
  16335. }
  16336. else if(strcmp(str, "trs")== 0)
  16337. {
  16338. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16339. isSuccess = ConfigurationStatus_Accepted;
  16340. }
  16341. else if(strcmp(str, "tsr")== 0)
  16342. {
  16343. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16344. isSuccess = ConfigurationStatus_Accepted;
  16345. }
  16346. else
  16347. {
  16348. isSuccess = ConfigurationStatus_Rejected;
  16349. }
  16350. }
  16351. else
  16352. {
  16353. isSuccess = ConfigurationStatus_Rejected;
  16354. }
  16355. }
  16356. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16357. {
  16358. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16359. {
  16360. check_ascii = value[0];
  16361. if( (check_ascii < 48) || (check_ascii > 57) )
  16362. {
  16363. isSuccess = ConfigurationStatus_Rejected;
  16364. }
  16365. else
  16366. {
  16367. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16368. isSuccess = ConfigurationStatus_Accepted;
  16369. }
  16370. }
  16371. else
  16372. {
  16373. isSuccess = ConfigurationStatus_Rejected;
  16374. }
  16375. }
  16376. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16377. {
  16378. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16379. {
  16380. strcpy(str, (const char*)value);
  16381. for(int i = 0; str[i]; i++)
  16382. {
  16383. str[i] = tolower(str[i]);
  16384. }
  16385. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16387. isSuccess = ConfigurationStatus_Accepted;
  16388. }
  16389. else
  16390. {
  16391. isSuccess = ConfigurationStatus_Rejected;
  16392. }
  16393. }
  16394. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16395. {
  16396. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16397. {
  16398. strcpy(str, (const char*)value);
  16399. for(int i = 0; str[i]; i++)
  16400. {
  16401. str[i] = tolower(str[i]);
  16402. }
  16403. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16404. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16405. isSuccess = ConfigurationStatus_Accepted;
  16406. }
  16407. else
  16408. {
  16409. isSuccess = ConfigurationStatus_Rejected;
  16410. }
  16411. }
  16412. if(strcmp(key, "StopTxnAlignedData") == 0)
  16413. {
  16414. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16415. {
  16416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16417. isSuccess = ConfigurationStatus_Accepted;
  16418. }
  16419. else
  16420. {
  16421. isSuccess = ConfigurationStatus_Rejected;
  16422. }
  16423. }
  16424. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16425. {
  16426. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16427. {
  16428. check_ascii = value[0];
  16429. if( (check_ascii < 48) || (check_ascii > 57) )
  16430. {
  16431. isSuccess = ConfigurationStatus_Rejected;
  16432. }
  16433. else
  16434. {
  16435. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16436. isSuccess = ConfigurationStatus_Accepted;
  16437. }
  16438. }
  16439. else
  16440. {
  16441. isSuccess = ConfigurationStatus_Rejected;
  16442. }
  16443. }
  16444. if(strcmp(key, "StopTxnSampledData") == 0)
  16445. {
  16446. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16447. {
  16448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16449. isSuccess = ConfigurationStatus_Accepted;
  16450. }
  16451. else
  16452. {
  16453. isSuccess = ConfigurationStatus_Rejected;
  16454. }
  16455. }
  16456. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16457. {
  16458. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16459. {
  16460. check_ascii = value[0];
  16461. if( (check_ascii < 48) || (check_ascii > 57) )
  16462. {
  16463. isSuccess = ConfigurationStatus_Rejected;
  16464. }
  16465. else
  16466. {
  16467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16468. isSuccess = ConfigurationStatus_Accepted;
  16469. }
  16470. }
  16471. else
  16472. {
  16473. isSuccess = ConfigurationStatus_Rejected;
  16474. }
  16475. }
  16476. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16477. {
  16478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16479. {
  16480. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16481. isSuccess = ConfigurationStatus_Accepted;
  16482. }
  16483. else
  16484. {
  16485. isSuccess = ConfigurationStatus_Rejected;
  16486. }
  16487. }
  16488. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16489. {
  16490. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16491. {
  16492. check_ascii = value[0];
  16493. if( (check_ascii < 48) || (check_ascii > 57) )
  16494. {
  16495. isSuccess = ConfigurationStatus_Rejected;
  16496. }
  16497. else
  16498. {
  16499. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16500. isSuccess = ConfigurationStatus_Accepted;
  16501. }
  16502. }
  16503. else
  16504. {
  16505. isSuccess = ConfigurationStatus_Rejected;
  16506. }
  16507. }
  16508. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16509. {
  16510. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16511. {
  16512. check_ascii = value[0];
  16513. if( (check_ascii < 48) || (check_ascii > 57) )
  16514. {
  16515. isSuccess = ConfigurationStatus_Rejected;
  16516. }
  16517. else
  16518. {
  16519. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16521. TransactionMessageAttemptsValue = atoi(value);
  16522. isSuccess = ConfigurationStatus_Accepted;
  16523. }
  16524. }
  16525. else
  16526. {
  16527. isSuccess = ConfigurationStatus_Rejected;
  16528. }
  16529. }
  16530. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16531. {
  16532. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16533. {
  16534. check_ascii = value[0];
  16535. if( (check_ascii < 48) || (check_ascii > 57) )
  16536. {
  16537. isSuccess = ConfigurationStatus_Rejected;
  16538. }
  16539. else
  16540. {
  16541. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16543. TransactionMessageRetryIntervalValue = atoi(value);
  16544. isSuccess = ConfigurationStatus_Accepted;
  16545. }
  16546. }
  16547. else
  16548. {
  16549. isSuccess = ConfigurationStatus_Rejected;
  16550. }
  16551. }
  16552. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16553. {
  16554. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16555. {
  16556. strcpy(str, (const char*)value);
  16557. for(int i = 0; str[i]; i++)
  16558. {
  16559. str[i] = tolower(str[i]);
  16560. }
  16561. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16563. isSuccess = ConfigurationStatus_Accepted;
  16564. }
  16565. else
  16566. {
  16567. isSuccess = ConfigurationStatus_Rejected;
  16568. }
  16569. }
  16570. if(strcmp(key, "WebSocketPingInterval") == 0)
  16571. {
  16572. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16573. {
  16574. check_ascii = value[0];
  16575. if( (check_ascii < 48) || (check_ascii > 57) )
  16576. {
  16577. isSuccess = ConfigurationStatus_Rejected;
  16578. }
  16579. else
  16580. {
  16581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16582. isSuccess = ConfigurationStatus_Accepted;
  16583. if((atoi(value) == 0) || (atoi(value) >= 10))
  16584. {
  16585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16586. isSuccess = ConfigurationStatus_Accepted;
  16587. }
  16588. else
  16589. isSuccess = ConfigurationStatus_Rejected;
  16590. }
  16591. }
  16592. else
  16593. {
  16594. isSuccess = ConfigurationStatus_Rejected;
  16595. }
  16596. }
  16597. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16598. {
  16599. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16600. {
  16601. strcpy(str, (const char*)value);
  16602. for(int i = 0; str[i]; i++)
  16603. {
  16604. str[i] = tolower(str[i]);
  16605. }
  16606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16607. isSuccess = ConfigurationStatus_Accepted;
  16608. }
  16609. else
  16610. {
  16611. isSuccess = ConfigurationStatus_Rejected;
  16612. }
  16613. }
  16614. if(strcmp(key, "AuthorizationKey") == 0)
  16615. {
  16616. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16617. {
  16618. strcpy(str, (const char*)value);
  16619. int strlength = strlen(str);
  16620. char capture[3];
  16621. char stackItem = 0;
  16622. char password[21] = {0};
  16623. printf("String length: %d\n", strlength);
  16624. for(int idx=0; idx<(strlength/2); idx++)
  16625. {
  16626. capture[0] = str[(idx*2)];
  16627. capture[1] = str[(idx*2)+1];
  16628. capture[2] = 0;
  16629. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  16630. sprintf(password,"%s%c", password, stackItem);
  16631. }
  16632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  16633. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16634. isSuccess = ConfigurationStatus_Accepted;
  16635. }
  16636. else
  16637. {
  16638. isSuccess = ConfigurationStatus_Rejected;
  16639. }
  16640. }
  16641. if(strcmp(key, "SecurityProfile") == 0)
  16642. {
  16643. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16644. {
  16645. check_ascii = value[0];
  16646. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16647. {
  16648. isSuccess = ConfigurationStatus_Rejected;
  16649. }
  16650. else if(check_ascii == 0x33)
  16651. {
  16652. isSuccess = NotSupported;
  16653. }
  16654. else
  16655. {
  16656. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16657. {
  16658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16659. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16660. isSuccess = ConfigurationStatus_Accepted;
  16661. }
  16662. else
  16663. isSuccess = ConfigurationStatus_Rejected;
  16664. }
  16665. }
  16666. else
  16667. {
  16668. isSuccess = ConfigurationStatus_Rejected;
  16669. }
  16670. }
  16671. if(strcmp(key, "DefaultPrice") == 0)
  16672. {
  16673. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16674. {
  16675. strcpy(str, (const char*)value);
  16676. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16677. isSuccess = ConfigurationStatus_Accepted;
  16678. }
  16679. else
  16680. {
  16681. isSuccess = ConfigurationStatus_Rejected;
  16682. }
  16683. }
  16684. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16685. {
  16686. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16687. {
  16688. strcpy(str, (const char*)value);
  16689. for(int i = 0; str[i]; i++)
  16690. {
  16691. str[i] = tolower(str[i]);
  16692. }
  16693. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16694. isSuccess = ConfigurationStatus_Accepted;
  16695. }
  16696. else
  16697. {
  16698. isSuccess = ConfigurationStatus_Rejected;
  16699. }
  16700. }
  16701. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16702. {
  16703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16704. {
  16705. strcpy(str, (const char*)value);
  16706. for(int i = 0; str[i]; i++)
  16707. {
  16708. str[i] = tolower(str[i]);
  16709. }
  16710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16711. isSuccess = ConfigurationStatus_Accepted;
  16712. }
  16713. else
  16714. {
  16715. isSuccess = ConfigurationStatus_Rejected;
  16716. }
  16717. }
  16718. if(strcmp(key, "SystemUptimeSec") == 0)
  16719. {
  16720. isSuccess = NotSupported;
  16721. }
  16722. if(strcmp(key, "FreeVend") == 0)
  16723. {
  16724. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16725. {
  16726. strcpy(str, (const char*)value);
  16727. for(int i = 0; str[i]; i++)
  16728. {
  16729. str[i] = tolower(str[i]);
  16730. }
  16731. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16732. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16733. isSuccess = ConfigurationStatus_Accepted;
  16734. }
  16735. else
  16736. {
  16737. isSuccess = ConfigurationStatus_Rejected;
  16738. }
  16739. }
  16740. if(strcmp(key, "FreeVendIdtag") == 0)
  16741. {
  16742. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16743. {
  16744. strcpy(str, (const char*)value);
  16745. if(strlen(str) <= 20)
  16746. {
  16747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16748. isSuccess = ConfigurationStatus_Accepted;
  16749. }
  16750. else
  16751. {
  16752. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16753. isSuccess = ConfigurationStatus_Rejected;
  16754. }
  16755. }
  16756. else
  16757. {
  16758. isSuccess = ConfigurationStatus_Rejected;
  16759. }
  16760. }
  16761. if(strcmp(key, "OcppServer") == 0)
  16762. {
  16763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16764. {
  16765. strcpy(str, (const char*)value);
  16766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16767. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16768. isSuccess = ConfigurationStatus_Accepted;
  16769. }
  16770. else
  16771. {
  16772. isSuccess = ConfigurationStatus_Rejected;
  16773. }
  16774. }
  16775. if(strcmp(key, "MaintainServer") == 0)
  16776. {
  16777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16778. {
  16779. strcpy(str, (const char*)value);
  16780. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16781. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16782. isSuccess = ConfigurationStatus_Accepted;
  16783. }
  16784. else
  16785. {
  16786. isSuccess = ConfigurationStatus_Rejected;
  16787. }
  16788. }
  16789. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16790. {
  16791. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16792. {
  16793. strcpy(str, (const char*)value);
  16794. for(int i = 0; str[i]; i++)
  16795. {
  16796. str[i] = tolower(str[i]);
  16797. }
  16798. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16799. isSuccess = ConfigurationStatus_Accepted;
  16800. }
  16801. else
  16802. {
  16803. isSuccess = ConfigurationStatus_Rejected;
  16804. }
  16805. }
  16806. if(strcmp(key, "StatusNotificationInterval") == 0)
  16807. {
  16808. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16809. {
  16810. check_ascii = value[0];
  16811. if( (check_ascii < 48) || (check_ascii > 57) )
  16812. {
  16813. isSuccess = ConfigurationStatus_Rejected;
  16814. }
  16815. else
  16816. {
  16817. if((atoi(value) == 0) || (atoi(value) >= 10))
  16818. {
  16819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16820. isSuccess = ConfigurationStatus_Accepted;
  16821. }
  16822. else
  16823. isSuccess = ConfigurationStatus_Rejected;
  16824. }
  16825. }
  16826. else
  16827. {
  16828. isSuccess = ConfigurationStatus_Rejected;
  16829. }
  16830. }
  16831. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16832. {
  16833. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16834. {
  16835. check_ascii = value[0];
  16836. if( (check_ascii < 48) || (check_ascii > 57) )
  16837. {
  16838. isSuccess = ConfigurationStatus_Rejected;
  16839. }
  16840. else
  16841. {
  16842. if(atoi(value) >= 0)
  16843. {
  16844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16845. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16846. isSuccess = ConfigurationStatus_Accepted;
  16847. }
  16848. else
  16849. isSuccess = ConfigurationStatus_Rejected;
  16850. }
  16851. }
  16852. else
  16853. {
  16854. isSuccess = ConfigurationStatus_Rejected;
  16855. }
  16856. }
  16857. if(strcmp(key, "PowerSharingServerIP") == 0)
  16858. {
  16859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16860. {
  16861. strcpy(str, (const char*)value);
  16862. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16863. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16864. isSuccess = ConfigurationStatus_Accepted;
  16865. }
  16866. else
  16867. {
  16868. isSuccess = ConfigurationStatus_Rejected;
  16869. }
  16870. }
  16871. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16872. {
  16873. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16874. {
  16875. strcpy(str, (const char*)value);
  16876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16877. isSuccess = ConfigurationStatus_Accepted;
  16878. }
  16879. else
  16880. {
  16881. isSuccess = ConfigurationStatus_Rejected;
  16882. }
  16883. }
  16884. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  16885. {
  16886. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16887. {
  16888. if(atoi(value) > modelnameInfo.ratedPower)
  16889. {
  16890. isSuccess = ConfigurationStatus_Rejected;
  16891. }
  16892. else{
  16893. strcpy(str, (const char*)value);
  16894. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  16895. isSuccess = ConfigurationStatus_Accepted;
  16896. }
  16897. }
  16898. else
  16899. {
  16900. isSuccess = ConfigurationStatus_Rejected;
  16901. }
  16902. }
  16903. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  16904. {
  16905. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16906. {
  16907. if((atoi(value) != 0) && (atoi(value) < 5))
  16908. {
  16909. isSuccess = ConfigurationStatus_Rejected;
  16910. }
  16911. else{
  16912. strcpy(str, (const char*)value);
  16913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  16914. isSuccess = ConfigurationStatus_Accepted;
  16915. }
  16916. }
  16917. else
  16918. {
  16919. isSuccess = ConfigurationStatus_Rejected;
  16920. }
  16921. }
  16922. if(strcmp(key, "OcppSoftwareVersion") == 0)
  16923. {
  16924. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  16925. {
  16926. strcpy(str, (const char*)value);
  16927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
  16928. isSuccess = ConfigurationStatus_Accepted;
  16929. }
  16930. else
  16931. {
  16932. isSuccess = ConfigurationStatus_Rejected;
  16933. }
  16934. }
  16935. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  16936. {
  16937. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  16938. {
  16939. strcpy(str, (const char*)value);
  16940. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", str );
  16941. isSuccess = ConfigurationStatus_Accepted;
  16942. }
  16943. else
  16944. {
  16945. isSuccess = ConfigurationStatus_Rejected;
  16946. }
  16947. }
  16948. #if 0
  16949. //For OCPP Test Case
  16950. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16951. {
  16952. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16953. {
  16954. strcpy(str, (const char*)value);
  16955. for(int i = 0; str[i]; i++)
  16956. {
  16957. str[i] = tolower(str[i]);
  16958. }
  16959. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16960. isSuccess = ConfigurationStatus_Accepted;
  16961. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16962. }
  16963. else
  16964. {
  16965. isSuccess = ConfigurationStatus_Rejected;
  16966. }
  16967. }
  16968. #endif
  16969. #if 1
  16970. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16971. {
  16972. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16973. {
  16974. strcpy(str, (const char*)value);
  16975. for(int i = 0; str[i]; i++)
  16976. {
  16977. str[i] = tolower(str[i]);
  16978. }
  16979. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16980. isSuccess = ConfigurationStatus_Accepted;
  16981. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16982. }
  16983. else
  16984. {
  16985. isSuccess = ConfigurationStatus_Rejected;
  16986. }
  16987. }
  16988. #endif
  16989. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16990. {
  16991. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16992. {
  16993. check_ascii = value[0];
  16994. if( (check_ascii < 48) || (check_ascii > 57) )
  16995. {
  16996. isSuccess = ConfigurationStatus_Rejected;
  16997. }
  16998. else
  16999. {
  17000. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17001. isSuccess = ConfigurationStatus_Accepted;
  17002. }
  17003. }
  17004. else
  17005. {
  17006. isSuccess = ConfigurationStatus_Rejected;
  17007. }
  17008. }
  17009. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17010. {
  17011. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17012. {
  17013. check_ascii = value[0];
  17014. if( (check_ascii < 48) || (check_ascii > 57) )
  17015. {
  17016. isSuccess = ConfigurationStatus_Rejected;
  17017. }
  17018. else
  17019. {
  17020. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17021. isSuccess = ConfigurationStatus_Accepted;
  17022. }
  17023. }
  17024. else
  17025. {
  17026. isSuccess = ConfigurationStatus_Rejected;
  17027. }
  17028. }
  17029. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17030. {
  17031. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17032. {
  17033. strcpy(str, (const char*)value);
  17034. for(int i = 0; str[i]; i++)
  17035. {
  17036. str[i] = tolower(str[i]);
  17037. }
  17038. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17039. isSuccess = ConfigurationStatus_Accepted;
  17040. }
  17041. else
  17042. {
  17043. isSuccess = ConfigurationStatus_Rejected;
  17044. }
  17045. }
  17046. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17047. {
  17048. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17049. {
  17050. check_ascii = value[0];
  17051. if( (check_ascii < 48) || (check_ascii > 57) )
  17052. {
  17053. isSuccess = ConfigurationStatus_Rejected;
  17054. }
  17055. else
  17056. {
  17057. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17058. isSuccess = ConfigurationStatus_Accepted;
  17059. }
  17060. }
  17061. else
  17062. {
  17063. isSuccess = ConfigurationStatus_Rejected;
  17064. }
  17065. }
  17066. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17067. {
  17068. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17069. {
  17070. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17071. isSuccess = ConfigurationStatus_Accepted;
  17072. }
  17073. else
  17074. {
  17075. isSuccess = ConfigurationStatus_Rejected;
  17076. }
  17077. }
  17078. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17079. {
  17080. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17081. {
  17082. check_ascii = value[0];
  17083. if( (check_ascii < 48) || (check_ascii > 57) )
  17084. {
  17085. isSuccess = ConfigurationStatus_Rejected;
  17086. }
  17087. else
  17088. {
  17089. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17090. isSuccess = ConfigurationStatus_Accepted;
  17091. }
  17092. }
  17093. else
  17094. {
  17095. isSuccess = ConfigurationStatus_Rejected;
  17096. }
  17097. }
  17098. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17099. {
  17100. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17101. {
  17102. strcpy(str, (const char*)value);
  17103. for(int i = 0; str[i]; i++)
  17104. {
  17105. str[i] = tolower(str[i]);
  17106. }
  17107. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17108. isSuccess = ConfigurationStatus_Accepted;
  17109. }
  17110. else
  17111. {
  17112. isSuccess = ConfigurationStatus_Rejected;
  17113. }
  17114. }
  17115. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17116. {
  17117. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17118. {
  17119. check_ascii = value[0];
  17120. if( (check_ascii < 48) || (check_ascii > 57) )
  17121. {
  17122. isSuccess = ConfigurationStatus_Rejected;
  17123. }
  17124. else
  17125. {
  17126. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17127. isSuccess = ConfigurationStatus_Accepted;
  17128. }
  17129. }
  17130. else
  17131. {
  17132. isSuccess = ConfigurationStatus_Rejected;
  17133. }
  17134. }
  17135. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17136. return isSuccess;
  17137. }
  17138. int TransactionMessageAttemptsGet(void)
  17139. {
  17140. return TransactionMessageAttemptsValue;
  17141. }
  17142. int FirstHeartBeatResponse(void)
  17143. {
  17144. return FirstHeartBeat;
  17145. }
  17146. int TransactionMessageRetryIntervalGet(void)
  17147. {
  17148. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17149. }
  17150. int ReadHttpStatus(int sock)
  17151. {
  17152. //char c;
  17153. char buff[1024]="",*ptr=buff+1;
  17154. int bytes_received, status;
  17155. DEBUG_INFO("Begin Response ..\n");
  17156. while((bytes_received = recv(sock, ptr, 1, 0))){
  17157. if(bytes_received==-1){
  17158. perror("ReadHttpStatus");
  17159. exit(1);
  17160. }
  17161. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17162. ptr++;
  17163. }
  17164. *ptr=0;
  17165. ptr=buff+1;
  17166. sscanf(ptr,"%*s %d ", &status);
  17167. DEBUG_INFO("%s\n",ptr);
  17168. DEBUG_INFO("status=%d\n",status);
  17169. DEBUG_INFO("End Response ..\n");
  17170. return (bytes_received>0)?status:0;
  17171. }
  17172. //the only filed that it parsed is 'Content-Length'
  17173. int ParseHeader(int sock)
  17174. {
  17175. //char c;
  17176. char buff[1024]="",*ptr=buff+4;
  17177. int bytes_received;
  17178. DEBUG_INFO("Begin HEADER ..\n");
  17179. while((bytes_received = recv(sock, ptr, 1, 0))){
  17180. if(bytes_received==-1){
  17181. perror("Parse Header");
  17182. exit(1);
  17183. }
  17184. if(
  17185. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17186. (ptr[-1]=='\r') && (*ptr=='\n' )
  17187. ) break;
  17188. ptr++;
  17189. }
  17190. *ptr=0;
  17191. ptr=buff+4;
  17192. //printf("%s",ptr);
  17193. if(bytes_received){
  17194. ptr=strstr(ptr,"Content-Length:");
  17195. if(ptr){
  17196. sscanf(ptr,"%*s %d",&bytes_received);
  17197. }else
  17198. bytes_received=-1; //unknown size
  17199. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17200. }
  17201. DEBUG_INFO("End HEADER ..\n");
  17202. return bytes_received ;
  17203. }
  17204. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17205. {
  17206. int result = TRUE;
  17207. char rmFileCmd[300]={0};
  17208. char FilePath[256]={0};
  17209. char ftpbuf[2048];
  17210. int systemresult;
  17211. sprintf(FilePath,"/mnt/%s",filename);
  17212. system("ping 8.8.8.8 &");
  17213. if((access(FilePath,F_OK))!=-1)
  17214. {
  17215. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17216. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17217. system(rmFileCmd);
  17218. }
  17219. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17220. if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  17221. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  17222. else
  17223. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17224. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17225. systemresult = system(ftpbuf);
  17226. if(systemresult != 0)
  17227. {
  17228. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17229. result = FALSE;
  17230. }
  17231. system("pkill ping");
  17232. return result;
  17233. }
  17234. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17235. {
  17236. int result = TRUE;
  17237. char rmFileCmd[300]={0};
  17238. char FilePath[256]={0};
  17239. char ftpbuf[2048];
  17240. int systemresult;
  17241. sprintf(FilePath,"/mnt/%s",filename);
  17242. system("ping 8.8.8.8 &");
  17243. if((access(FilePath,F_OK))!=-1)
  17244. {
  17245. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17246. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17247. system(rmFileCmd);
  17248. }
  17249. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17250. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17251. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17252. systemresult = system(ftpbuf);
  17253. if(systemresult != 0)
  17254. {
  17255. DEBUG_WARN("scp error!\n");
  17256. result = FALSE;
  17257. }
  17258. system("pkill ping");
  17259. return result;
  17260. }
  17261. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17262. {
  17263. int result = TRUE;
  17264. char rmFileCmd[300]={0};
  17265. char FilePath[256]={0};
  17266. char ftpbuf[2048];
  17267. int systemresult;
  17268. sprintf(FilePath,"/mnt/%s",filename);
  17269. system("ping 8.8.8.8 &");
  17270. if((access(FilePath,F_OK))!=-1)
  17271. {
  17272. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17273. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17274. system(rmFileCmd);
  17275. }
  17276. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17277. if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  17278. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  17279. else
  17280. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17281. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17282. systemresult = system(ftpbuf);
  17283. if(systemresult != 0)
  17284. {
  17285. if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  17286. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  17287. else
  17288. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  17289. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17290. systemresult = system(ftpbuf);
  17291. if(systemresult != 0)
  17292. {
  17293. DEBUG_WARN("FTP download fail!\n");
  17294. result = FALSE;
  17295. }
  17296. }
  17297. system("pkill ping");
  17298. return result;
  17299. }
  17300. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17301. {
  17302. char rmFileCmd[100]={0};
  17303. char FilePath[100]={0};
  17304. char buf[512];
  17305. int systemresult = 0;
  17306. //DEBUG_INFO("filename=%s\n",filename);
  17307. //DEBUG_INFO("url=%s\n",url);
  17308. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17309. if((access(FilePath,F_OK))!=-1)
  17310. {
  17311. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17312. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17313. system(rmFileCmd);
  17314. }
  17315. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17316. if(fp == NULL)
  17317. {
  17318. DEBUG_INFO("log is NULL\n");
  17319. return FALSE;
  17320. }
  17321. else
  17322. {
  17323. fprintf(fp, "%s\n", url);
  17324. fprintf(fp, "%s\n", filename);
  17325. fclose(fp);
  17326. }
  17327. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17328. if(phpFP == NULL)
  17329. {
  17330. DEBUG_INFO("PHP upload fail.\n");
  17331. return FALSE;
  17332. }
  17333. else
  17334. {
  17335. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17336. {
  17337. if(strstr(buf, "result") != NULL)
  17338. {
  17339. sscanf(buf, "result: %d", &systemresult);
  17340. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17341. }
  17342. }
  17343. pclose(phpFP);
  17344. }
  17345. if(systemresult != 1)
  17346. {
  17347. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17348. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17349. if(phpFP == NULL)
  17350. {
  17351. DEBUG_WARN("PHP PUT upload fail.\n");
  17352. return FALSE;
  17353. }
  17354. else
  17355. {
  17356. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17357. {
  17358. if(strstr(buf, "result") != NULL)
  17359. {
  17360. sscanf(buf, "result: %d", &systemresult);
  17361. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17362. }
  17363. }
  17364. pclose(phpFP);
  17365. }
  17366. }
  17367. if(systemresult != 1)
  17368. {
  17369. DEBUG_WARN("PHP PUT upload fail.\n");
  17370. return FALSE;
  17371. }
  17372. return TRUE;
  17373. }
  17374. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17375. {
  17376. int result = FALSE;
  17377. char ftpbuf[200];
  17378. int systemresult;
  17379. /*
  17380. // Domaind name transfer to IP address
  17381. struct hostent* server;
  17382. char *IPbuffer;
  17383. server = gethostbyname(location);
  17384. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17385. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17386. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17387. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17388. systemresult = system(ftpbuf);
  17389. if(systemresult != 0)
  17390. {
  17391. DEBUG_INFO("ftpput error!\n");
  17392. }
  17393. else
  17394. {
  17395. result = TRUE;
  17396. DEBUG_INFO("ftpput OK!\n");
  17397. }
  17398. return result;
  17399. }
  17400. int GetOcppServerURL()
  17401. {
  17402. int result = FALSE;
  17403. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17404. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17405. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17406. struct yuarel url;
  17407. char urlStr[512];
  17408. // OCPPPH only
  17409. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17410. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17411. {
  17412. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17413. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17414. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17415. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17416. if(yuarel_parse(&url, urlStr) != -1)
  17417. {
  17418. sprintf(OcppProtocol, "%s", url.scheme);
  17419. sprintf(OcppHost, "%s", url.host);
  17420. if(url.path == NULL)
  17421. OcppTempPath[0] = '\0';
  17422. else
  17423. sprintf(OcppTempPath, "%s", url.path);
  17424. if(url.port == 0)
  17425. {
  17426. if(strcmp(OcppProtocol, "wss") == 0)
  17427. OcppPort = 443;
  17428. else
  17429. OcppPort = 80;
  17430. }
  17431. else
  17432. OcppPort = url.port;
  17433. result = TRUE;
  17434. }
  17435. }
  17436. else
  17437. {
  17438. strcpy(OcppHost,"");
  17439. }
  17440. return result;
  17441. }
  17442. int GetOcppPath()
  17443. {
  17444. int result = FALSE;
  17445. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17446. {
  17447. if(OcppTempPath == NULL)
  17448. {
  17449. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17450. }
  17451. else
  17452. {
  17453. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17454. }
  17455. result = TRUE;
  17456. goto End;
  17457. }
  17458. else
  17459. {
  17460. strcpy(OcppPath,"");
  17461. }
  17462. End:
  17463. return result;
  17464. }
  17465. int GetOcppPort()
  17466. {
  17467. return OcppPort;
  17468. }
  17469. int GetOcppConnStatus(void)
  17470. {
  17471. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17472. }
  17473. void SetOcppConnStatus(uint8_t status)
  17474. {
  17475. ShmOCPP16DataPH->OcppConnStatus = status;
  17476. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17477. }
  17478. int GetHeartBeatWithNOResponse(void)
  17479. {
  17480. return HeartBeatWithNOResponse;
  17481. }
  17482. void SetHeartBeatWithNOResponse(void)
  17483. {
  17484. HeartBeatWithNOResponse = 0;
  17485. }
  17486. void GetStartTransactionIdTag(int gun_index)
  17487. {
  17488. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17489. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17490. }
  17491. int GetStartTransactionId(int gun_index)
  17492. {
  17493. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17494. }
  17495. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17496. {
  17497. char ch;
  17498. FILE *fptr1;
  17499. int temptransactionId;
  17500. char str[100]={0};
  17501. temptransactionId = 0;
  17502. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17503. {
  17504. DEBUG_INFO("IdTag is empty.\n");
  17505. return temptransactionId;
  17506. }
  17507. /*------ Read the file ----------------*/
  17508. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17509. if (!fptr1)
  17510. {
  17511. DEBUG_INFO("QueueTransactionId file open error.\n");
  17512. //printf(" File not found or unable to open the input file!!\n");
  17513. return temptransactionId;
  17514. }
  17515. ch=fgetc(fptr1);
  17516. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17517. rewind(fptr1);
  17518. if(ch!=EOF)
  17519. {
  17520. // printf("%c",ch);
  17521. while (fgets(str, 100, fptr1) != NULL)
  17522. {
  17523. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17524. if(str[0]=='\0')
  17525. {
  17526. break;
  17527. }
  17528. char *revbuf[8] = {0}; // Variable store string split
  17529. int num = 0;// Quantity after string split
  17530. DEBUG_INFO("Transaction queue data= %s\n", str);
  17531. splitstring(str,",",revbuf,&num); // String split
  17532. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17533. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17534. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17535. DEBUG_INFO("------------------------------\n");
  17536. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17537. {
  17538. if(isStopTransaction)
  17539. {
  17540. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17541. {
  17542. temptransactionId = atoi(revbuf[2]);
  17543. //break;
  17544. }
  17545. }
  17546. else
  17547. {
  17548. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17549. {
  17550. temptransactionId = atoi(revbuf[2]);
  17551. //break;
  17552. }
  17553. }
  17554. }
  17555. }
  17556. }
  17557. else
  17558. DEBUG_INFO("EOF\n");
  17559. fclose(fptr1);
  17560. /*------- End of reading ---------------*/
  17561. return temptransactionId;
  17562. }
  17563. void SetTransactionIdZero(int transactionId)
  17564. {
  17565. char ch;
  17566. FILE *fptr1, *fptr2;
  17567. int temptransactionId = 0;
  17568. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17569. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17570. if (!fptr1)
  17571. {
  17572. //printf(" File not found or unable to open the input file!!\n");
  17573. return ;
  17574. }
  17575. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17576. if (!fptr2)
  17577. {
  17578. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17579. fclose(fptr1);
  17580. return ;
  17581. }
  17582. ch=fgetc(fptr1);
  17583. rewind(fptr1);
  17584. if(ch!=EOF)
  17585. {
  17586. // copy all contents to the temporary file except the specific line
  17587. while (fgets(str, 100, fptr1) != NULL)
  17588. {
  17589. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17590. if(str[0]=='\0')
  17591. {
  17592. break;
  17593. }
  17594. char *revbuf[8] = {0};
  17595. int num = 0;
  17596. strcpy(strtemp, str);
  17597. splitstring(str,",",revbuf,&num);
  17598. if(revbuf[2][0] != '\0')
  17599. {
  17600. temptransactionId = atoi(revbuf[2]);
  17601. if(transactionId != temptransactionId)
  17602. {
  17603. fprintf(fptr2, "%s\n", strtemp);
  17604. }
  17605. }
  17606. }
  17607. }
  17608. fclose(fptr1);
  17609. fclose(fptr2);
  17610. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17611. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17612. /*------ Read the file ----------------*/
  17613. }
  17614. int InternetDisconnect(void)
  17615. {
  17616. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17617. }
  17618. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17619. void storeTempStopTransaction(int gun_index)
  17620. {
  17621. char guid[37]={0};
  17622. int tempIndex = 0;
  17623. char TempStopTransaction[256];
  17624. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17625. DEBUG_INFO("storeTempStopTransaction...\n");
  17626. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17627. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17628. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17629. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17630. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17631. {
  17632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17633. {
  17634. tempIndex = ((gun_index==2) ? 1: 0);
  17635. }
  17636. else
  17637. {
  17638. tempIndex = gun_index;
  17639. }
  17640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17641. {
  17642. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17643. {
  17644. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17645. }
  17646. }// END OF CHAdeMO_QUANTITY
  17647. }
  17648. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17649. {
  17650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17651. {
  17652. tempIndex = ((gun_index==2) ? 1: 0);
  17653. }
  17654. else
  17655. {
  17656. tempIndex = gun_index;
  17657. }
  17658. for (int index = 0; index < CCS_QUANTITY; index++)
  17659. {
  17660. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17661. {
  17662. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17663. }
  17664. }// END OF CCS_QUANTITY
  17665. }
  17666. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17667. {
  17668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17669. {
  17670. tempIndex = ((gun_index==2) ? 1: 0);
  17671. }
  17672. else
  17673. {
  17674. tempIndex = gun_index;
  17675. }
  17676. for (int index = 0; index < GB_QUANTITY; index++)
  17677. {
  17678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17679. {
  17680. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17681. }
  17682. }// END OF GB_QUANTITY
  17683. }
  17684. else if(gunType[gun_index] == GUN_TYPE_DO)
  17685. {
  17686. tempIndex = gun_index;
  17687. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17688. {
  17689. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17690. {
  17691. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17692. }
  17693. }
  17694. }
  17695. else
  17696. {
  17697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17698. {
  17699. tempIndex = 2;
  17700. }
  17701. else
  17702. {
  17703. tempIndex = gun_index;
  17704. }
  17705. for (int index = 0; index < AC_QUANTITY; index++)
  17706. {
  17707. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17708. {
  17709. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17710. }
  17711. }// END OF AC_QUANTITY
  17712. }
  17713. //Stop Transaction Time
  17714. struct timeval tmnow;
  17715. struct tm *tm;
  17716. char buf[28];//, usec_buf[6];
  17717. gettimeofday(&tmnow, NULL);
  17718. time_t t;
  17719. t = time(NULL);
  17720. /*UTC time and date*/
  17721. tm = gmtime(&t);
  17722. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17723. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17724. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17725. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17726. random_uuid(guid);
  17727. /***********************************transactionData******************************************************/
  17728. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17730. //=================================
  17731. //1. Transaction_Begin
  17732. //=================================
  17733. //============================== Energy.Active.Import.Interval ===========================================
  17734. //=================================
  17735. //2. Transaction_End
  17736. //=================================
  17737. //2.1====================================== Current.Import L1 ==============================================
  17738. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17739. {
  17740. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17741. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17742. {
  17743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17744. {
  17745. tempIndex = ((gun_index==2) ? 1: 0);
  17746. }
  17747. else
  17748. {
  17749. tempIndex = gun_index;
  17750. }
  17751. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17752. {
  17753. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17754. {
  17755. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17756. }
  17757. }// End of for CHAdeMO_QUANTITY
  17758. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17759. }
  17760. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17761. {
  17762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17763. {
  17764. tempIndex = ((gun_index==2) ? 1: 0);
  17765. }
  17766. else
  17767. {
  17768. tempIndex = gun_index;
  17769. }
  17770. for (int index = 0; index < CCS_QUANTITY; index++)
  17771. {
  17772. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17773. {
  17774. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17775. }
  17776. }// End of for CCS_QUANTITY
  17777. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17778. }
  17779. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17780. {
  17781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17782. {
  17783. tempIndex = ((gun_index==2) ? 1: 0);
  17784. }
  17785. else
  17786. {
  17787. tempIndex = gun_index;
  17788. }
  17789. for (int index = 0; index < GB_QUANTITY; index++)
  17790. {
  17791. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17792. {
  17793. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17794. }
  17795. }// End of for GB_QUANTITY
  17796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  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. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17806. }
  17807. }
  17808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17809. }
  17810. else
  17811. {
  17812. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17813. {
  17814. tempIndex = 2;
  17815. }
  17816. else
  17817. {
  17818. tempIndex = gun_index;
  17819. }
  17820. for (int index = 0; index < AC_QUANTITY; index++)
  17821. {
  17822. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17823. {
  17824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17825. }
  17826. }// End of for AC_QUANTITY
  17827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17828. }
  17829. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17831. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17832. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17833. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17834. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17835. }
  17836. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17837. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17838. {
  17839. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17840. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17841. {
  17842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17843. {
  17844. tempIndex = ((gun_index==2) ? 1: 0);
  17845. }
  17846. else
  17847. {
  17848. tempIndex = gun_index;
  17849. }
  17850. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17851. {
  17852. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17853. {
  17854. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17855. }
  17856. }// END OF CHAdeMO_QUANTITY
  17857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17858. }
  17859. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17860. {
  17861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17862. {
  17863. tempIndex = ((gun_index==2) ? 1: 0);
  17864. }
  17865. else
  17866. {
  17867. tempIndex = gun_index;
  17868. }
  17869. for (int index = 0; index < CCS_QUANTITY; index++)
  17870. {
  17871. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17872. {
  17873. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17874. }
  17875. }// END OF CCS_QUANTITY
  17876. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17877. }
  17878. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17879. {
  17880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17881. {
  17882. tempIndex = ((gun_index==2) ? 1: 0);
  17883. }
  17884. else
  17885. {
  17886. tempIndex = gun_index;
  17887. }
  17888. for (int index = 0; index < GB_QUANTITY; index++)
  17889. {
  17890. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17891. {
  17892. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17893. }
  17894. }// END OF GB_QUANTITY
  17895. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17896. }
  17897. else if(gunType[gun_index] == GUN_TYPE_DO)
  17898. {
  17899. tempIndex = gun_index;
  17900. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17901. {
  17902. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17903. {
  17904. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17905. }
  17906. }
  17907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17908. }
  17909. else
  17910. {
  17911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17912. {
  17913. tempIndex = 2;
  17914. }
  17915. else
  17916. {
  17917. tempIndex = gun_index;
  17918. }
  17919. for (int index = 0; index < AC_QUANTITY; index++)
  17920. {
  17921. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17922. {
  17923. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17924. }
  17925. }// END OF AC_QUANTITY
  17926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17927. }
  17928. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17930. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17931. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17932. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17933. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17934. }
  17935. //2.3====================================== Power.Active.Import =========================================
  17936. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17937. {
  17938. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17940. {
  17941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17942. {
  17943. tempIndex = ((gun_index==2) ? 1: 0);
  17944. }
  17945. else
  17946. {
  17947. tempIndex = gun_index;
  17948. }
  17949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17950. {
  17951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17952. {
  17953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17954. }
  17955. } // End for CHAdeMO_QUANTITY
  17956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17957. }
  17958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17959. {
  17960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17961. {
  17962. tempIndex = ((gun_index==2) ? 1: 0);
  17963. }
  17964. else
  17965. {
  17966. tempIndex = gun_index;
  17967. }
  17968. for (int index = 0; index < CCS_QUANTITY; index++)
  17969. {
  17970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17971. {
  17972. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17973. }
  17974. } // END for CCS_QUANTITY
  17975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17976. }
  17977. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17978. {
  17979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17980. {
  17981. tempIndex = ((gun_index==2) ? 1: 0);
  17982. }
  17983. else
  17984. {
  17985. tempIndex = gun_index;
  17986. }
  17987. for (int index = 0; index < GB_QUANTITY; index++)
  17988. {
  17989. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17990. {
  17991. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17992. }
  17993. }// END for GB_QUANTITY
  17994. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17995. }
  17996. else if(gunType[gun_index] == GUN_TYPE_DO)
  17997. {
  17998. tempIndex = gun_index;
  17999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18000. {
  18001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18002. {
  18003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18004. }
  18005. }
  18006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18007. }
  18008. else
  18009. {
  18010. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18011. {
  18012. tempIndex = 2;
  18013. }
  18014. else
  18015. {
  18016. tempIndex = gun_index;
  18017. }
  18018. for (int index = 0; index < AC_QUANTITY; index++)
  18019. {
  18020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18021. {
  18022. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18023. }
  18024. } // END for AC_QUANTITY
  18025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18026. }
  18027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18030. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18033. }
  18034. //2.4====================================== Voltage L1 ====================================================
  18035. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18036. {
  18037. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18038. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18039. {
  18040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18041. {
  18042. tempIndex = ((gun_index==2) ? 1: 0);
  18043. }
  18044. else
  18045. {
  18046. tempIndex = gun_index;
  18047. }
  18048. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18049. {
  18050. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18051. {
  18052. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18053. }
  18054. } // END OF FOR CHAdeMO_QUANTITY
  18055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18056. }
  18057. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18058. {
  18059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18060. {
  18061. tempIndex = ((gun_index==2) ? 1: 0);
  18062. }
  18063. else
  18064. {
  18065. tempIndex = gun_index;
  18066. }
  18067. for (int index = 0; index < CCS_QUANTITY; index++)
  18068. {
  18069. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18070. {
  18071. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18072. }
  18073. } // END OF FOR CCS_QUANTITY
  18074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18075. }
  18076. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18077. {
  18078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18079. {
  18080. tempIndex = ((gun_index==2) ? 1: 0);
  18081. }
  18082. else
  18083. {
  18084. tempIndex = gun_index;
  18085. }
  18086. for (int index = 0; index < GB_QUANTITY; index++)
  18087. {
  18088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18089. {
  18090. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18091. }
  18092. } // END OF FOR GB_QUANTITY
  18093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18094. }
  18095. else if(gunType[gun_index] == GUN_TYPE_DO)
  18096. {
  18097. tempIndex = gun_index;
  18098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18099. {
  18100. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18101. {
  18102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18103. }
  18104. }
  18105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18106. }
  18107. else
  18108. {
  18109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18110. {
  18111. tempIndex = 2;
  18112. }
  18113. else
  18114. {
  18115. tempIndex = gun_index;
  18116. }
  18117. for (int index = 0; index < AC_QUANTITY; index++)
  18118. {
  18119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18120. {
  18121. 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
  18122. }
  18123. } // END OF FOR AC_QUANTITY
  18124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18125. }
  18126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18127. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18129. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18130. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18131. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18132. }
  18133. //2.5============================================== End SoC =========================================================
  18134. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18135. {
  18136. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18137. 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))
  18138. {
  18139. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18140. {
  18141. tempIndex = ((gun_index==2) ? 1: 0);
  18142. }
  18143. else
  18144. {
  18145. tempIndex = gun_index;
  18146. }
  18147. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18148. {
  18149. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18150. {
  18151. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18152. {
  18153. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18154. }
  18155. }
  18156. }
  18157. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18158. {
  18159. for (int index = 0; index < CCS_QUANTITY; index++)
  18160. {
  18161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18162. {
  18163. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18164. }
  18165. }
  18166. }
  18167. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18168. {
  18169. for (int index = 0; index < GB_QUANTITY; index++)
  18170. {
  18171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18172. {
  18173. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18174. }
  18175. }
  18176. }
  18177. else if(gunType[gun_index] == GUN_TYPE_DO)
  18178. {
  18179. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18180. {
  18181. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18182. {
  18183. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18184. }
  18185. }
  18186. }
  18187. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18188. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18189. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18191. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18192. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18193. } // END FOR DC CASE
  18194. }
  18195. //2.6====================================== Current.Import L2 ==============================================
  18196. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18197. {
  18198. // AC 3 phase L2 current
  18199. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18200. {
  18201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18202. {
  18203. tempIndex = 2;
  18204. }
  18205. else
  18206. {
  18207. tempIndex = gun_index;
  18208. }
  18209. for (int index = 0; index < AC_QUANTITY; index++)
  18210. {
  18211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18212. {
  18213. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18214. }
  18215. }// End of for AC_QUANTITY
  18216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18217. }
  18218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18221. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18222. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18223. }
  18224. //2.7====================================== Current.Import L3 ==============================================
  18225. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18226. {
  18227. // AC 3 phase L3 current
  18228. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18229. {
  18230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18231. {
  18232. tempIndex = 2;
  18233. }
  18234. else
  18235. {
  18236. tempIndex = gun_index;
  18237. }
  18238. for (int index = 0; index < AC_QUANTITY; index++)
  18239. {
  18240. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18241. {
  18242. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18243. }
  18244. }// End of for AC_QUANTITY
  18245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18246. }
  18247. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18248. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18249. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18250. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18251. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18252. }
  18253. //2.9====================================== Voltage L2 ====================================================
  18254. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18255. {
  18256. // AC 3 phase L2 volatge
  18257. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18258. {
  18259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18260. {
  18261. tempIndex = 2;
  18262. }
  18263. else
  18264. {
  18265. tempIndex = gun_index;
  18266. }
  18267. for (int index = 0; index < AC_QUANTITY; index++)
  18268. {
  18269. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18270. {
  18271. 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
  18272. }
  18273. } // END OF FOR AC_QUANTITY
  18274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18275. }
  18276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18281. }
  18282. //2.10====================================== Voltage L3 ====================================================
  18283. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18284. {
  18285. // AC 3 phase L3 volatge
  18286. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18287. {
  18288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18289. {
  18290. tempIndex = 2;
  18291. }
  18292. else
  18293. {
  18294. tempIndex = gun_index;
  18295. }
  18296. for (int index = 0; index < AC_QUANTITY; index++)
  18297. {
  18298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18299. {
  18300. 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
  18301. }
  18302. } // END OF FOR AC_QUANTITY
  18303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18304. }
  18305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18310. }
  18311. //====================== Start SoC ================================
  18312. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18313. {
  18314. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18315. 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))
  18316. {
  18317. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18318. {
  18319. tempIndex = ((gun_index==2) ? 1: 0);
  18320. }
  18321. else
  18322. {
  18323. tempIndex = gun_index;
  18324. }
  18325. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18326. {
  18327. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18328. {
  18329. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18330. {
  18331. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18332. }
  18333. }
  18334. }
  18335. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18336. {
  18337. for (int index = 0; index < CCS_QUANTITY; index++)
  18338. {
  18339. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18340. {
  18341. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18342. }
  18343. }
  18344. }
  18345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18346. {
  18347. for (int index = 0; index < GB_QUANTITY; index++)
  18348. {
  18349. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18350. {
  18351. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18352. }
  18353. }
  18354. }
  18355. else if(gunType[gun_index] == GUN_TYPE_DO)
  18356. {
  18357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18358. {
  18359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18360. {
  18361. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18362. }
  18363. }
  18364. }
  18365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18368. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18370. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18371. } // END FOR DC CASE
  18372. }
  18373. //======================================== Message create ==============================================
  18374. json_object *StopTransaction = json_object_new_object();
  18375. json_object *transactionDatas = json_object_new_array();
  18376. json_object *sampledValues = json_object_new_array();
  18377. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18378. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18379. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18380. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18381. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18382. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18383. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18384. {
  18385. json_object *transactionData = json_object_new_object();
  18386. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18387. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18388. {
  18389. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18390. {
  18391. json_object *sampledValue = json_object_new_object();
  18392. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18393. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18394. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18395. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18396. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18397. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18398. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18399. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18400. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18401. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18402. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18403. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18404. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18405. json_object_array_add(sampledValues, sampledValue);
  18406. }
  18407. }
  18408. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18409. json_object_array_add(transactionDatas, transactionData);
  18410. }
  18411. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18412. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18413. ,MESSAGE_TYPE_CALL
  18414. ,guid
  18415. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18416. json_object_put(StopTransaction);
  18417. // Check File "TempStopTransaction" Exist
  18418. if((access(TempStopTransaction,F_OK))!=-1)
  18419. {
  18420. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18421. fclose(fopen(TempStopTransaction, "w"));
  18422. }
  18423. else
  18424. {
  18425. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18426. FILE *log = fopen(TempStopTransaction, "w+");
  18427. if(log == NULL)
  18428. {
  18429. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18430. return ;
  18431. }
  18432. else
  18433. {
  18434. fclose(log);
  18435. }
  18436. }
  18437. //Add TempStopTransaction | Update TempStopTransaction
  18438. // open file for writing
  18439. FILE *outfile;
  18440. outfile = fopen (TempStopTransaction, "a");
  18441. //DEBUG_INFO("data = %s\n", queuedata);
  18442. fputs(queuedata, outfile);
  18443. fputs("\n", outfile);
  18444. fclose (outfile);
  18445. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18446. }
  18447. void checkTempStopTransaction(int gun_index)
  18448. {
  18449. FILE *fptr1;
  18450. char ch;
  18451. char str[QUEUE_MESSAGE_LENGTH]={0};
  18452. char guid[37]={0};
  18453. char tempdata[65]={0};
  18454. char connectorStr[2]={0};
  18455. char TempStopTransaction[256];
  18456. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18457. fptr1 = fopen(TempStopTransaction, "r");
  18458. //TempStopTransaction格式: 槍號,StopTransaction封包
  18459. if (!fptr1)
  18460. {
  18461. //printf(" File not found or unable to open the input file!!\n");
  18462. return ;
  18463. }
  18464. ch=fgetc(fptr1);
  18465. //printf(" Now the content of the file %s is : \n",fname);
  18466. rewind(fptr1);
  18467. if(ch!=EOF)
  18468. {
  18469. // copy all contents to the temporary file except the specific line
  18470. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18471. {
  18472. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18473. if(str[0]=='\0')
  18474. {
  18475. break;
  18476. }
  18477. //TempStopTransaction格式: 槍號,StopTransaction封包
  18478. strncpy(connectorStr, str, 1);
  18479. if(atoi(connectorStr) != (gun_index+1))
  18480. {
  18481. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18482. fclose(fptr1);
  18483. return ;
  18484. }
  18485. //random_uuid(guid);
  18486. strncpy(guid, str+6, 36); //copy guid
  18487. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18488. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18489. {
  18490. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18491. }
  18492. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18493. OCPP_insert_transaction_msg(NO, str);
  18494. memset(str,0,ARRAY_SIZE(str));
  18495. }
  18496. }
  18497. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18498. fclose(fptr1);
  18499. remove(TempStopTransaction); // remove the original file
  18500. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18501. }
  18502. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18503. {
  18504. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18505. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18506. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18507. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18508. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18509. }
  18510. int GetWebSocketPingInterval(void)
  18511. {
  18512. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18513. }
  18514. int GetServerSign(void)
  18515. {
  18516. return server_sign;
  18517. }
  18518. uint8_t GetOcppSecurityProfile()
  18519. {
  18520. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18521. }
  18522. void GetOcppChargerBoxId(uint8_t *data)
  18523. {
  18524. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18525. }
  18526. void GetOcppSecurityPassword(uint8_t *data)
  18527. {
  18528. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18529. }
  18530. void SetOcppVersion(uint8_t *version)
  18531. {
  18532. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18533. DEBUG_INFO("ocpp version: %s\n", version);
  18534. if(strstr((char*)version, "ocpp1.6") != NULL)
  18535. {
  18536. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18537. }
  18538. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18539. {
  18540. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18541. system("pkill OcppBackend");
  18542. }
  18543. }
  18544. void SetServerSign(int value)
  18545. {
  18546. server_sign = value;
  18547. }
  18548. int GetBootNotificationInterval(void)
  18549. {
  18550. return BootNotificationInterval;
  18551. }
  18552. int GetInternetConn(void)
  18553. {
  18554. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18555. }
  18556. int GetBackendConnectionTimeout(void)
  18557. {
  18558. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18559. }
  18560. int isConnectorInitMode(int gun_index)
  18561. {
  18562. int tempIndex = 0;
  18563. int result = TRUE;
  18564. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18565. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18566. {
  18567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18568. {
  18569. tempIndex = ((gun_index==2) ? 1: 0);
  18570. }
  18571. else
  18572. {
  18573. tempIndex = gun_index;
  18574. }
  18575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18576. {
  18577. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18578. {
  18579. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18580. } //end of the same index
  18581. }//end of for CHAdeMO_QUANTITY
  18582. }
  18583. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18584. {
  18585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18586. {
  18587. tempIndex = ((gun_index==2) ? 1: 0);
  18588. }
  18589. else
  18590. {
  18591. tempIndex = gun_index;
  18592. }
  18593. for (int index = 0; index < CCS_QUANTITY; index++)
  18594. {
  18595. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18596. {
  18597. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18598. } //end of the same index
  18599. } // end of for CCS_QUANTITY
  18600. }
  18601. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18602. {
  18603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18604. {
  18605. tempIndex = ((gun_index==2) ? 1: 0);
  18606. }
  18607. else
  18608. {
  18609. tempIndex = gun_index;
  18610. }
  18611. for (int index = 0; index < GB_QUANTITY; index++)
  18612. {
  18613. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18614. {
  18615. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18616. } //end of the same index
  18617. } // end of for GB_QUANTITY
  18618. }
  18619. else if(gunType[gun_index] == GUN_TYPE_DO)
  18620. {
  18621. tempIndex = gun_index;
  18622. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18623. {
  18624. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18625. {
  18626. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18627. } //end of the same index
  18628. }
  18629. }
  18630. else
  18631. {
  18632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18633. {
  18634. tempIndex = 2;
  18635. }
  18636. else
  18637. {
  18638. tempIndex = gun_index;
  18639. }
  18640. for (int index = 0; index < AC_QUANTITY; index++)
  18641. {
  18642. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18643. {
  18644. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18645. }//end of the same index
  18646. }//end of for AC_QUANTITY
  18647. }
  18648. return result;
  18649. }
  18650. void refreshProcDogTimer()
  18651. {
  18652. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18653. }
  18654. void InitialSystemValue(void)
  18655. {
  18656. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18657. locallistVersion=0;
  18658. BootNotificationInterval = 0;
  18659. authorizeRetryTimes = 0;
  18660. GunStatusInterval = 10;
  18661. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18662. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18663. //Heart Beat
  18664. HeartBeatWithNOResponse = 0;
  18665. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  18666. if(HeartBeatWaitTime == 0)
  18667. FirstHeartBeat = TRUE;
  18668. else
  18669. FirstHeartBeat = FALSE;
  18670. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18671. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18672. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18673. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18674. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18675. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18676. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18677. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18678. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18679. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18680. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18681. //Status && ConnectorPlugIn Setting
  18682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18683. {
  18684. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18685. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18686. }
  18687. for (int index = 0; index < CCS_QUANTITY; index++)
  18688. {
  18689. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18690. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18691. }
  18692. for (int index = 0; index < GB_QUANTITY; index++)
  18693. {
  18694. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18695. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18696. }
  18697. for (int index = 0; index < AC_QUANTITY; index++)
  18698. {
  18699. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18700. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18701. }
  18702. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18703. {
  18704. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18705. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18706. }
  18707. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18708. {
  18709. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18710. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18711. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18712. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18713. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18714. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18715. }
  18716. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18717. refreshStartTimer(&clientTime.Heartbeat);
  18718. sleep(1);
  18719. }
  18720. void LWS_Send(char *str)
  18721. {
  18722. //=====================================================
  18723. // Check InternetConn 0: disconnected, 1: connected
  18724. //====================================================
  18725. if(GetOcppConnStatus() == 0)
  18726. {
  18727. DEBUG_INFO("offline now !!!\n");
  18728. return;
  18729. }
  18730. // Only disable isWebsocketSendable operation initiated by charger
  18731. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18732. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18733. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18734. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18735. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18736. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18737. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18738. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18739. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18740. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18741. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18742. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18743. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18744. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18745. {
  18746. isWebsocketSendable = 0;
  18747. }
  18748. pthread_mutex_lock(&lock_send);
  18749. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18750. sprintf((char *)SendBuffer, "%s", str);
  18751. SendBufLen = strlen(str);
  18752. pthread_mutex_unlock(&lock_send);
  18753. lws_callback_on_writable(wsi_client);
  18754. //lws_service(context, 0);
  18755. //sleep(1);
  18756. }
  18757. void LWS_SendNow(char *str)
  18758. {
  18759. //=====================================================
  18760. // Check InternetConn 0: disconnected, 1: connected
  18761. //====================================================
  18762. if(GetOcppConnStatus() == 0)
  18763. {
  18764. DEBUG_INFO("offline now !!!\n");
  18765. return;
  18766. }
  18767. // Only disable isWebsocketSendable operation initiated by charger
  18768. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18769. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18770. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18771. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18772. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18773. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18774. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18775. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18776. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18777. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18778. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18779. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18780. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18781. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18782. {
  18783. isWebsocketSendable = 0;
  18784. }
  18785. pthread_mutex_lock(&lock_send);
  18786. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18787. sprintf((char *)SendBuffer, "%s", str);
  18788. SendBufLen = strlen(str);
  18789. pthread_mutex_unlock(&lock_send);
  18790. lws_callback_on_writable(wsi_client);
  18791. lws_service(context, 0);
  18792. //sleep(1);
  18793. }