MessageHandler.c 906 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '0');", txId, creditNo, deductResult, isDonateInvoice, amount, vemData);
  680. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  681. {
  682. result = FAIL;
  683. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  684. }
  685. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. return result;
  692. }
  693. int OCPP_update_deduct_info(int txId, char *creditNo)
  694. {
  695. int result = PASS;
  696. char* errMsg = NULL;
  697. char sqlStr[8192];
  698. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  699. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  700. {
  701. result = FAIL;
  702. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  703. }
  704. return result;
  705. }
  706. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  707. {
  708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s}",
  711. atoi(columnValue[1]),
  712. columnValue[2],
  713. atoi(columnValue[3])==1?"true":"false",
  714. atoi(columnValue[4])==1?"true":"false",
  715. columnValue[5]);
  716. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  717. return 0;
  718. }
  719. void OCPP_query_deduct_info()
  720. {
  721. int rc = 0;
  722. char sql[100];
  723. char zErrMsg[100];
  724. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  725. /* Execute SQL statement */
  726. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  727. if( rc != SQLITE_OK )
  728. {
  729. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  730. }
  731. }
  732. //==========================================
  733. // Check time passed since today
  734. //==========================================
  735. long long DiffTimebWithNow(struct timeb ST)
  736. {
  737. //return milli-second
  738. struct timeb ET;
  739. long long StartTime,StopTime;
  740. ftime(&ET);
  741. StartTime=(long long)ST.time;
  742. StopTime=(long long)ET.time;
  743. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  744. }
  745. int getTimePassSinceToday(uint8_t gun_index)
  746. {
  747. int result = -1;
  748. static time_t lastTime[4];
  749. time_t t;
  750. struct tm *tmStartToday;
  751. struct timeb tbStartToday;
  752. t=time(NULL);
  753. if(difftime(t, lastTime[gun_index])>0)
  754. {
  755. tmStartToday=localtime(&t);
  756. tmStartToday->tm_hour = 0;
  757. tmStartToday->tm_min = 0;
  758. tmStartToday->tm_sec = 0;
  759. tbStartToday.time = mktime(tmStartToday);
  760. tbStartToday.millitm = 0;
  761. result = DiffTimebWithNow(tbStartToday)/1000;
  762. lastTime[gun_index] = t;
  763. }
  764. return result;
  765. }
  766. void getNowDatetime(uint8_t *data)
  767. {
  768. time_t t = time(NULL);
  769. struct tm tm = *localtime(&t);
  770. 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);
  771. }
  772. int syncDateTimeRTC(uint8_t *data)
  773. {
  774. struct ParsingResult
  775. {
  776. int result;
  777. int scanedElement;
  778. int year;
  779. int month;
  780. int mday;
  781. int hour;
  782. int min;
  783. int sec;
  784. int tz_hour;
  785. int tz_min;
  786. float minSec;
  787. }result;
  788. struct tm tmOrg;
  789. struct tm *tmTarget;
  790. struct timeb tbTarget;
  791. char buf[128];
  792. memset(&result, 0x00, sizeof(struct ParsingResult));
  793. result.result = PASS;
  794. if(strstr((char*)data, ".") != NULL)
  795. {
  796. // Original data with mini second
  797. if(strstr((char*)data, "Z") != NULL)
  798. {
  799. // Original data with Z
  800. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  801. &result.year,
  802. &result.month,
  803. &result.mday,
  804. &result.hour,
  805. &result.min,
  806. &result.sec,
  807. &result.minSec);
  808. }
  809. else
  810. {
  811. // Original data without Z
  812. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  813. &result.year,
  814. &result.month,
  815. &result.mday,
  816. &result.hour,
  817. &result.min,
  818. &result.sec,
  819. &result.minSec,
  820. &result.tz_hour,
  821. &result.tz_min);
  822. }
  823. }
  824. else
  825. {
  826. // Original data without mini second
  827. if(strstr((char*)data, "Z") != NULL)
  828. {
  829. // Original data with Z
  830. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  831. &result.year,
  832. &result.month,
  833. &result.mday,
  834. &result.hour,
  835. &result.min,
  836. &result.sec);
  837. }
  838. else
  839. {
  840. // Original data without Z
  841. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  842. &result.year,
  843. &result.month,
  844. &result.mday,
  845. &result.hour,
  846. &result.min,
  847. &result.sec,
  848. &result.tz_hour,
  849. &result.tz_min);
  850. }
  851. }
  852. tmOrg.tm_year = result.year - 1900;
  853. tmOrg.tm_mon = result.month - 1;
  854. tmOrg.tm_mday = result.mday;
  855. tmOrg.tm_hour = result.hour;
  856. tmOrg.tm_min = result.min;
  857. tmOrg.tm_sec = result.sec;
  858. tmOrg.tm_gmtoff = 0;
  859. tbTarget.time = mktime(&tmOrg);
  860. tbTarget.timezone = 0;
  861. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  862. tmTarget = gmtime(&tbTarget.time);
  863. 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);
  864. //DEBUG_INFO(" org date time: %s\n", data);
  865. //DEBUG_INFO("parse date time: %s\n", buf);
  866. system(buf);
  867. system("/sbin/hwclock -w --systohc");
  868. if(result.scanedElement < 6)
  869. result.result = FAIL;
  870. return result.result;
  871. }
  872. //==========================================
  873. // GetCompositeSchedule logic related function
  874. //==========================================
  875. int DiffTimebSec(struct timeb ST, struct timeb ET)
  876. {
  877. //return milli-second
  878. unsigned int StartTime,StopTime;
  879. StartTime=(unsigned int)ST.time;
  880. StopTime=(unsigned int)ET.time;
  881. return (StopTime-StartTime);
  882. }
  883. int DiffTimebWithNowSec(struct timeb ST)
  884. {
  885. //return milli-second
  886. struct timeb ET;
  887. unsigned int StartTime,StopTime;
  888. ftime(&ET);
  889. StartTime=(unsigned int)ST.time;
  890. StopTime=(unsigned int)ET.time;
  891. return (StopTime-StartTime);
  892. }
  893. int getStartStop(uint8_t *start, uint8_t *stop)
  894. {
  895. int result = -1;
  896. struct tm tmStart;
  897. struct timeb tbStart;
  898. struct tm tmStop;
  899. struct timeb tbStop;
  900. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  901. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  902. {
  903. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  904. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  905. tmStart.tm_year -= 1900;
  906. tmStart.tm_mon -= 1;
  907. tbStart.time = mktime(&tmStart);
  908. tbStart.millitm = 0;
  909. tmStop.tm_year -= 1900;
  910. tmStop.tm_mon -= 1;
  911. tbStop.time = mktime(&tmStop);
  912. tbStop.millitm = 0;
  913. result = DiffTimebSec(tbStart, tbStop);
  914. //DEBUG_INFO("getStartStop(): %d\n", result);
  915. }
  916. else
  917. {
  918. DEBUG_WARN("Start or stop date parsing error.\r\n");
  919. }
  920. return result;
  921. }
  922. int isOvertNow(uint8_t *start)
  923. {
  924. int result = NO;
  925. struct ParsingResult
  926. {
  927. int result;
  928. int scanedElement;
  929. int year;
  930. int month;
  931. int mday;
  932. int hour;
  933. int min;
  934. int sec;
  935. int tz_hour;
  936. int tz_min;
  937. float minSec;
  938. }parsingResult;
  939. struct tm tmStart;
  940. struct timeb tbStart;
  941. if(strstr((char*)start, ".") != NULL)
  942. {
  943. // Original data with mini second
  944. if(strstr((char*)start, "Z") != NULL)
  945. {
  946. // Original data with Z
  947. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  948. &parsingResult.year,
  949. &parsingResult.month,
  950. &parsingResult.mday,
  951. &parsingResult.hour,
  952. &parsingResult.min,
  953. &parsingResult.sec,
  954. &parsingResult.minSec);
  955. }
  956. else
  957. {
  958. // Original data without Z
  959. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  960. &parsingResult.year,
  961. &parsingResult.month,
  962. &parsingResult.mday,
  963. &parsingResult.hour,
  964. &parsingResult.min,
  965. &parsingResult.sec,
  966. &parsingResult.minSec,
  967. &parsingResult.tz_hour,
  968. &parsingResult.tz_min);
  969. }
  970. }
  971. else
  972. {
  973. // Original data without mini second
  974. if(strstr((char*)start, "Z") != NULL)
  975. {
  976. // Original data with Z
  977. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  978. &parsingResult.year,
  979. &parsingResult.month,
  980. &parsingResult.mday,
  981. &parsingResult.hour,
  982. &parsingResult.min,
  983. &parsingResult.sec);
  984. }
  985. else
  986. {
  987. // Original data without Z
  988. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  989. &parsingResult.year,
  990. &parsingResult.month,
  991. &parsingResult.mday,
  992. &parsingResult.hour,
  993. &parsingResult.min,
  994. &parsingResult.sec,
  995. &parsingResult.tz_hour,
  996. &parsingResult.tz_min);
  997. }
  998. }
  999. if(parsingResult.scanedElement >= 6)
  1000. {
  1001. tmStart.tm_year = parsingResult.year - 1900;
  1002. tmStart.tm_mon = parsingResult.month - 1;
  1003. tmStart.tm_mday = parsingResult.mday;
  1004. tmStart.tm_hour = parsingResult.hour;
  1005. tmStart.tm_min = parsingResult.min;
  1006. tmStart.tm_sec = parsingResult.sec;
  1007. tmStart.tm_gmtoff = 0;
  1008. tbStart.time = mktime(&tmStart);
  1009. tbStart.timezone = 0;
  1010. tbStart.millitm = 0;
  1011. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1012. if(DiffTimebWithNowSec(tbStart) <= 0)
  1013. result = NO;
  1014. else
  1015. result = YES;
  1016. }
  1017. else
  1018. {
  1019. DEBUG_WARN("Start date parsing error.\n");
  1020. }
  1021. return result;
  1022. }
  1023. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1024. {
  1025. int result = -1;
  1026. struct tm tmStart;
  1027. struct timeb tbStart;
  1028. struct tm tmStop;
  1029. struct timeb tbStop;
  1030. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1031. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1032. {
  1033. tmStart.tm_year -= 1900;
  1034. tmStart.tm_mon -= 1;
  1035. tbStart.time = mktime(&tmStart);
  1036. tbStart.millitm = 0;
  1037. tmStop.tm_year -= 1900;
  1038. tmStop.tm_mon -= 1;
  1039. tbStop.time = mktime(&tmStop);
  1040. tbStop.millitm = 0;
  1041. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1042. }
  1043. return result;
  1044. }
  1045. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1046. {
  1047. FILE *fp;
  1048. char profileFileName[128];
  1049. char *line = NULL;
  1050. size_t len = 0;
  1051. time_t CurrentTime;
  1052. struct tm *tmComposite;
  1053. struct StructChargingProfile maxProfile;
  1054. uint8_t limitMax=0;
  1055. int compositePeriodIdx = 0;
  1056. CurrentTime = time(NULL);
  1057. tmComposite=localtime(&CurrentTime);
  1058. 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);
  1059. if(isUnitA)
  1060. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1061. else
  1062. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1063. compositeProfile->ChargingSchedule.Duration = durationReq;
  1064. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1065. {
  1066. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1067. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1068. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1069. }
  1070. compositeProfile->ChargingProfileId = 0;
  1071. compositeProfile->StackLevel = 99 ;
  1072. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1073. maxProfile.ChargingProfileId = -1;
  1074. maxProfile.ChargingSchedule.Duration = -1;
  1075. system("rm -f /tmp/*.json");
  1076. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1077. // Search max profile
  1078. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1079. if((access(profileFileName, F_OK))!=-1)
  1080. {
  1081. fp = fopen(profileFileName, "r");
  1082. while(getline(&line, &len, fp) != -1)
  1083. {
  1084. json_object *obj = NULL;
  1085. obj = json_tokener_parse(line);
  1086. if(is_error(obj))
  1087. {
  1088. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1089. }
  1090. else
  1091. {
  1092. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1093. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1094. )
  1095. {
  1096. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1097. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1098. )
  1099. {
  1100. struct tm tmFrom, tmTo;
  1101. struct timeb tbFrom, tbTo;
  1102. 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) &&
  1103. (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))
  1104. {
  1105. tmFrom.tm_year -= 1900;
  1106. tmFrom.tm_mon -= 1;
  1107. tbFrom.time = mktime(&tmFrom);
  1108. tmTo.tm_year -= 1900;
  1109. tmTo.tm_mon -= 1;
  1110. tbTo.time = mktime(&tmTo);
  1111. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1112. {
  1113. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1114. {
  1115. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1116. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1118. }
  1119. maxProfile.ChargingProfileId = -1;
  1120. maxProfile.StackLevel = -1;
  1121. if(maxProfile.ChargingProfileId == -1)
  1122. DEBUG_INFO("MaxProfile found.\n");
  1123. else
  1124. DEBUG_INFO("MaxProfile updated.\n");
  1125. // Required item
  1126. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1127. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1128. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1129. if(isUnitA)
  1130. {
  1131. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1132. 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++)
  1133. {
  1134. 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"));
  1135. 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?
  1136. 3:
  1137. 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")));
  1138. 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")));
  1139. }
  1140. }
  1141. else
  1142. {
  1143. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1144. 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++)
  1145. {
  1146. 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"));
  1147. 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?
  1148. 3:
  1149. 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")));
  1150. 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));
  1151. }
  1152. }
  1153. // Optional item
  1154. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1155. {
  1156. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1157. }
  1158. else
  1159. {
  1160. sprintf((char*)maxProfile.ValidFrom, " ");
  1161. }
  1162. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. {
  1164. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1165. }
  1166. else
  1167. {
  1168. sprintf((char*)maxProfile.ValidTo, " ");
  1169. }
  1170. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1171. {
  1172. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1173. }
  1174. else
  1175. {
  1176. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1177. }
  1178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1179. {
  1180. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1181. }
  1182. else
  1183. {
  1184. maxProfile.TransactionId = -1;
  1185. }
  1186. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1187. {
  1188. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1189. }
  1190. else
  1191. {
  1192. maxProfile.ChargingSchedule.Duration = 86400;
  1193. }
  1194. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1195. {
  1196. 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")));
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1201. }
  1202. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1203. {
  1204. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1205. }
  1206. else
  1207. {
  1208. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. else
  1214. {
  1215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1216. {
  1217. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1218. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1219. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1220. }
  1221. maxProfile.ChargingProfileId = -1;
  1222. maxProfile.StackLevel = -1;
  1223. if(maxProfile.ChargingProfileId == -1)
  1224. DEBUG_INFO("MaxProfile found.\n");
  1225. else
  1226. DEBUG_INFO("MaxProfile updated.\n");
  1227. // Required item
  1228. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1229. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1230. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1231. if(isUnitA)
  1232. {
  1233. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1234. 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++)
  1235. {
  1236. 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"));
  1237. 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?
  1238. 3:
  1239. 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")));
  1240. 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")));
  1241. }
  1242. }
  1243. else
  1244. {
  1245. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1246. 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++)
  1247. {
  1248. 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"));
  1249. 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?
  1250. 3:
  1251. 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")));
  1252. 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));
  1253. }
  1254. }
  1255. // Optional item
  1256. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1257. {
  1258. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1259. }
  1260. else
  1261. {
  1262. sprintf((char*)maxProfile.ValidFrom, " ");
  1263. }
  1264. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1265. {
  1266. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1267. }
  1268. else
  1269. {
  1270. sprintf((char*)maxProfile.ValidTo, " ");
  1271. }
  1272. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1273. {
  1274. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1275. }
  1276. else
  1277. {
  1278. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1279. }
  1280. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1281. {
  1282. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1283. }
  1284. else
  1285. {
  1286. maxProfile.TransactionId = -1;
  1287. }
  1288. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1289. {
  1290. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1291. }
  1292. else
  1293. {
  1294. maxProfile.ChargingSchedule.Duration = 86400;
  1295. }
  1296. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1297. {
  1298. 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")));
  1299. }
  1300. else
  1301. {
  1302. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1303. }
  1304. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1305. {
  1306. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1307. }
  1308. else
  1309. {
  1310. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1311. }
  1312. }
  1313. }
  1314. }
  1315. json_object_put(obj);
  1316. }
  1317. fclose(fp);
  1318. /*
  1319. if(maxProfile.ChargingProfileId !=-1)
  1320. {
  1321. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1322. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1323. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1324. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1325. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1326. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1327. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1328. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1329. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1330. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1331. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1332. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1333. {
  1334. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1335. {
  1336. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1337. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1338. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1339. }
  1340. }
  1341. }
  1342. else
  1343. DEBUG_INFO("MaxProfile not found.\n");
  1344. DEBUG_INFO("------------------------------------\n");*/
  1345. }
  1346. if(maxProfile.ChargingProfileId != -1)
  1347. {
  1348. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1349. {
  1350. if(maxProfile.ChargingSchedule.Duration != -1)
  1351. {
  1352. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1353. 0:
  1354. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1355. }
  1356. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1357. {
  1358. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1359. {
  1360. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1361. 0:
  1362. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1363. if(idxPeriod > 0)
  1364. {
  1365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1366. {
  1367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1374. {
  1375. if(maxProfile.ChargingSchedule.Duration != -1)
  1376. {
  1377. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1378. }
  1379. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1380. {
  1381. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1382. {
  1383. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1384. if(idxPeriod > 0)
  1385. {
  1386. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1387. {
  1388. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. else
  1395. {
  1396. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1397. {
  1398. if(maxProfile.ChargingSchedule.Duration != -1)
  1399. {
  1400. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1401. 0:
  1402. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1403. }
  1404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1405. {
  1406. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1407. {
  1408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1409. 0:
  1410. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1411. if(idxPeriod > 0)
  1412. {
  1413. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1414. {
  1415. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. }
  1421. else
  1422. {
  1423. if(maxProfile.ChargingSchedule.Duration != -1)
  1424. {
  1425. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1426. 0:
  1427. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1428. }
  1429. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1430. {
  1431. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1432. {
  1433. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1434. 0:
  1435. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1436. if(idxPeriod > 0)
  1437. {
  1438. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1439. {
  1440. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }
  1447. /*
  1448. DEBUG_INFO("MaxProfile after align.\n");
  1449. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1450. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1451. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1452. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1453. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1454. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1455. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1456. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1457. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1458. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1459. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1460. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1461. {
  1462. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1463. {
  1464. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1465. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1466. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1467. }
  1468. }
  1469. DEBUG_INFO("------------------------------------\n");*/
  1470. }
  1471. // Find each profile period quantity
  1472. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1473. {
  1474. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1475. limitMax = idx+1;
  1476. }
  1477. if(maxProfile.ChargingProfileId != -1)
  1478. {
  1479. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1480. {
  1481. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1482. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1483. (maxProfile.ChargingSchedule.Duration > 0))
  1484. {
  1485. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1486. {
  1487. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1488. compositePeriodIdx++;
  1489. }
  1490. else
  1491. {
  1492. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1493. }
  1494. }
  1495. }
  1496. }
  1497. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1498. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1499. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1500. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1502. {
  1503. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1504. {
  1505. compositeProfile->ChargingProfileId = 1;
  1506. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1507. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1508. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1509. }
  1510. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1512. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1514. }
  1515. if(line)
  1516. free(line);
  1517. }
  1518. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1519. {
  1520. FILE *fp;
  1521. char profileFileName[128];
  1522. char *line = NULL;
  1523. size_t len = 0;
  1524. time_t CurrentTime;
  1525. struct tm *tmComposite;
  1526. struct StructChargingProfile maxProfile;
  1527. struct StructChargingProfile defaultTxProfile;
  1528. struct StructChargingProfile txProfile;
  1529. struct StructChargingSchedulePeriod tmpPeriod;
  1530. uint8_t limitMax=0;
  1531. uint8_t limitDef=0;
  1532. uint8_t limitTx=0;
  1533. int compositePeriodIdx = 0;
  1534. CurrentTime = time(NULL);
  1535. tmComposite=localtime(&CurrentTime);
  1536. 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);
  1537. if(isUnitA)
  1538. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1539. else
  1540. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1541. compositeProfile->ChargingSchedule.Duration = durationReq;
  1542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1543. {
  1544. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1545. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1546. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1547. }
  1548. compositeProfile->ChargingProfileId = 0;
  1549. compositeProfile->StackLevel = 99 ;
  1550. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1551. maxProfile.ChargingProfileId = -1;
  1552. defaultTxProfile.ChargingProfileId = -1;
  1553. txProfile.ChargingProfileId = -1;
  1554. maxProfile.ChargingSchedule.Duration = -1;
  1555. defaultTxProfile.ChargingSchedule.Duration = -1;
  1556. txProfile.ChargingSchedule.Duration = -1;
  1557. system("rm -f /tmp/*.json");
  1558. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1559. /*
  1560. * Search valid charging profile
  1561. */
  1562. //DEBUG_INFO("====================================\n");
  1563. // Search tx profile
  1564. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1565. if((access(profileFileName, F_OK))!=-1)
  1566. {
  1567. fp = fopen(profileFileName, "r");
  1568. while(getline(&line, &len, fp) != -1)
  1569. {
  1570. json_object *obj = NULL;
  1571. obj = json_tokener_parse(line);
  1572. if(is_error(obj))
  1573. {
  1574. DEBUG_ERROR("Parse txProfile from file error.\n");
  1575. }
  1576. else
  1577. {
  1578. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1579. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1580. )
  1581. {
  1582. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1583. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1584. )
  1585. {
  1586. struct tm tmFrom, tmTo;
  1587. struct timeb tbFrom, tbTo;
  1588. 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) &&
  1589. (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))
  1590. {
  1591. tmFrom.tm_year -= 1900;
  1592. tmFrom.tm_mon -= 1;
  1593. tbFrom.time = mktime(&tmFrom);
  1594. tmTo.tm_year -= 1900;
  1595. tmTo.tm_mon -= 1;
  1596. tbTo.time = mktime(&tmTo);
  1597. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1598. {
  1599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1600. {
  1601. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1602. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1604. }
  1605. txProfile.ChargingProfileId = -1;
  1606. txProfile.StackLevel = -1;
  1607. if(txProfile.ChargingProfileId == -1)
  1608. DEBUG_INFO("TxProfile found.\n");
  1609. else
  1610. DEBUG_INFO("TxProfile updated.\n");
  1611. // Required item
  1612. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1613. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1614. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1615. if(isUnitA)
  1616. {
  1617. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1618. 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++)
  1619. {
  1620. 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"));
  1621. 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?
  1622. 3:
  1623. 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")));
  1624. 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")));
  1625. }
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1630. 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++)
  1631. {
  1632. 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"));
  1633. 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?
  1634. 3:
  1635. 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")));
  1636. 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));
  1637. }
  1638. }
  1639. // Optional item
  1640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1641. {
  1642. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1643. }
  1644. else
  1645. {
  1646. sprintf((char*)txProfile.ValidFrom, " ");
  1647. }
  1648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1649. {
  1650. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1651. }
  1652. else
  1653. {
  1654. sprintf((char*)txProfile.ValidTo, " ");
  1655. }
  1656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1657. {
  1658. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1659. }
  1660. else
  1661. {
  1662. sprintf((char*)txProfile.RecurrencyKind, " ");
  1663. }
  1664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1665. {
  1666. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1667. }
  1668. else
  1669. {
  1670. txProfile.TransactionId = -1;
  1671. }
  1672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1673. {
  1674. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1675. }
  1676. else
  1677. {
  1678. txProfile.ChargingSchedule.Duration = 86400;
  1679. }
  1680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1681. {
  1682. 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")));
  1683. }
  1684. else
  1685. {
  1686. 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));
  1687. }
  1688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1689. {
  1690. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1691. }
  1692. else
  1693. {
  1694. txProfile.ChargingSchedule.MinChargingRate = -1;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1704. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1706. }
  1707. txProfile.ChargingProfileId = -1;
  1708. txProfile.StackLevel = -1;
  1709. if(txProfile.ChargingProfileId == -1)
  1710. DEBUG_INFO("TxProfile found.\n");
  1711. else
  1712. DEBUG_INFO("TxProfile updated.\n");
  1713. // Required item
  1714. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1715. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1716. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1717. if(isUnitA)
  1718. {
  1719. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1720. 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++)
  1721. {
  1722. 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"));
  1723. 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?
  1724. 3:
  1725. 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")));
  1726. 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")));
  1727. }
  1728. }
  1729. else
  1730. {
  1731. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1732. 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++)
  1733. {
  1734. 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"));
  1735. 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?
  1736. 3:
  1737. 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")));
  1738. 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));
  1739. }
  1740. }
  1741. // Optional item
  1742. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1743. {
  1744. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1745. }
  1746. else
  1747. {
  1748. sprintf((char*)txProfile.ValidFrom, " ");
  1749. }
  1750. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1751. {
  1752. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1753. }
  1754. else
  1755. {
  1756. sprintf((char*)txProfile.ValidTo, " ");
  1757. }
  1758. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1759. {
  1760. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1761. }
  1762. else
  1763. {
  1764. sprintf((char*)txProfile.RecurrencyKind, " ");
  1765. }
  1766. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1767. {
  1768. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1769. }
  1770. else
  1771. {
  1772. txProfile.TransactionId = -1;
  1773. }
  1774. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1775. {
  1776. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1777. }
  1778. else
  1779. {
  1780. txProfile.ChargingSchedule.Duration = 86400;
  1781. }
  1782. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1783. {
  1784. 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")));
  1785. }
  1786. else
  1787. {
  1788. 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));
  1789. }
  1790. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1791. {
  1792. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1793. }
  1794. else
  1795. {
  1796. txProfile.ChargingSchedule.MinChargingRate = -1;
  1797. }
  1798. }
  1799. }
  1800. }
  1801. json_object_put(obj);
  1802. }
  1803. fclose(fp);
  1804. /*
  1805. if(txProfile.ChargingProfileId != -1)
  1806. {
  1807. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1808. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1809. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1810. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1811. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1812. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1813. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1814. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1815. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1816. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1817. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1818. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1819. {
  1820. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1821. {
  1822. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1823. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1824. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1825. }
  1826. }
  1827. }
  1828. else
  1829. DEBUG_INFO("TxProfile not found.\n");*/
  1830. }
  1831. // Search default tx profile
  1832. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1833. if((access(profileFileName, F_OK))==-1)
  1834. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1835. if((access(profileFileName, F_OK))!=-1)
  1836. {
  1837. fp = fopen(profileFileName, "r");
  1838. while(getline(&line, &len, fp) != -1)
  1839. {
  1840. json_object *obj = NULL;
  1841. obj = json_tokener_parse(line);
  1842. if(is_error(obj))
  1843. {
  1844. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1845. }
  1846. else
  1847. {
  1848. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1849. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1850. )
  1851. {
  1852. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1853. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1854. )
  1855. {
  1856. struct tm tmFrom, tmTo;
  1857. struct timeb tbFrom, tbTo;
  1858. 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) &&
  1859. (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))
  1860. {
  1861. tmFrom.tm_year -= 1900;
  1862. tmFrom.tm_mon -= 1;
  1863. tbFrom.time = mktime(&tmFrom);
  1864. tmTo.tm_year -= 1900;
  1865. tmTo.tm_mon -= 1;
  1866. tbTo.time = mktime(&tmTo);
  1867. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1868. {
  1869. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1870. {
  1871. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1872. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1874. }
  1875. defaultTxProfile.ChargingProfileId = -1;
  1876. defaultTxProfile.StackLevel = -1;
  1877. if(defaultTxProfile.ChargingProfileId == -1)
  1878. DEBUG_INFO("TxDefaultProfile found.\n");
  1879. else
  1880. DEBUG_INFO("TxDefaultProfile updated.\n");
  1881. // Required item
  1882. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1883. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1884. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1885. if(isUnitA)
  1886. {
  1887. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1888. 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++)
  1889. {
  1890. 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"));
  1891. 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?
  1892. 3:
  1893. 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")));
  1894. 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")));
  1895. }
  1896. }
  1897. else
  1898. {
  1899. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1900. 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++)
  1901. {
  1902. 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"));
  1903. 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?
  1904. 3:
  1905. 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")));
  1906. 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));
  1907. }
  1908. }
  1909. // Optional item
  1910. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1911. {
  1912. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1913. }
  1914. else
  1915. {
  1916. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1917. }
  1918. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1919. {
  1920. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1921. }
  1922. else
  1923. {
  1924. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1925. }
  1926. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1927. {
  1928. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1929. }
  1930. else
  1931. {
  1932. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1933. }
  1934. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1935. {
  1936. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1937. }
  1938. else
  1939. {
  1940. defaultTxProfile.TransactionId = -1;
  1941. }
  1942. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1943. {
  1944. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1945. }
  1946. else
  1947. {
  1948. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1949. }
  1950. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1951. {
  1952. 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")));
  1953. }
  1954. else
  1955. {
  1956. 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));
  1957. }
  1958. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1959. {
  1960. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1961. }
  1962. else
  1963. {
  1964. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1965. }
  1966. }
  1967. }
  1968. }
  1969. else
  1970. {
  1971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1972. {
  1973. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1974. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1976. }
  1977. defaultTxProfile.ChargingProfileId = -1;
  1978. defaultTxProfile.StackLevel = -1;
  1979. if(defaultTxProfile.ChargingProfileId == -1)
  1980. DEBUG_INFO("TxDefaultProfile found.\n");
  1981. else
  1982. DEBUG_INFO("TxDefaultProfile updated.\n");
  1983. // Required item
  1984. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1985. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1986. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1987. if(isUnitA)
  1988. {
  1989. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1990. 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++)
  1991. {
  1992. 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"));
  1993. 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?
  1994. 3:
  1995. 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")));
  1996. 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")));
  1997. }
  1998. }
  1999. else
  2000. {
  2001. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2002. 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++)
  2003. {
  2004. 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"));
  2005. 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?
  2006. 3:
  2007. 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")));
  2008. 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));
  2009. }
  2010. }
  2011. // Optional item
  2012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2013. {
  2014. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2015. }
  2016. else
  2017. {
  2018. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2019. }
  2020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2021. {
  2022. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2023. }
  2024. else
  2025. {
  2026. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2027. }
  2028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2029. {
  2030. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2031. }
  2032. else
  2033. {
  2034. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2035. }
  2036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2037. {
  2038. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2039. }
  2040. else
  2041. {
  2042. defaultTxProfile.TransactionId = -1;
  2043. }
  2044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2045. {
  2046. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2047. }
  2048. else
  2049. {
  2050. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2051. }
  2052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2053. {
  2054. 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")));
  2055. }
  2056. else
  2057. {
  2058. 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));
  2059. }
  2060. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2061. {
  2062. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2063. }
  2064. else
  2065. {
  2066. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2067. }
  2068. }
  2069. }
  2070. }
  2071. json_object_put(obj);
  2072. }
  2073. fclose(fp);
  2074. /*
  2075. if(defaultTxProfile.ChargingProfileId != -1)
  2076. {
  2077. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2078. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2079. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2080. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2081. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2082. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2083. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2084. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2085. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2086. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2087. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2088. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2089. {
  2090. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2091. {
  2092. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2093. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2094. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2095. }
  2096. }
  2097. }
  2098. else
  2099. DEBUG_INFO("TxDefaultProfile not found.\n");
  2100. DEBUG_INFO("------------------------------------\n");*/
  2101. }
  2102. // Search max profile
  2103. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2104. if((access(profileFileName, F_OK))!=-1)
  2105. {
  2106. fp = fopen(profileFileName, "r");
  2107. while(getline(&line, &len, fp) != -1)
  2108. {
  2109. json_object *obj = NULL;
  2110. obj = json_tokener_parse(line);
  2111. if(is_error(obj))
  2112. {
  2113. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2114. }
  2115. else
  2116. {
  2117. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2118. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2119. )
  2120. {
  2121. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2122. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2123. )
  2124. {
  2125. struct tm tmFrom, tmTo;
  2126. struct timeb tbFrom, tbTo;
  2127. 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) &&
  2128. (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))
  2129. {
  2130. tmFrom.tm_year -= 1900;
  2131. tmFrom.tm_mon -= 1;
  2132. tbFrom.time = mktime(&tmFrom);
  2133. tmTo.tm_year -= 1900;
  2134. tmTo.tm_mon -= 1;
  2135. tbTo.time = mktime(&tmTo);
  2136. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2137. {
  2138. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2139. {
  2140. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2141. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2142. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2143. }
  2144. maxProfile.ChargingProfileId = -1;
  2145. maxProfile.StackLevel = -1;
  2146. if(maxProfile.ChargingProfileId == -1)
  2147. DEBUG_INFO("MaxProfile found.\n");
  2148. else
  2149. DEBUG_INFO("MaxProfile updated.\n");
  2150. // Required item
  2151. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2152. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2153. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2154. if(isUnitA)
  2155. {
  2156. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2157. 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++)
  2158. {
  2159. 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"));
  2160. 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?
  2161. 3:
  2162. 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")));
  2163. 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")));
  2164. }
  2165. }
  2166. else
  2167. {
  2168. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2169. 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++)
  2170. {
  2171. 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"));
  2172. 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?
  2173. 3:
  2174. 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")));
  2175. 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));
  2176. }
  2177. }
  2178. // Optional item
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2180. {
  2181. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)maxProfile.ValidFrom, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2188. {
  2189. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)maxProfile.ValidTo, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2196. {
  2197. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2198. }
  2199. else
  2200. {
  2201. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2202. }
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2204. {
  2205. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2206. }
  2207. else
  2208. {
  2209. maxProfile.TransactionId = -1;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2212. {
  2213. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2214. }
  2215. else
  2216. {
  2217. maxProfile.ChargingSchedule.Duration = 86400;
  2218. }
  2219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2220. {
  2221. 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")));
  2222. }
  2223. else
  2224. {
  2225. 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));
  2226. }
  2227. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2228. {
  2229. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2230. }
  2231. else
  2232. {
  2233. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. else
  2239. {
  2240. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2241. {
  2242. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2243. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2244. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2245. }
  2246. maxProfile.ChargingProfileId = -1;
  2247. maxProfile.StackLevel = -1;
  2248. if(maxProfile.ChargingProfileId == -1)
  2249. DEBUG_INFO("MaxProfile found.\n");
  2250. else
  2251. DEBUG_INFO("MaxProfile updated.\n");
  2252. // Required item
  2253. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2254. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2255. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2256. if(isUnitA)
  2257. {
  2258. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2259. 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++)
  2260. {
  2261. 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"));
  2262. 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?
  2263. 3:
  2264. 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")));
  2265. 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")));
  2266. }
  2267. }
  2268. else
  2269. {
  2270. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2271. 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++)
  2272. {
  2273. 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"));
  2274. 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?
  2275. 3:
  2276. 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")));
  2277. 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));
  2278. }
  2279. }
  2280. // Optional item
  2281. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2282. {
  2283. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2284. }
  2285. else
  2286. {
  2287. sprintf((char*)maxProfile.ValidFrom, " ");
  2288. }
  2289. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2290. {
  2291. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2292. }
  2293. else
  2294. {
  2295. sprintf((char*)maxProfile.ValidTo, " ");
  2296. }
  2297. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2298. {
  2299. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2300. }
  2301. else
  2302. {
  2303. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2304. }
  2305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2306. {
  2307. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2308. }
  2309. else
  2310. {
  2311. maxProfile.TransactionId = -1;
  2312. }
  2313. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2314. {
  2315. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2316. }
  2317. else
  2318. {
  2319. maxProfile.ChargingSchedule.Duration = 86400;
  2320. }
  2321. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2322. {
  2323. 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")));
  2324. }
  2325. else
  2326. {
  2327. 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));
  2328. }
  2329. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2330. {
  2331. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2332. }
  2333. else
  2334. {
  2335. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2336. }
  2337. }
  2338. }
  2339. }
  2340. json_object_put(obj);
  2341. }
  2342. fclose(fp);
  2343. /*
  2344. if(maxProfile.ChargingProfileId !=-1)
  2345. {
  2346. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2347. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2348. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2349. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2350. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2351. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2352. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2353. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2354. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2355. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2356. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2357. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2358. {
  2359. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2360. {
  2361. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2362. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2363. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2364. }
  2365. }
  2366. }
  2367. else
  2368. DEBUG_INFO("MaxProfile not found.\n");
  2369. DEBUG_INFO("------------------------------------\n");*/
  2370. }
  2371. /*
  2372. * Align found profile start schedule & periods
  2373. */
  2374. //DEBUG_INFO("====================================\n");
  2375. /*
  2376. // For local test usage, force modify found profile start schedule info
  2377. 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);
  2378. 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);
  2379. 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);
  2380. */
  2381. if(txProfile.ChargingProfileId != -1)
  2382. {
  2383. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2384. {
  2385. if(txProfile.ChargingSchedule.Duration != -1)
  2386. {
  2387. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2388. 0:
  2389. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2390. }
  2391. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2392. {
  2393. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2394. {
  2395. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2396. 0:
  2397. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2398. if(idxPeriod > 0)
  2399. {
  2400. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2401. {
  2402. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2409. {
  2410. if(txProfile.ChargingSchedule.Duration != -1)
  2411. {
  2412. 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?
  2413. 0:
  2414. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2415. }
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2419. {
  2420. 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?
  2421. 0:
  2422. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2423. if(idxPeriod > 0)
  2424. {
  2425. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2426. {
  2427. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. else
  2434. {
  2435. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2436. {
  2437. if(txProfile.ChargingSchedule.Duration != -1)
  2438. {
  2439. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2440. 0:
  2441. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2442. }
  2443. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2444. {
  2445. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2446. {
  2447. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2448. 0:
  2449. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2450. if(idxPeriod > 0)
  2451. {
  2452. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2453. {
  2454. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. }
  2460. else
  2461. {
  2462. if(txProfile.ChargingSchedule.Duration != -1)
  2463. {
  2464. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2465. 0:
  2466. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2467. }
  2468. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2469. {
  2470. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2471. {
  2472. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2473. 0:
  2474. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2475. if(idxPeriod > 0)
  2476. {
  2477. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2478. {
  2479. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2480. }
  2481. }
  2482. }
  2483. }
  2484. }
  2485. }
  2486. /*
  2487. DEBUG_INFO("txProfile after align.\n");
  2488. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2489. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2490. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2491. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2492. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2493. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2494. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2495. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2496. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2497. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2498. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2499. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2500. {
  2501. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2502. {
  2503. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2504. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2505. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2506. }
  2507. }*/
  2508. }
  2509. if(defaultTxProfile.ChargingProfileId != -1)
  2510. {
  2511. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2512. {
  2513. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2514. {
  2515. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2516. 0:
  2517. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2518. }
  2519. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2520. {
  2521. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2522. {
  2523. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2524. 0:
  2525. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2526. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2527. {
  2528. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2529. }
  2530. if(idxPeriod > 0)
  2531. {
  2532. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2533. {
  2534. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2535. }
  2536. }
  2537. }
  2538. }
  2539. }
  2540. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2541. {
  2542. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2543. {
  2544. 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?
  2545. 0:
  2546. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2547. }
  2548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2549. {
  2550. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2551. {
  2552. 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?
  2553. 0:
  2554. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2555. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2556. {
  2557. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2558. }
  2559. if(idxPeriod > 0)
  2560. {
  2561. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2562. {
  2563. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2564. }
  2565. }
  2566. }
  2567. }
  2568. }
  2569. else
  2570. {
  2571. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2572. {
  2573. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2574. {
  2575. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2576. 0:
  2577. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2578. }
  2579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2580. {
  2581. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2582. {
  2583. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2584. 0:
  2585. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2586. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2587. {
  2588. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2589. }
  2590. if(idxPeriod > 0)
  2591. {
  2592. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2593. {
  2594. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. else
  2601. {
  2602. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2603. {
  2604. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2605. 0:
  2606. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2607. }
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2611. {
  2612. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2613. 0:
  2614. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2615. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2616. {
  2617. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2618. }
  2619. if(idxPeriod > 0)
  2620. {
  2621. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2622. {
  2623. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2624. }
  2625. }
  2626. }
  2627. }
  2628. }
  2629. }
  2630. /*
  2631. DEBUG_INFO("defaultTxProfile after align.\n");
  2632. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2633. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2634. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2635. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2636. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2637. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2638. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2639. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2640. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2641. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2642. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2644. {
  2645. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2646. {
  2647. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2648. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2649. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2650. }
  2651. }
  2652. DEBUG_INFO("------------------------------------\n");*/
  2653. }
  2654. if(maxProfile.ChargingProfileId != -1)
  2655. {
  2656. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2657. {
  2658. if(maxProfile.ChargingSchedule.Duration != -1)
  2659. {
  2660. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2661. 0:
  2662. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2663. }
  2664. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2665. {
  2666. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2667. {
  2668. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2669. 0:
  2670. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2671. if(idxPeriod > 0)
  2672. {
  2673. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2674. {
  2675. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2682. {
  2683. if(maxProfile.ChargingSchedule.Duration != -1)
  2684. {
  2685. 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?
  2686. 0:
  2687. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2688. }
  2689. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2690. {
  2691. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2692. {
  2693. 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?
  2694. 0:
  2695. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2696. if(idxPeriod > 0)
  2697. {
  2698. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2699. {
  2700. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2701. }
  2702. }
  2703. }
  2704. }
  2705. }
  2706. else
  2707. {
  2708. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2709. {
  2710. if(maxProfile.ChargingSchedule.Duration != -1)
  2711. {
  2712. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2713. 0:
  2714. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2715. }
  2716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2717. {
  2718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2719. {
  2720. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2721. 0:
  2722. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2723. if(idxPeriod > 0)
  2724. {
  2725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2726. {
  2727. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2728. }
  2729. }
  2730. }
  2731. }
  2732. }
  2733. else
  2734. {
  2735. if(maxProfile.ChargingSchedule.Duration != -1)
  2736. {
  2737. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2738. 0:
  2739. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2740. }
  2741. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2742. {
  2743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2744. {
  2745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2746. 0:
  2747. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2748. if(idxPeriod > 0)
  2749. {
  2750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2751. {
  2752. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. /*
  2760. DEBUG_INFO("MaxProfile after align.\n");
  2761. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2762. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2763. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2764. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2765. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2766. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2767. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2768. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2769. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2770. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2771. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2772. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2773. {
  2774. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2775. {
  2776. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2777. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2778. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2779. }
  2780. }
  2781. DEBUG_INFO("------------------------------------\n");*/
  2782. }
  2783. /*
  2784. * Merge to conposite schedule
  2785. */
  2786. //DEBUG_INFO("====================================\n");
  2787. // Find each profile period quantity
  2788. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2789. {
  2790. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2791. limitMax = idx+1;
  2792. }
  2793. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2794. {
  2795. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2796. limitDef = idx+1;
  2797. }
  2798. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2799. {
  2800. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2801. limitTx = idx+1;
  2802. }
  2803. // TxProfile found, composite schedule based on it
  2804. if(txProfile.ChargingProfileId != -1)
  2805. {
  2806. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2807. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2808. {
  2809. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2810. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2811. (txProfile.ChargingSchedule.Duration > 0))
  2812. {
  2813. if(maxProfile.ChargingProfileId != -1)
  2814. {
  2815. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2816. {
  2817. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2818. {
  2819. if((maxProfile.ChargingSchedule.Duration > 0))
  2820. {
  2821. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2822. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2823. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2824. }
  2825. else
  2826. {
  2827. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2828. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2829. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2830. }
  2831. }
  2832. if(idxMaxPeriod == (limitMax-1))
  2833. {
  2834. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2835. {
  2836. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2837. {
  2838. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2839. compositePeriodIdx++;
  2840. }
  2841. else
  2842. {
  2843. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. else
  2850. {
  2851. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2852. {
  2853. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2854. compositePeriodIdx++;
  2855. }
  2856. else
  2857. {
  2858. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2859. }
  2860. }
  2861. }
  2862. if(idxTxPeriod == (limitTx-1))
  2863. {
  2864. if(defaultTxProfile.ChargingProfileId != -1)
  2865. {
  2866. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2867. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2868. {
  2869. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2871. (defaultTxProfile.ChargingSchedule.Duration>0))
  2872. {
  2873. if(maxProfile.ChargingProfileId != -1)
  2874. {
  2875. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2876. {
  2877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2878. {
  2879. if((maxProfile.ChargingSchedule.Duration > 0))
  2880. {
  2881. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2882. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2883. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2884. }
  2885. else
  2886. {
  2887. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2888. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2889. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2890. }
  2891. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2892. {
  2893. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2894. {
  2895. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2896. compositePeriodIdx++;
  2897. }
  2898. else
  2899. {
  2900. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2901. }
  2902. }
  2903. // Delete duplicate period
  2904. if(compositePeriodIdx > 1)
  2905. {
  2906. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2907. {
  2908. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2909. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2910. compositePeriodIdx -= 1;
  2911. }
  2912. }
  2913. }
  2914. else
  2915. {
  2916. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2919. compositePeriodIdx++;
  2920. }
  2921. else
  2922. {
  2923. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2924. }
  2925. break;
  2926. }
  2927. }
  2928. }
  2929. else
  2930. {
  2931. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2932. {
  2933. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2934. compositePeriodIdx++;
  2935. }
  2936. else
  2937. {
  2938. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2939. }
  2940. }
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2948. else if(defaultTxProfile.ChargingProfileId != -1)
  2949. {
  2950. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2951. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2952. {
  2953. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2954. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2955. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2956. {
  2957. if(maxProfile.ChargingProfileId != -1)
  2958. {
  2959. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2960. {
  2961. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2962. {
  2963. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2964. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2965. if((maxProfile.ChargingSchedule.Duration > 0))
  2966. {
  2967. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2968. }
  2969. else
  2970. {
  2971. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2972. }
  2973. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2974. {
  2975. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2976. {
  2977. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2978. compositePeriodIdx++;
  2979. }
  2980. else
  2981. {
  2982. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2983. }
  2984. }
  2985. // Delete duplicate period
  2986. if(compositePeriodIdx > 1)
  2987. {
  2988. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2989. {
  2990. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2991. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2992. compositePeriodIdx -= 1;
  2993. }
  2994. }
  2995. }
  2996. else
  2997. {
  2998. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2999. {
  3000. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3001. compositePeriodIdx++;
  3002. }
  3003. else
  3004. {
  3005. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3006. }
  3007. break;
  3008. }
  3009. }
  3010. }
  3011. else
  3012. {
  3013. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3014. {
  3015. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3016. compositePeriodIdx++;
  3017. }
  3018. else
  3019. {
  3020. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3021. }
  3022. }
  3023. }
  3024. }
  3025. }
  3026. // Fill other period by MaxProfile
  3027. if(maxProfile.ChargingProfileId != -1)
  3028. {
  3029. if(compositePeriodIdx==0)
  3030. {
  3031. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3032. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3033. {
  3034. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3035. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3036. (maxProfile.ChargingSchedule.Duration > 0))
  3037. {
  3038. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3039. {
  3040. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3041. compositePeriodIdx++;
  3042. }
  3043. else
  3044. {
  3045. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3046. }
  3047. }
  3048. }
  3049. }
  3050. else
  3051. {
  3052. int lastCompositePeriodIdx = compositePeriodIdx;
  3053. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3054. {
  3055. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3056. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3057. (maxProfile.ChargingSchedule.Duration > 0))
  3058. {
  3059. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3060. {
  3061. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3062. {
  3063. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3064. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3065. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3066. }
  3067. else
  3068. {
  3069. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3070. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3071. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3072. }
  3073. }
  3074. if(tmpPeriod.Limit != -1)
  3075. {
  3076. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3077. {
  3078. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3079. {
  3080. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3081. compositePeriodIdx++;
  3082. }
  3083. else
  3084. {
  3085. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3086. }
  3087. }
  3088. // Delete duplicate period
  3089. if(compositePeriodIdx > 1)
  3090. {
  3091. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3092. {
  3093. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3094. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3095. compositePeriodIdx -= 1;
  3096. }
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. compositeProfile->ChargingSchedule.Duration = durationReq;
  3104. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3105. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3106. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3107. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3108. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3109. {
  3110. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3111. {
  3112. compositeProfile->ChargingProfileId = 1;
  3113. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3114. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3115. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3116. }
  3117. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3118. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3119. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3120. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3121. }
  3122. if(line)
  3123. free(line);
  3124. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3125. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3126. }
  3127. //==========================================
  3128. // Init all share memory
  3129. //==========================================
  3130. int InitShareMemory()
  3131. {
  3132. int result = PASS;
  3133. int MeterSMId;
  3134. //creat ShmSysConfigAndInfo
  3135. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3136. {
  3137. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3138. result = FAIL;
  3139. }
  3140. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3141. {
  3142. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3143. result = FAIL;
  3144. }
  3145. else
  3146. {}
  3147. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3148. {
  3149. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3150. result = FAIL;
  3151. }
  3152. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3153. {
  3154. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3155. result = FAIL;
  3156. }
  3157. else
  3158. {}
  3159. //creat ShmPsuData
  3160. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3161. {
  3162. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3163. result = FAIL;
  3164. }
  3165. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3166. {
  3167. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3168. result = FAIL;
  3169. }
  3170. else
  3171. {}
  3172. //link ShmOCPP16Data
  3173. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3174. {
  3175. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3176. result = FAIL;
  3177. }
  3178. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3179. {
  3180. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3181. result = FAIL;
  3182. }
  3183. else
  3184. {}
  3185. //creat ShmOCPP16DataPH
  3186. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3187. {
  3188. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3189. result = FAIL;
  3190. }
  3191. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3192. {
  3193. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3194. result = FAIL;
  3195. }
  3196. else
  3197. {}
  3198. /****************************** For Initial Settings************************************************/
  3199. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3200. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3201. // allocate Configuration memory address
  3202. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3203. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3204. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3205. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3206. //offline MeterValue Interval
  3207. TempMeterValueInterval = 0;
  3208. return result;
  3209. }
  3210. int ProcessShareMemory()
  3211. {
  3212. int result = PASS;
  3213. if(InitShareMemory() == FAIL)
  3214. {
  3215. DEBUG_ERROR("InitShareMemory NG\n");
  3216. if(ShmStatusCodeData!=NULL)
  3217. {
  3218. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3219. }
  3220. result = FAIL;
  3221. }
  3222. // Model name parsing
  3223. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3224. {
  3225. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3226. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3227. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3228. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3229. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3230. ) // 'D' means DC
  3231. {
  3232. // DO series
  3233. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3234. {
  3235. SystemInitial += 1;
  3236. gunTotalNumber += 1;
  3237. gunType[gun_index] = GUN_TYPE_DO;
  3238. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3239. {
  3240. case Gun_Type_Chademo:
  3241. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3242. break;
  3243. case Gun_Type_CCS_2:
  3244. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3245. break;
  3246. case Gun_Type_GB:
  3247. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3248. break;
  3249. case Gun_Type_AC:
  3250. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3251. break;
  3252. default:
  3253. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3254. break;
  3255. }
  3256. }
  3257. }
  3258. else
  3259. {
  3260. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3261. {
  3262. SystemInitial += 1;
  3263. gunTotalNumber += 1;
  3264. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3265. {
  3266. case Gun_Type_Chademo:
  3267. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3268. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3269. break;
  3270. case Gun_Type_CCS_2:
  3271. gunType[gun_index] = GUN_TYPE_CCS;
  3272. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3273. break;
  3274. case Gun_Type_GB:
  3275. gunType[gun_index] = GUN_TYPE_GBT;
  3276. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3277. break;
  3278. case Gun_Type_AC:
  3279. gunType[gun_index] = GUN_TYPE_AC;
  3280. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3281. break;
  3282. default:
  3283. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3284. break;
  3285. }
  3286. }
  3287. }
  3288. }
  3289. else
  3290. {
  3291. DEBUG_ERROR("Model name parsing fail.\n");
  3292. result = FAIL;
  3293. }
  3294. if(result != PASS)sleep(5);
  3295. return result;
  3296. }
  3297. void checkRemoteStart(uint8_t connectorIdInt)
  3298. {
  3299. uint8_t tempIndex;
  3300. int result = PASS;
  3301. char cmdBuf[512];
  3302. //check Transaction active
  3303. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3304. {
  3305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3306. {
  3307. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3308. }
  3309. else
  3310. {
  3311. tempIndex = connectorIdInt -1;
  3312. }
  3313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3314. {
  3315. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3316. {
  3317. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3318. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3319. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3320. {
  3321. //Reserved
  3322. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3323. }
  3324. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3325. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3326. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3327. {
  3328. //Reserved
  3329. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3330. result = FAIL;
  3331. goto end;
  3332. }
  3333. else
  3334. {
  3335. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3336. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3337. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3339. {
  3340. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3341. result = FAIL;
  3342. goto end;
  3343. }
  3344. }//END FOR ELSE
  3345. }
  3346. }// END FOR CHAdeMO_QUANTITY
  3347. }
  3348. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3349. {
  3350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3351. {
  3352. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3353. }
  3354. else
  3355. {
  3356. tempIndex = connectorIdInt -1;
  3357. }
  3358. for (int index = 0; index < CCS_QUANTITY; index++)
  3359. {
  3360. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3361. {
  3362. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3363. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3364. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3365. {
  3366. //Reserved
  3367. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3368. }
  3369. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3370. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3371. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3372. {
  3373. //Reserved
  3374. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3375. result = FAIL;
  3376. goto end;
  3377. }
  3378. else
  3379. {
  3380. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3381. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3382. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3383. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3384. {
  3385. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3386. result = FAIL;
  3387. goto end;
  3388. }
  3389. }// END FOR ELSE
  3390. }
  3391. }// END FOR CCS_QUANTITY
  3392. }
  3393. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3394. {
  3395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3396. {
  3397. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3398. }
  3399. else
  3400. {
  3401. tempIndex = connectorIdInt -1;
  3402. }
  3403. for (int index = 0; index < GB_QUANTITY; index++)
  3404. {
  3405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3406. {
  3407. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3408. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3409. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3410. {
  3411. //Reserved
  3412. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3413. }
  3414. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3415. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3416. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3417. {
  3418. //Reserved
  3419. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3420. result = FAIL;
  3421. goto end;
  3422. }
  3423. else
  3424. {
  3425. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3426. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3427. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3429. {
  3430. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3431. result = FAIL;
  3432. goto end;
  3433. }
  3434. }// END FOR ELSE
  3435. }
  3436. } // END FOR GB_QUANTITY
  3437. }
  3438. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3439. {
  3440. tempIndex = connectorIdInt -1;
  3441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3442. {
  3443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3444. {
  3445. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3446. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3447. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3448. {
  3449. //Reserved
  3450. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3451. }
  3452. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3453. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3454. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3455. {
  3456. //Reserved
  3457. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3458. result = FAIL;
  3459. goto end;
  3460. }
  3461. else
  3462. {
  3463. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3464. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3465. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3466. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3467. {
  3468. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3469. result = FAIL;
  3470. goto end;
  3471. }
  3472. }// END FOR ELSE
  3473. }
  3474. } // END FOR GB_QUANTITY
  3475. }
  3476. else
  3477. {
  3478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3479. {
  3480. tempIndex = 2;
  3481. }
  3482. else
  3483. {
  3484. tempIndex = connectorIdInt -1;
  3485. }
  3486. for (int index = 0; index < AC_QUANTITY; index++)
  3487. {
  3488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3489. {
  3490. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3492. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3493. {
  3494. //Reserved
  3495. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3496. }
  3497. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3498. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3499. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3500. {
  3501. //Reserved
  3502. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3503. result = FAIL;
  3504. goto end;
  3505. }
  3506. else
  3507. {
  3508. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3509. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3510. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3511. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3512. {
  3513. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3514. result = FAIL;
  3515. goto end;
  3516. }
  3517. }//END FOR ELSE
  3518. }
  3519. }// END FOR AC_QUANTITY
  3520. }
  3521. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3522. {
  3523. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3524. {
  3525. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3526. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3527. {
  3528. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3529. system(cmdBuf);
  3530. }
  3531. }
  3532. else
  3533. {
  3534. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3535. result = FAIL;
  3536. }
  3537. }
  3538. end:
  3539. if(result == PASS)
  3540. {
  3541. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3542. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3543. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3544. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3546. }
  3547. }
  3548. void CheckSystemValue(void)
  3549. {
  3550. char filenmae[100]={0};
  3551. char str[100]={0};
  3552. int tempIndex = 0;
  3553. //===============================
  3554. // send Heartbeat
  3555. //===============================
  3556. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3557. {
  3558. //parameter for test
  3559. sendHeartbeatRequest(0);
  3560. //==============================================
  3561. // Reset Waiting Time
  3562. //==============================================
  3563. HeartBeatWithNOResponse += 2;
  3564. }
  3565. //===============================
  3566. // Credit deduct report
  3567. //===============================
  3568. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3569. {
  3570. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo, ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice, ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData);
  3571. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3572. }
  3573. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3574. {
  3575. OCPP_query_deduct_info();
  3576. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3577. }
  3578. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3579. {
  3580. // ClockAlign MeterValue
  3581. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3582. {
  3583. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3584. {
  3585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3586. {
  3587. tempIndex = ((gun_index==2) ? 1: 0);
  3588. }
  3589. else
  3590. {
  3591. tempIndex = gun_index;
  3592. }
  3593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3594. {
  3595. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3596. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3597. {
  3598. reqClockAlignMeter[gun_index] = 1;
  3599. }
  3600. }// End for CHAdeMO
  3601. }
  3602. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3603. {
  3604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3605. {
  3606. tempIndex = ((gun_index==2) ? 1: 0);
  3607. }
  3608. else
  3609. {
  3610. tempIndex = gun_index;
  3611. }
  3612. for (int index = 0; index < CCS_QUANTITY; index++)
  3613. {
  3614. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3615. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3616. {
  3617. reqClockAlignMeter[gun_index] = 1;
  3618. }
  3619. } // End for CCS
  3620. }
  3621. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3624. {
  3625. tempIndex = ((gun_index==2) ? 1: 0);
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < GB_QUANTITY; index++)
  3632. {
  3633. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3634. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3635. {
  3636. reqClockAlignMeter[gun_index] = 1;
  3637. }
  3638. }// End for GB
  3639. }
  3640. else if(gunType[gun_index] == GUN_TYPE_DO)
  3641. {
  3642. tempIndex = gun_index;
  3643. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3644. {
  3645. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3646. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3647. {
  3648. reqClockAlignMeter[gun_index] = 1;
  3649. }
  3650. }
  3651. }
  3652. else
  3653. {
  3654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3655. {
  3656. tempIndex = 2;
  3657. }
  3658. else
  3659. {
  3660. tempIndex = gun_index;
  3661. }
  3662. for (int index = 0; index < AC_QUANTITY; index++)
  3663. {
  3664. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3665. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3666. {
  3667. reqClockAlignMeter[gun_index] = 1;
  3668. }
  3669. }//End for AC
  3670. }
  3671. }
  3672. }
  3673. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3674. {
  3675. //==========================================
  3676. // Check remote start without connector id
  3677. //==========================================
  3678. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3679. {
  3680. int connectorIdInt = -1;
  3681. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3682. {
  3683. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3684. {
  3685. connectorIdInt = (gun_index+1);
  3686. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3687. checkRemoteStart(connectorIdInt);
  3688. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3689. break;
  3690. }
  3691. }
  3692. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3693. {
  3694. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3695. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3696. }
  3697. }
  3698. //==========================================
  3699. // csu trigger DataTransferReq
  3700. //==========================================
  3701. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3702. {
  3703. sendDataTransferRequest(gun_index);
  3704. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3705. }
  3706. //===============================
  3707. // CSU Trigger Authorize Request
  3708. //===============================
  3709. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3710. {
  3711. sendAuthorizeRequest(0);
  3712. authorizeRetryTimes = authorizeRetryTimes + 1;
  3713. if(authorizeRetryTimes < 3)
  3714. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3715. }
  3716. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3717. {
  3718. authorizeRetryTimes = 0;
  3719. SetOcppConnStatus(FALSE);
  3720. server_sign = FALSE;
  3721. }
  3722. 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))
  3723. {
  3724. sendAuthorizeRequest(0);
  3725. }
  3726. //==============================================
  3727. // Charger start transaction
  3728. //==============================================
  3729. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3730. {
  3731. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3732. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3733. sendStartTransactionRequest(gun_index);
  3734. refreshStartTimer(&clientTime.StartTransaction);
  3735. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3736. //storeTempStopTransaction(gun_index);
  3737. }
  3738. //==============================================
  3739. // Charger stop transaction
  3740. //==============================================
  3741. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3742. {
  3743. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3744. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3745. sendStopTransactionRequest(gun_index);
  3746. refreshStartTimer(&clientTime.StopTransaction);
  3747. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3748. }
  3749. //==============================================
  3750. // Charger status report
  3751. //==============================================
  3752. //--- Check Mode Change ---//
  3753. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3754. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3757. {
  3758. tempIndex = ((gun_index==2) ? 1: 0);
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3765. {
  3766. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3767. {
  3768. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3769. {
  3770. // Sent unplug message for California pricing logic
  3771. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3772. {
  3773. uint8_t ts[20];
  3774. getNowDatetime(ts);
  3775. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3776. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3777. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3778. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3779. }
  3780. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3781. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3782. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3783. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3784. {
  3785. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3786. if((access(filenmae,F_OK))!=-1)
  3787. {
  3788. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3789. sprintf(str,"rm -f %s",filenmae);
  3790. system(str);
  3791. }
  3792. }
  3793. }
  3794. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3795. #if 1 // for TempStopTransaction
  3796. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3797. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3798. {
  3799. checkTempStopTransaction(gun_index);
  3800. }
  3801. #endif
  3802. }
  3803. }
  3804. }
  3805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3806. {
  3807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3808. {
  3809. tempIndex = ((gun_index==2) ? 1: 0);
  3810. }
  3811. else
  3812. {
  3813. tempIndex = gun_index;
  3814. }
  3815. for (int index = 0; index < CCS_QUANTITY; index++)
  3816. {
  3817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3818. {
  3819. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  3820. {
  3821. // Sent unplug message for California pricing logic
  3822. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3823. {
  3824. uint8_t ts[20];
  3825. getNowDatetime(ts);
  3826. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3827. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3828. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3829. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3830. }
  3831. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3832. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3833. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3834. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3835. {
  3836. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3837. if((access(filenmae,F_OK))!=-1)
  3838. {
  3839. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3840. sprintf(str,"rm -f %s",filenmae);
  3841. system(str);
  3842. }
  3843. }
  3844. }
  3845. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3846. #if 1 // for TempStopTransaction
  3847. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3848. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3849. {
  3850. checkTempStopTransaction(gun_index);
  3851. }
  3852. #endif
  3853. }
  3854. }
  3855. }
  3856. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3857. {
  3858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3859. {
  3860. tempIndex = ((gun_index==2) ? 1: 0);
  3861. }
  3862. else
  3863. {
  3864. tempIndex = gun_index;
  3865. }
  3866. for (int index = 0; index < GB_QUANTITY; index++)
  3867. {
  3868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3869. {
  3870. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3871. {
  3872. // Sent unplug message for California pricing logic
  3873. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3874. {
  3875. uint8_t ts[20];
  3876. getNowDatetime(ts);
  3877. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3878. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3879. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3880. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3881. }
  3882. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3883. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3884. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3885. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3886. {
  3887. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3888. if((access(filenmae,F_OK))!=-1)
  3889. {
  3890. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3891. sprintf(str,"rm -f %s",filenmae);
  3892. system(str);
  3893. }
  3894. }
  3895. }
  3896. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3897. #if 1 // for TempStopTransaction
  3898. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3899. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3900. {
  3901. checkTempStopTransaction(gun_index);
  3902. }
  3903. #endif
  3904. }
  3905. }
  3906. }
  3907. else if(gunType[gun_index] == GUN_TYPE_DO)
  3908. {
  3909. tempIndex = gun_index;
  3910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3911. {
  3912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3913. {
  3914. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3915. {
  3916. // Sent unplug message for California pricing logic
  3917. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3918. {
  3919. uint8_t ts[20];
  3920. getNowDatetime(ts);
  3921. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3922. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3923. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3924. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3925. }
  3926. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3927. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3928. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3929. 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
  3930. {
  3931. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3932. if((access(filenmae,F_OK))!=-1)
  3933. {
  3934. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3935. sprintf(str,"rm -f %s",filenmae);
  3936. system(str);
  3937. }
  3938. }
  3939. }
  3940. 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);
  3941. #if 1 // for TempStopTransaction
  3942. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3943. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3944. {
  3945. checkTempStopTransaction(gun_index);
  3946. }
  3947. #endif
  3948. }
  3949. }
  3950. }
  3951. else
  3952. {
  3953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3954. {
  3955. tempIndex = 2;
  3956. }
  3957. else
  3958. {
  3959. tempIndex = gun_index;
  3960. }
  3961. for (int index = 0; index < AC_QUANTITY; index++)
  3962. {
  3963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3964. {
  3965. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3966. {
  3967. // Sent unplug message for California pricing logic
  3968. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3969. {
  3970. uint8_t ts[20];
  3971. getNowDatetime(ts);
  3972. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3973. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3974. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3975. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3976. }
  3977. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3978. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3979. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3980. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3981. {
  3982. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3983. if((access(filenmae,F_OK))!=-1)
  3984. {
  3985. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3986. sprintf(str,"rm -f %s",filenmae);
  3987. system(str);
  3988. }
  3989. }
  3990. }
  3991. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3992. #if 1 // for TempStopTransaction
  3993. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3994. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3995. {
  3996. checkTempStopTransaction(gun_index);
  3997. }
  3998. #endif
  3999. }
  4000. }// END
  4001. }
  4002. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4003. (
  4004. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4005. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4006. )
  4007. )
  4008. {
  4009. if(SystemInitial > 0)
  4010. SystemInitial -= 1;
  4011. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4012. sendStatusNotificationRequest(gun_index);
  4013. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4014. }
  4015. //==============================================
  4016. // CSU Trigger Smart Charging Profilw
  4017. //==============================================
  4018. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4019. {
  4020. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4021. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4022. }
  4023. //==============================================
  4024. // Meter report
  4025. //==============================================
  4026. // Trigger MeterValue
  4027. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4028. {
  4029. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4030. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4031. }
  4032. // Clock-aligned Meter value
  4033. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4034. {
  4035. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4036. reqClockAlignMeter[gun_index] = 0;
  4037. }
  4038. // Sample period MeterValue
  4039. 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))))
  4040. {
  4041. //check Transaction active
  4042. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4043. {
  4044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4045. {
  4046. tempIndex = ((gun_index==2) ? 1: 0);
  4047. }
  4048. else
  4049. {
  4050. tempIndex = gun_index;
  4051. }
  4052. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4053. {
  4054. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4055. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4056. {
  4057. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4058. {
  4059. reqSampleMeter[gun_index] = 1;
  4060. }
  4061. }
  4062. }// End for CHAdeMO
  4063. }
  4064. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4065. {
  4066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4067. {
  4068. tempIndex = ((gun_index==2) ? 1: 0);
  4069. }
  4070. else
  4071. {
  4072. tempIndex = gun_index;
  4073. }
  4074. for (int index = 0; index < CCS_QUANTITY; index++)
  4075. {
  4076. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4077. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4078. {
  4079. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4080. {
  4081. reqSampleMeter[gun_index] = 1;
  4082. }
  4083. }
  4084. } // End for CCS
  4085. }
  4086. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4087. {
  4088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4089. {
  4090. tempIndex = ((gun_index==2) ? 1: 0);
  4091. }
  4092. else
  4093. {
  4094. tempIndex = gun_index;
  4095. }
  4096. for (int index = 0; index < GB_QUANTITY; index++)
  4097. {
  4098. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4099. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4100. {
  4101. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4102. {
  4103. reqSampleMeter[gun_index] = 1;
  4104. }
  4105. }
  4106. }// End for GB
  4107. }
  4108. else if(gunType[gun_index] == GUN_TYPE_DO)
  4109. {
  4110. tempIndex = gun_index;
  4111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4112. {
  4113. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4114. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4117. {
  4118. reqSampleMeter[gun_index] = 1;
  4119. }
  4120. }
  4121. }
  4122. }
  4123. else
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4126. {
  4127. tempIndex = 2;
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < AC_QUANTITY; index++)
  4134. {
  4135. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4136. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4137. {
  4138. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4139. {
  4140. reqSampleMeter[gun_index] = 1;
  4141. }
  4142. }
  4143. }//End for AC
  4144. }
  4145. if(reqSampleMeter[gun_index] == 1)
  4146. {
  4147. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4148. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4149. //storeTempStopTransaction(gun_index);
  4150. reqSampleMeter[gun_index] = 0;
  4151. }
  4152. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4153. }
  4154. //==============================================
  4155. // Check Connector reserved
  4156. //==============================================
  4157. //===============================
  4158. // Check if Reserve is expired
  4159. //===============================
  4160. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4161. {
  4162. double diff_t;
  4163. struct tm tp;
  4164. // current time
  4165. time_t t = time(NULL);
  4166. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4167. tp.tm_isdst = -1;
  4168. time_t utc = mktime(&tp);
  4169. diff_t = difftime(utc, t);
  4170. if(diff_t <= 0)
  4171. {
  4172. DEBUG_INFO("reserve expired.\n");
  4173. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4174. }
  4175. }//END OF Check if Reserve is expired
  4176. //==========================================
  4177. // csu trigger FirmwareStatusNotificationReq
  4178. //==========================================
  4179. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4180. {
  4181. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4182. }
  4183. //==========================================
  4184. // csu trigger DiagnosticsStatusNotificationReq
  4185. //==========================================
  4186. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4187. {
  4188. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4189. }
  4190. //==========================================
  4191. // csu trigger CancelReservationConf
  4192. //==========================================
  4193. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4194. {
  4195. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4196. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4197. }
  4198. //==========================================
  4199. // csu trigger ChangeAvailabilityConf
  4200. //==========================================
  4201. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4202. {
  4203. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4204. }
  4205. //==========================================
  4206. // csu trigger UnlockConnectorConf
  4207. //==========================================
  4208. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4209. {
  4210. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4211. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4212. }
  4213. //==========================================
  4214. // csu trigger ReserveNowConf
  4215. //==========================================
  4216. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4217. {
  4218. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4219. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4220. }
  4221. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4222. {
  4223. sendSignCertificateRequest();
  4224. }
  4225. }
  4226. }
  4227. //==========================================
  4228. // send request routine
  4229. //==========================================
  4230. int sendAuthorizeRequest(int gun_index)
  4231. {
  4232. mtrace();
  4233. int result = FAIL;
  4234. char message[100]={0};
  4235. char guid[37];
  4236. char tempdata[65]={0};
  4237. DEBUG_INFO("sendAuthorizeRequest...\n");
  4238. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4239. //Local Authorize
  4240. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4241. {
  4242. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4243. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4244. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4245. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4246. result = PASS;
  4247. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4248. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4249. authorizeRetryTimes = 0;
  4250. return result;
  4251. }
  4252. 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))||
  4253. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4254. {
  4255. // Query from cache
  4256. DEBUG_INFO("Authorize from cache.\n");
  4257. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4258. // Query from list
  4259. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4260. {
  4261. DEBUG_INFO("Authorize from list.\n");
  4262. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4263. }
  4264. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4265. {
  4266. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4267. {
  4268. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4269. }
  4270. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4271. {
  4272. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4273. }
  4274. if(!GetOcppConnStatus())
  4275. {
  4276. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4277. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4278. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4279. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4280. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4281. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4282. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4283. authorizeRetryTimes = 0;
  4284. return result;
  4285. }
  4286. }
  4287. else
  4288. {
  4289. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4290. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4291. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4292. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4293. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4294. else
  4295. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4296. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4297. result = PASS;
  4298. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4299. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4300. authorizeRetryTimes = 0;
  4301. return result;
  4302. }
  4303. }
  4304. //initialize struct Authorize
  4305. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4306. //get data from shared memory
  4307. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4308. random_uuid(guid);
  4309. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4310. LWS_Send(message);
  4311. sprintf(tempdata, "Authorize,%d", gun_index);
  4312. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4313. {
  4314. result = PASS;
  4315. DEBUG_INFO("Authorize mapItem pass\n");
  4316. }
  4317. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4318. return result;
  4319. }
  4320. int sendBootNotificationRequest(void)
  4321. {
  4322. mtrace();
  4323. int result = FAIL;
  4324. char message[500]={0}, payload[700]={0};
  4325. char guid[37]={0};
  4326. char tempdata[65]={0};
  4327. // Fill BootNotification fields
  4328. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4329. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4330. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4331. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4332. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4333. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4334. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4335. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4336. ShmOCPP16DataPH->ChargeBoxId
  4337. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4338. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4339. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4340. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4341. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4342. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4343. random_uuid(guid);
  4344. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4345. LWS_Send(message);
  4346. sprintf(tempdata, "BootNotification,0");
  4347. 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*/)
  4348. {
  4349. result = PASS;
  4350. }
  4351. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4352. strcpy(queuedata,message);
  4353. return result;
  4354. }
  4355. int sendDataTransferRequest(int gun_index)
  4356. {
  4357. mtrace();
  4358. char message[1000]={0};
  4359. char guid[37]={0};
  4360. char tempdata[65]={0};
  4361. int result = FAIL;
  4362. random_uuid(guid);
  4363. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4364. MESSAGE_TYPE_CALL,
  4365. guid,
  4366. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4367. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4368. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4369. LWS_Send(message);
  4370. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4371. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4372. {
  4373. result = PASS;
  4374. DEBUG_INFO("DataTransfer mapItem pass\n");
  4375. }
  4376. return result;
  4377. }
  4378. int sendDiagnosticsStatusNotificationRequest(char *status)
  4379. {
  4380. mtrace();
  4381. int result = FAIL;
  4382. char message[110]={0};
  4383. char guid[37]={0};
  4384. char tempdata[65]={0};
  4385. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4386. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4387. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4388. random_uuid(guid);
  4389. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4390. LWS_SendNow(message);
  4391. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4392. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4393. {
  4394. result = PASS;
  4395. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4396. }
  4397. //#ifdef SystemLogMessage
  4398. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4399. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4400. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4401. //#endif
  4402. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4403. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4404. //record status
  4405. if(strcmp(status,"Idle")==0)
  4406. {
  4407. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4408. }
  4409. else if(strcmp(status,"Uploaded")==0)
  4410. {
  4411. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4412. }
  4413. else if(strcmp(status,"UploadFailed")==0)
  4414. {
  4415. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4416. }
  4417. else if(strcmp(status,"Uploading")==0)
  4418. {
  4419. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4420. }
  4421. return result;
  4422. }
  4423. int sendFirmwareStatusNotificationRequest(char *status)
  4424. {
  4425. mtrace();
  4426. int result = FAIL;
  4427. char message[110]={0};
  4428. char guid[37]={0};
  4429. char tempdata[65]={0};
  4430. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4431. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4432. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4433. random_uuid(guid);
  4434. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4435. LWS_SendNow(message);
  4436. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4437. 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*/)
  4438. {
  4439. result = PASS;
  4440. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4441. }
  4442. //#ifdef SystemLogMessage
  4443. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4444. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4445. //#endif
  4446. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4447. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4448. //record status
  4449. if(strcmp(status,"Downloaded")==0)
  4450. {
  4451. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4452. }
  4453. else if(strcmp(status,"DownloadFailed")==0)
  4454. {
  4455. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4456. }
  4457. else if(strcmp(status,"Downloading")==0)
  4458. {
  4459. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4460. }
  4461. else if(strcmp(status,"Idle")==0)
  4462. {
  4463. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4464. }
  4465. else if(strcmp(status,"InstallationFailed")==0)
  4466. {
  4467. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4468. }
  4469. else if(strcmp(status,"Installing")==0)
  4470. {
  4471. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4472. }
  4473. else if(strcmp(status,"Installed")==0)
  4474. {
  4475. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4476. }
  4477. return result;
  4478. }
  4479. int sendHeartbeatRequest(int gun_index)
  4480. {
  4481. mtrace();
  4482. int result = FAIL;
  4483. char message[80]={0};
  4484. char guid[37]={0};
  4485. char tempdata[65]={0};
  4486. random_uuid(guid);
  4487. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4488. , MESSAGE_TYPE_CALL
  4489. , guid );
  4490. LWS_Send(message);
  4491. sprintf(tempdata, "Heartbeat,%d", 0);
  4492. 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*/)
  4493. {
  4494. result = PASS;
  4495. }
  4496. return result;
  4497. }
  4498. int sendStartTransactionRequest(int gun_index)
  4499. {
  4500. mtrace();
  4501. int result = FAIL;
  4502. char message[250]={0};
  4503. char guid[37]={0};
  4504. struct timeval tmnow;
  4505. struct tm *tm;
  4506. char buf[28];//, usec_buf[6];
  4507. char tempdata[65]={0};
  4508. int tempIndex = 0;
  4509. DEBUG_INFO("sendStartTransactionRequest...\n");
  4510. gettimeofday(&tmnow, NULL);
  4511. time_t t;
  4512. t = time(NULL);
  4513. /*UTC time and date*/
  4514. tm = gmtime(&t);
  4515. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4516. #if 0 // remove temporally
  4517. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4518. strcat(buf,".");
  4519. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4520. strcat(buf,usec_buf);
  4521. #endif
  4522. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4523. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4524. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4525. // clear StartTransaction Response
  4526. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4527. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4528. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4529. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4530. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4531. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4532. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4535. {
  4536. tempIndex = ((gun_index==2) ? 1: 0);
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4545. {
  4546. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4547. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4548. }
  4549. }
  4550. }
  4551. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4552. {
  4553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4554. {
  4555. tempIndex = ((gun_index==2) ? 1: 0);
  4556. }
  4557. else
  4558. {
  4559. tempIndex = gun_index;
  4560. }
  4561. for (int index = 0; index < CCS_QUANTITY; index++)
  4562. {
  4563. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4564. {
  4565. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4566. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4567. }
  4568. }
  4569. }
  4570. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4571. {
  4572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4573. {
  4574. tempIndex = ((gun_index==2) ? 1: 0);
  4575. }
  4576. else
  4577. {
  4578. tempIndex = gun_index;
  4579. }
  4580. for (int index = 0; index < GB_QUANTITY; index++)
  4581. {
  4582. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4583. {
  4584. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4585. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4586. }
  4587. }
  4588. }
  4589. else if(gunType[gun_index] == GUN_TYPE_DO)
  4590. {
  4591. tempIndex = gun_index;
  4592. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4595. {
  4596. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4597. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4598. }
  4599. }
  4600. }
  4601. else
  4602. {
  4603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4604. {
  4605. tempIndex = 2;
  4606. }
  4607. else
  4608. {
  4609. tempIndex = gun_index;
  4610. }
  4611. for (int index = 0; index < AC_QUANTITY; index++)
  4612. {
  4613. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4614. {
  4615. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4616. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4617. }
  4618. }
  4619. }
  4620. random_uuid(guid);
  4621. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4622. {
  4623. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4624. , gun_index +1
  4625. , MESSAGE_TYPE_CALL
  4626. , guid
  4627. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4628. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4629. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4630. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4631. }
  4632. else
  4633. {
  4634. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4635. , gun_index +1
  4636. , MESSAGE_TYPE_CALL
  4637. , guid
  4638. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4639. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4640. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4641. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4642. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4643. }
  4644. #if 1
  4645. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4646. 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*/)
  4647. {
  4648. result = PASS;
  4649. }
  4650. #endif
  4651. strcpy(queuedata, message);
  4652. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4653. OCPP_insert_transaction_msg(YES, queuedata);
  4654. return result;
  4655. }
  4656. int sendStatusNotificationRequest(int gun_index)
  4657. {
  4658. mtrace();
  4659. int result = FAIL;
  4660. char message[600]={0};
  4661. char guid[37];
  4662. int currentStatus = 0;
  4663. struct timeval tmnow;
  4664. struct tm *tm;
  4665. char buf[28];//, usec_buf[6];
  4666. char tempdata[65]={0};
  4667. int tempIndex = 0;
  4668. uint8_t isStateChanged = TRUE;
  4669. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4670. gettimeofday(&tmnow, NULL);
  4671. time_t t;
  4672. t = time(NULL);
  4673. /*UTC time and date*/
  4674. tm = gmtime(&t);
  4675. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4676. #if 0 // remove temporally
  4677. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4678. strcat(buf,".");
  4679. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4680. strcat(buf,usec_buf);
  4681. #endif
  4682. //printf("%s",buf);
  4683. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4684. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4685. // it's option
  4686. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4687. /*
  4688. enum _SYSTEM_STATUS
  4689. {
  4690. S_BOOTING = 0,
  4691. S_IDLE, = 1
  4692. S_AUTHORIZING, =2
  4693. S_REASSIGN_CHECK, =3
  4694. S_REASSIGN, =4
  4695. S_PRECHARGE, =5
  4696. S_PREPARING_FOR_EV, =6
  4697. S_PREPARING_FOR_EVSE, =7
  4698. S_CHARGING, =8
  4699. S_TERMINATING, =9
  4700. S_COMPLETE, =10
  4701. S_ALARM, =11
  4702. S_FAULT =12
  4703. }
  4704. */
  4705. //check Transaction active
  4706. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4707. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4708. {
  4709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4710. {
  4711. tempIndex = ((gun_index==2) ? 1: 0);
  4712. }
  4713. else
  4714. {
  4715. tempIndex = gun_index;
  4716. }
  4717. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4718. {
  4719. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4720. {
  4721. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4722. {
  4723. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4724. {
  4725. currentStatus = Preparing; //OCPP Status: Preparing
  4726. }
  4727. else
  4728. {
  4729. currentStatus = Available; //OCPP Status: Available
  4730. }
  4731. }
  4732. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4733. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4734. ) //S_PRECHARGE
  4735. {
  4736. currentStatus = Preparing; //OCPP Status: Preparing
  4737. }
  4738. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4739. {
  4740. currentStatus = Charging; //OCPP Status: Charging
  4741. }
  4742. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4743. {
  4744. currentStatus = Finishing; //OCPP Status: Finishing
  4745. }
  4746. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4747. {
  4748. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4749. }
  4750. 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
  4751. {
  4752. currentStatus = Unavailable; //OCPP Status: Unavailable
  4753. }
  4754. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4755. {
  4756. currentStatus = Faulted; //OCPP Status: Faulted
  4757. }
  4758. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4759. {
  4760. currentStatus = Reserved; //OCPP Status: Reserved
  4761. }
  4762. } //end of the same index
  4763. }//end of for CHAdeMO_QUANTITY
  4764. }
  4765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4766. {
  4767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4768. {
  4769. tempIndex = ((gun_index==2) ? 1: 0);
  4770. }
  4771. else
  4772. {
  4773. tempIndex = gun_index;
  4774. }
  4775. for (int index = 0; index < CCS_QUANTITY; index++)
  4776. {
  4777. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4778. {
  4779. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4780. {
  4781. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4782. {
  4783. currentStatus = Preparing; //OCPP Status: Preparing
  4784. }
  4785. else
  4786. {
  4787. currentStatus = Available; //OCPP Status: Available
  4788. }
  4789. }
  4790. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4791. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4792. ) //S_PRECHARGE
  4793. {
  4794. currentStatus = Preparing; //OCPP Status: Preparing
  4795. }
  4796. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4797. {
  4798. currentStatus = Charging; //OCPP Status: Charging
  4799. }
  4800. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4801. {
  4802. currentStatus = Finishing; //OCPP Status: Finishing
  4803. }
  4804. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4805. {
  4806. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4807. }
  4808. 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
  4809. {
  4810. currentStatus = Unavailable; //OCPP Status : Unavailable
  4811. }
  4812. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4813. {
  4814. currentStatus = Faulted; //OCPP Status: Faulted
  4815. }
  4816. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4817. {
  4818. currentStatus = Reserved; //OCPP Status: Reserved
  4819. }
  4820. } //end of the same index
  4821. } // end of for CCS_QUANTITY
  4822. }
  4823. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4824. {
  4825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4826. {
  4827. tempIndex = ((gun_index==2) ? 1: 0);
  4828. }
  4829. else
  4830. {
  4831. tempIndex = gun_index;
  4832. }
  4833. for (int index = 0; index < GB_QUANTITY; index++)
  4834. {
  4835. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4836. {
  4837. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4838. {
  4839. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4840. {
  4841. currentStatus = Preparing; //OCPP Status: Preparing
  4842. }
  4843. else
  4844. {
  4845. currentStatus = Available; //OCPP Status: Available
  4846. }
  4847. }
  4848. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4849. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4850. ) //S_PRECHARGE
  4851. {
  4852. currentStatus = Preparing; //OCPP Status: Preparing
  4853. }
  4854. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4855. {
  4856. currentStatus = Charging; //OCPP Status: Charging
  4857. }
  4858. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4859. {
  4860. currentStatus = Finishing; //OCPP Status: Finishing
  4861. }
  4862. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4863. {
  4864. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4865. }
  4866. 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
  4867. {
  4868. currentStatus = Unavailable; //OCPP Status: Unavailable
  4869. }
  4870. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4871. {
  4872. currentStatus = Faulted; //OCPP Status: Faulted
  4873. }
  4874. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4875. {
  4876. currentStatus = Reserved; //OCPP Status: Reserved
  4877. }
  4878. } //end of the same index
  4879. } // end of for GB_QUANTITY
  4880. }
  4881. else if(gunType[gun_index] == GUN_TYPE_DO)
  4882. {
  4883. tempIndex = gun_index;
  4884. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4885. {
  4886. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4887. {
  4888. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4889. {
  4890. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4891. {
  4892. currentStatus = Preparing; //OCPP Status: Preparing
  4893. }
  4894. else
  4895. {
  4896. currentStatus = Available; //OCPP Status: Available
  4897. }
  4898. }
  4899. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4900. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4901. ) //S_PRECHARGE
  4902. {
  4903. currentStatus = Preparing; //OCPP Status: Preparing
  4904. }
  4905. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4906. {
  4907. currentStatus = Charging; //OCPP Status: Charging
  4908. }
  4909. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4910. {
  4911. currentStatus = Finishing; //OCPP Status: Finishing
  4912. }
  4913. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4914. {
  4915. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4916. }
  4917. 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
  4918. {
  4919. currentStatus = Unavailable; //OCPP Status: Unavailable
  4920. }
  4921. 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
  4922. {
  4923. currentStatus = Faulted; //OCPP Status: Faulted
  4924. }
  4925. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4926. {
  4927. currentStatus = Reserved; //OCPP Status: Reserved
  4928. }
  4929. } //end of the same index
  4930. }
  4931. }
  4932. else
  4933. {
  4934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4935. {
  4936. tempIndex = 2;
  4937. }
  4938. else
  4939. {
  4940. tempIndex = gun_index;
  4941. }
  4942. for (int index = 0; index < AC_QUANTITY; index++)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4945. {
  4946. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4947. {
  4948. 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))
  4949. {
  4950. currentStatus = Preparing; //OCPP Status: Preparing
  4951. }
  4952. else
  4953. {
  4954. currentStatus = Available; //OCPP Status: Available
  4955. }
  4956. }
  4957. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4958. {
  4959. currentStatus = Preparing; //OCPP Status: Preparing
  4960. }
  4961. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4962. {
  4963. currentStatus = Charging; //OCPP Status: Charging
  4964. }
  4965. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4966. {
  4967. currentStatus = Finishing; //OCPP Status: Finishing
  4968. }
  4969. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4970. {
  4971. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4972. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4973. else
  4974. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4975. }
  4976. 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
  4977. {
  4978. currentStatus = Unavailable; //OCPP Status: Unavailable
  4979. }
  4980. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4981. {
  4982. currentStatus = Faulted; //OCPP Status: Faulted
  4983. }
  4984. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4985. {
  4986. currentStatus = Reserved; //OCPP Status: Reserved
  4987. }
  4988. }//end of the same index
  4989. }//end of for AC_QUANTITY
  4990. }
  4991. //it's option
  4992. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4993. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  4994. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  4995. {
  4996. isStateChanged = FALSE;
  4997. }
  4998. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4999. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5000. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5001. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5002. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5003. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5004. random_uuid(guid);
  5005. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5006. , MESSAGE_TYPE_CALL
  5007. , guid
  5008. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5009. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5010. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5011. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5012. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5013. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5014. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5015. if((server_sign == TRUE) && isStateChanged)
  5016. {
  5017. LWS_Send(message);
  5018. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5019. 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*/)
  5020. {
  5021. //DEBUG_ERROR("statusNotification mapitem pass");
  5022. result = PASS;
  5023. }
  5024. }
  5025. else
  5026. {
  5027. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5028. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5029. result = PASS;
  5030. }
  5031. return result;
  5032. }
  5033. int sendStopTransactionRequest(int gun_index)
  5034. {
  5035. mtrace();
  5036. int result = FAIL;
  5037. //char message[1500]={0};
  5038. char guid[37]={0};
  5039. char tempdata[65]={0};
  5040. int tempIndex = 0;
  5041. char TempStopTransaction[256];
  5042. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5043. //int idx_sample=0;
  5044. DEBUG_INFO("sendStopTransactionRequest \n");
  5045. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5046. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5047. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5048. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5049. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5050. {
  5051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5052. {
  5053. tempIndex = ((gun_index==2) ? 1: 0);
  5054. }
  5055. else
  5056. {
  5057. tempIndex = gun_index;
  5058. }
  5059. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5060. {
  5061. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5062. {
  5063. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5064. }
  5065. }// END OF CHAdeMO_QUANTITY
  5066. }
  5067. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5068. {
  5069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5070. {
  5071. tempIndex = ((gun_index==2) ? 1: 0);
  5072. }
  5073. else
  5074. {
  5075. tempIndex = gun_index;
  5076. }
  5077. for (int index = 0; index < CCS_QUANTITY; index++)
  5078. {
  5079. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5080. {
  5081. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5082. }
  5083. }// END OF CCS_QUANTITY
  5084. }
  5085. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5086. {
  5087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5088. {
  5089. tempIndex = ((gun_index==2) ? 1: 0);
  5090. }
  5091. else
  5092. {
  5093. tempIndex = gun_index;
  5094. }
  5095. for (int index = 0; index < GB_QUANTITY; index++)
  5096. {
  5097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5098. {
  5099. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5100. }
  5101. }// END OF GB_QUANTITY
  5102. }
  5103. else if(gunType[gun_index] == GUN_TYPE_DO)
  5104. {
  5105. tempIndex = gun_index;
  5106. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5107. {
  5108. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5109. {
  5110. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5111. }
  5112. }// END OF GB_QUANTITY
  5113. }
  5114. else
  5115. {
  5116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5117. {
  5118. tempIndex = 2;
  5119. }
  5120. else
  5121. {
  5122. tempIndex = gun_index;
  5123. }
  5124. for (int index = 0; index < AC_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5127. {
  5128. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5129. }
  5130. }// END OF AC_QUANTITY
  5131. }
  5132. //====================================== Stop Transaction Time =====================================================
  5133. struct timeval tmnow;
  5134. struct tm *tm;
  5135. char buf[28];//, usec_buf[6];
  5136. gettimeofday(&tmnow, NULL);
  5137. time_t t;
  5138. t = time(NULL);
  5139. /*UTC time and date*/
  5140. tm = gmtime(&t);
  5141. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5143. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5144. random_uuid(guid);
  5145. /***********************************transactionData******************************************************/
  5146. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5148. //=================================
  5149. // Transaction_Begin
  5150. //=================================
  5151. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5152. {
  5153. //============================================ Energy.Active.Import.Interval ================================
  5154. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5158. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5159. 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))
  5160. {
  5161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5162. }
  5163. else
  5164. {
  5165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5166. }
  5167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5169. }
  5170. //=================================
  5171. // Transaction_End
  5172. //=================================
  5173. // ================================= Current.Import L1 ===============================================
  5174. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5175. {
  5176. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5177. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5192. }
  5193. }// End of for CHAdeMO_QUANTITY
  5194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5195. }
  5196. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5199. {
  5200. tempIndex = ((gun_index==2) ? 1: 0);
  5201. }
  5202. else
  5203. {
  5204. tempIndex = gun_index;
  5205. }
  5206. for (int index = 0; index < CCS_QUANTITY; index++)
  5207. {
  5208. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5209. {
  5210. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5211. }
  5212. }// End of for CCS_QUANTITY
  5213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5214. }
  5215. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5216. {
  5217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5218. {
  5219. tempIndex = ((gun_index==2) ? 1: 0);
  5220. }
  5221. else
  5222. {
  5223. tempIndex = gun_index;
  5224. }
  5225. for (int index = 0; index < GB_QUANTITY; index++)
  5226. {
  5227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5228. {
  5229. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5230. }
  5231. }// End of for GB_QUANTITY
  5232. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5233. }
  5234. else if(gunType[gun_index] == GUN_TYPE_DO)
  5235. {
  5236. tempIndex = gun_index;
  5237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5238. {
  5239. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5240. {
  5241. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5242. }
  5243. }
  5244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5245. }
  5246. else
  5247. {
  5248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5249. {
  5250. tempIndex = 2;
  5251. }
  5252. else
  5253. {
  5254. tempIndex = gun_index;
  5255. }
  5256. for (int index = 0; index < AC_QUANTITY; index++)
  5257. {
  5258. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5259. {
  5260. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5261. }
  5262. }// End of for AC_QUANTITY
  5263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5264. }
  5265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5270. }
  5271. // ================================= Energy.Active.Import.Interval ==============================================
  5272. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5273. {
  5274. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5275. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5276. {
  5277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5278. {
  5279. tempIndex = ((gun_index==2) ? 1: 0);
  5280. }
  5281. else
  5282. {
  5283. tempIndex = gun_index;
  5284. }
  5285. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5288. {
  5289. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5290. }
  5291. }// END OF CHAdeMO_QUANTITY
  5292. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5293. }
  5294. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5295. {
  5296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5297. {
  5298. tempIndex = ((gun_index==2) ? 1: 0);
  5299. }
  5300. else
  5301. {
  5302. tempIndex = gun_index;
  5303. }
  5304. for (int index = 0; index < CCS_QUANTITY; index++)
  5305. {
  5306. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5307. {
  5308. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5309. }
  5310. }// END OF CCS_QUANTITY
  5311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5312. }
  5313. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5314. {
  5315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5316. {
  5317. tempIndex = ((gun_index==2) ? 1: 0);
  5318. }
  5319. else
  5320. {
  5321. tempIndex = gun_index;
  5322. }
  5323. for (int index = 0; index < GB_QUANTITY; index++)
  5324. {
  5325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5326. {
  5327. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5328. }
  5329. }// END OF GB_QUANTITY
  5330. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5331. }
  5332. else if(gunType[gun_index] == GUN_TYPE_DO)
  5333. {
  5334. tempIndex = gun_index;
  5335. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5336. {
  5337. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5338. {
  5339. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5340. }
  5341. }
  5342. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5343. }
  5344. else
  5345. {
  5346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5347. {
  5348. tempIndex = 2;
  5349. }
  5350. else
  5351. {
  5352. tempIndex = gun_index;
  5353. }
  5354. for (int index = 0; index < AC_QUANTITY; index++)
  5355. {
  5356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5357. {
  5358. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5359. }
  5360. }// END OF AC_QUANTITY
  5361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5362. }
  5363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5368. }
  5369. //=================================== Power.Active.Import ==================================================
  5370. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5371. {
  5372. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5373. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5374. {
  5375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5376. {
  5377. tempIndex = ((gun_index==2) ? 1: 0);
  5378. }
  5379. else
  5380. {
  5381. tempIndex = gun_index;
  5382. }
  5383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5386. {
  5387. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5388. }
  5389. } // End for CHAdeMO_QUANTITY
  5390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5391. }
  5392. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5393. {
  5394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5395. {
  5396. tempIndex = ((gun_index==2) ? 1: 0);
  5397. }
  5398. else
  5399. {
  5400. tempIndex = gun_index;
  5401. }
  5402. for (int index = 0; index < CCS_QUANTITY; index++)
  5403. {
  5404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5405. {
  5406. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5407. }
  5408. } // END for CCS_QUANTITY
  5409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5410. }
  5411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5412. {
  5413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5414. {
  5415. tempIndex = ((gun_index==2) ? 1: 0);
  5416. }
  5417. else
  5418. {
  5419. tempIndex = gun_index;
  5420. }
  5421. for (int index = 0; index < GB_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5424. {
  5425. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5426. }
  5427. }// END for GB_QUANTITY
  5428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5429. }
  5430. else if(gunType[gun_index] == GUN_TYPE_DO)
  5431. {
  5432. tempIndex = gun_index;
  5433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5436. {
  5437. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5438. }
  5439. }
  5440. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5441. }
  5442. else
  5443. {
  5444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5445. {
  5446. tempIndex = 2;
  5447. }
  5448. else
  5449. {
  5450. tempIndex = gun_index;
  5451. }
  5452. for (int index = 0; index < AC_QUANTITY; index++)
  5453. {
  5454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5455. {
  5456. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5457. }
  5458. } // END for AC_QUANTITY
  5459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5460. }
  5461. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5466. }
  5467. //============================ Voltage L1 ====================================
  5468. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5469. {
  5470. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5471. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5474. {
  5475. tempIndex = ((gun_index==2) ? 1: 0);
  5476. }
  5477. else
  5478. {
  5479. tempIndex = gun_index;
  5480. }
  5481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5484. {
  5485. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5486. }
  5487. } // END OF FOR CHAdeMO_QUANTITY
  5488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5489. }
  5490. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5491. {
  5492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5493. {
  5494. tempIndex = ((gun_index==2) ? 1: 0);
  5495. }
  5496. else
  5497. {
  5498. tempIndex = gun_index;
  5499. }
  5500. for (int index = 0; index < CCS_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5503. {
  5504. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5505. }
  5506. } // END OF FOR CCS_QUANTITY
  5507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5508. }
  5509. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5510. {
  5511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5512. {
  5513. tempIndex = ((gun_index==2) ? 1: 0);
  5514. }
  5515. else
  5516. {
  5517. tempIndex = gun_index;
  5518. }
  5519. for (int index = 0; index < GB_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5522. {
  5523. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5524. }
  5525. } // END OF FOR GB_QUANTITY
  5526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5527. }
  5528. else if(gunType[gun_index] == GUN_TYPE_DO)
  5529. {
  5530. tempIndex = gun_index;
  5531. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5532. {
  5533. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5534. {
  5535. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5536. }
  5537. }
  5538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5539. }
  5540. else
  5541. {
  5542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5543. {
  5544. tempIndex = 2;
  5545. }
  5546. else
  5547. {
  5548. tempIndex = gun_index;
  5549. }
  5550. for (int index = 0; index < AC_QUANTITY; index++)
  5551. {
  5552. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5553. {
  5554. 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
  5555. }
  5556. } // END OF FOR AC_QUANTITY
  5557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5558. }
  5559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5562. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5564. }
  5565. //====================== End SoC ================================
  5566. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5567. {
  5568. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5569. 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))
  5570. {
  5571. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5572. {
  5573. tempIndex = ((gun_index==2) ? 1: 0);
  5574. }
  5575. else
  5576. {
  5577. tempIndex = gun_index;
  5578. }
  5579. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5580. {
  5581. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5582. {
  5583. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5584. {
  5585. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5586. }
  5587. }
  5588. }
  5589. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5590. {
  5591. for (int index = 0; index < CCS_QUANTITY; index++)
  5592. {
  5593. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5594. {
  5595. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5596. }
  5597. }
  5598. }
  5599. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5600. {
  5601. for (int index = 0; index < GB_QUANTITY; index++)
  5602. {
  5603. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5604. {
  5605. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5606. }
  5607. }
  5608. }
  5609. else if(gunType[gun_index] == GUN_TYPE_DO)
  5610. {
  5611. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5612. {
  5613. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5614. {
  5615. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5616. }
  5617. }
  5618. }
  5619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5625. } // END FOR DC CASE
  5626. }
  5627. // ================================= Current.Import L2 ===============================================
  5628. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5629. {
  5630. // AC 3 phse L2 current
  5631. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5632. {
  5633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5634. {
  5635. tempIndex = 2;
  5636. }
  5637. else
  5638. {
  5639. tempIndex = gun_index;
  5640. }
  5641. for (int index = 0; index < AC_QUANTITY; index++)
  5642. {
  5643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5644. {
  5645. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5646. }
  5647. }// End of for AC_QUANTITY
  5648. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5649. }
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5655. }
  5656. // ================================= Current.Import L3 ===============================================
  5657. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5658. {
  5659. // AC 3 phse L3 current
  5660. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5661. {
  5662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5663. {
  5664. tempIndex = 2;
  5665. }
  5666. else
  5667. {
  5668. tempIndex = gun_index;
  5669. }
  5670. for (int index = 0; index < AC_QUANTITY; index++)
  5671. {
  5672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5673. {
  5674. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5675. }
  5676. }// End of for AC_QUANTITY
  5677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5678. }
  5679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5684. }
  5685. //============================ Voltage L2 ====================================
  5686. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5687. {
  5688. // AC 3 phse L2 voltage
  5689. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5690. {
  5691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5692. {
  5693. tempIndex = 2;
  5694. }
  5695. else
  5696. {
  5697. tempIndex = gun_index;
  5698. }
  5699. for (int index = 0; index < AC_QUANTITY; index++)
  5700. {
  5701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5702. {
  5703. 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
  5704. }
  5705. } // END OF FOR AC_QUANTITY
  5706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5707. }
  5708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5711. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5713. }
  5714. //============================ Voltage L3 ====================================
  5715. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5716. {
  5717. // AC 3 phse L3 voltage
  5718. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5719. {
  5720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5721. {
  5722. tempIndex = 2;
  5723. }
  5724. else
  5725. {
  5726. tempIndex = gun_index;
  5727. }
  5728. for (int index = 0; index < AC_QUANTITY; index++)
  5729. {
  5730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5731. {
  5732. 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
  5733. }
  5734. } // END OF FOR AC_QUANTITY
  5735. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5736. }
  5737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5742. }
  5743. //====================== Start SoC ================================
  5744. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5745. {
  5746. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5747. 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))
  5748. {
  5749. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5758. {
  5759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5760. {
  5761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5762. {
  5763. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5764. }
  5765. }
  5766. }
  5767. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5768. {
  5769. for (int index = 0; index < CCS_QUANTITY; index++)
  5770. {
  5771. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5772. {
  5773. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5774. }
  5775. }
  5776. }
  5777. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5778. {
  5779. for (int index = 0; index < GB_QUANTITY; index++)
  5780. {
  5781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5782. {
  5783. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5784. }
  5785. }
  5786. }
  5787. else if(gunType[gun_index] == GUN_TYPE_DO)
  5788. {
  5789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5790. {
  5791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5792. {
  5793. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5794. }
  5795. }
  5796. }
  5797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5803. } // END FOR DC CASE
  5804. }
  5805. //================================================ Message create ====================================================
  5806. json_object *StopTransaction = json_object_new_object();
  5807. json_object *transactionDatas = json_object_new_array();
  5808. json_object *sampledValues = json_object_new_array();
  5809. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5810. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5811. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5812. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5813. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5814. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5815. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5816. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5817. {
  5818. json_object *transactionData = json_object_new_object();
  5819. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5820. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5821. {
  5822. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5823. {
  5824. json_object *sampledValue = json_object_new_object();
  5825. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5826. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5827. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5828. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5829. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5830. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5831. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5832. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5833. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5834. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5835. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5836. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5837. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5838. json_object_array_add(sampledValues, sampledValue);
  5839. }
  5840. }
  5841. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5842. json_object_array_add(transactionDatas, transactionData);
  5843. }
  5844. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5845. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5846. ,MESSAGE_TYPE_CALL
  5847. ,guid
  5848. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5849. json_object_put(StopTransaction);
  5850. #if 1 // for TempStopTransaction
  5851. //Delete TempStopTransaction
  5852. if((access(TempStopTransaction,F_OK))!=-1)
  5853. {
  5854. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5855. }
  5856. #endif
  5857. #if 1
  5858. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5859. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5860. {
  5861. result = PASS;
  5862. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5863. }
  5864. #endif
  5865. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5866. OCPP_insert_transaction_msg(NO, queuedata);
  5867. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5868. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5869. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5870. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5871. {
  5872. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5873. }
  5874. //for test
  5875. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5876. return result;
  5877. }
  5878. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5879. {
  5880. mtrace();
  5881. int result = FAIL;
  5882. char guid[37]={0};
  5883. char tempdata[65]={0};
  5884. int tempIndex = 0;
  5885. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5886. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5887. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5888. //set value
  5889. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5890. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5891. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5892. -1);
  5893. random_uuid(guid);
  5894. //UTC Date time
  5895. struct timeval tmnow;
  5896. struct tm *tm;
  5897. char buf[28];//, usec_buf[6];
  5898. gettimeofday(&tmnow, NULL);
  5899. time_t t;
  5900. t = time(NULL);
  5901. /*UTC time and date*/
  5902. tm = gmtime(&t);
  5903. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5904. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5905. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5906. //********************************(1)Current.Import L1************************************************/
  5907. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5908. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5909. (dataType == ReadingContext_Trigger))
  5910. {
  5911. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5913. {
  5914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5915. {
  5916. tempIndex = ((gun_index==2) ? 1: 0);
  5917. }
  5918. else
  5919. {
  5920. tempIndex = gun_index;
  5921. }
  5922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5923. {
  5924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5925. {
  5926. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5927. }
  5928. }
  5929. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5932. {
  5933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5934. {
  5935. tempIndex = ((gun_index==2) ? 1: 0);
  5936. }
  5937. else
  5938. {
  5939. tempIndex = gun_index;
  5940. }
  5941. for (int index = 0; index < CCS_QUANTITY; index++)
  5942. {
  5943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5944. {
  5945. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5946. }
  5947. }
  5948. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5949. }
  5950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5951. {
  5952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5953. {
  5954. tempIndex = ((gun_index==2) ? 1: 0);
  5955. }
  5956. else
  5957. {
  5958. tempIndex = gun_index;
  5959. }
  5960. for (int index = 0; index < GB_QUANTITY; index++)
  5961. {
  5962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5963. {
  5964. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5965. }
  5966. }
  5967. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5968. }
  5969. else if(gunType[gun_index] == GUN_TYPE_DO)
  5970. {
  5971. tempIndex = gun_index;
  5972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5973. {
  5974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5975. {
  5976. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5977. }
  5978. }
  5979. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5980. }
  5981. else
  5982. {
  5983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5984. {
  5985. tempIndex = 2;
  5986. }
  5987. else
  5988. {
  5989. tempIndex = gun_index;
  5990. }
  5991. for (int index = 0; index < AC_QUANTITY; index++)
  5992. {
  5993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5994. {
  5995. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5996. }
  5997. }
  5998. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5999. }
  6000. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6001. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6002. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6003. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6004. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6005. }
  6006. //********************************(2)Energy.Active.Import.Register ************************************************/
  6007. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6008. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6009. (dataType == ReadingContext_Trigger))
  6010. {
  6011. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6012. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6013. {
  6014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6015. {
  6016. tempIndex = ((gun_index==2) ? 1: 0);
  6017. }
  6018. else
  6019. {
  6020. tempIndex = gun_index;
  6021. }
  6022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6023. {
  6024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6025. {
  6026. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6027. }
  6028. }
  6029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6030. }
  6031. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6032. {
  6033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6034. {
  6035. tempIndex = ((gun_index==2) ? 1: 0);
  6036. }
  6037. else
  6038. {
  6039. tempIndex = gun_index;
  6040. }
  6041. for (int index = 0; index < CCS_QUANTITY; index++)
  6042. {
  6043. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6044. {
  6045. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6046. }
  6047. }
  6048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6049. }
  6050. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6051. {
  6052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6053. {
  6054. tempIndex = ((gun_index==2) ? 1: 0);
  6055. }
  6056. else
  6057. {
  6058. tempIndex = gun_index;
  6059. }
  6060. for (int index = 0; index < GB_QUANTITY; index++)
  6061. {
  6062. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6063. {
  6064. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6065. }
  6066. }
  6067. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6068. }
  6069. else if(gunType[gun_index] == GUN_TYPE_DO)
  6070. {
  6071. tempIndex = gun_index;
  6072. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6075. {
  6076. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6077. }
  6078. }
  6079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6080. }
  6081. else
  6082. {
  6083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6084. {
  6085. tempIndex = 2;
  6086. }
  6087. else
  6088. {
  6089. tempIndex = gun_index;
  6090. }
  6091. for (int index = 0; index < AC_QUANTITY; index++)
  6092. {
  6093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6094. {
  6095. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6096. }
  6097. }
  6098. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6099. }
  6100. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6101. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6102. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6103. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6105. }
  6106. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6107. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6108. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6109. (dataType == ReadingContext_Trigger))
  6110. {
  6111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6113. {
  6114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6115. {
  6116. tempIndex = ((gun_index==2) ? 1: 0);
  6117. }
  6118. else
  6119. {
  6120. tempIndex = gun_index;
  6121. }
  6122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6123. {
  6124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6125. {
  6126. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6127. }
  6128. } // END OF FOR CHAdeMO_QUANTITY
  6129. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6130. }
  6131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6132. {
  6133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6134. {
  6135. tempIndex = ((gun_index==2) ? 1: 0);
  6136. }
  6137. else
  6138. {
  6139. tempIndex = gun_index;
  6140. }
  6141. for (int index = 0; index < CCS_QUANTITY; index++)
  6142. {
  6143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6144. {
  6145. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6146. }
  6147. } // END OF CCS_QUANTITY
  6148. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6149. }
  6150. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6151. {
  6152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6153. {
  6154. tempIndex = ((gun_index==2) ? 1: 0);
  6155. }
  6156. else
  6157. {
  6158. tempIndex = gun_index;
  6159. }
  6160. for (int index = 0; index < GB_QUANTITY; index++)
  6161. {
  6162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6163. {
  6164. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6165. }
  6166. } // END OF GB_QUANTITY
  6167. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6168. }
  6169. else if(gunType[gun_index] == GUN_TYPE_DO)
  6170. {
  6171. tempIndex = gun_index;
  6172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6173. {
  6174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6175. {
  6176. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6177. }
  6178. }
  6179. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6180. }
  6181. else
  6182. {
  6183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6184. {
  6185. tempIndex = 2;
  6186. }
  6187. else
  6188. {
  6189. tempIndex = gun_index;
  6190. }
  6191. for (int index = 0; index < AC_QUANTITY; index++)
  6192. {
  6193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6194. {
  6195. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6196. }
  6197. }
  6198. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6199. }
  6200. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6201. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6202. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6203. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6204. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6205. }
  6206. //********************************(4)Power.Active.Import************************************************/
  6207. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6208. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6209. (dataType == ReadingContext_Trigger))
  6210. {
  6211. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6212. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6213. {
  6214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6215. {
  6216. tempIndex = ((gun_index==2) ? 1: 0);
  6217. }
  6218. else
  6219. {
  6220. tempIndex = gun_index;
  6221. }
  6222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6225. {
  6226. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6227. }
  6228. } // END OF FOR
  6229. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6230. }
  6231. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6232. {
  6233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6234. {
  6235. tempIndex = ((gun_index==2) ? 1: 0);
  6236. }
  6237. else
  6238. {
  6239. tempIndex = gun_index;
  6240. }
  6241. for (int index = 0; index < CCS_QUANTITY; index++)
  6242. {
  6243. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6244. {
  6245. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6246. }
  6247. }
  6248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6249. }
  6250. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6251. {
  6252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6253. {
  6254. tempIndex = ((gun_index==2) ? 1: 0);
  6255. }
  6256. else
  6257. {
  6258. tempIndex = gun_index;
  6259. }
  6260. for (int index = 0; index < GB_QUANTITY; index++)
  6261. {
  6262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6263. {
  6264. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6265. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6266. }
  6267. }
  6268. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6269. }
  6270. else if(gunType[gun_index] == GUN_TYPE_DO)
  6271. {
  6272. tempIndex = gun_index;
  6273. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6276. {
  6277. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6278. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6279. }
  6280. }
  6281. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6282. }
  6283. else
  6284. {
  6285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6286. {
  6287. tempIndex = 2;
  6288. }
  6289. else
  6290. {
  6291. tempIndex = gun_index;
  6292. }
  6293. for (int index = 0; index < AC_QUANTITY; index++)
  6294. {
  6295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6296. {
  6297. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6298. }
  6299. }
  6300. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6301. }
  6302. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6303. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6304. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6305. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6307. }
  6308. //***********************************************(5)VOLTAGE L1******************************************************/
  6309. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6310. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6311. (dataType == ReadingContext_Trigger))
  6312. {
  6313. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6314. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6315. {
  6316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6317. {
  6318. tempIndex = ((gun_index==2) ? 1: 0);
  6319. }
  6320. else
  6321. {
  6322. tempIndex = gun_index;
  6323. }
  6324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6325. {
  6326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6327. {
  6328. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6329. }
  6330. }
  6331. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6332. }
  6333. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6334. {
  6335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6336. {
  6337. tempIndex = ((gun_index==2) ? 1: 0);
  6338. }
  6339. else
  6340. {
  6341. tempIndex = gun_index;
  6342. }
  6343. for (int index = 0; index < CCS_QUANTITY; index++)
  6344. {
  6345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6346. {
  6347. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6348. }
  6349. }
  6350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6351. }
  6352. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6353. {
  6354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6355. {
  6356. tempIndex = ((gun_index==2) ? 1: 0);
  6357. }
  6358. else
  6359. {
  6360. tempIndex = gun_index;
  6361. }
  6362. for (int index = 0; index < GB_QUANTITY; index++)
  6363. {
  6364. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6365. {
  6366. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6367. }
  6368. }
  6369. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6370. }
  6371. else if(gunType[gun_index] == GUN_TYPE_DO)
  6372. {
  6373. tempIndex = gun_index;
  6374. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6375. {
  6376. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6377. {
  6378. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6379. }
  6380. }
  6381. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6382. }
  6383. else
  6384. {
  6385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6386. {
  6387. tempIndex = 2;
  6388. }
  6389. else
  6390. {
  6391. tempIndex = gun_index;
  6392. }
  6393. for (int index = 0; index < AC_QUANTITY; index++)
  6394. {
  6395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6396. {
  6397. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6398. }
  6399. }
  6400. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6401. }
  6402. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6403. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6404. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6405. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6406. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6407. }
  6408. //***********************************************(6)SOC******************************************************/
  6409. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6410. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6411. (dataType == ReadingContext_Trigger))
  6412. {
  6413. 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))
  6414. {
  6415. //idx_sample=5;
  6416. //sampledValue = NULL;
  6417. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6418. {
  6419. tempIndex = ((gun_index==2) ? 1: 0);
  6420. }
  6421. else
  6422. {
  6423. tempIndex = gun_index;
  6424. }
  6425. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6426. {
  6427. //tempIndex = ((gun_index==2) ? 1: 0);
  6428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6429. {
  6430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6431. {
  6432. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6433. }
  6434. }
  6435. }
  6436. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6437. {
  6438. //tempIndex = ((gun_index==2) ? 1: 0);
  6439. for (int index = 0; index < CCS_QUANTITY; index++)
  6440. {
  6441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6442. {
  6443. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6444. }
  6445. }
  6446. }
  6447. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6448. {
  6449. //tempIndex = ((gun_index==2) ? 1: 0);
  6450. for (int index = 0; index < GB_QUANTITY; index++)
  6451. {
  6452. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6453. {
  6454. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6455. }
  6456. }
  6457. }
  6458. else if(gunType[gun_index] == GUN_TYPE_DO)
  6459. {
  6460. //tempIndex = ((gun_index==2) ? 1: 0);
  6461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6462. {
  6463. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6464. {
  6465. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6466. }
  6467. }
  6468. }
  6469. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6470. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6471. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6472. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6473. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6474. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6475. }
  6476. }
  6477. //********************************(7)Current.Import L2************************************************/
  6478. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6479. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6480. (dataType == ReadingContext_Trigger))
  6481. {
  6482. // Only for AC 3 phase
  6483. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6484. {
  6485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6486. {
  6487. tempIndex = 2;
  6488. }
  6489. else
  6490. {
  6491. tempIndex = gun_index;
  6492. }
  6493. for (int index = 0; index < AC_QUANTITY; index++)
  6494. {
  6495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6496. {
  6497. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6498. }
  6499. }
  6500. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6501. }
  6502. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6503. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6504. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6507. }
  6508. //********************************(8)Current.Import L3************************************************/
  6509. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6510. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6511. (dataType == ReadingContext_Trigger))
  6512. {
  6513. // Only for AC 3 phase
  6514. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6515. {
  6516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6517. {
  6518. tempIndex = 2;
  6519. }
  6520. else
  6521. {
  6522. tempIndex = gun_index;
  6523. }
  6524. for (int index = 0; index < AC_QUANTITY; index++)
  6525. {
  6526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6527. {
  6528. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6529. }
  6530. }
  6531. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6532. }
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6538. }
  6539. //***********************************************(9)VOLTAGE L2******************************************************/
  6540. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6541. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6542. (dataType == ReadingContext_Trigger))
  6543. {
  6544. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6545. {
  6546. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6547. {
  6548. tempIndex = 2;
  6549. }
  6550. else
  6551. {
  6552. tempIndex = gun_index;
  6553. }
  6554. for (int index = 0; index < AC_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6557. {
  6558. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6559. }
  6560. }
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6562. }
  6563. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6564. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6565. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6566. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6567. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6568. }
  6569. //***********************************************(10)VOLTAGE L3******************************************************/
  6570. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6571. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6572. (dataType == ReadingContext_Trigger))
  6573. {
  6574. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6575. {
  6576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6577. {
  6578. tempIndex = 2;
  6579. }
  6580. else
  6581. {
  6582. tempIndex = gun_index;
  6583. }
  6584. for (int index = 0; index < AC_QUANTITY; index++)
  6585. {
  6586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6587. {
  6588. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6589. }
  6590. }
  6591. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6592. }
  6593. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6594. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6596. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6598. }
  6599. //***********************************************(11)Current.Offered******************************************************/
  6600. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6601. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6602. (dataType == ReadingContext_Trigger))
  6603. {
  6604. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6605. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6606. {
  6607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6608. {
  6609. tempIndex = ((gun_index==2) ? 1: 0);
  6610. }
  6611. else
  6612. {
  6613. tempIndex = gun_index;
  6614. }
  6615. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6616. {
  6617. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6618. {
  6619. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6620. }
  6621. } // END OF FOR CHAdeMO_QUANTITY
  6622. }
  6623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6624. {
  6625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6626. {
  6627. tempIndex = ((gun_index==2) ? 1: 0);
  6628. }
  6629. else
  6630. {
  6631. tempIndex = gun_index;
  6632. }
  6633. for (int index = 0; index < CCS_QUANTITY; index++)
  6634. {
  6635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6636. {
  6637. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6638. }
  6639. } // END OF CCS_QUANTITY
  6640. }
  6641. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6642. {
  6643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6644. {
  6645. tempIndex = ((gun_index==2) ? 1: 0);
  6646. }
  6647. else
  6648. {
  6649. tempIndex = gun_index;
  6650. }
  6651. for (int index = 0; index < GB_QUANTITY; index++)
  6652. {
  6653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6654. {
  6655. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6656. }
  6657. } // END OF GB_QUANTITY
  6658. }
  6659. else if(gunType[gun_index] == GUN_TYPE_DO)
  6660. {
  6661. tempIndex = gun_index;
  6662. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6663. {
  6664. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6665. {
  6666. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6667. }
  6668. }
  6669. }
  6670. else
  6671. {
  6672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6673. {
  6674. tempIndex = 2;
  6675. }
  6676. else
  6677. {
  6678. tempIndex = gun_index;
  6679. }
  6680. for (int index = 0; index < AC_QUANTITY; index++)
  6681. {
  6682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6683. {
  6684. uint16_t currentOffer;
  6685. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6686. {
  6687. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6688. }
  6689. else
  6690. {
  6691. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6692. }
  6693. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6694. }
  6695. }
  6696. }
  6697. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6698. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6699. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6701. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6702. }
  6703. //***********************************************(12)Power.Offered******************************************************/
  6704. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6705. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6706. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6707. {
  6708. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6709. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6710. {
  6711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6712. {
  6713. tempIndex = ((gun_index==2) ? 1: 0);
  6714. }
  6715. else
  6716. {
  6717. tempIndex = gun_index;
  6718. }
  6719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6720. {
  6721. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6722. {
  6723. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6724. }
  6725. } // END OF FOR CHAdeMO_QUANTITY
  6726. }
  6727. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6728. {
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6730. {
  6731. tempIndex = ((gun_index==2) ? 1: 0);
  6732. }
  6733. else
  6734. {
  6735. tempIndex = gun_index;
  6736. }
  6737. for (int index = 0; index < CCS_QUANTITY; index++)
  6738. {
  6739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6740. {
  6741. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6742. }
  6743. } // END OF CCS_QUANTITY
  6744. }
  6745. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6746. {
  6747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6748. {
  6749. tempIndex = ((gun_index==2) ? 1: 0);
  6750. }
  6751. else
  6752. {
  6753. tempIndex = gun_index;
  6754. }
  6755. for (int index = 0; index < GB_QUANTITY; index++)
  6756. {
  6757. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6758. {
  6759. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6760. }
  6761. } // END OF GB_QUANTITY
  6762. }
  6763. else if(gunType[gun_index] == GUN_TYPE_DO)
  6764. {
  6765. tempIndex = gun_index;
  6766. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6767. {
  6768. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6769. {
  6770. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6771. }
  6772. }
  6773. }
  6774. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6775. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6776. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6778. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6779. }
  6780. // Message create ====================================================================================================
  6781. if(TRUE)
  6782. {
  6783. json_object *MeterValueReq = json_object_new_object();
  6784. json_object *MeterValues = json_object_new_array();
  6785. json_object *sampledValues = json_object_new_array();
  6786. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6787. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6788. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6789. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6790. {
  6791. json_object *MeterValue = json_object_new_object();
  6792. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6793. {
  6794. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6795. {
  6796. json_object *sampledValue = json_object_new_object();
  6797. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6798. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6799. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6800. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6801. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6802. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6803. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6804. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6805. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6806. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6807. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6808. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6809. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6810. json_object_array_add(sampledValues, sampledValue);
  6811. }
  6812. }
  6813. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6814. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6815. json_object_array_add(MeterValues, MeterValue);
  6816. }
  6817. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6818. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6819. ,gun_index + 1
  6820. ,MESSAGE_TYPE_CALL
  6821. ,guid
  6822. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6823. json_object_put(MeterValueReq);
  6824. }
  6825. // Put request guid to hash map
  6826. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6827. 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*/)
  6828. {
  6829. result = PASS;
  6830. //DEBUG_INFO("MeterValues mapitem pass\n");
  6831. }
  6832. if((dataType != ReadingContext_Trigger) &&
  6833. (dataType != ReadingContext_Sample_Clock) &&
  6834. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6835. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6836. else
  6837. {
  6838. if(FirstHeartBeat)
  6839. LWS_Send(queuedata +2);
  6840. }
  6841. return result;
  6842. }
  6843. int sendLogStatusNotificationRequest(char *status)
  6844. {
  6845. mtrace();
  6846. int result = PASS;
  6847. char message[4096]={0};
  6848. char guid[37]={0};
  6849. char tempdata[128]={0};
  6850. json_object *LogStatusNotification = json_object_new_object();
  6851. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6852. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6853. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6854. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6855. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6856. random_uuid(guid);
  6857. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6858. json_object_put(LogStatusNotification);
  6859. LWS_Send(message);
  6860. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6861. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6862. {
  6863. result = PASS;
  6864. }
  6865. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6866. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6867. return result;
  6868. }
  6869. int sendSecurityEventNotificationRequest()
  6870. {
  6871. mtrace();
  6872. int result = PASS;
  6873. char message[4096]={0};
  6874. char guid[37]={0};
  6875. char tempdata[128]={0};
  6876. json_object *SecurityEventNotification = json_object_new_object();
  6877. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6878. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6879. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6880. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6881. random_uuid(guid);
  6882. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6883. json_object_put(SecurityEventNotification);
  6884. LWS_Send(message);
  6885. sprintf(tempdata, "SecurityEventNotification,0");
  6886. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6887. {
  6888. result = PASS;
  6889. }
  6890. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6891. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6892. return result;
  6893. }
  6894. int sendSignCertificateRequest()
  6895. {
  6896. mtrace();
  6897. int result = PASS;
  6898. char message[4096]={0};
  6899. char guid[37]={0};
  6900. char tempdata[128]={0};
  6901. json_object *SignCertificate = json_object_new_object();
  6902. DEBUG_INFO("sendSignCertificateRequest...\n");
  6903. // Read csr file content
  6904. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6905. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6906. char *line = NULL;
  6907. size_t len = 0;
  6908. while(getline(&line, &len, fp) != -1)
  6909. {
  6910. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6911. {
  6912. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6913. }
  6914. }
  6915. fclose(fp);
  6916. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6917. random_uuid(guid);
  6918. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6919. json_object_put(SignCertificate);
  6920. LWS_Send(message);
  6921. sprintf(tempdata, "SignCertificate,0");
  6922. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6923. {
  6924. result = PASS;
  6925. }
  6926. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6927. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6928. return result;
  6929. }
  6930. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6931. {
  6932. mtrace();
  6933. int result = PASS;
  6934. char message[110]={0};
  6935. char guid[37]={0};
  6936. char tempdata[65]={0};
  6937. json_object *FirmwareStatusNotification = json_object_new_object();
  6938. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6939. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6940. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6941. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6942. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6943. random_uuid(guid);
  6944. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6945. json_object_put(FirmwareStatusNotification);
  6946. LWS_Send(message);
  6947. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6948. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6949. {
  6950. result = PASS;
  6951. }
  6952. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6953. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6954. return result;
  6955. }
  6956. //==========================================
  6957. // send confirm routine
  6958. //==========================================
  6959. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6960. {
  6961. mtrace();
  6962. int result = FAIL;
  6963. char message[100]={0};
  6964. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6965. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6966. LWS_Send(message);
  6967. result = TRUE;
  6968. return result;
  6969. }
  6970. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6971. {
  6972. mtrace();
  6973. int result = FAIL;
  6974. char message[100]={0};
  6975. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6977. LWS_Send(message);
  6978. result = TRUE;
  6979. return result;
  6980. }
  6981. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6982. {
  6983. mtrace();
  6984. int result = FAIL;
  6985. char message[100]={0};
  6986. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6987. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6988. LWS_Send(message);
  6989. result = TRUE;
  6990. return result;
  6991. }
  6992. int sendClearCacheConfirmation(char *uuid,char *payload)
  6993. {
  6994. mtrace();
  6995. int result = FAIL;
  6996. char message[500]={0};
  6997. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6998. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6999. LWS_Send(message);
  7000. return result;
  7001. }
  7002. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7003. {
  7004. mtrace();
  7005. int result = FAIL;
  7006. char message[500]={0};
  7007. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7008. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7009. LWS_Send(message);
  7010. return result;
  7011. }
  7012. int sendDataTransferConfirmation(char *uuid,char *payload)
  7013. {
  7014. mtrace();
  7015. char statusStr[20]={0};
  7016. char dataStr[10]={0};
  7017. char sstr[20]={0};
  7018. int c = 0;
  7019. char *loc;
  7020. int result = FAIL;
  7021. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7022. /**********************status**************************/
  7023. loc = strstr(payload, "status");
  7024. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7025. c = 0;
  7026. while (loc[3+strlen("status")+c] != '\"')
  7027. {
  7028. sstr[c] = loc[3+strlen("status")+c];
  7029. c++;
  7030. }
  7031. sstr[c] = '\0';
  7032. strcpy(statusStr, sstr);
  7033. /**********************data**************************/
  7034. loc = strstr(payload, "data");
  7035. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7036. c = 0;
  7037. while (loc[3+strlen("data")+c] != '\"')
  7038. {
  7039. sstr[c] = loc[3+strlen("data")+c];
  7040. c++;
  7041. }
  7042. sstr[c] = '\0';
  7043. strcpy(dataStr, sstr);
  7044. return result;
  7045. }
  7046. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7047. {
  7048. mtrace();
  7049. int result = FAIL;
  7050. char message[1000]={0};
  7051. int CompositeScheduleIndex = 0;
  7052. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7053. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7054. if(nPeriod == 0)
  7055. {
  7056. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7057. {
  7058. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7059. ,MESSAGE_TYPE_CALLRESULT
  7060. ,uuid
  7061. ,payload
  7062. ,connectorIdInt);
  7063. }
  7064. else
  7065. {
  7066. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7067. ,MESSAGE_TYPE_CALLRESULT
  7068. ,uuid
  7069. ,payload
  7070. ,connectorIdInt
  7071. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7072. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7073. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7074. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7075. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7076. }
  7077. }
  7078. else
  7079. {
  7080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7081. ,MESSAGE_TYPE_CALLRESULT
  7082. ,uuid
  7083. ,payload
  7084. ,connectorIdInt
  7085. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7086. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7087. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7088. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7089. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7090. {
  7091. if (idx_sample == 0)
  7092. {
  7093. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7094. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7095. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7096. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7097. }
  7098. else
  7099. {
  7100. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7101. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7102. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7103. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7104. }
  7105. }
  7106. sprintf(message + strlen(message), "]}}]");
  7107. }
  7108. LWS_Send(message);
  7109. result = TRUE;
  7110. return result;
  7111. }
  7112. int sendGetConfigurationConfirmation(char *uuid)
  7113. {
  7114. mtrace();
  7115. int result = FAIL;
  7116. int MaxKeySupported = 0;
  7117. int sentConfigurationNumber= 0;
  7118. int sentunConfigurationNumber= 0;
  7119. char message[1024*10]={0};
  7120. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7121. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7122. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7123. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7124. ,MESSAGE_TYPE_CALLRESULT
  7125. ,uuid );
  7126. //configuration key
  7127. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7128. {
  7129. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7130. {
  7131. if (sentConfigurationNumber == 0)
  7132. {
  7133. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7134. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7135. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7136. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7137. }
  7138. else
  7139. {
  7140. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7141. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7142. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7143. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7144. }
  7145. sentConfigurationNumber = sentConfigurationNumber + 1;
  7146. }
  7147. }
  7148. sprintf(message + strlen(message), "]");
  7149. if(UnknownKeynum != 0)
  7150. {
  7151. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7152. //unkown key
  7153. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7154. {
  7155. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7156. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7157. if(sentunConfigurationNumber == 0)
  7158. {
  7159. sprintf(message + strlen(message), "\"%s\""
  7160. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7161. }
  7162. else
  7163. {
  7164. sprintf(message + strlen(message), ",\"%s\""
  7165. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7166. }
  7167. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7168. }
  7169. sprintf(message + strlen(message), "]");
  7170. }
  7171. sprintf(message + strlen(message), "}]");
  7172. LWS_Send(message);
  7173. return result;
  7174. }
  7175. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7176. {
  7177. mtrace();
  7178. int result = FAIL;
  7179. char message[400]={0};
  7180. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7181. if(strcmp(payload,"")==0)
  7182. {
  7183. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7184. }
  7185. else
  7186. {
  7187. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7188. }
  7189. LWS_Send(message);
  7190. result = TRUE;
  7191. return result;
  7192. }
  7193. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7194. {
  7195. mtrace();
  7196. int result = FAIL;
  7197. char message[80]={0};
  7198. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7199. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7200. LWS_Send(message);
  7201. result = TRUE;
  7202. return result;
  7203. }
  7204. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7205. {
  7206. mtrace();
  7207. int result = FAIL;
  7208. char message[80]={0};
  7209. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7210. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7211. LWS_Send(message);
  7212. result = TRUE;
  7213. return result;
  7214. }
  7215. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7216. {
  7217. mtrace();
  7218. int result = FAIL;
  7219. char message[80]={0};
  7220. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7221. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7222. LWS_Send(message);
  7223. result = TRUE;
  7224. return result;
  7225. }
  7226. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7227. {
  7228. mtrace();
  7229. int result = FAIL;
  7230. char message[80]={0};
  7231. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7232. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7233. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7234. LWS_Send(message);
  7235. result = TRUE;
  7236. return result;
  7237. }
  7238. int sendResetConfirmation(char *uuid,char *payload)
  7239. {
  7240. mtrace();
  7241. int result = FAIL;
  7242. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7243. char message[80]={0};
  7244. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7245. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7246. LWS_Send(message);
  7247. result = TRUE;
  7248. return result;
  7249. }
  7250. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7251. {
  7252. mtrace();
  7253. int result = FAIL;
  7254. char message[500]={0};
  7255. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7256. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7257. LWS_Send(message);
  7258. result = TRUE;
  7259. return result;
  7260. }
  7261. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7262. {
  7263. mtrace();
  7264. int result = FAIL;
  7265. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7266. char message[80]={0};
  7267. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7268. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7269. LWS_Send(message);
  7270. result = TRUE;
  7271. return result;
  7272. }
  7273. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7274. {
  7275. mtrace();
  7276. int result = FAIL;
  7277. char message[80]={0};
  7278. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7279. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7280. LWS_Send(message);
  7281. result = TRUE;
  7282. return result;
  7283. }
  7284. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7285. {
  7286. mtrace();
  7287. int result = FAIL;
  7288. char message[80]={0};
  7289. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7290. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7291. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7292. LWS_Send(message);
  7293. result = TRUE;
  7294. return result;
  7295. }
  7296. int sendUpdateFirmwareConfirmation(char *uuid)
  7297. {
  7298. mtrace();
  7299. int result = FAIL;
  7300. char message[60]={0};
  7301. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7302. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7303. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7304. LWS_Send(message);
  7305. result = TRUE;
  7306. return result;
  7307. }
  7308. int sendCertificateSignedConfirmation(char *uuid)
  7309. {
  7310. mtrace();
  7311. int result = PASS;
  7312. char message[4096]={0};
  7313. json_object *CertificateSigned = json_object_new_object();
  7314. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7315. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7316. sprintf(message,"[%d,\"%s\",%s]"
  7317. ,MESSAGE_TYPE_CALLRESULT
  7318. ,uuid
  7319. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7320. json_object_put(CertificateSigned);
  7321. LWS_Send(message);
  7322. return result;
  7323. }
  7324. int sendDeleteCertificateConfirmation(char *uuid)
  7325. {
  7326. mtrace();
  7327. int result = PASS;
  7328. char message[4096]={0};
  7329. json_object *DeleteCertificate = json_object_new_object();
  7330. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7331. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7332. sprintf(message,"[%d,\"%s\",%s]"
  7333. ,MESSAGE_TYPE_CALLRESULT
  7334. ,uuid
  7335. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7336. json_object_put(DeleteCertificate);
  7337. LWS_Send(message);
  7338. return result;
  7339. }
  7340. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7341. {
  7342. mtrace();
  7343. int result = PASS;
  7344. char message[4096]={0};
  7345. json_object *ExtendedTriggerMessage = json_object_new_object();
  7346. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7347. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7348. sprintf(message,"[%d,\"%s\",%s]"
  7349. ,MESSAGE_TYPE_CALLRESULT
  7350. ,uuid
  7351. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7352. json_object_put(ExtendedTriggerMessage);
  7353. LWS_Send(message);
  7354. return result;
  7355. }
  7356. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7357. {
  7358. mtrace();
  7359. int result = PASS;
  7360. char message[4096]={0};
  7361. json_object *GetInstalledCertificateIds = json_object_new_object();
  7362. json_object *certificateHashDataDatas = json_object_new_array();
  7363. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7364. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7365. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7366. {
  7367. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7368. {
  7369. json_object *certificateHashData = json_object_new_object();
  7370. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7371. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7372. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7373. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7374. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7375. }
  7376. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7377. }
  7378. else
  7379. {
  7380. json_object_put(certificateHashDataDatas);
  7381. }
  7382. sprintf(message,"[%d,\"%s\",%s]"
  7383. ,MESSAGE_TYPE_CALLRESULT
  7384. ,uuid
  7385. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7386. json_object_put(GetInstalledCertificateIds);
  7387. LWS_Send(message);
  7388. return result;
  7389. }
  7390. int sendGetLogConfirmation(char *uuid)
  7391. {
  7392. mtrace();
  7393. int result = PASS;
  7394. char message[4096]={0};
  7395. json_object *GetLog = json_object_new_object();
  7396. DEBUG_INFO("sendGetLogConfirmation...\n");
  7397. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7398. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7399. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7400. sprintf(message,"[%d,\"%s\",%s]"
  7401. ,MESSAGE_TYPE_CALLRESULT
  7402. ,uuid
  7403. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7404. json_object_put(GetLog);
  7405. LWS_Send(message);
  7406. return result;
  7407. }
  7408. int sendInstallCertificateConfirmation(char *uuid)
  7409. {
  7410. mtrace();
  7411. int result = PASS;
  7412. char message[4096]={0};
  7413. json_object *InstallCertificate = json_object_new_object();
  7414. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7415. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7416. sprintf(message,"[%d,\"%s\",%s]"
  7417. ,MESSAGE_TYPE_CALLRESULT
  7418. ,uuid
  7419. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7420. json_object_put(InstallCertificate);
  7421. LWS_Send(message);
  7422. return result;
  7423. }
  7424. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7425. {
  7426. mtrace();
  7427. int result = PASS;
  7428. char message[4096]={0};
  7429. json_object *SignedUpdateFirmware = json_object_new_object();
  7430. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7431. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7432. sprintf(message,"[%d,\"%s\",%s]"
  7433. ,MESSAGE_TYPE_CALLRESULT
  7434. ,uuid
  7435. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7436. json_object_put(SignedUpdateFirmware);
  7437. LWS_Send(message);
  7438. return result;
  7439. }
  7440. int sendUnknownConfirmation(char *uuid)
  7441. {
  7442. mtrace();
  7443. int result = PASS;
  7444. char message[256]={0};
  7445. DEBUG_INFO("sendUnknownConfirmation...\n");
  7446. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7447. LWS_Send(message);
  7448. return result;
  7449. }
  7450. //==========================================
  7451. // Handle server request routine Start
  7452. //==========================================
  7453. int handleCancelReservationRequest(char *uuid, char *payload)
  7454. {
  7455. mtrace();
  7456. int result = FAIL;
  7457. int gunNO = 0;
  7458. int reservationIdInt = -1;
  7459. char comfirmstr[20];
  7460. DEBUG_INFO("handleCancelReservationRequest...\n");
  7461. json_object *CancelReservation;
  7462. CancelReservation = json_tokener_parse(payload);
  7463. if(!is_error(CancelReservation))
  7464. {
  7465. // Required data
  7466. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7467. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7468. }
  7469. json_object_put(CancelReservation);
  7470. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7471. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7472. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7473. if(reservationIdInt != -1)
  7474. {
  7475. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7476. //check Transaction active
  7477. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7479. {
  7480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7481. {
  7482. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7483. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7484. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7485. {
  7486. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7487. }
  7488. else
  7489. {
  7490. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7491. }
  7492. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7493. goto end;
  7494. }
  7495. }
  7496. for (int index = 0; index < CCS_QUANTITY; index++)
  7497. {
  7498. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7499. {
  7500. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7501. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7502. if(gunType[2] == GUN_TYPE_CCS)
  7503. {
  7504. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7505. }
  7506. else
  7507. {
  7508. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7509. }
  7510. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7511. goto end;
  7512. }
  7513. }
  7514. for (int index = 0; index < GB_QUANTITY; index++)
  7515. {
  7516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7517. {
  7518. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7519. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7520. if(gunType[2] == GUN_TYPE_GBT)
  7521. {
  7522. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7523. }
  7524. else
  7525. {
  7526. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7527. }
  7528. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7529. goto end;
  7530. }
  7531. }
  7532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7533. {
  7534. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7535. {
  7536. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7537. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7538. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7539. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7540. goto end;
  7541. }
  7542. }
  7543. for (int index = 0; index < AC_QUANTITY; index++)
  7544. {
  7545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7546. {
  7547. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7548. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7550. {
  7551. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7552. }
  7553. else
  7554. {
  7555. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7556. }
  7557. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7558. goto end;
  7559. }
  7560. }
  7561. }
  7562. //The reservationId does NOT match the reservationId
  7563. sendCancelReservationConfirmation(uuid, comfirmstr);
  7564. end:
  7565. // Fill in ocpp packet uuid
  7566. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7567. return result;
  7568. }
  7569. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7570. {
  7571. mtrace();
  7572. int result = FAIL;
  7573. int gunIndex = -1;
  7574. char typeStr[16]={0};
  7575. char comfirmstr[20];
  7576. int specificId = FALSE;
  7577. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7578. json_object *ChangeAvailability;
  7579. ChangeAvailability = json_tokener_parse(payload);
  7580. if(!is_error(ChangeAvailability))
  7581. {
  7582. // Required data
  7583. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7584. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7585. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7586. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7587. }
  7588. json_object_put(ChangeAvailability);
  7589. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7590. {
  7591. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7592. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7593. }
  7594. else if(gunIndex == 0)
  7595. {
  7596. for(int i=0; i < gunTotalNumber; i++)
  7597. {
  7598. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7599. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7600. }
  7601. }
  7602. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7604. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7605. {
  7606. specificId = TRUE;
  7607. }
  7608. if(specificId == FALSE)
  7609. goto end;
  7610. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7611. {
  7612. //----------------------gunIndex is 0 ------------------------------------------------//
  7613. if(gunIndex == 0)
  7614. {
  7615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7616. {
  7617. for(int i=0; i < gunTotalNumber; i++)
  7618. {
  7619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7620. {
  7621. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7622. {
  7623. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7624. {
  7625. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7626. goto end;
  7627. }
  7628. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7629. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7632. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7633. {
  7634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7635. goto end;
  7636. }
  7637. }
  7638. }//END FOR CHAdeMO_QUANTITY
  7639. for (int index = 0; index < CCS_QUANTITY; index++)
  7640. {
  7641. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7642. {
  7643. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7644. {
  7645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7646. goto end;
  7647. }
  7648. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7652. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7653. {
  7654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7655. goto end;
  7656. }
  7657. }
  7658. }//END FOR CCS_QUANTITY
  7659. for (int index = 0; index < GB_QUANTITY; index++)
  7660. {
  7661. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7662. {
  7663. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7664. {
  7665. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7666. goto end;
  7667. }
  7668. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7669. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7670. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7671. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7673. {
  7674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7675. goto end;
  7676. }
  7677. }
  7678. }// END FOR GB_QUANTITY
  7679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7680. {
  7681. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7682. {
  7683. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7684. {
  7685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7686. goto end;
  7687. }
  7688. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7689. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7690. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7691. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7692. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7693. {
  7694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7695. goto end;
  7696. }
  7697. }
  7698. }// END FOR GENERAL_GUN_QUANTITY
  7699. for (int index = 0; index < AC_QUANTITY; index++)
  7700. {
  7701. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7702. {
  7703. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7704. {
  7705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7706. goto end;
  7707. }
  7708. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7709. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7710. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7711. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7712. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7713. {
  7714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7715. goto end;
  7716. }
  7717. }
  7718. }//END FOR AC_QUANTITY
  7719. }// END FOR gunTotalNumber
  7720. }
  7721. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7722. {
  7723. for(int i=0; i < gunTotalNumber; i++)
  7724. {
  7725. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7726. {
  7727. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7728. goto end;
  7729. }
  7730. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7731. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7732. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7733. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7734. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7735. {
  7736. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7737. goto end;
  7738. }
  7739. }
  7740. }
  7741. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7742. goto end;
  7743. }
  7744. //----------------------gunIndex is not 0 ------------------------------------------------//
  7745. //check Transaction active
  7746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7747. {
  7748. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7749. {
  7750. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7751. {
  7752. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7753. goto end;
  7754. }
  7755. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7756. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7757. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7758. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7759. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7760. {
  7761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7762. goto end;
  7763. }
  7764. else
  7765. {
  7766. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7768. goto end;
  7769. }
  7770. }
  7771. }//END FOR CHAdeMO_QUANTITY
  7772. for (int index = 0; index < CCS_QUANTITY; index++)
  7773. {
  7774. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7775. {
  7776. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7777. {
  7778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7779. goto end;
  7780. }
  7781. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7782. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7783. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7784. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7785. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7786. {
  7787. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7788. goto end;
  7789. }
  7790. else
  7791. {
  7792. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7794. goto end;
  7795. }
  7796. }
  7797. }//END FOR CCS_QUANTITY
  7798. for (int index = 0; index < GB_QUANTITY; index++)
  7799. {
  7800. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7801. {
  7802. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7803. {
  7804. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7805. goto end;
  7806. }
  7807. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7808. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7809. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7810. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7811. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7812. {
  7813. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7814. goto end;
  7815. }
  7816. else
  7817. {
  7818. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7820. goto end;
  7821. }
  7822. }
  7823. }// END FOR GB_QUANTITY
  7824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7825. {
  7826. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7827. {
  7828. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7829. {
  7830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7831. goto end;
  7832. }
  7833. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7834. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7837. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7838. {
  7839. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7840. goto end;
  7841. }
  7842. else
  7843. {
  7844. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7846. goto end;
  7847. }
  7848. }
  7849. }// END FOR GENERAL_GUN_QUANTITY
  7850. for (int index = 0; index < AC_QUANTITY; index++)
  7851. {
  7852. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7853. {
  7854. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7855. {
  7856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7857. goto end;
  7858. }
  7859. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7860. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7861. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7862. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7863. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7864. {
  7865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7866. goto end;
  7867. }
  7868. else
  7869. {
  7870. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7872. goto end;
  7873. }
  7874. }
  7875. }//END FOR AC_QUANTITY
  7876. }//END FOR AvailabilityTypeStr[Inoperative]
  7877. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7878. {
  7879. //----------------------gunIndex is 0 ------------------------------------------------//
  7880. if(gunIndex == 0)
  7881. {
  7882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7883. {
  7884. for(int i=0; i < gunTotalNumber; i++)
  7885. {
  7886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7887. {
  7888. 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
  7889. {
  7890. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7891. goto end;
  7892. }
  7893. }//END FOR CHAdeMO_QUANTITY
  7894. for (int index = 0; index < CCS_QUANTITY; index++)
  7895. {
  7896. 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
  7897. {
  7898. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7899. goto end;
  7900. }
  7901. }//END FOR CCS_QUANTITY
  7902. for (int index = 0; index < GB_QUANTITY; index++)
  7903. {
  7904. 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
  7905. {
  7906. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7907. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7908. goto end;
  7909. }
  7910. }// END FOR GB_QUANTITY
  7911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7912. {
  7913. 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
  7914. {
  7915. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7916. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7917. goto end;
  7918. }
  7919. }// END FOR GENERAL_GUN_QUANTITY
  7920. for (int index = 0; index < AC_QUANTITY; index++)
  7921. {
  7922. 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
  7923. {
  7924. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7925. goto end;
  7926. }
  7927. }//END FOR CHAdeMO_QUANTITY
  7928. }// END FOR gunTotalNumber
  7929. }
  7930. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7931. {
  7932. for(int i=0; i < gunTotalNumber; i++)
  7933. {
  7934. for (int index = 0; index < AC_QUANTITY; index++)
  7935. {
  7936. 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
  7937. {
  7938. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7939. goto end;
  7940. }
  7941. }//END FOR CHAdeMO_QUANTITY
  7942. } // END FOR gunTotalNumber
  7943. }
  7944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7945. goto end;
  7946. }
  7947. //----------------------gunIndex is not 0 ------------------------------------------------//
  7948. //check Transaction active
  7949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7950. {
  7951. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7952. {
  7953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7954. goto end;
  7955. }
  7956. }//END FOR CHAdeMO_QUANTITY
  7957. for (int index = 0; index < CCS_QUANTITY; index++)
  7958. {
  7959. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7960. {
  7961. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7962. goto end;
  7963. }
  7964. }//END FOR CCS_QUANTITY
  7965. for (int index = 0; index < GB_QUANTITY; index++)
  7966. {
  7967. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7968. {
  7969. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7970. goto end;
  7971. }
  7972. }// END FOR GB_QUANTITY
  7973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7974. {
  7975. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7976. {
  7977. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7978. goto end;
  7979. }
  7980. }// END FOR GENERAL_GUN_QUANTITY
  7981. for (int index = 0; index < AC_QUANTITY; index++)
  7982. {
  7983. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7984. {
  7985. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7986. goto end;
  7987. }
  7988. }//END FOR AC_QUANTITY
  7989. }//END FOR AvailabilityTypeStr[Operative]
  7990. end:
  7991. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7992. {
  7993. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7994. }
  7995. else
  7996. {
  7997. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7998. }
  7999. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8000. {
  8001. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8002. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8003. }
  8004. else if(gunIndex == 0)
  8005. {
  8006. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8007. {
  8008. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8009. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8010. }
  8011. }
  8012. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8013. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8014. return result;
  8015. }
  8016. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8017. {
  8018. mtrace();
  8019. int valueInvalid = NO;
  8020. int result = FAIL;
  8021. char keystr[40]={0};
  8022. char valuestr[501]={0}; //value should be limited in 500 bytes
  8023. char comfirmstr[20]={0};
  8024. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8025. json_object *ChangeConfiguration;
  8026. ChangeConfiguration = json_tokener_parse(payload);
  8027. if(!is_error(ChangeConfiguration))
  8028. {
  8029. // Required data
  8030. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8031. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8032. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8033. {
  8034. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8035. }
  8036. else
  8037. {
  8038. valueInvalid = YES;
  8039. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8040. }
  8041. }
  8042. json_object_put(ChangeConfiguration);
  8043. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8044. {
  8045. DEBUG_ERROR("Payload is null or not accepted.\n");
  8046. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8047. }
  8048. else
  8049. {
  8050. int status = setKeyValue(keystr, valuestr);
  8051. switch(status)
  8052. {
  8053. case ConfigurationStatus_Accepted:
  8054. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8055. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8056. StoreConfigurationTable();
  8057. break;
  8058. case RebootRequired:
  8059. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8060. StoreConfigurationTable();
  8061. break;
  8062. case NotSupported:
  8063. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8064. break;
  8065. case ConfigurationStatus_Rejected:
  8066. default:
  8067. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8068. break;
  8069. }
  8070. }
  8071. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8072. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8073. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8074. {
  8075. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8076. SetOcppConnStatus(FALSE);
  8077. }
  8078. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8079. {
  8080. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8081. }
  8082. return result;
  8083. }
  8084. int handleClearCacheRequest(char *uuid, char *payload)
  8085. {
  8086. mtrace();
  8087. int result = FAIL;
  8088. char comfirmstr[20];
  8089. char rmFileCmd[100]={0};
  8090. struct stat stats;
  8091. DEBUG_INFO("handleClearCacheRequest...\n");
  8092. stat("/Storage/OCPP_PH", &stats);
  8093. // Check for directory existence
  8094. if (S_ISDIR(stats.st_mode) == 1)
  8095. {}
  8096. else
  8097. {
  8098. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8099. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8100. system(rmFileCmd);
  8101. }
  8102. if(OCPP_cleanLocalCache())
  8103. {
  8104. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8105. }
  8106. else
  8107. {
  8108. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8109. }
  8110. sendClearCacheConfirmation(uuid, comfirmstr);
  8111. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8112. return result;
  8113. }
  8114. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8115. {
  8116. mtrace();
  8117. int result = FAIL;
  8118. int resultRename;
  8119. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8120. char chargingProfilePurposeStr[26]={0};
  8121. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8122. char tempchargingProfilePurposeStr[26]={0};
  8123. char str[100]={0};
  8124. char fname[200]={0};
  8125. char comfirmstr[20]={0};
  8126. char word[1600]={0};
  8127. int clearflag = FALSE;
  8128. int chargingProfileIdIsNULL = FALSE;
  8129. int connectorIsNULL = FALSE;
  8130. int chargingProfilePurposeIsNULL = FALSE;
  8131. int stackLevelIsNULL = FALSE;
  8132. //int GotoEnd = FALSE;
  8133. FILE *fptr1, *fptr2;
  8134. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8135. int n_chargingProfile=0;
  8136. int isEmptyFile = FALSE;
  8137. char sLineWord[1600]={0};
  8138. char chargingProfiles[10][100]={0};
  8139. int ChargeProfileCount = 0;
  8140. int ch;
  8141. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8142. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8143. json_object *ClearChargingProfile;
  8144. ClearChargingProfile = json_tokener_parse(payload);
  8145. if(!is_error(ClearChargingProfile))
  8146. {
  8147. // Optional data
  8148. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8149. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8150. else
  8151. chargingProfileIdIsNULL = TRUE;
  8152. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8153. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8154. else
  8155. connectorIsNULL = TRUE;
  8156. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8157. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8158. else
  8159. chargingProfilePurposeIsNULL = TRUE;
  8160. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8161. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8162. else
  8163. stackLevelIsNULL = TRUE;
  8164. }
  8165. json_object_put(ClearChargingProfile);
  8166. if(connectorIsNULL == FALSE)
  8167. {
  8168. switch(connectorIdInt)
  8169. {
  8170. case 0:
  8171. if(chargingProfilePurposeIsNULL == TRUE)
  8172. {
  8173. int l = 0;
  8174. strcpy(fname, ChargePointMaxProfile_JSON);
  8175. if((access(fname,F_OK))!=-1)
  8176. {
  8177. strcpy(chargingProfiles[l], fname);
  8178. l = l + 1;
  8179. }
  8180. strcpy(fname, TxDefaultProfile_0_JSON);
  8181. if((access(fname,F_OK))!=-1)
  8182. {
  8183. strcpy(chargingProfiles[l], fname);
  8184. l = l + 1;
  8185. }
  8186. ChargeProfileCount = l;
  8187. }
  8188. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8189. {
  8190. strcpy(fname, ChargePointMaxProfile_JSON);
  8191. if((access(fname,F_OK))!=-1)
  8192. {
  8193. strcpy(chargingProfiles[0], fname);
  8194. ChargeProfileCount = 1;
  8195. }
  8196. }
  8197. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8198. {
  8199. strcpy(fname, TxDefaultProfile_0_JSON);
  8200. if((access(fname,F_OK))!=-1)
  8201. {
  8202. strcpy(chargingProfiles[0], fname);
  8203. ChargeProfileCount = 1;
  8204. }
  8205. }
  8206. break;
  8207. default:
  8208. if(chargingProfilePurposeIsNULL == TRUE)
  8209. {
  8210. int m = 0;
  8211. memset(fname, 0, ARRAY_SIZE(fname));
  8212. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8213. if((access(fname,F_OK))!=-1)
  8214. {
  8215. strcpy(chargingProfiles[m], fname);
  8216. m = m + 1;
  8217. }
  8218. memset(fname, 0, ARRAY_SIZE(fname));
  8219. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8220. if((access(fname,F_OK))!=-1)
  8221. {
  8222. strcpy(chargingProfiles[m], fname);
  8223. m = m + 1;
  8224. }
  8225. ChargeProfileCount = m;
  8226. }
  8227. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8228. {
  8229. //strcpy(fname, TxDefaultProfile_1_JSON);
  8230. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8231. if((access(fname,F_OK))!=-1)
  8232. {
  8233. strcpy(chargingProfiles[0], fname);
  8234. ChargeProfileCount = 1;
  8235. }
  8236. }
  8237. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8238. {
  8239. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8240. if((access(fname,F_OK))!=-1)
  8241. {
  8242. strcpy(chargingProfiles[0], fname);
  8243. ChargeProfileCount = 1;
  8244. }
  8245. //strcpy(fname, TxProfile_1_JSON);
  8246. }
  8247. //strcpy(fname, ChargePointMaxProfile_JSON );
  8248. break;
  8249. }
  8250. }
  8251. else // Check all Charging Profiles
  8252. {
  8253. int i = 0;
  8254. char fnametemp[200]={0};
  8255. ChargeProfileCount = 0;
  8256. //Check ChargePointMaxProfile.json exit
  8257. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8258. {
  8259. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8260. i = i + 1;
  8261. }
  8262. //Check TxDefaultProfile_0.json exit
  8263. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8264. {
  8265. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8266. i = i + 1;
  8267. }
  8268. //Check TxDefaultProfile_%d.json
  8269. for(int j=1; j <= gunTotalNumber; j++)
  8270. {
  8271. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8272. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8273. if((access(fnametemp,F_OK))!=-1)
  8274. {
  8275. strcpy(chargingProfiles[i], fnametemp);
  8276. i = i + 1;
  8277. }
  8278. }
  8279. //Check TxProfile_%d.json
  8280. for(int j=1; j <= gunTotalNumber; j++)
  8281. {
  8282. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8283. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8284. if((access(fnametemp,F_OK))!=-1)
  8285. {
  8286. strcpy(chargingProfiles[i], fnametemp);
  8287. i = i + 1;
  8288. }
  8289. }
  8290. ChargeProfileCount = i;
  8291. }// End connectorIsNULL is TRUE
  8292. if(ChargeProfileCount == 0)
  8293. {
  8294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8295. goto end;
  8296. }
  8297. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8298. {
  8299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8300. goto end;
  8301. }
  8302. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8303. {
  8304. memset(str, 0, ARRAY_SIZE(str));
  8305. // clear temp file
  8306. sprintf(str,"rm -f %s",temp);
  8307. system(str);
  8308. for(int k=0; k < ChargeProfileCount; k++)
  8309. {
  8310. memset(str, 0, ARRAY_SIZE(str));
  8311. //clear file in C
  8312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8313. system(str);
  8314. }
  8315. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8316. goto end;
  8317. }
  8318. else if(connectorIsNULL == TRUE)
  8319. {
  8320. for(int k=0; k < ChargeProfileCount; k++)
  8321. {
  8322. fptr1 = fopen(chargingProfiles[k], "r");
  8323. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8324. //Check Charging Profile Count
  8325. while(fscanf(fptr1, "%s", word) != EOF)
  8326. {
  8327. //DEBUG_INFO("word=%s\n",word);
  8328. if(strstr(word, "chargingProfileId")!= NULL)
  8329. {
  8330. //DEBUG_INFO("test chargingProfileId \n");
  8331. n_chargingProfile = n_chargingProfile + 1;
  8332. //DEBUG_INFO("chargingProfileId Found\n");
  8333. }
  8334. }
  8335. rewind(fptr1);
  8336. //search Charging Profile Element
  8337. //int i= 0;
  8338. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8339. {
  8340. json_object *tmpProfilee;
  8341. tmpProfilee = json_tokener_parse(sLineWord);
  8342. if(!is_error(tmpProfilee))
  8343. {
  8344. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8345. {
  8346. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8347. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8348. }
  8349. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8350. {
  8351. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8352. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8353. }
  8354. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8355. {
  8356. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8357. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8358. }
  8359. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8360. {
  8361. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8362. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8363. }
  8364. }
  8365. json_object_put(tmpProfilee);
  8366. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8367. {
  8368. //------- not write to fptr2-------//
  8369. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8370. //clearflag = TRUE;
  8371. }
  8372. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8373. {
  8374. //------- not write to fptr2-------//
  8375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8376. }
  8377. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8378. {
  8379. //------- not write to fptr2-------//
  8380. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8381. }
  8382. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8383. {
  8384. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8385. }
  8386. else
  8387. {
  8388. fprintf(fptr2, sLineWord);//writing data into file
  8389. }
  8390. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8391. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8392. if(clearflag == TRUE)
  8393. {
  8394. fclose(fptr1);
  8395. fclose(fptr2);
  8396. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8397. system(str);
  8398. // clear temp file
  8399. sprintf(str,"rm -f %s",temp);
  8400. system(str);
  8401. }
  8402. else
  8403. {
  8404. fclose(fptr1);
  8405. fclose(fptr2);
  8406. memset(str, 0, ARRAY_SIZE(str));
  8407. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8408. system(str);
  8409. resultRename = rename(temp, chargingProfiles[k]);
  8410. if(resultRename == 0)
  8411. {
  8412. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8413. }
  8414. else
  8415. {
  8416. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8417. }
  8418. if(comfirmstr[0]== 0)
  8419. {
  8420. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8421. }
  8422. //Check chargingProfile is empty file
  8423. /*------ Read the file ----------------*/
  8424. fptr1=fopen(chargingProfiles[k],"r");
  8425. ch=fgetc(fptr1);
  8426. rewind(fptr1);
  8427. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8428. if(ch!=EOF)
  8429. {
  8430. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8431. {
  8432. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8433. if(sLineWord[0]=='\0')
  8434. {
  8435. isEmptyFile = TRUE;
  8436. break;
  8437. }
  8438. else
  8439. {
  8440. isEmptyFile = FALSE;
  8441. break;
  8442. }
  8443. }
  8444. }
  8445. else
  8446. isEmptyFile = TRUE;
  8447. fclose(fptr1);
  8448. if(isEmptyFile == TRUE)
  8449. {
  8450. memset(str, 0, ARRAY_SIZE(str));
  8451. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8452. system(str);
  8453. }
  8454. }
  8455. }// End of while(int k=0; k < ChargePointCount; k++)
  8456. }
  8457. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8458. {
  8459. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8460. for(int k=0; k < ChargeProfileCount; k++)
  8461. {
  8462. fptr1 = fopen(chargingProfiles[k], "r");
  8463. fptr2 = fopen(temp, "w+");
  8464. //Check Charging Profile Count
  8465. while(fscanf(fptr1, "%s", word) != EOF)
  8466. {
  8467. //DEBUG_INFO("word=%s\n",word);
  8468. if(strstr(word, "chargingProfileId")!= NULL)
  8469. {
  8470. n_chargingProfile = n_chargingProfile + 1;
  8471. }
  8472. }
  8473. rewind(fptr1);
  8474. //search Charging Profile Element
  8475. //int i= 0;
  8476. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8477. {
  8478. json_object *tmpProfilee;
  8479. tmpProfilee = json_tokener_parse(sLineWord);
  8480. if(!is_error(tmpProfilee))
  8481. {
  8482. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8483. {
  8484. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8485. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8486. }
  8487. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8488. {
  8489. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8490. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8491. }
  8492. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8493. {
  8494. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8495. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8496. }
  8497. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8498. {
  8499. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8500. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8501. }
  8502. }
  8503. json_object_put(tmpProfilee);
  8504. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8505. {
  8506. //------- not write to fptr2-------//
  8507. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8508. //clearflag = TRUE;
  8509. }
  8510. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8511. {
  8512. //------- not write to fptr2-------//
  8513. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8514. }
  8515. else if(stackLevelIsNULL == TRUE)
  8516. {
  8517. //Clear Whole File
  8518. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8519. clearflag = TRUE;
  8520. break;
  8521. }
  8522. else
  8523. {
  8524. fprintf(fptr2, sLineWord);//writing data into file
  8525. }
  8526. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8527. }
  8528. if(clearflag == TRUE)
  8529. {
  8530. fclose(fptr1);
  8531. fclose(fptr2);
  8532. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8533. system(str);
  8534. // clear temp file
  8535. sprintf(str,"rm -f %s",temp);
  8536. system(str);
  8537. }
  8538. else
  8539. {
  8540. fclose(fptr1);
  8541. fclose(fptr2);
  8542. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8543. system(str);
  8544. resultRename = rename(temp, chargingProfiles[k]);
  8545. if(resultRename == 0)
  8546. {
  8547. DEBUG_INFO("File ChargingProfile renamed successfully");
  8548. }
  8549. else
  8550. {
  8551. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8552. }
  8553. if(comfirmstr[0]== 0)
  8554. {
  8555. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8556. }
  8557. //Check chargingProfile is empty file
  8558. /*------ Read the file ----------------*/
  8559. fptr1=fopen(chargingProfiles[k],"r");
  8560. ch=fgetc(fptr1);
  8561. rewind(fptr1);
  8562. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8563. if(ch!=EOF)
  8564. {
  8565. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8566. {
  8567. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8568. if(sLineWord[0]=='\0')
  8569. {
  8570. isEmptyFile = TRUE;
  8571. break;
  8572. }
  8573. else
  8574. {
  8575. isEmptyFile = FALSE;
  8576. break;
  8577. }
  8578. }
  8579. }
  8580. else
  8581. isEmptyFile = TRUE;
  8582. fclose(fptr1);
  8583. if(isEmptyFile == TRUE)
  8584. {
  8585. memset(str, 0, ARRAY_SIZE(str));
  8586. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8587. system(str);
  8588. }
  8589. /*------- End of reading ---------------*/
  8590. }
  8591. } // while(int k=0; k < ChargeProfileCount; k++)
  8592. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8593. end:
  8594. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8595. {
  8596. if(connectorIdInt == 0)
  8597. {
  8598. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8599. {
  8600. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8601. }
  8602. }
  8603. else
  8604. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8605. }
  8606. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8607. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8608. return result;
  8609. }
  8610. void createFirmwareVersionByDataTransfer(void)
  8611. {
  8612. json_object *FirmwareDataTransfer = json_object_new_object();
  8613. // AC & DC model
  8614. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8615. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8616. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8617. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8618. // DC model
  8619. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8620. {
  8621. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8622. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8623. (gunType[3] != GUN_TYPE_UNKNOWN))
  8624. {
  8625. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8626. }
  8627. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8628. {
  8629. // DS DM DW
  8630. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8631. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8632. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8633. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8634. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8635. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8636. }
  8637. else
  8638. {
  8639. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8640. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8641. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8642. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8643. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8644. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8645. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8646. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8647. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8648. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8649. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8650. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8651. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8652. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8653. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8654. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8655. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8656. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8657. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8658. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8659. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8660. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8661. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8663. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8665. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8667. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8669. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8670. }
  8671. }
  8672. // 4G model
  8673. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8674. {
  8675. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8676. }
  8677. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8678. json_object_put(FirmwareDataTransfer);
  8679. }
  8680. int handleDataTransferRequest(char *uuid, char *payload)
  8681. {
  8682. mtrace();
  8683. json_object *response = json_object_new_object();
  8684. int result = FAIL;
  8685. char tempvendorId[255]={0};
  8686. char tempmessageId[50]={0};
  8687. char tempdata[512]={0};
  8688. char message[2048]={0};
  8689. DEBUG_INFO("handleDataTransferRequest...\n");
  8690. if((uuid != NULL) && (payload != NULL))
  8691. {
  8692. json_object *DataTransfer;
  8693. DataTransfer = json_tokener_parse(payload);
  8694. if(!is_error(DataTransfer))
  8695. {
  8696. // Required data
  8697. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8698. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8699. // Optional data
  8700. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8701. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8702. if(json_object_object_get(DataTransfer, "data") != NULL)
  8703. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8704. result = PASS;
  8705. }
  8706. json_object_put(DataTransfer);
  8707. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8708. {
  8709. // Send all moudle firmware version on EVSE
  8710. createFirmwareVersionByDataTransfer();
  8711. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8712. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8713. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8714. json_object_put(response);
  8715. }
  8716. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8717. {
  8718. system("/usr/bin/run_tmate_restart.sh &");
  8719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8720. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8721. json_object_put(response);
  8722. }
  8723. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8724. {
  8725. json_object *data;
  8726. data = json_tokener_parse(tempdata);
  8727. if(!is_error(data))
  8728. {
  8729. 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))
  8730. {
  8731. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8732. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8733. if(json_object_object_get(data, "SOC") != NULL)
  8734. {
  8735. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8736. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8737. }
  8738. if(json_object_object_get(data, "Energy") != NULL)
  8739. {
  8740. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8741. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8742. }
  8743. if(json_object_object_get(data, "Duration") != NULL)
  8744. {
  8745. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8746. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8747. }
  8748. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8749. }
  8750. else
  8751. {
  8752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8753. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8754. }
  8755. }
  8756. else
  8757. {
  8758. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8759. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8760. }
  8761. json_object_put(data);
  8762. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8763. json_object_put(response);
  8764. }
  8765. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8766. {
  8767. json_object *data;
  8768. data = json_tokener_parse(tempdata);
  8769. if(!is_error(data))
  8770. {
  8771. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8772. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8773. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8774. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8775. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8776. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8777. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8778. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8779. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8780. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8781. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8782. }
  8783. else
  8784. {
  8785. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8786. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8787. }
  8788. json_object_put(data);
  8789. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8790. json_object_put(response);
  8791. }
  8792. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8793. {
  8794. json_object *data;
  8795. data = json_tokener_parse(tempdata);
  8796. if(!is_error(data))
  8797. {
  8798. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8799. if(json_object_object_get(data, "idToken") != NULL)
  8800. {
  8801. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8802. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8803. }
  8804. if(json_object_object_get(data, "price") != NULL)
  8805. {
  8806. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8807. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8808. }
  8809. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8810. }
  8811. else
  8812. {
  8813. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8814. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8815. }
  8816. json_object_put(data);
  8817. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8818. json_object_put(response);
  8819. }
  8820. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8821. {
  8822. json_object *data;
  8823. data = json_tokener_parse(tempdata);
  8824. if(!is_error(data))
  8825. {
  8826. if(json_object_object_get(data, "txId") != NULL)
  8827. {
  8828. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8829. for(int idx = 0;idx<gunTotalNumber;idx++)
  8830. {
  8831. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8832. {
  8833. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8834. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8835. if(json_object_object_get(data, "description") != NULL)
  8836. {
  8837. // California pricing V1.0
  8838. DEBUG_INFO("California pricing V1.0\n");
  8839. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8840. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8841. }
  8842. else
  8843. {
  8844. // California pricing V1.1
  8845. DEBUG_INFO("California pricing V1.1\n");
  8846. if(json_object_object_get(data, "timestamp") != NULL)
  8847. {
  8848. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8849. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8850. }
  8851. if(json_object_object_get(data, "meterValue") != NULL)
  8852. {
  8853. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8854. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8855. }
  8856. if(json_object_object_get(data, "cost") != NULL)
  8857. {
  8858. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8859. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8860. }
  8861. if(json_object_object_get(data, "state") != NULL)
  8862. {
  8863. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8864. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8865. }
  8866. if(json_object_object_get(data, "chargingPrice") != NULL)
  8867. {
  8868. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8869. {
  8870. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8871. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8872. }
  8873. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8874. {
  8875. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8876. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8877. }
  8878. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8879. {
  8880. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8881. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8882. }
  8883. }
  8884. if(json_object_object_get(data, "idlePrice") != NULL)
  8885. {
  8886. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8887. {
  8888. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8889. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8890. }
  8891. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8892. {
  8893. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8894. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8895. }
  8896. }
  8897. if(json_object_object_get(data, "nextPeriod") != NULL)
  8898. {
  8899. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8900. {
  8901. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8902. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8903. }
  8904. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8905. {
  8906. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8907. {
  8908. 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")));
  8909. 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"));
  8910. }
  8911. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8912. {
  8913. 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")));
  8914. 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"));
  8915. }
  8916. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8917. {
  8918. 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")));
  8919. 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"));
  8920. }
  8921. }
  8922. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8923. {
  8924. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8925. {
  8926. 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")));
  8927. 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"));
  8928. }
  8929. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8930. {
  8931. 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")));
  8932. 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"));
  8933. }
  8934. }
  8935. }
  8936. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8937. {
  8938. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8939. {
  8940. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8941. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8942. }
  8943. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8944. {
  8945. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8946. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8947. }
  8948. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8949. {
  8950. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8951. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8952. }
  8953. }
  8954. }
  8955. }
  8956. }
  8957. }
  8958. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8959. }
  8960. else
  8961. {
  8962. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8963. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8964. }
  8965. json_object_put(data);
  8966. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8967. json_object_put(response);
  8968. }
  8969. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8970. {
  8971. json_object *data;
  8972. data = json_tokener_parse(tempdata);
  8973. if(!is_error(data))
  8974. {
  8975. if(json_object_object_get(data, "txId") != NULL)
  8976. {
  8977. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8978. for(int idx = 0;idx<gunTotalNumber;idx++)
  8979. {
  8980. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8981. {
  8982. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8983. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8984. if(json_object_object_get(data, "description") != NULL)
  8985. {
  8986. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8987. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8988. }
  8989. }
  8990. }
  8991. }
  8992. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8993. }
  8994. else
  8995. {
  8996. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8997. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8998. }
  8999. json_object_put(data);
  9000. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9001. json_object_put(response);
  9002. }
  9003. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9004. {
  9005. json_object *data;
  9006. data = json_tokener_parse(tempdata);
  9007. if(!is_error(data))
  9008. {
  9009. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9010. if(json_object_object_get(data, "Content_Type") != NULL)
  9011. {
  9012. 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))
  9013. {
  9014. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9015. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9016. {
  9017. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9018. }
  9019. }
  9020. else
  9021. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9022. }
  9023. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9024. }
  9025. else
  9026. {
  9027. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9028. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9029. }
  9030. json_object_put(data);
  9031. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9032. json_object_put(response);
  9033. }
  9034. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9035. {
  9036. json_object *data;
  9037. data = json_tokener_parse(tempdata);
  9038. if(!is_error(data))
  9039. {
  9040. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9041. if(json_object_object_get(data, "ConnectorId") != NULL)
  9042. {
  9043. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9044. }
  9045. if(json_object_object_get(data, "Page_Index") != NULL)
  9046. {
  9047. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9048. }
  9049. if(json_object_object_get(data, "Duration") != NULL)
  9050. {
  9051. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9052. }
  9053. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9054. }
  9055. else
  9056. {
  9057. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9058. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9059. }
  9060. json_object_put(data);
  9061. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9062. json_object_put(response);
  9063. }
  9064. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9065. {
  9066. json_object *data;
  9067. data = json_tokener_parse(tempdata);
  9068. if(!is_error(data))
  9069. {
  9070. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9071. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9072. {
  9073. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9074. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9075. else
  9076. {
  9077. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9078. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9079. }
  9080. }
  9081. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9082. {
  9083. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9084. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9085. else
  9086. {
  9087. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9088. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9089. }
  9090. }
  9091. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9092. {
  9093. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9094. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9095. else
  9096. {
  9097. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9098. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9099. }
  9100. }
  9101. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9102. {
  9103. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9104. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9105. else
  9106. {
  9107. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9108. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9109. }
  9110. }
  9111. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9112. {
  9113. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9114. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9115. else
  9116. {
  9117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9118. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9119. }
  9120. }
  9121. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9122. {
  9123. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9124. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9125. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9126. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9127. else
  9128. {
  9129. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9130. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9131. }
  9132. }
  9133. if(json_object_object_get(data, "isAuthentication") != NULL)
  9134. {
  9135. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9136. {
  9137. case 0:
  9138. case 1:
  9139. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9140. break;
  9141. default:
  9142. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9143. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9144. break;
  9145. }
  9146. }
  9147. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9148. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9149. }
  9150. else
  9151. {
  9152. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9153. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9154. }
  9155. json_object_put(data);
  9156. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9157. json_object_put(response);
  9158. }
  9159. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9160. {
  9161. json_object *data;
  9162. data = json_tokener_parse(tempdata);
  9163. if(!is_error(data))
  9164. {
  9165. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9166. if(json_object_object_get(data, "stationName") != NULL)
  9167. {
  9168. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9169. }
  9170. else
  9171. {
  9172. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9173. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9174. }
  9175. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9176. {
  9177. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9178. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9179. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9180. }
  9181. }
  9182. else
  9183. {
  9184. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9185. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9186. }
  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_Weather_Info") != NULL)
  9191. {
  9192. json_object *data;
  9193. data = json_tokener_parse(tempdata);
  9194. if(!is_error(data))
  9195. {
  9196. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9197. if(json_object_object_get(data, "weatherId") != NULL)
  9198. {
  9199. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9200. }
  9201. else
  9202. {
  9203. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9204. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9205. }
  9206. if(json_object_object_get(data, "Temperature") != NULL)
  9207. {
  9208. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9209. }
  9210. else
  9211. {
  9212. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9213. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9214. }
  9215. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9216. {
  9217. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9218. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9219. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9220. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9221. }
  9222. }
  9223. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9224. {
  9225. json_object *data;
  9226. data = json_tokener_parse(tempdata);
  9227. if(!is_error(data))
  9228. {
  9229. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9230. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9231. {
  9232. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9233. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9234. }
  9235. else
  9236. {
  9237. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9238. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9239. }
  9240. }
  9241. else
  9242. {
  9243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9244. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9245. }
  9246. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9247. json_object_put(response);
  9248. }
  9249. else
  9250. {
  9251. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9252. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9253. }
  9254. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9255. json_object_put(response);
  9256. }
  9257. else
  9258. {
  9259. // Can not find valid message id
  9260. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9261. }
  9262. }
  9263. else
  9264. {
  9265. // Payload is null
  9266. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9267. }
  9268. LWS_Send(message);
  9269. return result;
  9270. }
  9271. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9272. {
  9273. mtrace();
  9274. int result = FAIL;
  9275. int connectorIdInt, durationInt;
  9276. char chargingRateUnitStr[4]={0};
  9277. char comfirmstr[20];
  9278. int confirmPeriods = 0;
  9279. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9280. json_object *GetCompositeSchedule;
  9281. GetCompositeSchedule = json_tokener_parse(payload);
  9282. if(!is_error(GetCompositeSchedule))
  9283. {
  9284. // Required data
  9285. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9286. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9287. else
  9288. connectorIdInt = -1;
  9289. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9290. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9291. else
  9292. durationInt = 86400;
  9293. // Optional data
  9294. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9295. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9296. }
  9297. json_object_put(GetCompositeSchedule);
  9298. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9299. if((connectorIdInt == 0) ||
  9300. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9301. {
  9302. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9303. struct StructChargingProfile tmpProfile[1];
  9304. if(strstr(chargingRateUnitStr, "W") != NULL)
  9305. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9306. else
  9307. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9308. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9309. {
  9310. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9311. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9312. }
  9313. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9314. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9315. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9316. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9317. {
  9318. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9319. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9320. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9321. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9322. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9323. {
  9324. confirmPeriods = idx;
  9325. break;
  9326. }
  9327. }
  9328. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9329. {
  9330. confirmPeriods += 1;
  9331. }
  9332. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9333. }
  9334. else
  9335. {
  9336. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9337. }
  9338. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9339. return result;
  9340. }
  9341. int handleGetConfigurationRequest(char *uuid, char *payload)
  9342. {
  9343. mtrace();
  9344. int result = FAIL;
  9345. int MaxKeySupported = 0;
  9346. int n_keys = 0;
  9347. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9348. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9349. json_object *GetConfiguration;
  9350. GetConfiguration = json_tokener_parse(payload);
  9351. if(!is_error(GetConfiguration))
  9352. {
  9353. // Optional data
  9354. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9355. {
  9356. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9357. {
  9358. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9359. n_keys = idx + 1;
  9360. }
  9361. }
  9362. }
  9363. json_object_put(GetConfiguration);
  9364. UnknownKeynum = 0;
  9365. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9366. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9367. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9368. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9369. if(n_keys != 0)
  9370. {
  9371. for(int i=0;i<n_keys;i++)
  9372. {
  9373. getKeyValue(requestKey[i]);
  9374. }
  9375. }
  9376. else
  9377. {
  9378. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9379. getKeyValue("");
  9380. }
  9381. processUnkownKey();
  9382. sendGetConfigurationConfirmation(uuid);
  9383. return result;
  9384. }
  9385. static char fnamePlusPath[100]={0};
  9386. static char fnamePWithNoPath[60]={0};
  9387. void checkUploadLog(void)
  9388. {
  9389. FILE *fp;
  9390. /* Open the command for reading. */
  9391. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9392. if (fp == NULL) {
  9393. DEBUG_WARN("Failed to run command\n" );
  9394. exit(1);
  9395. }
  9396. int ftppathlen = 0;
  9397. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9398. int i = 0;
  9399. /* Read the output a line at a time - output it. */
  9400. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9401. if(i==0)
  9402. {
  9403. ftppathlen = strlen(fnamePlusPath);
  9404. DEBUG_INFO("%s\n", fnamePlusPath);
  9405. fnamePlusPath[ftppathlen]='\0';
  9406. break;
  9407. }
  9408. i= i+1;
  9409. }
  9410. /* close */
  9411. pclose(fp);
  9412. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9413. {
  9414. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9415. {
  9416. fnamePlusPath[k]='\0';
  9417. }
  9418. }
  9419. i=1;
  9420. //char fname[60]={0};
  9421. while(i < ftppathlen)
  9422. {
  9423. int len=ftppathlen-i;
  9424. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9425. {
  9426. DEBUG_INFO("compare '/' all right\n");
  9427. break;
  9428. }
  9429. i=i+1;
  9430. }
  9431. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9432. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9433. fnamePWithNoPath[i+1] = '\0';
  9434. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9435. {
  9436. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9437. {
  9438. fnamePWithNoPath[j]='\0';
  9439. }
  9440. }
  9441. FILE* fp1 = fopen(fnamePlusPath, "r");
  9442. if (fp1)
  9443. {
  9444. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9445. // file exists
  9446. fclose(fp1);
  9447. }
  9448. else
  9449. {
  9450. // file doesn't exist
  9451. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9452. }
  9453. }
  9454. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9455. {
  9456. mtrace();
  9457. int result = FAIL;
  9458. time_t CurrentTime;
  9459. struct tm *tm;
  9460. pthread_t th_Status;
  9461. CurrentTime = time(NULL);
  9462. tm = localtime(&CurrentTime);
  9463. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9464. 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);
  9465. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9466. if(!interLock.isGetDiagnosticGoing)
  9467. {
  9468. interLock.isGetDiagnosticGoing = 1;
  9469. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9470. sleep(1);
  9471. }
  9472. else
  9473. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9474. return result;
  9475. }
  9476. void* GetDiagnosticsProcess(void* data)
  9477. {
  9478. pthread_detach(pthread_self());
  9479. mtrace();
  9480. int retriesInt=0, retryIntervalInt=0;
  9481. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9482. 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};
  9483. int port=0;
  9484. int isSuccess = FALSE;
  9485. char ftpbuf[200]={0};
  9486. char cmdBuf[2048];
  9487. struct tm *tmNow;
  9488. time_t CurrentTime;
  9489. struct tm tmStart;
  9490. struct tm tmStop;
  9491. CurrentTime = time(NULL);
  9492. tmNow=localtime(&CurrentTime);
  9493. uint16_t targetYear, targetMonth;
  9494. json_object *GetDiagnostics;
  9495. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9496. GetDiagnostics = json_tokener_parse(data);
  9497. if(!is_error(GetDiagnostics))
  9498. {
  9499. // Required data
  9500. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9501. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9502. // Optional data
  9503. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9504. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9505. else
  9506. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9507. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9508. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9509. else
  9510. retryIntervalInt = 30;
  9511. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9512. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9513. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9514. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9515. }
  9516. json_object_put(GetDiagnostics);
  9517. // Pack log to compress file
  9518. 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) &&
  9519. (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))
  9520. {
  9521. // Pack system log
  9522. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9523. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9524. targetYear = tmStart.tm_year;
  9525. targetMonth = tmStart.tm_mon;
  9526. do
  9527. {
  9528. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9529. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9530. if(targetMonth+1>=13)
  9531. {
  9532. targetYear += 1;
  9533. targetMonth = 1;
  9534. }
  9535. else
  9536. {
  9537. targetMonth += 1;
  9538. }
  9539. }while((targetYear < (tmNow->tm_year+1900)) ||
  9540. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9541. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9542. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9543. system(cmdBuf);
  9544. // Pack charging & event log
  9545. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9546. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9547. targetYear = tmStart.tm_year;
  9548. targetMonth = tmStart.tm_mon;
  9549. do
  9550. {
  9551. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9552. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9553. if(targetMonth+1>=13)
  9554. {
  9555. targetYear += 1;
  9556. targetMonth = 1;
  9557. }
  9558. else
  9559. {
  9560. targetMonth += 1;
  9561. }
  9562. }while((targetYear < (tmNow->tm_year+1900)) ||
  9563. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9564. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9565. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9566. system(cmdBuf);
  9567. // Combine log file
  9568. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9569. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9570. }
  9571. else
  9572. {
  9573. system("exec /root/logPackTools 'log' 6");
  9574. }
  9575. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9576. system(cmdBuf);
  9577. checkUploadLog();
  9578. //****************location*******************/
  9579. if(strcmp(locationstr,"")==0)
  9580. {
  9581. DEBUG_INFO("location is <Empty>!\n");
  9582. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9583. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9584. goto end;
  9585. }
  9586. memset(protocol, 0, ARRAY_SIZE(protocol));
  9587. memset(user, 0, ARRAY_SIZE(user) );
  9588. memset(password, 0, ARRAY_SIZE(password));
  9589. memset(host, 0, ARRAY_SIZE(host));
  9590. memset(path, 0, ARRAY_SIZE(path));
  9591. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9592. memset(host1, 0, ARRAY_SIZE(host1));
  9593. memset(path1, 0, ARRAY_SIZE(path1));
  9594. /*location: ftp://user:password@host:port/path*/
  9595. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9596. if((access(fnamePlusPath,F_OK))!=-1)
  9597. {
  9598. DEBUG_INFO("fnamePlusPath exist.\n");
  9599. }
  9600. else
  9601. {
  9602. DEBUG_INFO("fnamePlusPath not exist!\n");
  9603. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9604. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9605. goto end;
  9606. }
  9607. if(strchr(locationstr,'@')==NULL)
  9608. {
  9609. sscanf(locationstr,
  9610. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9611. protocol, host, &port, path);
  9612. strcpy(user,"anonymous");
  9613. strcpy(password,"");
  9614. }
  9615. else
  9616. {
  9617. //DEBUG_INFO("pch=%s\n", pch);
  9618. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9619. protocol, user, password, host, &port, path);
  9620. }
  9621. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9622. {
  9623. DEBUG_INFO("protocol is not ftp/http ! \n");
  9624. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9625. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9626. goto end;
  9627. }
  9628. if(strncmp(locationstr,"http", 4) == 0)
  9629. {
  9630. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9631. sprintf(ftppath,"/%s", path);
  9632. do
  9633. {
  9634. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9635. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9636. sleep(3);
  9637. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9638. if(!isSuccess)
  9639. {
  9640. DEBUG_INFO("Diagnostics fail.\n");
  9641. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9642. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9643. sleep(retryIntervalInt);
  9644. }
  9645. else
  9646. {
  9647. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9648. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9649. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9650. }
  9651. retriesInt--;
  9652. }while((isSuccess == 0)&&(retriesInt >= 0));
  9653. }
  9654. else
  9655. {
  9656. sscanf(host,"%[^/]%s",host1, path1);
  9657. if(strlen(path) > 0)
  9658. sprintf(ftppath,"/%s", path);
  9659. else
  9660. sprintf(ftppath,"/%s", path1);
  9661. int ftppathlen=strlen(ftppath);
  9662. int i=1;
  9663. char filenametemp[50];
  9664. while(i < ftppathlen)
  9665. {
  9666. int len=ftppathlen-i;
  9667. if(ftppath[len]== 47) // '/' ascll code: 47
  9668. {
  9669. DEBUG_INFO("find '/' all right\n");
  9670. break;
  9671. }
  9672. i=i+1;
  9673. }
  9674. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9675. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9676. filenametemp[i+1] = 0;
  9677. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9678. if(port == 0)
  9679. port = 21;
  9680. do
  9681. {
  9682. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9683. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9684. sleep(3);
  9685. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9686. if(!isSuccess)
  9687. {
  9688. DEBUG_INFO("Diagnostics fail.\n");
  9689. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9690. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9691. sleep(retryIntervalInt);
  9692. }
  9693. else
  9694. {
  9695. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9696. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9697. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9698. }
  9699. retriesInt--;
  9700. }while((!isSuccess)&&(retriesInt >= 0));
  9701. }
  9702. end:
  9703. system("rm -f /mnt/*");
  9704. sleep(5);
  9705. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9706. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9707. interLock.isGetDiagnosticGoing = 0;
  9708. pthread_exit(NULL);
  9709. }
  9710. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9711. {
  9712. mtrace();
  9713. int result = FAIL;
  9714. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9715. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9716. {
  9717. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9718. locallistVersion = -1;
  9719. }
  9720. else
  9721. {
  9722. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9723. OCPP_getListVerion();
  9724. }
  9725. //from db.OCPP_getListVerion
  9726. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9727. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9728. sendGetLocalListVersionConfirmation(uuid,"");
  9729. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9730. return result;
  9731. }
  9732. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9733. {
  9734. mtrace();
  9735. int result = FAIL;
  9736. int connectorIdInt=-1;
  9737. int tempIndex = 0;
  9738. int connectorIdIsNULL, chargingProfileIsNULL;
  9739. char comfirmstr[20]={0};
  9740. char cmdBuf[512];
  9741. json_object *RemoteStartTransaction;
  9742. FILE *fp;
  9743. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9744. if(server_pending == TRUE)
  9745. {
  9746. return 0;
  9747. }
  9748. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9749. RemoteStartTransaction = json_tokener_parse(payload);
  9750. if(!is_error(RemoteStartTransaction))
  9751. {
  9752. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9753. {
  9754. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9755. }
  9756. else
  9757. {
  9758. connectorIdIsNULL = TRUE;
  9759. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9760. {
  9761. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9762. {
  9763. connectorIdIsNULL = FALSE;
  9764. connectorIdInt = (gun_index+1);
  9765. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9766. break;
  9767. }
  9768. }
  9769. }
  9770. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9771. {
  9772. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9773. // Required data
  9774. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9775. // Optional data
  9776. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9777. {
  9778. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9779. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9780. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9781. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9782. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9783. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9784. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9785. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9786. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9787. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9788. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9789. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9790. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9791. {
  9792. 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")));
  9793. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9794. 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"));
  9795. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9796. 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"));
  9797. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9798. 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")));
  9799. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9800. {
  9801. 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++)
  9802. {
  9803. 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"));
  9804. 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"));
  9805. 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)
  9806. 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"));
  9807. }
  9808. }
  9809. }
  9810. }
  9811. else
  9812. {
  9813. chargingProfileIsNULL = TRUE;
  9814. }
  9815. }
  9816. }
  9817. else
  9818. {
  9819. connectorIdIsNULL = TRUE;
  9820. }
  9821. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9822. {
  9823. DEBUG_WARN("Connector id is NULL\n.");
  9824. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9825. goto end;
  9826. }
  9827. /*
  9828. enum _SYSTEM_STATUS
  9829. {
  9830. S_BOOTING = 0,
  9831. S_IDLE, = 1
  9832. S_AUTHORIZING, = 2
  9833. S_REASSIGN_CHECK, = 3
  9834. S_REASSIGN, = 4
  9835. S_PRECHARGE, = 5
  9836. S_PREPARING_FOR_EV, = 6
  9837. S_PREPARING_FOR_EVSE, = 7
  9838. S_CHARGING, = 8
  9839. S_TERMINATING, = 9
  9840. S_COMPLETE, = 10
  9841. S_ALARM, = 11
  9842. S_FAULT = 12
  9843. }
  9844. */
  9845. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9846. {
  9847. //check Transaction active
  9848. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9849. {
  9850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9851. {
  9852. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9853. }
  9854. else
  9855. {
  9856. tempIndex = connectorIdInt -1;
  9857. }
  9858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9859. {
  9860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9861. {
  9862. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9863. {
  9864. //Reserved
  9865. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9866. }
  9867. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9868. {
  9869. //Reserved
  9870. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9871. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9872. goto end;
  9873. }
  9874. else
  9875. {
  9876. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9877. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9878. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9879. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9880. {
  9881. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9882. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9883. goto end;
  9884. }
  9885. }//END FOR ELSE
  9886. }
  9887. }// END FOR CHAdeMO_QUANTITY
  9888. }
  9889. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9890. {
  9891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9892. {
  9893. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9894. }
  9895. else
  9896. {
  9897. tempIndex = connectorIdInt -1;
  9898. }
  9899. for (int index = 0; index < CCS_QUANTITY; index++)
  9900. {
  9901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9902. {
  9903. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9904. {
  9905. //Reserved
  9906. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9907. }
  9908. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9909. {
  9910. //Reserved
  9911. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9912. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9913. goto end;
  9914. }
  9915. else
  9916. {
  9917. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9918. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9919. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9920. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9921. {
  9922. DEBUG_WARN("CCS connector not allow start\n.");
  9923. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9924. goto end;
  9925. }
  9926. }// END FOR ELSE
  9927. }
  9928. }// END FOR CCS_QUANTITY
  9929. }
  9930. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9931. {
  9932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9933. {
  9934. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9935. }
  9936. else
  9937. {
  9938. tempIndex = connectorIdInt -1;
  9939. }
  9940. for (int index = 0; index < GB_QUANTITY; index++)
  9941. {
  9942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9943. {
  9944. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9945. {
  9946. //Reserved
  9947. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9948. }
  9949. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9950. {
  9951. //Reserved
  9952. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9953. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9954. goto end;
  9955. }
  9956. else
  9957. {
  9958. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9959. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9960. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9961. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9962. {
  9963. DEBUG_WARN("GB connector not allow start\n.");
  9964. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9965. goto end;
  9966. }
  9967. }// END FOR ELSE
  9968. }
  9969. } // END FOR GB_QUANTITY
  9970. }
  9971. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9972. {
  9973. tempIndex = connectorIdInt -1;
  9974. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9975. {
  9976. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9977. {
  9978. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9979. {
  9980. //Reserved
  9981. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9982. }
  9983. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9984. {
  9985. //Reserved
  9986. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9987. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9988. goto end;
  9989. }
  9990. else
  9991. {
  9992. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9993. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9994. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9995. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9996. {
  9997. DEBUG_WARN("GB connector not allow start\n.");
  9998. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9999. goto end;
  10000. }
  10001. }// END FOR ELSE
  10002. }
  10003. } // END FOR GB_QUANTITY
  10004. }
  10005. else
  10006. {
  10007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10008. {
  10009. tempIndex = 2;
  10010. }
  10011. else
  10012. {
  10013. tempIndex = connectorIdInt -1;
  10014. }
  10015. for (int index = 0; index < AC_QUANTITY; index++)
  10016. {
  10017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10018. {
  10019. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10020. {
  10021. //Reserved
  10022. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10023. }
  10024. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10025. {
  10026. //Reserved
  10027. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10028. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10029. goto end;
  10030. }
  10031. else
  10032. {
  10033. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10034. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10035. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10036. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10037. {
  10038. DEBUG_WARN("AC connector not allow start\n.");
  10039. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10040. goto end;
  10041. }
  10042. }//END FOR ELSE
  10043. }
  10044. }// END FOR AC_QUANTITY
  10045. }
  10046. if(chargingProfileIsNULL == FALSE)
  10047. {
  10048. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10049. {
  10050. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10051. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10052. //memset idTag
  10053. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10054. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10055. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10057. // Save profile to file
  10058. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10059. system(cmdBuf);
  10060. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10061. fp = fopen(cmdBuf, "w");
  10062. 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));
  10063. fclose(fp);
  10064. }
  10065. else
  10066. {
  10067. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10068. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10069. }
  10070. }
  10071. else
  10072. {
  10073. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10075. //memset idTag
  10076. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10077. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10078. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10080. }
  10081. }
  10082. else
  10083. {
  10084. DEBUG_WARN("Connector id over\n.");
  10085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10086. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10087. }
  10088. end:
  10089. json_object_put(RemoteStartTransaction);
  10090. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10091. {
  10092. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10093. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10094. }
  10095. //OCPP send RemoteStartConfirmation by first.
  10096. sendRemoteStartConfirmation(uuid, comfirmstr);
  10097. return result;
  10098. }
  10099. int handleRemoteStartRequest(char *uuid, char *payload)
  10100. {
  10101. mtrace();
  10102. int result = PASS;
  10103. int connectorIdInt=-1;
  10104. int tempIndex = 0;
  10105. char comfirmstr[20]={0};
  10106. char cmdBuf[512];
  10107. json_object *RemoteStartTransaction;
  10108. FILE *fp;
  10109. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10110. if(server_pending == TRUE)
  10111. {
  10112. result = FAIL;
  10113. }
  10114. RemoteStartTransaction = json_tokener_parse(payload);
  10115. if(!is_error(RemoteStartTransaction))
  10116. {
  10117. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10118. {
  10119. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10120. }
  10121. else
  10122. {
  10123. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10124. {
  10125. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10126. {
  10127. connectorIdInt = (gun_index+1);
  10128. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10129. break;
  10130. }
  10131. }
  10132. }
  10133. if(connectorIdInt == 0)
  10134. {
  10135. DEBUG_WARN("Connector id shall not equal 0.\n");
  10136. result = FAIL;
  10137. }
  10138. else if(connectorIdInt == -1)
  10139. {
  10140. DEBUG_INFO("Connector id does not specific.\n");
  10141. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10142. {
  10143. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10144. // Required data
  10145. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10146. // Optional data
  10147. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10148. {
  10149. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10150. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10151. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10152. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10153. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10154. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10155. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10156. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10157. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10158. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10159. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10160. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10161. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10162. {
  10163. 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")));
  10164. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10165. 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"));
  10166. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10167. 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"));
  10168. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10169. 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")));
  10170. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10171. {
  10172. 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++)
  10173. {
  10174. 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"));
  10175. 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"));
  10176. 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)
  10177. 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"));
  10178. }
  10179. }
  10180. }
  10181. }
  10182. else
  10183. {
  10184. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10185. }
  10186. }
  10187. }
  10188. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10189. {
  10190. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10191. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10192. // Required data
  10193. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10194. // Optional data
  10195. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10196. {
  10197. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10198. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10199. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10200. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10201. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10202. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10203. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10204. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10205. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10206. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10207. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10208. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10209. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10210. {
  10211. 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")));
  10212. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10213. 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"));
  10214. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10215. 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"));
  10216. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10217. 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")));
  10218. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10219. {
  10220. 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++)
  10221. {
  10222. 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"));
  10223. 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"));
  10224. 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)
  10225. 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"));
  10226. }
  10227. }
  10228. }
  10229. }
  10230. else
  10231. {
  10232. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10233. }
  10234. }
  10235. else
  10236. {
  10237. DEBUG_WARN("Connector id is over maximun value.\n");
  10238. result = FAIL;
  10239. }
  10240. }
  10241. if(result == PASS)
  10242. {
  10243. if(connectorIdInt > 0)
  10244. {
  10245. //check Transaction active
  10246. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10247. {
  10248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10249. {
  10250. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10251. }
  10252. else
  10253. {
  10254. tempIndex = connectorIdInt -1;
  10255. }
  10256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10257. {
  10258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10259. {
  10260. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10261. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10262. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10263. {
  10264. //Reserved
  10265. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10266. }
  10267. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10268. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10269. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10270. {
  10271. //Reserved
  10272. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10273. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10274. goto end;
  10275. }
  10276. else
  10277. {
  10278. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10279. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10280. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10281. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10282. {
  10283. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10284. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10285. goto end;
  10286. }
  10287. }//END FOR ELSE
  10288. }
  10289. }// END FOR CHAdeMO_QUANTITY
  10290. }
  10291. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10292. {
  10293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10294. {
  10295. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10296. }
  10297. else
  10298. {
  10299. tempIndex = connectorIdInt -1;
  10300. }
  10301. for (int index = 0; index < CCS_QUANTITY; index++)
  10302. {
  10303. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10304. {
  10305. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10307. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10308. {
  10309. //Reserved
  10310. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10311. }
  10312. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10313. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10314. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10315. {
  10316. //Reserved
  10317. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10318. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10319. goto end;
  10320. }
  10321. else
  10322. {
  10323. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10324. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10325. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10326. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10327. {
  10328. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10329. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10330. goto end;
  10331. }
  10332. }// END FOR ELSE
  10333. }
  10334. }// END FOR CCS_QUANTITY
  10335. }
  10336. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10337. {
  10338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10339. {
  10340. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10341. }
  10342. else
  10343. {
  10344. tempIndex = connectorIdInt -1;
  10345. }
  10346. for (int index = 0; index < GB_QUANTITY; index++)
  10347. {
  10348. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10349. {
  10350. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10351. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10352. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10353. {
  10354. //Reserved
  10355. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10356. }
  10357. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10358. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10359. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10360. {
  10361. //Reserved
  10362. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10363. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10364. goto end;
  10365. }
  10366. else
  10367. {
  10368. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10369. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10370. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10371. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10372. {
  10373. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10374. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10375. goto end;
  10376. }
  10377. }// END FOR ELSE
  10378. }
  10379. } // END FOR GB_QUANTITY
  10380. }
  10381. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10382. {
  10383. tempIndex = connectorIdInt -1;
  10384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10385. {
  10386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10387. {
  10388. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10389. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10390. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10391. {
  10392. //Reserved
  10393. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10394. }
  10395. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10396. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10397. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10398. {
  10399. //Reserved
  10400. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10402. goto end;
  10403. }
  10404. else
  10405. {
  10406. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10407. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10408. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10409. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10410. {
  10411. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10413. goto end;
  10414. }
  10415. }// END FOR ELSE
  10416. }
  10417. } // END FOR GB_QUANTITY
  10418. }
  10419. else
  10420. {
  10421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10422. {
  10423. tempIndex = 2;
  10424. }
  10425. else
  10426. {
  10427. tempIndex = connectorIdInt -1;
  10428. }
  10429. for (int index = 0; index < AC_QUANTITY; index++)
  10430. {
  10431. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10432. {
  10433. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10434. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10435. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10436. {
  10437. //Reserved
  10438. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10439. }
  10440. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10441. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10442. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10443. {
  10444. //Reserved
  10445. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10447. goto end;
  10448. }
  10449. else
  10450. {
  10451. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10452. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10453. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10454. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10455. {
  10456. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10458. goto end;
  10459. }
  10460. }//END FOR ELSE
  10461. }
  10462. }// END FOR AC_QUANTITY
  10463. }
  10464. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10465. {
  10466. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10467. {
  10468. // Save profile to file
  10469. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10470. system(cmdBuf);
  10471. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10472. fp = fopen(cmdBuf, "w");
  10473. 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));
  10474. fclose(fp);
  10475. }
  10476. else
  10477. {
  10478. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10480. goto end;
  10481. }
  10482. }
  10483. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10485. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10486. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10487. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10489. }
  10490. else
  10491. {
  10492. uint8_t isHasIdleConnector = FALSE;
  10493. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10494. {
  10495. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10496. {
  10497. isHasIdleConnector = TRUE;
  10498. break;
  10499. }
  10500. }
  10501. if(isHasIdleConnector == TRUE)
  10502. {
  10503. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10504. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10505. {
  10506. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10507. {
  10508. // Save profile to file
  10509. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10510. system(cmdBuf);
  10511. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10512. fp = fopen(cmdBuf, "w");
  10513. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10514. fclose(fp);
  10515. refreshStartTimer(&clientTime.RemoteStartWait);
  10516. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10518. }
  10519. else
  10520. {
  10521. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10522. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10523. }
  10524. }
  10525. else
  10526. {
  10527. refreshStartTimer(&clientTime.RemoteStartWait);
  10528. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10529. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10530. }
  10531. }
  10532. else
  10533. {
  10534. DEBUG_INFO("There is not any connector is idle.\n");
  10535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10536. }
  10537. }
  10538. }
  10539. else
  10540. {
  10541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10542. }
  10543. end:
  10544. json_object_put(RemoteStartTransaction);
  10545. sendRemoteStartConfirmation(uuid, comfirmstr);
  10546. return result;
  10547. }
  10548. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10549. {
  10550. mtrace();
  10551. int result = FAIL;
  10552. int match = FALSE;
  10553. int GunNO = 0;
  10554. int tempIndex = 0;
  10555. int transactionIdInt=0;
  10556. int transactionIdIsNULL= TRUE;
  10557. char comfirmstr[20];
  10558. json_object *RemoteStopTransaction;
  10559. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10560. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10561. if(server_pending == TRUE)
  10562. {
  10563. return 0;
  10564. }
  10565. RemoteStopTransaction = json_tokener_parse(payload);
  10566. if(!is_error(RemoteStopTransaction))
  10567. {
  10568. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10569. {
  10570. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10571. transactionIdIsNULL = FALSE;
  10572. }
  10573. }
  10574. json_object_put(RemoteStopTransaction);
  10575. if(transactionIdIsNULL == FALSE)
  10576. {
  10577. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10578. {
  10579. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10580. {
  10581. //check Transaction active
  10582. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10583. {
  10584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10585. {
  10586. tempIndex = ((gun_index==2) ? 1: 0);
  10587. }
  10588. else
  10589. {
  10590. tempIndex = gun_index;
  10591. }
  10592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10593. {
  10594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10595. {
  10596. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10597. {
  10598. match = TRUE;
  10599. GunNO = gun_index;
  10600. }
  10601. }
  10602. }// END FOR CHAdeMO_QUANTITY
  10603. }
  10604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10605. {
  10606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10607. {
  10608. tempIndex = ((gun_index==2) ? 1: 0);
  10609. }
  10610. else
  10611. {
  10612. tempIndex = gun_index;
  10613. }
  10614. for (int index = 0; index < CCS_QUANTITY; index++)
  10615. {
  10616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10617. {
  10618. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10619. {
  10620. match = TRUE;
  10621. GunNO = gun_index;
  10622. }
  10623. }
  10624. }// END FOR CCS_QUANTITY
  10625. }
  10626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10627. {
  10628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10629. {
  10630. tempIndex = ((gun_index==2) ? 1: 0);
  10631. }
  10632. else
  10633. {
  10634. tempIndex = gun_index;
  10635. }
  10636. for (int index = 0; index < GB_QUANTITY; index++)
  10637. {
  10638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10639. {
  10640. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10641. {
  10642. match = TRUE;
  10643. GunNO = gun_index;
  10644. }
  10645. }
  10646. }// END FOR GB_QUANTITY
  10647. }
  10648. else if(gunType[gun_index] == GUN_TYPE_DO)
  10649. {
  10650. tempIndex = gun_index;
  10651. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10652. {
  10653. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10654. {
  10655. 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
  10656. {
  10657. match = TRUE;
  10658. GunNO = gun_index;
  10659. }
  10660. }
  10661. }// END FOR GB_QUANTITY
  10662. }
  10663. else
  10664. {
  10665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10666. {
  10667. tempIndex = 2;
  10668. }
  10669. else
  10670. {
  10671. tempIndex = gun_index;
  10672. }
  10673. for (int index = 0; index < AC_QUANTITY; index++)
  10674. {
  10675. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10676. {
  10677. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10678. {
  10679. match = TRUE;
  10680. GunNO = gun_index;
  10681. }
  10682. }
  10683. }// END FOR CHAdeMO_QUANTITY
  10684. } // END FOR AC ELSE
  10685. }// CHECK IF ResponseTransactionId == transactionIdInt
  10686. }//END FOR
  10687. if( match == TRUE)
  10688. {
  10689. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10691. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10692. }
  10693. else
  10694. {
  10695. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10696. }
  10697. }
  10698. else
  10699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10700. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10701. return result;
  10702. }
  10703. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10704. {
  10705. mtrace();
  10706. int result = FAIL;
  10707. int connectorIdInt=0, reservationIdInt=0;
  10708. int tempIndex = 0;
  10709. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10710. char comfirmstr[20]={0};
  10711. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10712. int c = 0;
  10713. char *loc;
  10714. //char *ptr;
  10715. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10716. strcpy(sstrtemp, stringtrimspace(payload));
  10717. //***(1)connectorId ****/
  10718. c=0;
  10719. loc = strstr(sstrtemp, "connectorId");
  10720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10721. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10722. {
  10723. sstr[c] = loc[strlen("connectorId")+2+c];
  10724. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10725. c++;
  10726. }
  10727. sstr[c] = '\0';
  10728. connectorIdInt = atoi(sstr);
  10729. //***(2)expiryDate ****/
  10730. loc = strstr(sstrtemp, "expiryDate");
  10731. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10732. c = 0;
  10733. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10734. {
  10735. sstr[c] = loc[3+strlen("expiryDate")+c];
  10736. c++;
  10737. }
  10738. sstr[c] = '\0';
  10739. strcpy(expiryDatestr, sstr);
  10740. //***(3)idTag ****/
  10741. loc = strstr(sstrtemp, "idTag");
  10742. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10743. c = 0;
  10744. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10745. {
  10746. sstr[c] = loc[3+strlen("idTag")+c];
  10747. c++;
  10748. }
  10749. sstr[c] = '\0';
  10750. strcpy(idTagstr, sstr);
  10751. //***(4)parentIdTag ****/
  10752. loc = strstr(sstrtemp, "parentIdTag");
  10753. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10754. c = 0;
  10755. if(loc == NULL)
  10756. {
  10757. strcpy(parentIdTagstr, "");
  10758. }
  10759. else
  10760. {
  10761. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10762. {
  10763. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10764. c++;
  10765. }
  10766. sstr[c] = '\0';
  10767. strcpy(parentIdTagstr, sstr);
  10768. }
  10769. //***(5)reservationId ****/
  10770. c=0;
  10771. loc = strstr(sstrtemp, "reservationId");
  10772. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10773. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10774. {
  10775. sstr[c] = loc[strlen("reservationId")+2+c];
  10776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10777. c++;
  10778. }
  10779. sstr[c] = '\0';
  10780. reservationIdInt = atoi(sstr);
  10781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10782. /*
  10783. enum SYSTEM_STATUS
  10784. {
  10785. SYS_MODE_BOOTING = 0,
  10786. SYS_MODE_IDLE = 1,
  10787. SYS_MODE_AUTHORIZING = 2,
  10788. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10789. SYS_MODE_REASSIGN = 4,
  10790. SYS_MODE_PREPARING = 5,
  10791. SYS_MODE_PREPARE_FOR_EV = 6,
  10792. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10793. SYS_MODE_CHARGING = 8,
  10794. SYS_MODE_TERMINATING = 9,
  10795. SYS_MODE_COMPLETE = 10,
  10796. SYS_MODE_ALARM = 11,
  10797. SYS_MODE_FAULT = 12,
  10798. SYS_MODE_RESERVATION = 13,
  10799. SYS_MODE_BOOKING = 14,
  10800. SYS_MODE_MAINTAIN = 15,
  10801. SYS_MODE_DEBUG = 16,
  10802. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10803. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10804. SYS_MODE_UPDATE = 19
  10805. };
  10806. */
  10807. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10808. {
  10809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10810. goto end;
  10811. }
  10812. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10813. {
  10814. //check Transaction active
  10815. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10816. {
  10817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10818. {
  10819. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10820. }
  10821. else
  10822. {
  10823. tempIndex = connectorIdInt -1;
  10824. }
  10825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10826. {
  10827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10828. {
  10829. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10830. {
  10831. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10832. {
  10833. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10834. {
  10835. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10837. }
  10838. 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'))
  10839. {
  10840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10841. }
  10842. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10843. {
  10844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10845. }
  10846. else
  10847. {
  10848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10849. }
  10850. }
  10851. 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
  10852. {
  10853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10854. }
  10855. }
  10856. else
  10857. {
  10858. //replace reservation
  10859. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10861. }
  10862. }
  10863. } // END FOR CHAdeMO_QUANTITY
  10864. }
  10865. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10866. {
  10867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10868. {
  10869. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10870. }
  10871. else
  10872. {
  10873. tempIndex = connectorIdInt -1;
  10874. }
  10875. for (int index = 0; index < CCS_QUANTITY; index++)
  10876. {
  10877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10878. {
  10879. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10880. {
  10881. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10882. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10883. {
  10884. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10885. {
  10886. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10888. }
  10889. 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'))
  10890. {
  10891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10892. }
  10893. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10894. {
  10895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10896. }
  10897. else
  10898. {
  10899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10900. }
  10901. }
  10902. 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
  10903. {
  10904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10905. }
  10906. }
  10907. else
  10908. {
  10909. //replace reservation
  10910. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10912. }
  10913. }
  10914. } // END FOR CCS_QUANTITY
  10915. }
  10916. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10917. {
  10918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10919. {
  10920. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10921. }
  10922. else
  10923. {
  10924. tempIndex = connectorIdInt -1;
  10925. }
  10926. for (int index = 0; index < GB_QUANTITY; index++)
  10927. {
  10928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10929. {
  10930. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10931. {
  10932. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10933. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10934. {
  10935. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10936. {
  10937. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10939. }
  10940. 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'))
  10941. {
  10942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10943. }
  10944. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10945. {
  10946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10947. }
  10948. else
  10949. {
  10950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10951. }
  10952. }
  10953. 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
  10954. {
  10955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10956. }
  10957. }
  10958. else
  10959. {
  10960. //replace reservation
  10961. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10963. }
  10964. }
  10965. }// END FOR GB_QUANTITY
  10966. }
  10967. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10968. {
  10969. tempIndex = connectorIdInt -1;
  10970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10971. {
  10972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10973. {
  10974. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10975. {
  10976. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10977. 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
  10978. {
  10979. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10980. {
  10981. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10983. }
  10984. 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'))
  10985. {
  10986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10987. }
  10988. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10989. {
  10990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10991. }
  10992. else
  10993. {
  10994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10995. }
  10996. }
  10997. 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
  10998. {
  10999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11000. }
  11001. }
  11002. else
  11003. {
  11004. //replace reservation
  11005. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11007. }
  11008. }
  11009. }// END FOR GB_QUANTITY
  11010. }
  11011. else
  11012. {
  11013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11014. {
  11015. tempIndex = 2;
  11016. }
  11017. else
  11018. {
  11019. tempIndex = (connectorIdInt -1);
  11020. }
  11021. for (int index = 0; index < AC_QUANTITY; index++)
  11022. {
  11023. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11024. {
  11025. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11026. {
  11027. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11028. {
  11029. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11030. {
  11031. 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))
  11032. {
  11033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11034. }
  11035. else
  11036. {
  11037. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11039. }
  11040. }
  11041. 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'))
  11042. {
  11043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11044. }
  11045. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11046. {
  11047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11048. }
  11049. else
  11050. {
  11051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11052. }
  11053. }
  11054. 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
  11055. {
  11056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11057. }
  11058. }
  11059. else
  11060. {
  11061. //replace reservation
  11062. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11064. }
  11065. }
  11066. } // END FOR AC_QUANTITY
  11067. }
  11068. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11069. }
  11070. else if(connectorIdInt == 0)
  11071. {
  11072. //check Transaction active
  11073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11074. {
  11075. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11076. {
  11077. 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'))
  11078. {
  11079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11080. goto end;
  11081. }
  11082. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11083. {
  11084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11085. goto end;
  11086. }
  11087. 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
  11088. {
  11089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11090. goto end;
  11091. }
  11092. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11093. {
  11094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11095. goto end;
  11096. }
  11097. }
  11098. }// END FOR CHAdeMO_QUANTITY
  11099. for (int index = 0; index < CCS_QUANTITY; index++)
  11100. {
  11101. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11102. {
  11103. 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'))
  11104. {
  11105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11106. goto end;
  11107. }
  11108. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11109. {
  11110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11111. goto end;
  11112. }
  11113. 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
  11114. {
  11115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11116. goto end;
  11117. }
  11118. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11119. {
  11120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11121. goto end;
  11122. }
  11123. }
  11124. } // END FOR CCS_QUANTITY
  11125. for (int index = 0; index < GB_QUANTITY; index++)
  11126. {
  11127. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11128. {
  11129. 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'))
  11130. {
  11131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11132. goto end;
  11133. }
  11134. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11135. {
  11136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11137. goto end;
  11138. }
  11139. 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
  11140. {
  11141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11142. goto end;
  11143. }
  11144. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11145. {
  11146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11147. goto end;
  11148. }
  11149. }
  11150. } // END FOR GB_QUANTITY
  11151. for (int index = 0; index < AC_QUANTITY; index++)
  11152. {
  11153. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11154. {
  11155. 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'))
  11156. {
  11157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11158. goto end;
  11159. }
  11160. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11161. {
  11162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11163. goto end;
  11164. }
  11165. 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
  11166. {
  11167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11168. goto end;
  11169. }
  11170. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11171. {
  11172. 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))
  11173. {
  11174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11175. goto end;
  11176. }
  11177. }
  11178. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11179. {
  11180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11181. goto end;
  11182. }
  11183. }
  11184. }// END FOR AC_QUANTITY
  11185. //The connectorId is 0
  11186. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11188. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11189. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11190. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11191. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11192. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11193. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11194. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11195. result = TRUE;
  11196. return result;
  11197. }
  11198. else
  11199. {
  11200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11201. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11202. }
  11203. if(strcmp(comfirmstr,"Accepted") == 0)
  11204. {
  11205. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11206. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11207. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11208. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11209. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11210. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11211. result = TRUE;
  11212. return result;
  11213. }
  11214. end:
  11215. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11216. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11217. return result;
  11218. }
  11219. int handleResetRequest(char *uuid, char *payload)
  11220. {
  11221. mtrace();
  11222. int result = FAIL;
  11223. char sstr[10]={0},sstrtemp[30]={ 0 };
  11224. char typestr[10]={0};
  11225. char comfirmstr[20]={0};
  11226. int c = 0;
  11227. char *loc;
  11228. DEBUG_INFO("handleResetRequest...\n");
  11229. strcpy(sstrtemp, stringtrimspace(payload));
  11230. loc = strstr(sstrtemp, "type");
  11231. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11232. c = 0;
  11233. while (loc[3+strlen("type")+c] != '\"')
  11234. {
  11235. sstr[c] = loc[3+strlen("type")+c];
  11236. c++;
  11237. }
  11238. sstr[c] = '\0';
  11239. strcpy(typestr,sstr);
  11240. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11241. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11242. {
  11243. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11244. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11245. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11246. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11247. }
  11248. else
  11249. {
  11250. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11251. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11252. result = PASS;
  11253. }
  11254. sendResetConfirmation(uuid, comfirmstr);
  11255. return result;
  11256. }
  11257. int handleSendLocalListRequest(char *uuid, char *payload)
  11258. {
  11259. mtrace();
  11260. int result = FAIL;
  11261. char comfirmstr[20];
  11262. int checkState_Faulted = FALSE;
  11263. json_object *SendLocalList;
  11264. DEBUG_INFO("handleSendLocalListRequest...\n");
  11265. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11266. {
  11267. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11268. goto end;
  11269. }
  11270. //check Charge Point state
  11271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11272. {
  11273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11274. {
  11275. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11276. }
  11277. }
  11278. for (int index = 0; index < CCS_QUANTITY; index++)
  11279. {
  11280. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11281. {
  11282. checkState_Faulted = TRUE; //OCPP Status
  11283. }
  11284. }
  11285. for (int index = 0; index < GB_QUANTITY; index++)
  11286. {
  11287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11288. {
  11289. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11290. }
  11291. }
  11292. //check Charge Point state
  11293. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11294. {
  11295. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11296. {
  11297. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11298. }
  11299. }
  11300. //check Charge Point state
  11301. for (int index = 0; index < AC_QUANTITY; index++)
  11302. {
  11303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11304. {
  11305. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11306. }
  11307. }
  11308. if(checkState_Faulted == TRUE)
  11309. {
  11310. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11311. goto end;
  11312. }
  11313. // Parsing payload
  11314. SendLocalList = json_tokener_parse(payload);
  11315. if(!is_error(SendLocalList))
  11316. {
  11317. // Required data
  11318. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11319. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11320. // Optional data
  11321. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11322. {
  11323. //Check UpdateType
  11324. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11325. {
  11326. //Local list full update
  11327. DEBUG_INFO("Local list full update.\n");
  11328. OCPP_getListVerion();
  11329. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11330. {
  11331. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11332. goto end;
  11333. }
  11334. OCPP_cleanLocalList();
  11335. }
  11336. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11337. {
  11338. //Local list different update
  11339. DEBUG_INFO("Local list different update.\n");
  11340. OCPP_getListVerion();
  11341. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11342. {
  11343. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11344. goto end;
  11345. }
  11346. }
  11347. else
  11348. {
  11349. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11350. goto end;
  11351. }
  11352. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11353. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11354. {
  11355. 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")));
  11356. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11357. {
  11358. 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")));
  11359. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11360. 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")));
  11361. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11362. 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")));
  11363. }
  11364. // Add to db
  11365. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11366. {
  11367. //Local list full update
  11368. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11369. idx,
  11370. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11371. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11372. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11373. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11374. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11375. // update list
  11376. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11377. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11378. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11379. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11380. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11381. }
  11382. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11383. {
  11384. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11385. idx,
  11386. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11387. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11388. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11389. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11390. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11391. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11392. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11393. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11394. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11395. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11396. }
  11397. }
  11398. }
  11399. else
  11400. {
  11401. //Check UpdateType
  11402. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11403. {
  11404. //Local list full update
  11405. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11406. OCPP_cleanLocalList();
  11407. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11408. goto end;
  11409. }
  11410. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11411. {
  11412. //Local list different update
  11413. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11414. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11415. goto end;
  11416. }
  11417. }
  11418. result = PASS;
  11419. }
  11420. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11421. end:
  11422. json_object_put(SendLocalList);
  11423. sendSendLocalListConfirmation(uuid, comfirmstr);
  11424. return result;
  11425. }
  11426. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11427. {
  11428. mtrace();
  11429. int result = FAIL;
  11430. struct StructSetChargingProfile SetProfileReq = {0};
  11431. int tempchargingProfileIdInt;
  11432. int chargingSchedulePeriodCount = 0;
  11433. char comfirmstr[20]={0};
  11434. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11435. char rmFileCmd[128]={0};
  11436. int profileQuantity = 0;
  11437. json_object *SetChargingProfile;
  11438. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11439. SetChargingProfile = json_tokener_parse(payload);
  11440. if(!is_error(SetChargingProfile))
  11441. {
  11442. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11443. {
  11444. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11445. }
  11446. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11447. {
  11448. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11449. {
  11450. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11451. }
  11452. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11453. {
  11454. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11455. }
  11456. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11457. {
  11458. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11459. }
  11460. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11461. {
  11462. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11463. }
  11464. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11465. {
  11466. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11467. }
  11468. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11469. {
  11470. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11471. }
  11472. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11473. {
  11474. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11475. }
  11476. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11477. {
  11478. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11479. }
  11480. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11481. {
  11482. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11483. {
  11484. 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")));
  11485. }
  11486. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11487. {
  11488. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11489. }
  11490. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11491. {
  11492. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11493. }
  11494. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11495. {
  11496. 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")));
  11497. }
  11498. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11499. {
  11500. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11501. if(chargingSchedulePeriodCount <= 10)
  11502. {
  11503. 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++)
  11504. {
  11505. 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)
  11506. {
  11507. 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"));
  11508. }
  11509. 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)
  11510. {
  11511. 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"));
  11512. }
  11513. 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)
  11514. {
  11515. 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"));
  11516. }
  11517. }
  11518. }
  11519. }
  11520. }
  11521. }
  11522. }
  11523. // Profile periods quantity check
  11524. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11525. {
  11526. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11527. goto end;
  11528. }
  11529. // Check invalid limit
  11530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11531. {
  11532. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11533. {
  11534. 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)))) ||
  11535. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11536. {
  11537. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11538. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11539. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11540. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11541. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11542. goto end;
  11543. }
  11544. }
  11545. }
  11546. else
  11547. {
  11548. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11549. {
  11550. 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))
  11551. {
  11552. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11553. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11554. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11555. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11556. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11557. goto end;
  11558. }
  11559. }
  11560. }
  11561. // Profile purpose info check
  11562. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11563. {
  11564. FILE *fp;
  11565. char dataLine[4096]={0};
  11566. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11567. if(SetProfileReq.ConnectorId != 0)
  11568. {
  11569. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11570. goto end;
  11571. }
  11572. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11573. if (!fp)
  11574. {
  11575. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11576. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11577. }
  11578. else
  11579. {
  11580. while(fscanf(fp, "%s", dataLine) != EOF)
  11581. {
  11582. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11583. {
  11584. profileQuantity += 1;
  11585. }
  11586. }
  11587. }
  11588. fclose(fp);
  11589. }
  11590. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11591. {
  11592. FILE *fp;
  11593. char dataLine[4096]={0};
  11594. char filename[128]={0};
  11595. int tmpProfileQuantity;
  11596. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11597. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11598. {
  11599. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11600. goto end;
  11601. }
  11602. if(SetProfileReq.ConnectorId == 0)
  11603. {
  11604. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11605. {
  11606. tmpProfileQuantity = 0;
  11607. memset(filename, 0, ARRAY_SIZE(filename));
  11608. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11609. fp = fopen(filename, "r");
  11610. if (!fp)
  11611. {
  11612. DEBUG_INFO("%s does not create.\n", filename);
  11613. fp = fopen(filename, "w+");
  11614. }
  11615. else
  11616. {
  11617. while(fscanf(fp, "%s", dataLine) != EOF)
  11618. {
  11619. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11620. {
  11621. tmpProfileQuantity += 1;
  11622. }
  11623. }
  11624. }
  11625. fclose(fp);
  11626. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11627. }
  11628. }
  11629. else
  11630. {
  11631. memset(filename, 0, ARRAY_SIZE(filename));
  11632. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11633. fp = fopen(filename, "r");
  11634. if (!fp)
  11635. {
  11636. DEBUG_INFO("%s does not create.\n", filename);
  11637. fp = fopen(filename, "w+");
  11638. }
  11639. else
  11640. {
  11641. while(fscanf(fp, "%s", dataLine) != EOF)
  11642. {
  11643. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11644. {
  11645. profileQuantity += 1;
  11646. }
  11647. }
  11648. }
  11649. fclose(fp);
  11650. }
  11651. }
  11652. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11653. {
  11654. int isMatchTransactiodId= FALSE;
  11655. FILE *fp;
  11656. char dataLine[4096]={0};
  11657. char filename[128]={0};
  11658. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11659. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11660. if(SetProfileReq.ConnectorId == 0)
  11661. {
  11662. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11663. goto end;
  11664. }
  11665. int tempIndex = 0;
  11666. //check Transaction active
  11667. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11668. {
  11669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11670. {
  11671. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11672. }
  11673. else
  11674. {
  11675. tempIndex = SetProfileReq.ConnectorId -1;
  11676. }
  11677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11678. {
  11679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11680. {
  11681. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11682. {
  11683. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11684. {
  11685. isMatchTransactiodId = TRUE;
  11686. break;
  11687. }
  11688. }
  11689. }
  11690. }
  11691. }
  11692. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11693. {
  11694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11695. {
  11696. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11697. }
  11698. else
  11699. {
  11700. tempIndex = SetProfileReq.ConnectorId -1;
  11701. }
  11702. for (int index = 0; index < CCS_QUANTITY; index++)
  11703. {
  11704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11705. {
  11706. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11707. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11708. {
  11709. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11710. {
  11711. isMatchTransactiodId = TRUE;
  11712. break;
  11713. }
  11714. }
  11715. }
  11716. }
  11717. }
  11718. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11719. {
  11720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11721. {
  11722. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11723. }
  11724. else
  11725. {
  11726. tempIndex = SetProfileReq.ConnectorId -1;
  11727. }
  11728. for (int index = 0; index < GB_QUANTITY; index++)
  11729. {
  11730. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11731. {
  11732. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11733. {
  11734. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11735. {
  11736. isMatchTransactiodId = TRUE;
  11737. break;
  11738. }
  11739. }
  11740. }
  11741. }
  11742. }
  11743. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11744. {
  11745. tempIndex = SetProfileReq.ConnectorId -1;
  11746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11747. {
  11748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11749. {
  11750. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11751. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11752. {
  11753. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11754. {
  11755. isMatchTransactiodId = TRUE;
  11756. break;
  11757. }
  11758. }
  11759. }
  11760. }
  11761. }
  11762. else
  11763. {
  11764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11765. {
  11766. tempIndex = 2;
  11767. }
  11768. else
  11769. {
  11770. tempIndex = (SetProfileReq.ConnectorId -1);
  11771. }
  11772. for (int index = 0; index < AC_QUANTITY; index++)
  11773. {
  11774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11775. {
  11776. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11777. {
  11778. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11779. {
  11780. isMatchTransactiodId = TRUE;
  11781. break;
  11782. }
  11783. }
  11784. }
  11785. }
  11786. }
  11787. //check Transaction active
  11788. if(isMatchTransactiodId == FALSE)
  11789. {
  11790. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11791. goto end;
  11792. }
  11793. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11794. {
  11795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11796. goto end;
  11797. }
  11798. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11799. fp = fopen(filename, "r");
  11800. if (!fp)
  11801. {
  11802. DEBUG_INFO("%s does not create.\n", filename);
  11803. fp = fopen(filename, "w+");
  11804. }
  11805. else
  11806. {
  11807. //Check Charging Profile Count
  11808. while(fscanf(fp, "%s", dataLine) != EOF)
  11809. {
  11810. //DEBUG_INFO("word=%s\n",word);
  11811. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11812. {
  11813. profileQuantity += 1;
  11814. }
  11815. }
  11816. }
  11817. fclose(fp);
  11818. }
  11819. // Check ChargeProfileMaxStackLevel
  11820. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11821. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11822. {
  11823. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11824. goto end;
  11825. }
  11826. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11827. {
  11828. FILE *fp;
  11829. char dataLine[4096]={0};
  11830. char fnametemp[128]={0};
  11831. int tmpProfileQuantity;
  11832. //Check ChargePointMaxProfile.json exit
  11833. profileQuantity = 0;
  11834. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11835. {
  11836. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11837. //Check Charging Profile Count
  11838. tmpProfileQuantity = 0;
  11839. while(fscanf(fp, "%s", dataLine) != EOF)
  11840. {
  11841. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11842. {
  11843. profileQuantity += 1;
  11844. tmpProfileQuantity += 1;
  11845. }
  11846. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11847. }
  11848. fclose(fp);
  11849. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11850. }
  11851. //Check TxDefaultProfile_%d.json
  11852. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11853. {
  11854. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11855. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11856. if((access(fnametemp,F_OK))!=-1)
  11857. {
  11858. fp = fopen(fnametemp, "r");
  11859. //Check Charging Profile Count
  11860. tmpProfileQuantity = 0;
  11861. while(fscanf(fp, "%s", dataLine) != EOF)
  11862. {
  11863. //DEBUG_INFO("word=%s\n",word);
  11864. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11865. {
  11866. profileQuantity += 1;
  11867. tmpProfileQuantity += 1;
  11868. }
  11869. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11870. }
  11871. fclose(fp);
  11872. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11873. }
  11874. }
  11875. //Check TxProfile_%d.json
  11876. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11877. {
  11878. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11879. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11880. if((access(fnametemp,F_OK))!=-1)
  11881. {
  11882. fp = fopen(fnametemp, "r");
  11883. //Check Charging Profile Count
  11884. tmpProfileQuantity = 0;
  11885. while(fscanf(fp, "%s", dataLine) != EOF)
  11886. {
  11887. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11888. {
  11889. profileQuantity += 1;
  11890. tmpProfileQuantity += 1;
  11891. }
  11892. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11893. }
  11894. fclose(fp);
  11895. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11896. }
  11897. }
  11898. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11899. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11900. {
  11901. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11902. goto end;
  11903. }
  11904. }
  11905. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11906. //**********************************Write to File********************************************************/
  11907. {
  11908. FILE *infile;
  11909. FILE *outfile;
  11910. char dataLine[4096]={0};
  11911. char filename[128]={0};
  11912. int chkChar=0;
  11913. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11914. {
  11915. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11916. {
  11917. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11918. }
  11919. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11920. {
  11921. if(SetProfileReq.ConnectorId==0)
  11922. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11923. else
  11924. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11925. }
  11926. else
  11927. {
  11928. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11929. }
  11930. infile = fopen (filename, "r");
  11931. outfile = fopen (tempfile, "w");
  11932. chkChar = fgetc(infile);
  11933. rewind(infile);
  11934. if(chkChar == EOF)
  11935. {
  11936. // Profile is empty
  11937. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11938. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11939. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11940. fclose(infile);
  11941. fclose(outfile);
  11942. sprintf(rmFileCmd,"rm -f %s",filename);
  11943. system(rmFileCmd);
  11944. rename(tempfile, filename);
  11945. }
  11946. else
  11947. {
  11948. // Profile is not empty
  11949. int ChargingProfileAdded = FALSE;
  11950. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11951. {
  11952. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11953. json_object *tmpChargingProfile;
  11954. tmpChargingProfile = json_tokener_parse(dataLine);
  11955. if(!is_error(SetChargingProfile))
  11956. {
  11957. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11958. {
  11959. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11960. {
  11961. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11962. }
  11963. }
  11964. }
  11965. json_object_put(tmpChargingProfile);
  11966. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11967. {
  11968. if(ChargingProfileAdded == FALSE)
  11969. {
  11970. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11971. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11972. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11973. ChargingProfileAdded = TRUE;
  11974. }
  11975. }
  11976. else
  11977. {
  11978. fprintf(outfile,"%s\n",dataLine);
  11979. if(ChargingProfileAdded == FALSE)
  11980. {
  11981. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11982. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11983. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11984. ChargingProfileAdded = TRUE;
  11985. }
  11986. }
  11987. } // end of while loop
  11988. fclose(infile);
  11989. fclose(outfile);
  11990. sprintf(rmFileCmd,"rm -f %s",filename);
  11991. system(rmFileCmd);
  11992. rename(tempfile, filename);
  11993. }
  11994. }
  11995. sleep(1);
  11996. result = TRUE;
  11997. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11998. }
  11999. end:
  12000. json_object_put(SetChargingProfile);
  12001. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12002. {
  12003. if(SetProfileReq.ConnectorId == 0)
  12004. {
  12005. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12006. {
  12007. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12008. }
  12009. }
  12010. else
  12011. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12012. }
  12013. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12014. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12015. return result;
  12016. }
  12017. int handleTriggerMessageRequest(char *uuid, char *payload)
  12018. {
  12019. mtrace();
  12020. int result = FAIL;
  12021. int connectorIdIsNULL = FALSE;
  12022. int connectorIdInt =0;
  12023. char sstr[40]={0},sstrtemp[100]={ 0 };
  12024. char requestedMessagestr[40]={0};
  12025. char comfirmstr[20]={0};
  12026. int c = 0;
  12027. char *loc;
  12028. DEBUG_INFO("handleTriggerMessageRequest\n");
  12029. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12030. strcpy(sstrtemp, stringtrimspace(payload));
  12031. c = 0;
  12032. loc = strstr(sstrtemp, "requestedMessage");
  12033. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12034. {
  12035. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12036. c++;
  12037. }
  12038. sstr[c] = '\0';
  12039. strcpy(requestedMessagestr, sstr);
  12040. c = 0;
  12041. loc = strstr(sstrtemp, "connectorId");
  12042. if(loc == NULL)
  12043. {
  12044. connectorIdIsNULL = TRUE;
  12045. }
  12046. else
  12047. {
  12048. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12049. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12050. {
  12051. sstr[c] = loc[strlen("connectorId")+2+c];
  12052. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12053. c++;
  12054. }
  12055. sstr[c] = '\0';
  12056. connectorIdInt = atoi(sstr);
  12057. }
  12058. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12059. {
  12060. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12061. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12062. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12063. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12064. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12065. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12066. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12067. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12068. {
  12069. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12070. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12071. return TRUE;
  12072. }
  12073. else
  12074. {
  12075. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12076. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12077. }
  12078. }
  12079. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12080. {
  12081. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12082. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12083. return TRUE;
  12084. }
  12085. //==========================
  12086. // Trigger message
  12087. //==========================
  12088. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12089. {
  12090. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12091. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12092. {
  12093. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12094. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12095. }
  12096. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12097. }
  12098. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12099. {
  12100. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12101. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12102. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12103. }
  12104. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12105. {
  12106. //sendBootNotificationRequest();
  12107. server_sign = FALSE;
  12108. }
  12109. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12110. {
  12111. refreshStartTimer(&clientTime.Heartbeat);
  12112. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12113. }
  12114. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12115. {
  12116. if(connectorIdIsNULL == FALSE)
  12117. {
  12118. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12119. {
  12120. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12121. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12122. }
  12123. }
  12124. else
  12125. {
  12126. for(int idx=0;idx< gunTotalNumber;idx++)
  12127. {
  12128. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12129. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12130. }
  12131. }
  12132. }
  12133. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12134. {
  12135. if(connectorIdIsNULL == FALSE)
  12136. {
  12137. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12138. {
  12139. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12140. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12141. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12142. }
  12143. }
  12144. else
  12145. {
  12146. for(int idx=0;idx< gunTotalNumber;idx++)
  12147. {
  12148. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12149. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12150. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12151. }
  12152. }
  12153. }
  12154. return result;
  12155. }
  12156. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12157. {
  12158. mtrace();
  12159. int result = FAIL;
  12160. int connectorIdInt =0;
  12161. char comfirmstr[20]={0};
  12162. int tempIndex = 0;
  12163. json_object *UnlockConnector;
  12164. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12165. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12166. UnlockConnector = json_tokener_parse(payload);
  12167. if(!is_error(UnlockConnector))
  12168. {
  12169. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12170. {
  12171. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12172. }
  12173. }
  12174. json_object_put(UnlockConnector);
  12175. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12176. if(gunTotalNumber == 0)
  12177. {
  12178. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12179. goto end;
  12180. }
  12181. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12182. {
  12183. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12184. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12185. goto end;
  12186. }
  12187. else
  12188. {
  12189. //check Transaction active
  12190. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12191. {
  12192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12193. {
  12194. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12195. }
  12196. else
  12197. {
  12198. tempIndex = connectorIdInt -1;
  12199. }
  12200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12201. {
  12202. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12203. {
  12204. //stop Transaction
  12205. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12206. }
  12207. }
  12208. }
  12209. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12210. {
  12211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12212. {
  12213. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12214. }
  12215. else
  12216. {
  12217. tempIndex = connectorIdInt -1;
  12218. }
  12219. for (int index = 0; index < CCS_QUANTITY; index++)
  12220. {
  12221. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12222. {
  12223. //stop Transaction
  12224. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12225. }
  12226. }
  12227. }
  12228. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12229. {
  12230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12231. {
  12232. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12233. }
  12234. else
  12235. {
  12236. tempIndex = connectorIdInt -1;
  12237. }
  12238. for (int index = 0; index < GB_QUANTITY; index++)
  12239. {
  12240. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12241. {
  12242. //stop Transaction
  12243. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12244. }
  12245. }
  12246. }
  12247. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12248. {
  12249. tempIndex = connectorIdInt -1;
  12250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12251. {
  12252. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12253. {
  12254. //stop Transaction
  12255. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12256. }
  12257. }
  12258. }
  12259. else
  12260. {
  12261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12262. {
  12263. tempIndex = 2;
  12264. }
  12265. else
  12266. {
  12267. tempIndex = connectorIdInt-1;
  12268. }
  12269. for (int index = 0; index < AC_QUANTITY; index++)
  12270. {
  12271. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12272. {
  12273. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12274. }
  12275. }
  12276. }
  12277. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12278. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12279. result = TRUE;
  12280. return result;
  12281. }
  12282. end:
  12283. //json_object_put(obj); --- remove temporally
  12284. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12285. return result;
  12286. }
  12287. static char UpdateFirmwarepayloadData[300]={0};
  12288. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12289. {
  12290. mtrace();
  12291. int result = FAIL;
  12292. pthread_t t;
  12293. sendUpdateFirmwareConfirmation(uuid);
  12294. memset(UpdateFirmwarepayloadData, 0, 300);
  12295. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12296. if(!interLock.isUpdateFirmwareGoing)
  12297. {
  12298. interLock.isUpdateFirmwareGoing = 1;
  12299. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12300. sleep(1);
  12301. }
  12302. else
  12303. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12304. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12305. return result;
  12306. }
  12307. void *UpdateFirmwareProcess(void *data)
  12308. {
  12309. pthread_detach(pthread_self());
  12310. mtrace();
  12311. int retriesInt =0, retryIntervalInt=0;
  12312. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12313. int port=0;
  12314. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12315. int isSuccess = 0;
  12316. char ftpbuf[512];
  12317. char temp[100];
  12318. char * pch;
  12319. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12320. json_object *UpdateFirmware;
  12321. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12322. if(!is_error(UpdateFirmware))
  12323. {
  12324. // Required data
  12325. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12326. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12327. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12328. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12329. // Optional data
  12330. if(json_object_object_get(UpdateFirmware, "retries"))
  12331. {
  12332. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12333. }
  12334. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12335. {
  12336. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12337. }
  12338. }
  12339. json_object_put(UpdateFirmware);
  12340. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12341. memset(path, 0, ARRAY_SIZE(path));
  12342. // Wait retrieveData
  12343. if(strlen(retrieveDatestr) > 10)
  12344. {
  12345. do
  12346. {
  12347. sleep(1);
  12348. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12349. }
  12350. // Ready to download
  12351. system("rm -f /mnt/*");
  12352. if(strncmp(locationstr,"http", 4) == 0)
  12353. {
  12354. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12355. sprintf(ftppath,"/%s", path);
  12356. DEBUG_INFO("locationstr: %s\n", locationstr);
  12357. DEBUG_INFO("protocol: %s\n",protocol);
  12358. DEBUG_INFO("host: %s\n",host);
  12359. DEBUG_INFO("path: %s\n",path);
  12360. DEBUG_INFO("ftppath: %s\n",ftppath);
  12361. int ftppathlen=strlen(ftppath);
  12362. int i=1;
  12363. char filenametemp[50];
  12364. while(i < ftppathlen)
  12365. {
  12366. int len=ftppathlen-i;
  12367. if(ftppath[len]== 47) // '/' ascll code: 47
  12368. {
  12369. DEBUG_INFO("compare '/' all right\n");
  12370. break;
  12371. }
  12372. i=i+1;
  12373. }
  12374. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12375. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12376. filenametemp[i+1] = 0;
  12377. do
  12378. {
  12379. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12380. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12381. sleep(1);
  12382. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12383. if(!isSuccess)
  12384. {
  12385. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12386. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12387. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12388. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12389. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12390. }
  12391. else
  12392. {
  12393. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12394. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12395. }
  12396. retriesInt--;
  12397. }while((isSuccess == 0)&&(retriesInt >= 0));
  12398. }
  12399. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12400. {
  12401. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12402. memset(temp, 0, ARRAY_SIZE(temp));
  12403. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12404. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12405. int ftppathlen=strlen(ftpbuf);
  12406. int i=1;
  12407. char filenametemp[50];
  12408. while(i < ftppathlen)
  12409. {
  12410. int len=ftppathlen-i;
  12411. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12412. {
  12413. DEBUG_INFO(" compare '/' all right\n");
  12414. break;
  12415. }
  12416. i=i+1;
  12417. }
  12418. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12419. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12420. filenametemp[i+1] = 0;
  12421. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12422. pch=strchr(temp,'@');
  12423. if(pch==NULL)
  12424. {
  12425. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12426. protocol, host, &port, path);
  12427. strcpy(user,"anonymous");
  12428. strcpy(password,"");
  12429. }
  12430. else
  12431. {
  12432. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12433. protocol, user, password, host, &port, path);
  12434. }
  12435. sscanf(host,"%[^/]%s",host1, path1);
  12436. sprintf(ftppath,"%s", path1);
  12437. //DEBUG_INFO("protocol =%s\n",protocol);
  12438. //DEBUG_INFO("user =%s\n",user);
  12439. //DEBUG_INFO("password =%s\n",password);
  12440. //DEBUG_INFO("host1 =%s\n",host1);
  12441. //DEBUG_INFO("port =%d\n",port);
  12442. //DEBUG_INFO("path1 =%s\n",path1);
  12443. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12444. //ftpFile(host, user, password, port, ftppath, fname);
  12445. //download firmware pthred
  12446. if(port == 0)
  12447. {
  12448. port = 21;
  12449. }
  12450. do
  12451. {
  12452. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12453. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12454. sleep(1);
  12455. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12456. if(!isSuccess)
  12457. {
  12458. //BulldogUtil.sleepMs(interval*1000);
  12459. DEBUG_INFO("Update firmware request and download file fail.\n");
  12460. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12461. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12462. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12463. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12464. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12465. }
  12466. else
  12467. {
  12468. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12469. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12470. }
  12471. retriesInt--;
  12472. }while((!isSuccess)&&(retriesInt >= 0));
  12473. }
  12474. else
  12475. {
  12476. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12477. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12478. sleep(1);
  12479. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12480. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12481. }
  12482. // OCPPPH only, must announce CSU upgrade firmware
  12483. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12484. interLock.isUpdateFirmwareGoing = 0;
  12485. pthread_exit(NULL);
  12486. }
  12487. int handleCertificateSignedRequest(char *uuid, char *payload)
  12488. {
  12489. mtrace();
  12490. int result = PASS;
  12491. json_object *CertificateSigned;
  12492. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12493. CertificateSigned = json_tokener_parse(payload);
  12494. if(!is_error(CertificateSigned))
  12495. {
  12496. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12497. }
  12498. json_object_put(CertificateSigned);
  12499. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12500. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12501. fclose(fp);
  12502. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12503. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12504. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12505. sendCertificateSignedConfirmation(uuid);
  12506. return result;
  12507. }
  12508. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12509. {
  12510. mtrace();
  12511. int result = PASS;
  12512. json_object *DeleteCertificate;
  12513. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12514. DeleteCertificate = json_tokener_parse(payload);
  12515. if(!is_error(DeleteCertificate))
  12516. {
  12517. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12518. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12519. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12520. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12521. }
  12522. json_object_put(DeleteCertificate);
  12523. /*
  12524. * TODO: Delete certificateSigned process
  12525. */
  12526. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12527. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12528. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12529. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12530. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12531. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12532. sendDeleteCertificateConfirmation(uuid);
  12533. return result;
  12534. }
  12535. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12536. {
  12537. mtrace();
  12538. int result = PASS;
  12539. json_object *ExtendedTriggerMessage;
  12540. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12541. ExtendedTriggerMessage = json_tokener_parse(payload);
  12542. if(!is_error(ExtendedTriggerMessage))
  12543. {
  12544. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12545. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12546. {
  12547. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12548. }
  12549. else
  12550. {
  12551. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12552. }
  12553. }
  12554. json_object_put(ExtendedTriggerMessage);
  12555. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12556. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12557. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12558. {
  12559. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12560. }
  12561. else
  12562. {
  12563. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12564. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12565. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12566. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12567. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12568. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12569. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12570. {
  12571. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12572. }
  12573. else
  12574. {
  12575. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12576. }
  12577. }
  12578. sendExtendedTriggerMessageConfirmation(uuid);
  12579. //==========================
  12580. // Trigger message
  12581. //==========================
  12582. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12583. {
  12584. //sendBootNotificationRequest();
  12585. server_sign = FALSE;
  12586. }
  12587. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12588. {
  12589. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12590. }
  12591. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12592. {
  12593. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12594. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12595. {
  12596. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12597. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12598. }
  12599. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12600. }
  12601. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12602. {
  12603. refreshStartTimer(&clientTime.Heartbeat);
  12604. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12605. }
  12606. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12607. {
  12608. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12609. {
  12610. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12611. }
  12612. else
  12613. {
  12614. for(int idx=0;idx< gunTotalNumber;idx++)
  12615. {
  12616. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12617. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12618. }
  12619. }
  12620. }
  12621. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12622. {
  12623. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12624. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12625. {
  12626. 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\" &");
  12627. }
  12628. }
  12629. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12630. {
  12631. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12632. {
  12633. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12634. }
  12635. else
  12636. {
  12637. for(int idx=0;idx< gunTotalNumber;idx++)
  12638. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12639. }
  12640. }
  12641. return result;
  12642. }
  12643. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12644. {
  12645. mtrace();
  12646. int result = PASS;
  12647. json_object *GetInstalledCertificateIds;
  12648. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12649. GetInstalledCertificateIds = json_tokener_parse(payload);
  12650. if(!is_error(GetInstalledCertificateIds))
  12651. {
  12652. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12653. }
  12654. json_object_put(GetInstalledCertificateIds);
  12655. /*
  12656. * TODO: Return installed certificate process
  12657. */
  12658. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12659. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12660. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12661. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12662. sendGetInstalledCertificateIdsConfirmation(uuid);
  12663. return result;
  12664. }
  12665. int handleGetLogRequest(char *uuid, char *payload)
  12666. {
  12667. mtrace();
  12668. int result = PASS;
  12669. json_object *GetLog;
  12670. DEBUG_INFO("handleGetLogRequest...\n");
  12671. GetLog = json_tokener_parse(payload);
  12672. if(!is_error(GetLog))
  12673. {
  12674. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12675. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12676. if(json_object_object_get(GetLog, "retries") != NULL)
  12677. {
  12678. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12679. }
  12680. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12681. {
  12682. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12683. }
  12684. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12685. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12686. {
  12687. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12688. }
  12689. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12690. {
  12691. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12692. }
  12693. }
  12694. json_object_put(GetLog);
  12695. /*
  12696. * TODO: Upload log process
  12697. */
  12698. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12699. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12700. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12701. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12702. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12703. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12704. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12705. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12706. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12707. sendGetLogConfirmation(uuid);
  12708. return result;
  12709. }
  12710. int handleInstallCertificateRequest(char *uuid, char *payload)
  12711. {
  12712. mtrace();
  12713. int result = PASS;
  12714. json_object *InstallCertificate;
  12715. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12716. InstallCertificate = json_tokener_parse(payload);
  12717. if(!is_error(InstallCertificate))
  12718. {
  12719. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12720. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12721. /*
  12722. * TODO: Install certificate process
  12723. */
  12724. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12725. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12726. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12727. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12728. sendInstallCertificateConfirmation(uuid);
  12729. }
  12730. json_object_put(InstallCertificate);
  12731. return result;
  12732. }
  12733. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12734. {
  12735. mtrace();
  12736. int result = PASS;
  12737. json_object *SignedUpdateFirmware;
  12738. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12739. SignedUpdateFirmware = json_tokener_parse(payload);
  12740. if(!is_error(SignedUpdateFirmware))
  12741. {
  12742. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12743. {
  12744. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12745. }
  12746. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12747. {
  12748. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12749. }
  12750. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12751. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12752. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12753. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12754. {
  12755. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12756. }
  12757. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12758. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12759. }
  12760. json_object_put(SignedUpdateFirmware);
  12761. /*
  12762. * TODO: Upgrade firmware process
  12763. */
  12764. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12765. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12766. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12767. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12768. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12769. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12770. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12771. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12772. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12773. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12774. sendInstallCertificateConfirmation(uuid);
  12775. return result;
  12776. }
  12777. int handleUnknownRequest(char *uuid, char *payload)
  12778. {
  12779. mtrace();
  12780. int result = PASS;
  12781. DEBUG_INFO("handleUnknownRequest...\n");
  12782. sendUnknownConfirmation(uuid);
  12783. result = PASS;
  12784. return result;
  12785. }
  12786. //==========================================
  12787. // Handle server response routine
  12788. //==========================================
  12789. void handleAuthorizeResponse(char *payload, int gun_index)
  12790. {
  12791. mtrace();
  12792. char expiryDatestr[30]={0};
  12793. char parentIdTagstr[20]={0};
  12794. char statusstr[20]={0};
  12795. int expiryDateISNULL=FALSE;
  12796. int parentIdTagISNULL=FALSE;
  12797. DEBUG_INFO("handleAuthorizeResponse...\n");
  12798. json_object *Authorize;
  12799. Authorize = json_tokener_parse(payload);
  12800. if(!is_error(Authorize))
  12801. {
  12802. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12803. {
  12804. // Required data
  12805. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12806. // Optional data
  12807. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12808. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12809. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12810. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12811. }
  12812. }
  12813. json_object_put(Authorize);
  12814. if(expiryDateISNULL == FALSE)
  12815. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12816. if(parentIdTagISNULL == FALSE)
  12817. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12818. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12819. //Update idTag information to authorization cache if supproted
  12820. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12821. {
  12822. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12823. }
  12824. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12825. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12826. authorizeRetryTimes = 0;
  12827. }
  12828. void handleBootNotificationResponse(char *payload, int gun_index)
  12829. {
  12830. mtrace();
  12831. char statusStr[12]={0};
  12832. char currentTimeStr[30]={0};
  12833. int intervalInt = 0;
  12834. DEBUG_INFO("handleBootNotificationResponse...\n");
  12835. json_object *BootNotification;
  12836. BootNotification = json_tokener_parse(payload);
  12837. if(!is_error(BootNotification))
  12838. {
  12839. // Required data
  12840. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12841. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12842. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12843. }
  12844. json_object_put(BootNotification);
  12845. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12846. BootNotificationInterval = intervalInt;
  12847. HeartBeatWaitTime = intervalInt;
  12848. //write back to ShmOCPP16DataPH->BootNotification
  12849. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12850. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12851. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12852. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12853. {
  12854. if((intervalInt == 0) || (intervalInt >= 10))
  12855. {
  12856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12857. HeartBeatWaitTime = intervalInt;
  12858. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12859. }
  12860. server_sign = TRUE;
  12861. server_pending =FALSE;
  12862. }
  12863. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12864. {
  12865. server_pending = TRUE;
  12866. }
  12867. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12868. srand(time(NULL));
  12869. refreshStartTimer(&clientTime.Heartbeat);
  12870. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12871. SetOcppConnStatus(TRUE);
  12872. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12873. }
  12874. void handleDataTransferResponse(char *payload, int gun_index)
  12875. {
  12876. json_object *DataTransfer = json_tokener_parse(payload);
  12877. if(!is_error(DataTransfer))
  12878. {
  12879. // Required data
  12880. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12881. // Optional data
  12882. if(json_object_object_get(DataTransfer, "data") != NULL)
  12883. {
  12884. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12885. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12886. if(!is_error(Data))
  12887. {
  12888. if(json_object_object_get(Data, "msgId") != NULL)
  12889. {
  12890. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12891. {
  12892. 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")));
  12893. }
  12894. }
  12895. }
  12896. json_object_put(Data);
  12897. }
  12898. }
  12899. json_object_put(DataTransfer);
  12900. }
  12901. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12902. {
  12903. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12904. //struct json_object *obj;
  12905. // obj = json_tokener_parse(payload);
  12906. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12907. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12908. //No fields are defined.
  12909. }
  12910. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12911. {
  12912. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12913. //struct json_object *obj;
  12914. // obj = json_tokener_parse(payload);
  12915. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12916. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12917. //No fields are defined.
  12918. }
  12919. void handleHeartbeatResponse(char *payload, int gun_index)
  12920. {
  12921. mtrace();
  12922. DEBUG_INFO("handleHeartbeatResponse...\n");
  12923. json_object *Heartbeat;
  12924. Heartbeat = json_tokener_parse(payload);
  12925. if(!is_error(Heartbeat))
  12926. {
  12927. // Required data
  12928. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12929. }
  12930. json_object_put(Heartbeat);
  12931. if(FirstHeartBeat == 0)
  12932. {
  12933. FirstHeartBeat = 1;
  12934. DEBUG_INFO("FirstHeartBeat \n");
  12935. }
  12936. HeartBeatWithNOResponse = 0;
  12937. refreshStartTimer(&clientTime.Heartbeat);
  12938. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12939. }
  12940. void handleMeterValuesResponse(char *payload, int gun_index)
  12941. {
  12942. mtrace();
  12943. DEBUG_INFO("handleMeterValuesResponse...\n");
  12944. isQueueSendable = 1;
  12945. }
  12946. void handleStartTransactionResponse(char *payload, int gun_index)
  12947. {
  12948. mtrace();
  12949. //int transactionIdInt = 0;
  12950. FILE *outfile;
  12951. char data[100]={0};
  12952. DEBUG_INFO("handleStartTransactionResponse...\n");
  12953. json_object *StartTransaction;
  12954. StartTransaction = json_tokener_parse(payload);
  12955. if(!is_error(StartTransaction))
  12956. {
  12957. // Required data
  12958. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12959. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12960. // Optional data
  12961. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12962. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12963. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12964. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12965. }
  12966. json_object_put(StartTransaction);
  12967. isQueueSendable = 1;
  12968. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12969. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12970. //-----------Start : write to the Queue TransactionId file -----------------//
  12971. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12972. {}
  12973. else
  12974. {
  12975. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12976. if(log == NULL)
  12977. {
  12978. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12979. return ;
  12980. }
  12981. else
  12982. {
  12983. fclose(log);
  12984. }
  12985. }
  12986. // open file for writing
  12987. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12988. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12989. {
  12990. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12991. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12992. fputs(data, outfile);
  12993. fclose (outfile);
  12994. }
  12995. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12996. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12997. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12998. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12999. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13000. }
  13001. void handleStatusNotificationResponse(char *payload, int gun_index)
  13002. {
  13003. mtrace();
  13004. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13005. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13006. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13007. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13008. }
  13009. void handleStopTransactionnResponse(char *payload, int gun_index)
  13010. {
  13011. mtrace();
  13012. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13013. json_object *StopTransaction;
  13014. StopTransaction = json_tokener_parse(payload);
  13015. if(!is_error(StopTransaction))
  13016. {
  13017. // Optional data
  13018. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13019. {
  13020. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13021. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13022. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13023. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13024. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13025. }
  13026. }
  13027. json_object_put(StopTransaction);
  13028. isQueueSendable = 1;
  13029. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13030. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13031. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13032. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13033. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13034. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13035. }
  13036. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13037. {
  13038. mtrace();
  13039. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13040. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13041. }
  13042. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13043. {
  13044. mtrace();
  13045. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13046. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13047. }
  13048. void handleSignCertificateResponse(char *payload, int gun_index)
  13049. {
  13050. mtrace();
  13051. DEBUG_INFO("handleSignCertificateResponse...\n");
  13052. json_object *SignCertificate;
  13053. SignCertificate = json_tokener_parse(payload);
  13054. if(!is_error(SignCertificate))
  13055. {
  13056. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13057. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13058. }
  13059. json_object_put(SignCertificate);
  13060. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13061. }
  13062. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13063. {
  13064. mtrace();
  13065. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13066. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13067. }
  13068. //==========================================
  13069. // Handle Error routine
  13070. //==========================================
  13071. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13072. {
  13073. mtrace();
  13074. #ifdef SystemLogMessage
  13075. DEBUG_INFO("errorCode: %s\n", errorCode);
  13076. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13077. DEBUG_INFO("errorDetails: %s\n", payload);
  13078. #endif
  13079. }
  13080. //===============================================
  13081. // Common routine
  13082. //===============================================
  13083. int initialConfigurationTable(void)
  13084. {
  13085. //clock_t start_t, end_t, total_t;
  13086. FILE *fp;
  13087. FILE *outfile;
  13088. char str[512]={0};
  13089. char sstr[256]={0};
  13090. int c = 0;
  13091. char *loc;
  13092. int confVersion = 13;
  13093. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13094. //start_t = clock();
  13095. //printf("Starting of the program, start_t = %ld\n", start_t);
  13096. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13097. // Check configuration file size is correct
  13098. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13099. {
  13100. struct stat st;
  13101. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13102. if(st.st_size < 3100)
  13103. {
  13104. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13105. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13106. }
  13107. }
  13108. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13109. {
  13110. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13111. if(outfile == NULL)
  13112. {
  13113. DEBUG_INFO("Error opening file\n");
  13114. return FALSE;
  13115. }
  13116. /*Core Profile*/
  13117. //AllowOfflineTxForUnknownId
  13118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13122. //AuthorizationCacheEnabled
  13123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13127. //AuthorizeRemoteTxRequests
  13128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13132. //BlinkRepeat
  13133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13137. //ClockAlignedDataInterval
  13138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13142. //ConnectionTimeOut
  13143. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13147. //GetConfigurationMaxKeys
  13148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13150. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13152. // HeartbeatInterval
  13153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13157. // LightIntensity
  13158. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13162. // LocalAuthorizeOffline
  13163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13167. // LocalPreAuthorize
  13168. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13172. // MaxEnergyOnInvalidId
  13173. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13177. // MeterValuesAlignedData
  13178. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13181. 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" );
  13182. else
  13183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13185. // MeterValuesAlignedDataMaxLength
  13186. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13190. else
  13191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13193. // MeterValuesSampledData
  13194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13197. 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" );
  13198. else
  13199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13201. // MeterValuesSampledDataMaxLength
  13202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13206. else
  13207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13209. // MeterValueSampleInterval
  13210. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13214. // MinimumStatusDuration
  13215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13218. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13220. // NumberOfConnectors
  13221. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13224. {
  13225. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13226. }
  13227. else
  13228. {
  13229. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13230. }
  13231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13232. // ResetRetries
  13233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13237. // ConnectorPhaseRotation
  13238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13242. // ConnectorPhaseRotationMaxLength
  13243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13247. // StopTransactionOnEVSideDisconnect
  13248. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13252. // StopTransactionOnInvalidId
  13253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13257. // StopTxnAlignedData
  13258. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13262. // StopTxnAlignedDataMaxLength
  13263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13267. // StopTxnSampledData
  13268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13272. else
  13273. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13275. // StopTxnSampledDataMaxLength
  13276. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13279. {
  13280. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13281. }
  13282. else
  13283. {
  13284. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13285. }
  13286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13287. // SupportedFeatureProfiles
  13288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13292. // SupportedFeatureProfilesMaxLength
  13293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13297. // TransactionMessageAttempts
  13298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13301. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13303. // TransactionMessageRetryInterval
  13304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13307. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13309. // UnlockConnectorOnEVSideDisconnect
  13310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13314. // WebSocketPingInterval
  13315. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13319. // QueueOffLineMeterValues
  13320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13324. // AuthorizationKey
  13325. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13329. // SecurityProfile
  13330. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13332. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13334. // DefaultPrice
  13335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13339. // CustomDisplayCostAndPrice
  13340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13344. // CustomIdleFeeAfterStop
  13345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13349. // SystemUptimeSec
  13350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13354. // FreeVend
  13355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13359. // FreeVendIdtag
  13360. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13364. // OcppServer
  13365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13367. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13369. // MaintainServer
  13370. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13372. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13374. // StatusNotificationPeriodically
  13375. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13379. // StatusNotificationInterval
  13380. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13384. // Configuration Version
  13385. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13389. //* Local Auth List Management Profile*/
  13390. #if 0
  13391. //For OCTT Test Case
  13392. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13395. #endif
  13396. #if 1
  13397. //LocalAuthListEnabled
  13398. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13402. #endif
  13403. //LocalAuthListMaxLength
  13404. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13408. //SendLocalListMaxLength
  13409. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13410. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13413. //ReserveConnectorZeroSupported
  13414. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13415. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13418. //* Smart Charging Profile */
  13419. //ChargeProfileMaxStackLevel
  13420. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13424. // ChargingScheduleAllowedChargingRateUnit
  13425. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13429. // ChargingScheduleMaxPeriods
  13430. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13434. // ConnectorSwitch3to1PhaseSupported
  13435. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13439. // MaxChargingProfilesInstalled
  13440. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13444. fclose(outfile);
  13445. }
  13446. else
  13447. {
  13448. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13449. char keystr[60]={0};
  13450. char readonlystr[10]={0};
  13451. char valuestr[256]={0};
  13452. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13453. if(fp == NULL) {
  13454. DEBUG_INFO("Error opening file");
  13455. return FALSE;
  13456. }
  13457. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13458. {
  13459. //DEBUG_INFO("Get Configuration \n");
  13460. if(strlen(str) > 0)
  13461. {
  13462. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13463. //*************************key*********************************/
  13464. if(strstr(str, "key") != NULL)
  13465. {
  13466. loc = strstr(str, "key");
  13467. c = 0;
  13468. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13469. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13470. {
  13471. sstr[c] = loc[strlen("key")+3+c];
  13472. c++;
  13473. }
  13474. sstr[c] = '\0';
  13475. strcpy(keystr,sstr);
  13476. }
  13477. //*************************readonly*********************************/
  13478. if(strstr(str, "readonly") != NULL)
  13479. {
  13480. loc = strstr(str, "readonly");
  13481. c = 0;
  13482. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13483. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13484. {
  13485. sstr[c] = loc[strlen("readonly")+2+c];
  13486. c++;
  13487. }
  13488. sstr[c] = '\0';
  13489. strcpy(readonlystr,sstr);
  13490. }
  13491. //*************************value*********************************/
  13492. if(strstr(str, "value") != NULL)
  13493. {
  13494. loc = strstr(str, "value");
  13495. c = 0;
  13496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13497. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13498. {
  13499. sstr[c] = loc[strlen("value")+3+c];
  13500. c++;
  13501. }
  13502. sstr[c] = '\0';
  13503. strcpy(valuestr,sstr);
  13504. }
  13505. // DEBUG_INFO("keystr=%s\n",keystr);
  13506. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13507. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13508. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13509. {
  13510. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13511. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13512. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13513. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13514. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13515. }
  13516. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13517. {
  13518. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13521. }
  13522. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13523. {
  13524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13526. }
  13527. if(strcmp(keystr, "BlinkRepeat") == 0)
  13528. {
  13529. //Charger.BlinkRepeat = Integer.parseInt(value);
  13530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13532. }
  13533. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13534. {
  13535. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13537. }
  13538. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13539. {
  13540. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13542. }
  13543. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13544. {
  13545. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13547. }
  13548. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13549. {
  13550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13552. HeartBeatWaitTime = atoi(valuestr);
  13553. }
  13554. if(strcmp(keystr, "LightIntensity") == 0)
  13555. {
  13556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13558. }
  13559. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13560. {
  13561. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13563. }
  13564. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13565. {
  13566. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13567. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13568. }
  13569. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13570. {
  13571. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13572. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13573. }
  13574. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13575. {
  13576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13578. }
  13579. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13580. {
  13581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13582. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13583. }
  13584. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13585. {
  13586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13587. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13588. }
  13589. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13590. {
  13591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13593. }
  13594. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13595. {
  13596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13597. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13598. }
  13599. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13600. {
  13601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13603. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13604. }
  13605. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13606. {
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13609. }
  13610. if(strcmp(keystr, "ResetRetries") == 0)
  13611. {
  13612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13613. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13614. }
  13615. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13616. {
  13617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13619. }
  13620. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13621. {
  13622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13624. }
  13625. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13626. {
  13627. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13629. }
  13630. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13631. {
  13632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13633. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13634. }
  13635. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13636. {
  13637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13639. }
  13640. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13641. {
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13643. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13644. }
  13645. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13646. {
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13649. }
  13650. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13651. {
  13652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13654. }
  13655. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13656. {
  13657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13659. }
  13660. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13661. {
  13662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13663. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13664. }
  13665. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13666. {
  13667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13668. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13669. TransactionMessageAttemptsValue = atoi(valuestr);
  13670. }
  13671. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13672. {
  13673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13675. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13676. }
  13677. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13678. {
  13679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13681. }
  13682. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13683. {
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13686. }
  13687. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13688. {
  13689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13691. }
  13692. if(strcmp(keystr, "AuthorizationKey") == 0)
  13693. {
  13694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13695. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13697. }
  13698. if(strcmp(keystr, "SecurityProfile") == 0)
  13699. {
  13700. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13701. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13703. }
  13704. if(strcmp(keystr, "DefaultPrice") == 0)
  13705. {
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13707. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13708. }
  13709. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13710. {
  13711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13712. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13713. }
  13714. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13715. {
  13716. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13717. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13718. }
  13719. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13720. {
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13722. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13723. }
  13724. if(strcmp(keystr, "FreeVend") == 0)
  13725. {
  13726. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13727. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13728. }
  13729. if(strcmp(keystr, "FreeVendIdtag") == 0)
  13730. {
  13731. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13732. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  13733. }
  13734. if(strcmp(keystr, "OcppServer") == 0)
  13735. {
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13737. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13738. }
  13739. if(strcmp(keystr, "MaintainServer") == 0)
  13740. {
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13742. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13743. }
  13744. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13745. {
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13748. }
  13749. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13750. {
  13751. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13753. }
  13754. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13755. {
  13756. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13758. }
  13759. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13760. {
  13761. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13763. }
  13764. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13765. {
  13766. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13768. }
  13769. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13770. {
  13771. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13772. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13773. }
  13774. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13775. {
  13776. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13777. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13778. }
  13779. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13780. {
  13781. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13782. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13783. }
  13784. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13785. {
  13786. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13788. }
  13789. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13790. {
  13791. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13793. }
  13794. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13795. {
  13796. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13797. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13798. }
  13799. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13800. {
  13801. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13803. }
  13804. }
  13805. }
  13806. fclose(fp);
  13807. }
  13808. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13809. {
  13810. return PASS;
  13811. }
  13812. else
  13813. {
  13814. return FAIL;
  13815. }
  13816. }
  13817. void StoreConfigurationTable(void)
  13818. {
  13819. FILE *outfile;
  13820. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13821. if(outfile == NULL)
  13822. {
  13823. DEBUG_INFO("Error opening file");
  13824. return ;
  13825. }
  13826. /*Core Profile*/
  13827. //AllowOfflineTxForUnknownId
  13828. /*
  13829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13830. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13833. */
  13834. //DEBUG_INFO("data=%s\n",data);
  13835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13836. //AuthorizationCacheEnabled
  13837. /*
  13838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13841. */
  13842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13843. //AuthorizeRemoteTxRequests
  13844. /*
  13845. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13848. */
  13849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13850. //BlinkRepeat
  13851. /*
  13852. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13855. */
  13856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13857. //ClockAlignedDataInterval
  13858. /*
  13859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13862. */
  13863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13864. //ConnectionTimeOut
  13865. /*
  13866. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13869. */
  13870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13871. //GetConfigurationMaxKeys
  13872. /*
  13873. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13876. */
  13877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13878. // HeartbeatInterval
  13879. /*
  13880. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13883. */
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13885. // LightIntensity
  13886. /*
  13887. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13890. */
  13891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13892. // LocalAuthorizeOffline
  13893. /*
  13894. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13897. */
  13898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13899. // LocalPreAuthorize
  13900. /*
  13901. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13904. */
  13905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13906. // MaxEnergyOnInvalidId
  13907. /*
  13908. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13911. */
  13912. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13914. // MeterValuesAlignedData
  13915. /*
  13916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13919. */
  13920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13921. // MeterValuesAlignedDataMaxLength
  13922. /*
  13923. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13926. */
  13927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13928. // MeterValuesSampledData
  13929. /*
  13930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13933. */
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13935. // MeterValuesSampledDataMaxLength
  13936. /*
  13937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13940. */
  13941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13942. // MeterValueSampleInterval
  13943. /*
  13944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13947. */
  13948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13949. // MinimumStatusDuration
  13950. /*
  13951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13954. */
  13955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13956. // NumberOfConnectors
  13957. /*
  13958. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13960. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13961. {
  13962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13963. }
  13964. else
  13965. {
  13966. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13967. }
  13968. */
  13969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13970. // ResetRetries
  13971. /*
  13972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13975. */
  13976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13977. // ConnectorPhaseRotation
  13978. /*
  13979. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13982. */
  13983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13984. // ConnectorPhaseRotationMaxLength
  13985. /*
  13986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13989. */
  13990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13991. // StopTransactionOnEVSideDisconnect
  13992. /*
  13993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13996. */
  13997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13998. // StopTransactionOnInvalidId
  13999. /*
  14000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14003. */
  14004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14005. // StopTxnAlignedData
  14006. /*
  14007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14010. */
  14011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14012. // StopTxnAlignedDataMaxLength
  14013. /*
  14014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14017. */
  14018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14019. // StopTxnSampledData
  14020. /*
  14021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14024. */
  14025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14026. // StopTxnSampledDataMaxLength
  14027. /*
  14028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14031. */
  14032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14033. // SupportedFeatureProfiles
  14034. /*
  14035. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14038. */
  14039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14040. // SupportedFeatureProfilesMaxLength
  14041. /*
  14042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14045. */
  14046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14047. // TransactionMessageAttempts
  14048. /*
  14049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14052. */
  14053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14054. // TransactionMessageRetryInterval
  14055. /*
  14056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14059. */
  14060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14061. // UnlockConnectorOnEVSideDisconnect
  14062. /*
  14063. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14066. */
  14067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14068. // WebSocketPingInterval
  14069. /*
  14070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14073. */
  14074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14075. // QueueOffLineMeterValues
  14076. /*
  14077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14080. */
  14081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14082. // AuthorizationKey
  14083. /*
  14084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14087. */
  14088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14089. // SecurityProfile
  14090. /*
  14091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14094. */
  14095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14096. // DefaultPrice
  14097. /*
  14098. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14101. */
  14102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14103. // CustomDisplayCostAndPrice
  14104. /*
  14105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14108. */
  14109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14110. // CustomIdleFeeAfterStop
  14111. /*
  14112. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14115. */
  14116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14117. // SystemUptimeSec
  14118. /*
  14119. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14122. */
  14123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14124. // FreeVend
  14125. /*
  14126. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14129. */
  14130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14131. // FreeVendIdtag
  14132. /*
  14133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14136. */
  14137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14138. // OcppServer
  14139. /*
  14140. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14143. */
  14144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14145. // MaintainServer
  14146. /*
  14147. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14150. */
  14151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14152. // StatusNotificationPeriodically
  14153. /*
  14154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14157. */
  14158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14159. // StatusNotificationInterval
  14160. /*
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14164. */
  14165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14166. // ConfigurationVersion
  14167. /*
  14168. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14171. */
  14172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14173. //* Local Auth List Management Profile*/
  14174. //LocalAuthListEnabled
  14175. /*
  14176. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14179. */
  14180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14181. //LocalAuthListMaxLength
  14182. /*
  14183. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14186. */
  14187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14188. //SendLocalListMaxLength
  14189. /*
  14190. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14193. */
  14194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14195. //ReserveConnectorZeroSupported
  14196. /*
  14197. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14200. */
  14201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14202. //* Smart Charging Profile */
  14203. //ChargeProfileMaxStackLevel
  14204. /*
  14205. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14208. */
  14209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14210. // ChargingScheduleAllowedChargingRateUnit
  14211. /*
  14212. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14215. */
  14216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14217. // ChargingScheduleMaxPeriods
  14218. /*
  14219. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14222. */
  14223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14224. // ConnectorSwitch3to1PhaseSupported
  14225. /*
  14226. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14229. */
  14230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14231. // MaxChargingProfilesInstalled
  14232. /*
  14233. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14236. */
  14237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14238. fclose(outfile);
  14239. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14240. }
  14241. void getKeyValue(char *keyReq)
  14242. {
  14243. int isEmpty = FALSE;
  14244. int isKnowKey = FALSE;
  14245. DEBUG_INFO("keyReq = %s\n", keyReq);
  14246. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14247. isEmpty = TRUE;
  14248. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14249. {
  14250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14252. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14253. {
  14254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14255. }
  14256. else
  14257. {
  14258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14259. }
  14260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14261. isKnowKey = TRUE;
  14262. }
  14263. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14264. {
  14265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14267. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14268. {
  14269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14270. }
  14271. else
  14272. {
  14273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14274. }
  14275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14276. isKnowKey = TRUE;
  14277. }
  14278. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14279. {
  14280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14282. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14283. {
  14284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14285. }
  14286. else
  14287. {
  14288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14289. }
  14290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14291. isKnowKey = TRUE;
  14292. }
  14293. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14294. {
  14295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14297. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14298. {
  14299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14300. }
  14301. else
  14302. {
  14303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14304. }
  14305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14306. isKnowKey = TRUE;
  14307. }
  14308. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14309. {
  14310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14312. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14313. {
  14314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14315. }
  14316. else
  14317. {
  14318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14319. }
  14320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14321. isKnowKey = TRUE;
  14322. }
  14323. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14324. {
  14325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14327. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14328. {
  14329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14330. }
  14331. else
  14332. {
  14333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14334. }
  14335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14336. isKnowKey = TRUE;
  14337. }
  14338. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14339. {
  14340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14343. {
  14344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14345. }
  14346. else
  14347. {
  14348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14349. }
  14350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14351. isKnowKey = TRUE;
  14352. }
  14353. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14354. {
  14355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14357. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14358. {
  14359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14360. }
  14361. else
  14362. {
  14363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14364. }
  14365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14366. isKnowKey = TRUE;
  14367. }
  14368. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14369. {
  14370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14372. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14373. {
  14374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14375. }
  14376. else
  14377. {
  14378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14379. }
  14380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14381. isKnowKey = TRUE;
  14382. }
  14383. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14384. {
  14385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14387. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14388. {
  14389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14390. }
  14391. else
  14392. {
  14393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14394. }
  14395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14396. isKnowKey = TRUE;
  14397. }
  14398. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14399. {
  14400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14402. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14403. {
  14404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14405. }
  14406. else
  14407. {
  14408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14409. }
  14410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14411. isKnowKey = TRUE;
  14412. }
  14413. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14414. {
  14415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14418. {
  14419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14420. }
  14421. else
  14422. {
  14423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14424. }
  14425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14426. isKnowKey = TRUE;
  14427. }
  14428. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14429. {
  14430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14433. {
  14434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14435. }
  14436. else
  14437. {
  14438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14439. }
  14440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14441. isKnowKey = TRUE;
  14442. }
  14443. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14444. {
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14447. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14448. {
  14449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14450. }
  14451. else
  14452. {
  14453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14454. }
  14455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14456. isKnowKey = TRUE;
  14457. }
  14458. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14459. {
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14462. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14463. {
  14464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14465. }
  14466. else
  14467. {
  14468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14469. }
  14470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14471. isKnowKey = TRUE;
  14472. }
  14473. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14474. {
  14475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14477. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14478. {
  14479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14480. }
  14481. else
  14482. {
  14483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14484. }
  14485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14486. isKnowKey = TRUE;
  14487. }
  14488. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14489. {
  14490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14492. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14493. {
  14494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14495. }
  14496. else
  14497. {
  14498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14499. }
  14500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14501. isKnowKey = TRUE;
  14502. }
  14503. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14504. {
  14505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14507. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14508. {
  14509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14510. }
  14511. else
  14512. {
  14513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14514. }
  14515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14516. isKnowKey = TRUE;
  14517. }
  14518. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14519. {
  14520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14522. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14523. {
  14524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14525. }
  14526. else
  14527. {
  14528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14529. }
  14530. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14532. isKnowKey = TRUE;
  14533. }
  14534. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14535. {
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14538. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14539. {
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14541. }
  14542. else
  14543. {
  14544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14545. }
  14546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14547. isKnowKey = TRUE;
  14548. }
  14549. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14550. {
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14553. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14554. {
  14555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14556. }
  14557. else
  14558. {
  14559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14560. }
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14562. isKnowKey = TRUE;
  14563. }
  14564. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14565. {
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14568. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14569. {
  14570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14571. }
  14572. else
  14573. {
  14574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14575. }
  14576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14577. isKnowKey = TRUE;
  14578. }
  14579. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14580. {
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14583. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14584. {
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14586. }
  14587. else
  14588. {
  14589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14590. }
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14592. isKnowKey = TRUE;
  14593. }
  14594. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14595. {
  14596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14598. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14599. {
  14600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14601. }
  14602. else
  14603. {
  14604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14605. }
  14606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14607. isKnowKey = TRUE;
  14608. }
  14609. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14610. {
  14611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14613. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14614. {
  14615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14616. }
  14617. else
  14618. {
  14619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14620. }
  14621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14622. isKnowKey = TRUE;
  14623. }
  14624. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14625. {
  14626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14628. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14629. {
  14630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14631. }
  14632. else
  14633. {
  14634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14635. }
  14636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14637. isKnowKey = TRUE;
  14638. }
  14639. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14640. {
  14641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14643. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14644. {
  14645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14646. }
  14647. else
  14648. {
  14649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14650. }
  14651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14652. isKnowKey = TRUE;
  14653. }
  14654. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14655. {
  14656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14658. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14659. {
  14660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14661. }
  14662. else
  14663. {
  14664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14665. }
  14666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14667. isKnowKey = TRUE;
  14668. }
  14669. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14670. {
  14671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14673. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14674. {
  14675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14676. }
  14677. else
  14678. {
  14679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14680. }
  14681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14682. isKnowKey = TRUE;
  14683. }
  14684. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14685. {
  14686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14688. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14689. {
  14690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14691. }
  14692. else
  14693. {
  14694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14695. }
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14697. isKnowKey = TRUE;
  14698. }
  14699. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14700. {
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14704. {
  14705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14706. }
  14707. else
  14708. {
  14709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14710. }
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14712. isKnowKey = TRUE;
  14713. }
  14714. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14715. {
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14718. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14719. {
  14720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14721. }
  14722. else
  14723. {
  14724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14725. }
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14727. isKnowKey = TRUE;
  14728. }
  14729. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14730. {
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14733. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14734. {
  14735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14736. }
  14737. else
  14738. {
  14739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14740. }
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14742. isKnowKey = TRUE;
  14743. }
  14744. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14745. {
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14748. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14749. {
  14750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14751. }
  14752. else
  14753. {
  14754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14755. }
  14756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14757. isKnowKey = TRUE;
  14758. }
  14759. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14760. {
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14764. {
  14765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14766. }
  14767. else
  14768. {
  14769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14770. }
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14772. isKnowKey = TRUE;
  14773. }
  14774. /*
  14775. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14776. {
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14779. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14780. {
  14781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14782. }
  14783. else
  14784. {
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14786. }
  14787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14788. isKnowKey = TRUE;
  14789. }*/
  14790. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14791. {
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14794. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14795. {
  14796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14797. }
  14798. else
  14799. {
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14801. }
  14802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14803. isKnowKey = TRUE;
  14804. }
  14805. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14806. {
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14809. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14810. {
  14811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14812. }
  14813. else
  14814. {
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14816. }
  14817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14818. isKnowKey = TRUE;
  14819. }
  14820. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14821. {
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14824. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14825. {
  14826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14827. }
  14828. else
  14829. {
  14830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14831. }
  14832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14833. isKnowKey = TRUE;
  14834. }
  14835. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14836. {
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14839. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14840. {
  14841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14842. }
  14843. else
  14844. {
  14845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14846. }
  14847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14848. isKnowKey = TRUE;
  14849. }
  14850. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14851. {
  14852. struct sysinfo s_info;
  14853. int error = sysinfo(&s_info);
  14854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14856. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14857. {
  14858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14859. }
  14860. else
  14861. {
  14862. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14863. }
  14864. if(error != 0)
  14865. {
  14866. DEBUG_WARN("System uptime get error: %d\n", error);
  14867. }
  14868. else
  14869. {
  14870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14871. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14872. }
  14873. isKnowKey = TRUE;
  14874. }
  14875. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14876. {
  14877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14879. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14880. {
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14882. }
  14883. else
  14884. {
  14885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14886. }
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14888. isKnowKey = TRUE;
  14889. }
  14890. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  14891. {
  14892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  14894. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  14895. {
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  14897. }
  14898. else
  14899. {
  14900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  14901. }
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14903. isKnowKey = TRUE;
  14904. }
  14905. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14906. {
  14907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14909. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14910. {
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14912. }
  14913. else
  14914. {
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14916. }
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14918. isKnowKey = TRUE;
  14919. }
  14920. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14921. {
  14922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14924. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14925. {
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14927. }
  14928. else
  14929. {
  14930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14931. }
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14933. isKnowKey = TRUE;
  14934. }
  14935. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14936. {
  14937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  14939. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  14940. {
  14941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  14942. }
  14943. else
  14944. {
  14945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  14946. }
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  14948. isKnowKey = TRUE;
  14949. }
  14950. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  14951. {
  14952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  14954. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  14955. {
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  14957. }
  14958. else
  14959. {
  14960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  14961. }
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  14963. isKnowKey = TRUE;
  14964. }
  14965. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14966. {
  14967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14969. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14970. {
  14971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14972. }
  14973. else
  14974. {
  14975. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14976. }
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14978. isKnowKey = TRUE;
  14979. }
  14980. #if 1
  14981. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14982. {
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14985. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14988. }
  14989. else
  14990. {
  14991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14992. }
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14994. isKnowKey = TRUE;
  14995. }
  14996. #endif
  14997. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14998. {
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15001. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15002. {
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15004. }
  15005. else
  15006. {
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15008. }
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15010. isKnowKey = TRUE;
  15011. }
  15012. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15013. {
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15016. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15017. {
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15019. }
  15020. else
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15023. }
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15025. isKnowKey = TRUE;
  15026. }
  15027. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15028. {
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15031. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15032. {
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15034. }
  15035. else
  15036. {
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15038. }
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15040. isKnowKey = TRUE;
  15041. }
  15042. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15043. {
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15046. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15049. }
  15050. else
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15053. }
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15055. isKnowKey = TRUE;
  15056. }
  15057. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15058. {
  15059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15061. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15062. {
  15063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15064. }
  15065. else
  15066. {
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15068. }
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15070. isKnowKey = TRUE;
  15071. }
  15072. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15073. {
  15074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15076. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15077. {
  15078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15079. }
  15080. else
  15081. {
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15083. }
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15085. isKnowKey = TRUE;
  15086. }
  15087. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15088. {
  15089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15091. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15092. {
  15093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15094. }
  15095. else
  15096. {
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15098. }
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15100. isKnowKey = TRUE;
  15101. }
  15102. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15103. {
  15104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15106. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15107. {
  15108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15109. }
  15110. else
  15111. {
  15112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15113. }
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15115. isKnowKey = TRUE;
  15116. }
  15117. //=========================================================
  15118. if(!isEmpty && !isKnowKey)
  15119. {
  15120. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15121. strcpy(unknownkey[UnknownKeynum], keyReq);
  15122. UnknownKeynum = UnknownKeynum + 1;
  15123. }
  15124. }
  15125. void processUnkownKey(void)
  15126. {
  15127. DEBUG_INFO("processUnkownKey...\n");
  15128. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15129. for(int index=0; index < UnknownKeynum; index++)
  15130. {
  15131. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15132. {
  15133. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15134. }
  15135. }
  15136. }
  15137. int setKeyValue(char *key, char *value)
  15138. {
  15139. int isSuccess = NotSupported;
  15140. int check_ascii=0;
  15141. char str[501]={0};
  15142. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15143. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15144. {
  15145. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15146. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15147. {
  15148. strcpy(str, (const char*)value);
  15149. for(int i = 0; str[i]; i++){
  15150. str[i] = tolower(str[i]);
  15151. }
  15152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15153. isSuccess = ConfigurationStatus_Accepted;
  15154. }
  15155. else
  15156. {
  15157. isSuccess = ConfigurationStatus_Rejected;
  15158. }
  15159. }
  15160. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15161. {
  15162. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15163. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15164. {
  15165. strcpy(str, (const char*)value);
  15166. for(int i = 0; str[i]; i++){
  15167. str[i] = tolower(str[i]);
  15168. }
  15169. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15170. isSuccess = ConfigurationStatus_Accepted;
  15171. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15172. }
  15173. else
  15174. {
  15175. isSuccess = ConfigurationStatus_Rejected;
  15176. }
  15177. }
  15178. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15179. {
  15180. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15181. {
  15182. strcpy(str, (const char*)value);
  15183. for(int i = 0; str[i]; i++)
  15184. {
  15185. str[i] = tolower(str[i]);
  15186. }
  15187. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15189. isSuccess = ConfigurationStatus_Accepted;
  15190. }
  15191. else
  15192. {
  15193. isSuccess = ConfigurationStatus_Rejected;
  15194. }
  15195. }
  15196. if(strcmp(key, "BlinkRepeat") == 0)
  15197. {
  15198. //Charger.BlinkRepeat = Integer.parseInt(value);
  15199. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15200. {
  15201. check_ascii = value[0];
  15202. if( (check_ascii < 48) || (check_ascii > 57) )
  15203. {
  15204. isSuccess = ConfigurationStatus_Rejected;
  15205. }
  15206. else
  15207. {
  15208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15209. isSuccess = ConfigurationStatus_Accepted;
  15210. }
  15211. }
  15212. else
  15213. {
  15214. isSuccess = ConfigurationStatus_Rejected;
  15215. }
  15216. }
  15217. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15218. {
  15219. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15220. {
  15221. check_ascii = value[0];
  15222. if( (check_ascii < 48) || (check_ascii > 57) )
  15223. {
  15224. isSuccess = ConfigurationStatus_Rejected;
  15225. }
  15226. else
  15227. {
  15228. if((atoi(value) == 0) || (atoi(value) >= 5))
  15229. {
  15230. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15231. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15232. isSuccess = ConfigurationStatus_Accepted;
  15233. }
  15234. else
  15235. isSuccess = ConfigurationStatus_Rejected;
  15236. }
  15237. }
  15238. else
  15239. {
  15240. isSuccess = ConfigurationStatus_Rejected;
  15241. }
  15242. }
  15243. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15244. {
  15245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15246. {
  15247. check_ascii = value[0];
  15248. if( (check_ascii < 48) || (check_ascii > 57) )
  15249. {
  15250. isSuccess = ConfigurationStatus_Rejected;
  15251. }
  15252. else
  15253. {
  15254. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15255. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15256. isSuccess = ConfigurationStatus_Accepted;
  15257. }
  15258. }
  15259. else
  15260. {
  15261. isSuccess = ConfigurationStatus_Rejected;
  15262. }
  15263. }
  15264. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15265. {
  15266. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15267. {
  15268. check_ascii = value[0];
  15269. if( (check_ascii < 48) || (check_ascii > 57) )
  15270. {
  15271. isSuccess = ConfigurationStatus_Rejected;
  15272. }
  15273. else
  15274. {
  15275. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15277. isSuccess = ConfigurationStatus_Accepted;
  15278. }
  15279. }
  15280. else
  15281. {
  15282. isSuccess = ConfigurationStatus_Rejected;
  15283. }
  15284. }
  15285. if(strcmp(key, "HeartbeatInterval") == 0)
  15286. {
  15287. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15288. {
  15289. check_ascii = value[0];
  15290. if( (check_ascii < 48) || (check_ascii > 57) )
  15291. {
  15292. isSuccess = ConfigurationStatus_Rejected;
  15293. }
  15294. else
  15295. {
  15296. if((atoi(value) == 0) || (atoi(value) >= 10))
  15297. {
  15298. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15299. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15300. HeartBeatWaitTime = atoi(value);
  15301. isSuccess = ConfigurationStatus_Accepted;
  15302. }
  15303. else
  15304. {
  15305. isSuccess = ConfigurationStatus_Rejected;
  15306. }
  15307. }
  15308. }
  15309. else
  15310. {
  15311. isSuccess = ConfigurationStatus_Rejected;
  15312. }
  15313. }
  15314. if(strcmp(key, "LightIntensity") == 0)
  15315. {
  15316. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15317. {
  15318. check_ascii = value[0];
  15319. if( (check_ascii < 48) || (check_ascii > 57) )
  15320. {
  15321. isSuccess = ConfigurationStatus_Rejected;
  15322. }
  15323. else
  15324. {
  15325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15326. isSuccess = ConfigurationStatus_Accepted;
  15327. }
  15328. }
  15329. else
  15330. {
  15331. isSuccess = ConfigurationStatus_Rejected;
  15332. }
  15333. }
  15334. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15335. {
  15336. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15337. {
  15338. strcpy(str, (const char*)value);
  15339. for(int i = 0; str[i]; i++)
  15340. {
  15341. str[i] = tolower(str[i]);
  15342. }
  15343. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15344. isSuccess = ConfigurationStatus_Accepted;
  15345. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15346. }
  15347. else
  15348. {
  15349. isSuccess = ConfigurationStatus_Rejected;
  15350. }
  15351. }
  15352. if(strcmp(key, "LocalPreAuthorize") == 0)
  15353. {
  15354. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15355. {
  15356. strcpy(str, (const char*)value);
  15357. for(int i = 0; str[i]; i++)
  15358. {
  15359. str[i] = tolower(str[i]);
  15360. }
  15361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15362. isSuccess = ConfigurationStatus_Accepted;
  15363. }
  15364. else
  15365. {
  15366. isSuccess = ConfigurationStatus_Rejected;
  15367. }
  15368. }
  15369. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15370. {
  15371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15372. {
  15373. check_ascii = value[0];
  15374. if( (check_ascii < 48) || (check_ascii > 57) )
  15375. {
  15376. isSuccess = ConfigurationStatus_Rejected;
  15377. }
  15378. else
  15379. {
  15380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15381. isSuccess = ConfigurationStatus_Accepted;
  15382. }
  15383. }
  15384. else
  15385. {
  15386. isSuccess = ConfigurationStatus_Rejected;
  15387. }
  15388. }
  15389. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15390. {
  15391. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15392. {
  15393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15394. isSuccess = ConfigurationStatus_Accepted;
  15395. }
  15396. else
  15397. {
  15398. isSuccess = ConfigurationStatus_Rejected;
  15399. }
  15400. }
  15401. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15402. {
  15403. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15404. {
  15405. check_ascii = value[0];
  15406. if( (check_ascii < 48) || (check_ascii > 57) )
  15407. {
  15408. isSuccess = ConfigurationStatus_Rejected;
  15409. }
  15410. else
  15411. {
  15412. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15413. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15414. isSuccess = ConfigurationStatus_Accepted;
  15415. }
  15416. }
  15417. else
  15418. {
  15419. isSuccess = ConfigurationStatus_Rejected;
  15420. }
  15421. }
  15422. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15423. {
  15424. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15425. {
  15426. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15427. isSuccess = ConfigurationStatus_Accepted;
  15428. }
  15429. else
  15430. {
  15431. isSuccess = ConfigurationStatus_Rejected;
  15432. }
  15433. }
  15434. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15435. {
  15436. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15437. {
  15438. check_ascii = value[0];
  15439. if( (check_ascii < 48) || (check_ascii > 57) )
  15440. {
  15441. isSuccess = ConfigurationStatus_Rejected;
  15442. }
  15443. else
  15444. {
  15445. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15446. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15447. isSuccess = ConfigurationStatus_Accepted;
  15448. }
  15449. }
  15450. else
  15451. {
  15452. isSuccess = ConfigurationStatus_Rejected;
  15453. }
  15454. }
  15455. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15456. {
  15457. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15458. {
  15459. check_ascii = value[0];
  15460. if( (check_ascii < 48) || (check_ascii > 57) )
  15461. {
  15462. isSuccess = ConfigurationStatus_Rejected;
  15463. }
  15464. else
  15465. {
  15466. if((atoi(value) == 0) || (atoi(value) >= 3))
  15467. {
  15468. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15470. isSuccess = ConfigurationStatus_Accepted;
  15471. }
  15472. else
  15473. {
  15474. isSuccess = ConfigurationStatus_Rejected;
  15475. }
  15476. }
  15477. }
  15478. else
  15479. {
  15480. isSuccess = ConfigurationStatus_Rejected;
  15481. }
  15482. }
  15483. if(strcmp(key, "MinimumStatusDuration") == 0)
  15484. {
  15485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15486. {
  15487. check_ascii = value[0];
  15488. if( (check_ascii < 48) || (check_ascii > 57) )
  15489. {
  15490. isSuccess = ConfigurationStatus_Rejected;
  15491. }
  15492. else
  15493. {
  15494. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15495. {
  15496. isSuccess = ConfigurationStatus_Rejected;
  15497. }
  15498. else
  15499. {
  15500. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15501. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15502. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15503. isSuccess = ConfigurationStatus_Accepted;
  15504. }
  15505. }
  15506. }
  15507. else
  15508. {
  15509. isSuccess = ConfigurationStatus_Rejected;
  15510. }
  15511. }
  15512. if(strcmp(key, "NumberOfConnectors") == 0)
  15513. {
  15514. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15515. {
  15516. check_ascii = value[0];
  15517. if( (check_ascii < 48) || (check_ascii > 57) )
  15518. {
  15519. isSuccess = ConfigurationStatus_Rejected;
  15520. }
  15521. else
  15522. {
  15523. //Charger.ResetRetries = Integer.parseInt(value);
  15524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15525. isSuccess = ConfigurationStatus_Accepted;
  15526. }
  15527. }
  15528. else
  15529. {
  15530. isSuccess = ConfigurationStatus_Rejected;
  15531. }
  15532. }
  15533. if(strcmp(key, "ResetRetries") == 0)
  15534. {
  15535. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15536. {
  15537. check_ascii = value[0];
  15538. if( (check_ascii < 48) || (check_ascii > 57) )
  15539. {
  15540. isSuccess = ConfigurationStatus_Rejected;
  15541. }
  15542. else
  15543. {
  15544. //Charger.ResetRetries = Integer.parseInt(value);
  15545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15546. isSuccess = ConfigurationStatus_Accepted;
  15547. }
  15548. }
  15549. else
  15550. {
  15551. isSuccess = ConfigurationStatus_Rejected;
  15552. }
  15553. }
  15554. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15555. {
  15556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15557. {
  15558. strcpy(str, (const char*)value);
  15559. for(int i = 0; str[i]; i++)
  15560. {
  15561. str[i] = tolower(str[i]);
  15562. }
  15563. if(strcmp(str, "notapplicable")== 0)
  15564. {
  15565. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15566. isSuccess = ConfigurationStatus_Accepted;
  15567. }
  15568. else if(strcmp(str, "unknown")== 0)
  15569. {
  15570. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15571. isSuccess = ConfigurationStatus_Accepted;
  15572. }
  15573. else if(strcmp(str, "rst")== 0)
  15574. {
  15575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15576. isSuccess = ConfigurationStatus_Accepted;
  15577. }
  15578. else if(strcmp(str, "rts")== 0)
  15579. {
  15580. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15581. isSuccess = ConfigurationStatus_Accepted;
  15582. }
  15583. else if(strcmp(str, "srt")== 0)
  15584. {
  15585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15586. isSuccess = ConfigurationStatus_Accepted;
  15587. }
  15588. else if(strcmp(str, "str")== 0)
  15589. {
  15590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15591. isSuccess = ConfigurationStatus_Accepted;
  15592. }
  15593. else if(strcmp(str, "trs")== 0)
  15594. {
  15595. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15596. isSuccess = ConfigurationStatus_Accepted;
  15597. }
  15598. else if(strcmp(str, "tsr")== 0)
  15599. {
  15600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15601. isSuccess = ConfigurationStatus_Accepted;
  15602. }
  15603. else
  15604. {
  15605. isSuccess = ConfigurationStatus_Rejected;
  15606. }
  15607. }
  15608. else
  15609. {
  15610. isSuccess = ConfigurationStatus_Rejected;
  15611. }
  15612. }
  15613. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15614. {
  15615. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15616. {
  15617. check_ascii = value[0];
  15618. if( (check_ascii < 48) || (check_ascii > 57) )
  15619. {
  15620. isSuccess = ConfigurationStatus_Rejected;
  15621. }
  15622. else
  15623. {
  15624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15625. isSuccess = ConfigurationStatus_Accepted;
  15626. }
  15627. }
  15628. else
  15629. {
  15630. isSuccess = ConfigurationStatus_Rejected;
  15631. }
  15632. }
  15633. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15634. {
  15635. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15636. {
  15637. strcpy(str, (const char*)value);
  15638. for(int i = 0; str[i]; i++)
  15639. {
  15640. str[i] = tolower(str[i]);
  15641. }
  15642. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15643. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15644. isSuccess = ConfigurationStatus_Accepted;
  15645. }
  15646. else
  15647. {
  15648. isSuccess = ConfigurationStatus_Rejected;
  15649. }
  15650. }
  15651. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15652. {
  15653. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15654. {
  15655. strcpy(str, (const char*)value);
  15656. for(int i = 0; str[i]; i++)
  15657. {
  15658. str[i] = tolower(str[i]);
  15659. }
  15660. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15662. isSuccess = ConfigurationStatus_Accepted;
  15663. }
  15664. else
  15665. {
  15666. isSuccess = ConfigurationStatus_Rejected;
  15667. }
  15668. }
  15669. if(strcmp(key, "StopTxnAlignedData") == 0)
  15670. {
  15671. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15672. {
  15673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15674. isSuccess = ConfigurationStatus_Accepted;
  15675. }
  15676. else
  15677. {
  15678. isSuccess = ConfigurationStatus_Rejected;
  15679. }
  15680. }
  15681. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15682. {
  15683. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15684. {
  15685. check_ascii = value[0];
  15686. if( (check_ascii < 48) || (check_ascii > 57) )
  15687. {
  15688. isSuccess = ConfigurationStatus_Rejected;
  15689. }
  15690. else
  15691. {
  15692. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15693. isSuccess = ConfigurationStatus_Accepted;
  15694. }
  15695. }
  15696. else
  15697. {
  15698. isSuccess = ConfigurationStatus_Rejected;
  15699. }
  15700. }
  15701. if(strcmp(key, "StopTxnSampledData") == 0)
  15702. {
  15703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15704. {
  15705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15706. isSuccess = ConfigurationStatus_Accepted;
  15707. }
  15708. else
  15709. {
  15710. isSuccess = ConfigurationStatus_Rejected;
  15711. }
  15712. }
  15713. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15714. {
  15715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15716. {
  15717. check_ascii = value[0];
  15718. if( (check_ascii < 48) || (check_ascii > 57) )
  15719. {
  15720. isSuccess = ConfigurationStatus_Rejected;
  15721. }
  15722. else
  15723. {
  15724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15725. isSuccess = ConfigurationStatus_Accepted;
  15726. }
  15727. }
  15728. else
  15729. {
  15730. isSuccess = ConfigurationStatus_Rejected;
  15731. }
  15732. }
  15733. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15734. {
  15735. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15736. {
  15737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15738. isSuccess = ConfigurationStatus_Accepted;
  15739. }
  15740. else
  15741. {
  15742. isSuccess = ConfigurationStatus_Rejected;
  15743. }
  15744. }
  15745. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15746. {
  15747. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15748. {
  15749. check_ascii = value[0];
  15750. if( (check_ascii < 48) || (check_ascii > 57) )
  15751. {
  15752. isSuccess = ConfigurationStatus_Rejected;
  15753. }
  15754. else
  15755. {
  15756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15757. isSuccess = ConfigurationStatus_Accepted;
  15758. }
  15759. }
  15760. else
  15761. {
  15762. isSuccess = ConfigurationStatus_Rejected;
  15763. }
  15764. }
  15765. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15766. {
  15767. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15768. {
  15769. check_ascii = value[0];
  15770. if( (check_ascii < 48) || (check_ascii > 57) )
  15771. {
  15772. isSuccess = ConfigurationStatus_Rejected;
  15773. }
  15774. else
  15775. {
  15776. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15777. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15778. TransactionMessageAttemptsValue = atoi(value);
  15779. isSuccess = ConfigurationStatus_Accepted;
  15780. }
  15781. }
  15782. else
  15783. {
  15784. isSuccess = ConfigurationStatus_Rejected;
  15785. }
  15786. }
  15787. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15788. {
  15789. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15790. {
  15791. check_ascii = value[0];
  15792. if( (check_ascii < 48) || (check_ascii > 57) )
  15793. {
  15794. isSuccess = ConfigurationStatus_Rejected;
  15795. }
  15796. else
  15797. {
  15798. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15799. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15800. TransactionMessageRetryIntervalValue = atoi(value);
  15801. isSuccess = ConfigurationStatus_Accepted;
  15802. }
  15803. }
  15804. else
  15805. {
  15806. isSuccess = ConfigurationStatus_Rejected;
  15807. }
  15808. }
  15809. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15810. {
  15811. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15812. {
  15813. strcpy(str, (const char*)value);
  15814. for(int i = 0; str[i]; i++)
  15815. {
  15816. str[i] = tolower(str[i]);
  15817. }
  15818. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15820. isSuccess = ConfigurationStatus_Accepted;
  15821. }
  15822. else
  15823. {
  15824. isSuccess = ConfigurationStatus_Rejected;
  15825. }
  15826. }
  15827. if(strcmp(key, "WebSocketPingInterval") == 0)
  15828. {
  15829. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15830. {
  15831. check_ascii = value[0];
  15832. if( (check_ascii < 48) || (check_ascii > 57) )
  15833. {
  15834. isSuccess = ConfigurationStatus_Rejected;
  15835. }
  15836. else
  15837. {
  15838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15839. isSuccess = ConfigurationStatus_Accepted;
  15840. if((atoi(value) == 0) || (atoi(value) >= 10))
  15841. {
  15842. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15843. isSuccess = ConfigurationStatus_Accepted;
  15844. }
  15845. else
  15846. isSuccess = ConfigurationStatus_Rejected;
  15847. }
  15848. }
  15849. else
  15850. {
  15851. isSuccess = ConfigurationStatus_Rejected;
  15852. }
  15853. }
  15854. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15855. {
  15856. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15857. {
  15858. strcpy(str, (const char*)value);
  15859. for(int i = 0; str[i]; i++)
  15860. {
  15861. str[i] = tolower(str[i]);
  15862. }
  15863. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15864. isSuccess = ConfigurationStatus_Accepted;
  15865. }
  15866. else
  15867. {
  15868. isSuccess = ConfigurationStatus_Rejected;
  15869. }
  15870. }
  15871. if(strcmp(key, "AuthorizationKey") == 0)
  15872. {
  15873. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15874. {
  15875. strcpy(str, (const char*)value);
  15876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15877. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15878. isSuccess = ConfigurationStatus_Accepted;
  15879. }
  15880. else
  15881. {
  15882. isSuccess = ConfigurationStatus_Rejected;
  15883. }
  15884. }
  15885. if(strcmp(key, "SecurityProfile") == 0)
  15886. {
  15887. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15888. {
  15889. check_ascii = value[0];
  15890. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15891. {
  15892. isSuccess = ConfigurationStatus_Rejected;
  15893. }
  15894. else if(check_ascii == 0x33)
  15895. {
  15896. isSuccess = NotSupported;
  15897. }
  15898. else
  15899. {
  15900. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15901. {
  15902. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15903. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15904. isSuccess = ConfigurationStatus_Accepted;
  15905. }
  15906. else
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. else
  15911. {
  15912. isSuccess = ConfigurationStatus_Rejected;
  15913. }
  15914. }
  15915. if(strcmp(key, "DefaultPrice") == 0)
  15916. {
  15917. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15918. {
  15919. strcpy(str, (const char*)value);
  15920. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15921. isSuccess = ConfigurationStatus_Accepted;
  15922. }
  15923. else
  15924. {
  15925. isSuccess = ConfigurationStatus_Rejected;
  15926. }
  15927. }
  15928. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15929. {
  15930. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15931. {
  15932. strcpy(str, (const char*)value);
  15933. for(int i = 0; str[i]; i++)
  15934. {
  15935. str[i] = tolower(str[i]);
  15936. }
  15937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15938. isSuccess = ConfigurationStatus_Accepted;
  15939. }
  15940. else
  15941. {
  15942. isSuccess = ConfigurationStatus_Rejected;
  15943. }
  15944. }
  15945. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15946. {
  15947. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15948. {
  15949. strcpy(str, (const char*)value);
  15950. for(int i = 0; str[i]; i++)
  15951. {
  15952. str[i] = tolower(str[i]);
  15953. }
  15954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15955. isSuccess = ConfigurationStatus_Accepted;
  15956. }
  15957. else
  15958. {
  15959. isSuccess = ConfigurationStatus_Rejected;
  15960. }
  15961. }
  15962. if(strcmp(key, "SystemUptimeSec") == 0)
  15963. {
  15964. isSuccess = NotSupported;
  15965. }
  15966. if(strcmp(key, "FreeVend") == 0)
  15967. {
  15968. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15969. {
  15970. strcpy(str, (const char*)value);
  15971. for(int i = 0; str[i]; i++)
  15972. {
  15973. str[i] = tolower(str[i]);
  15974. }
  15975. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15976. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15977. isSuccess = ConfigurationStatus_Accepted;
  15978. }
  15979. else
  15980. {
  15981. isSuccess = ConfigurationStatus_Rejected;
  15982. }
  15983. }
  15984. if(strcmp(key, "FreeVendIdtag") == 0)
  15985. {
  15986. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15987. {
  15988. strcpy(str, (const char*)value);
  15989. if(strlen(str) <= 20)
  15990. {
  15991. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  15992. isSuccess = ConfigurationStatus_Accepted;
  15993. }
  15994. else
  15995. {
  15996. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  15997. isSuccess = ConfigurationStatus_Rejected;
  15998. }
  15999. }
  16000. else
  16001. {
  16002. isSuccess = ConfigurationStatus_Rejected;
  16003. }
  16004. }
  16005. if(strcmp(key, "OcppServer") == 0)
  16006. {
  16007. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16008. {
  16009. strcpy(str, (const char*)value);
  16010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16011. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16012. isSuccess = ConfigurationStatus_Accepted;
  16013. }
  16014. else
  16015. {
  16016. isSuccess = ConfigurationStatus_Rejected;
  16017. }
  16018. }
  16019. if(strcmp(key, "MaintainServer") == 0)
  16020. {
  16021. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16022. {
  16023. strcpy(str, (const char*)value);
  16024. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16025. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16026. isSuccess = ConfigurationStatus_Accepted;
  16027. }
  16028. else
  16029. {
  16030. isSuccess = ConfigurationStatus_Rejected;
  16031. }
  16032. }
  16033. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16034. {
  16035. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16036. {
  16037. strcpy(str, (const char*)value);
  16038. for(int i = 0; str[i]; i++)
  16039. {
  16040. str[i] = tolower(str[i]);
  16041. }
  16042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16043. isSuccess = ConfigurationStatus_Accepted;
  16044. }
  16045. else
  16046. {
  16047. isSuccess = ConfigurationStatus_Rejected;
  16048. }
  16049. }
  16050. if(strcmp(key, "StatusNotificationInterval") == 0)
  16051. {
  16052. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16053. {
  16054. check_ascii = value[0];
  16055. if( (check_ascii < 48) || (check_ascii > 57) )
  16056. {
  16057. isSuccess = ConfigurationStatus_Rejected;
  16058. }
  16059. else
  16060. {
  16061. if((atoi(value) == 0) || (atoi(value) >= 10))
  16062. {
  16063. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16064. isSuccess = ConfigurationStatus_Accepted;
  16065. }
  16066. else
  16067. isSuccess = ConfigurationStatus_Rejected;
  16068. }
  16069. }
  16070. else
  16071. {
  16072. isSuccess = ConfigurationStatus_Rejected;
  16073. }
  16074. }
  16075. #if 0
  16076. //For OCPP Test Case
  16077. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16078. {
  16079. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].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.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16087. isSuccess = ConfigurationStatus_Accepted;
  16088. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16089. }
  16090. else
  16091. {
  16092. isSuccess = ConfigurationStatus_Rejected;
  16093. }
  16094. }
  16095. #endif
  16096. #if 1
  16097. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16098. {
  16099. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16100. {
  16101. strcpy(str, (const char*)value);
  16102. for(int i = 0; str[i]; i++)
  16103. {
  16104. str[i] = tolower(str[i]);
  16105. }
  16106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16107. isSuccess = ConfigurationStatus_Accepted;
  16108. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16109. }
  16110. else
  16111. {
  16112. isSuccess = ConfigurationStatus_Rejected;
  16113. }
  16114. }
  16115. #endif
  16116. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16117. {
  16118. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16119. {
  16120. check_ascii = value[0];
  16121. if( (check_ascii < 48) || (check_ascii > 57) )
  16122. {
  16123. isSuccess = ConfigurationStatus_Rejected;
  16124. }
  16125. else
  16126. {
  16127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16128. isSuccess = ConfigurationStatus_Accepted;
  16129. }
  16130. }
  16131. else
  16132. {
  16133. isSuccess = ConfigurationStatus_Rejected;
  16134. }
  16135. }
  16136. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16137. {
  16138. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16139. {
  16140. check_ascii = value[0];
  16141. if( (check_ascii < 48) || (check_ascii > 57) )
  16142. {
  16143. isSuccess = ConfigurationStatus_Rejected;
  16144. }
  16145. else
  16146. {
  16147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16148. isSuccess = ConfigurationStatus_Accepted;
  16149. }
  16150. }
  16151. else
  16152. {
  16153. isSuccess = ConfigurationStatus_Rejected;
  16154. }
  16155. }
  16156. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16157. {
  16158. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16159. {
  16160. strcpy(str, (const char*)value);
  16161. for(int i = 0; str[i]; i++)
  16162. {
  16163. str[i] = tolower(str[i]);
  16164. }
  16165. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16166. isSuccess = ConfigurationStatus_Accepted;
  16167. }
  16168. else
  16169. {
  16170. isSuccess = ConfigurationStatus_Rejected;
  16171. }
  16172. }
  16173. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16174. {
  16175. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16176. {
  16177. check_ascii = value[0];
  16178. if( (check_ascii < 48) || (check_ascii > 57) )
  16179. {
  16180. isSuccess = ConfigurationStatus_Rejected;
  16181. }
  16182. else
  16183. {
  16184. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16185. isSuccess = ConfigurationStatus_Accepted;
  16186. }
  16187. }
  16188. else
  16189. {
  16190. isSuccess = ConfigurationStatus_Rejected;
  16191. }
  16192. }
  16193. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16194. {
  16195. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16196. {
  16197. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16198. isSuccess = ConfigurationStatus_Accepted;
  16199. }
  16200. else
  16201. {
  16202. isSuccess = ConfigurationStatus_Rejected;
  16203. }
  16204. }
  16205. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16206. {
  16207. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16208. {
  16209. check_ascii = value[0];
  16210. if( (check_ascii < 48) || (check_ascii > 57) )
  16211. {
  16212. isSuccess = ConfigurationStatus_Rejected;
  16213. }
  16214. else
  16215. {
  16216. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16217. isSuccess = ConfigurationStatus_Accepted;
  16218. }
  16219. }
  16220. else
  16221. {
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. }
  16225. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16226. {
  16227. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16228. {
  16229. strcpy(str, (const char*)value);
  16230. for(int i = 0; str[i]; i++)
  16231. {
  16232. str[i] = tolower(str[i]);
  16233. }
  16234. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16235. isSuccess = ConfigurationStatus_Accepted;
  16236. }
  16237. else
  16238. {
  16239. isSuccess = ConfigurationStatus_Rejected;
  16240. }
  16241. }
  16242. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16243. {
  16244. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16245. {
  16246. check_ascii = value[0];
  16247. if( (check_ascii < 48) || (check_ascii > 57) )
  16248. {
  16249. isSuccess = ConfigurationStatus_Rejected;
  16250. }
  16251. else
  16252. {
  16253. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16254. isSuccess = ConfigurationStatus_Accepted;
  16255. }
  16256. }
  16257. else
  16258. {
  16259. isSuccess = ConfigurationStatus_Rejected;
  16260. }
  16261. }
  16262. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16263. return isSuccess;
  16264. }
  16265. int TransactionMessageAttemptsGet(void)
  16266. {
  16267. return TransactionMessageAttemptsValue;
  16268. }
  16269. int FirstHeartBeatResponse(void)
  16270. {
  16271. return FirstHeartBeat;
  16272. }
  16273. int TransactionMessageRetryIntervalGet(void)
  16274. {
  16275. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16276. }
  16277. int ReadHttpStatus(int sock)
  16278. {
  16279. //char c;
  16280. char buff[1024]="",*ptr=buff+1;
  16281. int bytes_received, status;
  16282. DEBUG_INFO("Begin Response ..\n");
  16283. while((bytes_received = recv(sock, ptr, 1, 0))){
  16284. if(bytes_received==-1){
  16285. perror("ReadHttpStatus");
  16286. exit(1);
  16287. }
  16288. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16289. ptr++;
  16290. }
  16291. *ptr=0;
  16292. ptr=buff+1;
  16293. sscanf(ptr,"%*s %d ", &status);
  16294. DEBUG_INFO("%s\n",ptr);
  16295. DEBUG_INFO("status=%d\n",status);
  16296. DEBUG_INFO("End Response ..\n");
  16297. return (bytes_received>0)?status:0;
  16298. }
  16299. //the only filed that it parsed is 'Content-Length'
  16300. int ParseHeader(int sock)
  16301. {
  16302. //char c;
  16303. char buff[1024]="",*ptr=buff+4;
  16304. int bytes_received;
  16305. DEBUG_INFO("Begin HEADER ..\n");
  16306. while((bytes_received = recv(sock, ptr, 1, 0))){
  16307. if(bytes_received==-1){
  16308. perror("Parse Header");
  16309. exit(1);
  16310. }
  16311. if(
  16312. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16313. (ptr[-1]=='\r') && (*ptr=='\n' )
  16314. ) break;
  16315. ptr++;
  16316. }
  16317. *ptr=0;
  16318. ptr=buff+4;
  16319. //printf("%s",ptr);
  16320. if(bytes_received){
  16321. ptr=strstr(ptr,"Content-Length:");
  16322. if(ptr){
  16323. sscanf(ptr,"%*s %d",&bytes_received);
  16324. }else
  16325. bytes_received=-1; //unknown size
  16326. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16327. }
  16328. DEBUG_INFO("End HEADER ..\n");
  16329. return bytes_received ;
  16330. }
  16331. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16332. {
  16333. int result = TRUE;
  16334. char rmFileCmd[100]={0};
  16335. char FilePath[100]={0};
  16336. char ftpbuf[200];
  16337. int systemresult;
  16338. sprintf(FilePath,"/mnt/%s",filename);
  16339. system("ping 8.8.8.8 &");
  16340. if((access(FilePath,F_OK))!=-1)
  16341. {
  16342. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16343. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16344. system(rmFileCmd);
  16345. }
  16346. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16347. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16348. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16349. systemresult = system(ftpbuf);
  16350. if(systemresult != 0)
  16351. {
  16352. DEBUG_INFO("http DownLoad error!\n");
  16353. result = FALSE;
  16354. }
  16355. system("pkill ping");
  16356. return result;
  16357. }
  16358. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16359. {
  16360. int result = TRUE;
  16361. char rmFileCmd[100]={0};
  16362. char FilePath[100]={0};
  16363. char ftpbuf[200];
  16364. int systemresult;
  16365. sprintf(FilePath,"/mnt/%s",filename);
  16366. system("ping 8.8.8.8 &");
  16367. if((access(FilePath,F_OK))!=-1)
  16368. {
  16369. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16370. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16371. system(rmFileCmd);
  16372. }
  16373. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16374. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16375. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16376. systemresult = system(ftpbuf);
  16377. if(systemresult != 0)
  16378. {
  16379. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16380. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16381. systemresult = system(ftpbuf);
  16382. if(systemresult != 0)
  16383. {
  16384. DEBUG_WARN("wget error!\n");
  16385. result = FALSE;
  16386. }
  16387. }
  16388. system("pkill ping");
  16389. return result;
  16390. }
  16391. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16392. {
  16393. char rmFileCmd[100]={0};
  16394. char FilePath[100]={0};
  16395. char buf[512];
  16396. int systemresult = 0;
  16397. //DEBUG_INFO("filename=%s\n",filename);
  16398. //DEBUG_INFO("url=%s\n",url);
  16399. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16400. if((access(FilePath,F_OK))!=-1)
  16401. {
  16402. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16403. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16404. system(rmFileCmd);
  16405. }
  16406. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16407. if(fp == NULL)
  16408. {
  16409. DEBUG_INFO("log is NULL\n");
  16410. return FALSE;
  16411. }
  16412. else
  16413. {
  16414. fprintf(fp, "%s\n", url);
  16415. fprintf(fp, "%s\n", filename);
  16416. fclose(fp);
  16417. }
  16418. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16419. if(phpFP == NULL)
  16420. {
  16421. DEBUG_INFO("PHP upload fail.\n");
  16422. return FALSE;
  16423. }
  16424. else
  16425. {
  16426. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16427. {
  16428. if(strstr(buf, "result") != NULL)
  16429. {
  16430. sscanf(buf, "result: %d", &systemresult);
  16431. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16432. }
  16433. }
  16434. pclose(phpFP);
  16435. }
  16436. if(systemresult != 1)
  16437. {
  16438. DEBUG_INFO("HTTP upload error!\n");
  16439. return FALSE;
  16440. }
  16441. return TRUE;
  16442. }
  16443. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16444. {
  16445. int result = FALSE;
  16446. char ftpbuf[200];
  16447. int systemresult;
  16448. /*
  16449. // Domaind name transfer to IP address
  16450. struct hostent* server;
  16451. char *IPbuffer;
  16452. server = gethostbyname(location);
  16453. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16454. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16455. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16456. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16457. systemresult = system(ftpbuf);
  16458. if(systemresult != 0)
  16459. {
  16460. DEBUG_INFO("ftpput error!\n");
  16461. }
  16462. else
  16463. {
  16464. result = TRUE;
  16465. DEBUG_INFO("ftpput OK!\n");
  16466. }
  16467. return result;
  16468. }
  16469. int GetOcppServerURL()
  16470. {
  16471. int result = FALSE;
  16472. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16473. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16474. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16475. struct yuarel url;
  16476. char urlStr[512];
  16477. // OCPPPH only
  16478. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16479. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16480. {
  16481. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16482. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16483. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16484. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16485. if(yuarel_parse(&url, urlStr) != -1)
  16486. {
  16487. sprintf(OcppProtocol, "%s", url.scheme);
  16488. sprintf(OcppHost, "%s", url.host);
  16489. if(url.path == NULL)
  16490. OcppTempPath[0] = '\0';
  16491. else
  16492. sprintf(OcppTempPath, "%s", url.path);
  16493. if(url.port == 0)
  16494. {
  16495. if(strcmp(OcppProtocol, "wss") == 0)
  16496. OcppPort = 443;
  16497. else
  16498. OcppPort = 80;
  16499. }
  16500. else
  16501. OcppPort = url.port;
  16502. result = TRUE;
  16503. }
  16504. }
  16505. else
  16506. {
  16507. strcpy(OcppHost,"");
  16508. }
  16509. return result;
  16510. }
  16511. int GetOcppPath()
  16512. {
  16513. int result = FALSE;
  16514. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16515. {
  16516. if(OcppTempPath == NULL)
  16517. {
  16518. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16519. }
  16520. else
  16521. {
  16522. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16523. }
  16524. result = TRUE;
  16525. goto End;
  16526. }
  16527. else
  16528. {
  16529. strcpy(OcppPath,"");
  16530. }
  16531. End:
  16532. return result;
  16533. }
  16534. int GetOcppPort()
  16535. {
  16536. return OcppPort;
  16537. }
  16538. int GetOcppConnStatus(void)
  16539. {
  16540. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16541. }
  16542. void SetOcppConnStatus(uint8_t status)
  16543. {
  16544. ShmOCPP16DataPH->OcppConnStatus = status;
  16545. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16546. }
  16547. int GetHeartBeatWithNOResponse(void)
  16548. {
  16549. return HeartBeatWithNOResponse;
  16550. }
  16551. void SetHeartBeatWithNOResponse(void)
  16552. {
  16553. HeartBeatWithNOResponse = 0;
  16554. }
  16555. void GetStartTransactionIdTag(int gun_index)
  16556. {
  16557. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16558. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16559. }
  16560. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16561. {
  16562. char ch;
  16563. FILE *fptr1;
  16564. int temptransactionId;
  16565. char str[100]={0};
  16566. temptransactionId = 0;
  16567. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16568. {
  16569. DEBUG_INFO("IdTag is empty.\n");
  16570. return temptransactionId;
  16571. }
  16572. /*------ Read the file ----------------*/
  16573. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16574. if (!fptr1)
  16575. {
  16576. DEBUG_INFO("QueueTransactionId file open error.\n");
  16577. //printf(" File not found or unable to open the input file!!\n");
  16578. return temptransactionId;
  16579. }
  16580. ch=fgetc(fptr1);
  16581. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16582. rewind(fptr1);
  16583. if(ch!=EOF)
  16584. {
  16585. // printf("%c",ch);
  16586. while (fgets(str, 100, fptr1) != NULL)
  16587. {
  16588. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16589. if(str[0]=='\0')
  16590. {
  16591. break;
  16592. }
  16593. char *revbuf[8] = {0}; // Variable store string split
  16594. int num = 0;// Quantity after string split
  16595. DEBUG_INFO("Transaction queue data= %s\n", str);
  16596. splitstring(str,",",revbuf,&num); // String split
  16597. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16598. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16599. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16600. DEBUG_INFO("------------------------------\n");
  16601. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16602. {
  16603. if(isStopTransaction)
  16604. {
  16605. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16606. {
  16607. temptransactionId = atoi(revbuf[2]);
  16608. //break;
  16609. }
  16610. }
  16611. else
  16612. {
  16613. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16614. {
  16615. temptransactionId = atoi(revbuf[2]);
  16616. //break;
  16617. }
  16618. }
  16619. }
  16620. }
  16621. }
  16622. else
  16623. DEBUG_INFO("EOF\n");
  16624. fclose(fptr1);
  16625. /*------- End of reading ---------------*/
  16626. return temptransactionId;
  16627. }
  16628. void SetTransactionIdZero(int transactionId)
  16629. {
  16630. char ch;
  16631. FILE *fptr1, *fptr2;
  16632. int temptransactionId = 0;
  16633. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16634. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16635. if (!fptr1)
  16636. {
  16637. //printf(" File not found or unable to open the input file!!\n");
  16638. return ;
  16639. }
  16640. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16641. if (!fptr2)
  16642. {
  16643. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16644. fclose(fptr1);
  16645. return ;
  16646. }
  16647. ch=fgetc(fptr1);
  16648. rewind(fptr1);
  16649. if(ch!=EOF)
  16650. {
  16651. // copy all contents to the temporary file except the specific line
  16652. while (fgets(str, 100, fptr1) != NULL)
  16653. {
  16654. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16655. if(str[0]=='\0')
  16656. {
  16657. break;
  16658. }
  16659. char *revbuf[8] = {0};
  16660. int num = 0;
  16661. strcpy(strtemp, str);
  16662. splitstring(str,",",revbuf,&num);
  16663. if(revbuf[2][0] != '\0')
  16664. {
  16665. temptransactionId = atoi(revbuf[2]);
  16666. if(transactionId != temptransactionId)
  16667. {
  16668. fprintf(fptr2, "%s\n", strtemp);
  16669. }
  16670. }
  16671. }
  16672. }
  16673. fclose(fptr1);
  16674. fclose(fptr2);
  16675. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16676. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16677. /*------ Read the file ----------------*/
  16678. }
  16679. int InternetDisconnect(void)
  16680. {
  16681. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16682. }
  16683. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16684. void storeTempStopTransaction(int gun_index)
  16685. {
  16686. char guid[37]={0};
  16687. int tempIndex = 0;
  16688. char TempStopTransaction[256];
  16689. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16690. DEBUG_INFO("storeTempStopTransaction...\n");
  16691. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16692. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16693. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16694. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16695. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16696. {
  16697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16698. {
  16699. tempIndex = ((gun_index==2) ? 1: 0);
  16700. }
  16701. else
  16702. {
  16703. tempIndex = gun_index;
  16704. }
  16705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16706. {
  16707. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16708. {
  16709. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16710. }
  16711. }// END OF CHAdeMO_QUANTITY
  16712. }
  16713. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16714. {
  16715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16716. {
  16717. tempIndex = ((gun_index==2) ? 1: 0);
  16718. }
  16719. else
  16720. {
  16721. tempIndex = gun_index;
  16722. }
  16723. for (int index = 0; index < CCS_QUANTITY; index++)
  16724. {
  16725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16726. {
  16727. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16728. }
  16729. }// END OF CCS_QUANTITY
  16730. }
  16731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16732. {
  16733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16734. {
  16735. tempIndex = ((gun_index==2) ? 1: 0);
  16736. }
  16737. else
  16738. {
  16739. tempIndex = gun_index;
  16740. }
  16741. for (int index = 0; index < GB_QUANTITY; index++)
  16742. {
  16743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16744. {
  16745. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16746. }
  16747. }// END OF GB_QUANTITY
  16748. }
  16749. else if(gunType[gun_index] == GUN_TYPE_DO)
  16750. {
  16751. tempIndex = gun_index;
  16752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16753. {
  16754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16755. {
  16756. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16757. }
  16758. }
  16759. }
  16760. else
  16761. {
  16762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16763. {
  16764. tempIndex = 2;
  16765. }
  16766. else
  16767. {
  16768. tempIndex = gun_index;
  16769. }
  16770. for (int index = 0; index < AC_QUANTITY; index++)
  16771. {
  16772. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16773. {
  16774. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16775. }
  16776. }// END OF AC_QUANTITY
  16777. }
  16778. //Stop Transaction Time
  16779. struct timeval tmnow;
  16780. struct tm *tm;
  16781. char buf[28];//, usec_buf[6];
  16782. gettimeofday(&tmnow, NULL);
  16783. time_t t;
  16784. t = time(NULL);
  16785. /*UTC time and date*/
  16786. tm = gmtime(&t);
  16787. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16788. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16789. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16790. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16791. random_uuid(guid);
  16792. /***********************************transactionData******************************************************/
  16793. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16794. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16795. //=================================
  16796. //1. Transaction_Begin
  16797. //=================================
  16798. //============================== Energy.Active.Import.Interval ===========================================
  16799. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16800. {
  16801. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  16805. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16806. 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))
  16807. {
  16808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16809. }
  16810. else
  16811. {
  16812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16813. }
  16814. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16815. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16816. }
  16817. //=================================
  16818. //2. Transaction_End
  16819. //=================================
  16820. //2.1====================================== Current.Import L1 ==============================================
  16821. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16822. {
  16823. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16824. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16825. {
  16826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16827. {
  16828. tempIndex = ((gun_index==2) ? 1: 0);
  16829. }
  16830. else
  16831. {
  16832. tempIndex = gun_index;
  16833. }
  16834. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16835. {
  16836. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16837. {
  16838. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16839. }
  16840. }// End of for CHAdeMO_QUANTITY
  16841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16842. }
  16843. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16844. {
  16845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16846. {
  16847. tempIndex = ((gun_index==2) ? 1: 0);
  16848. }
  16849. else
  16850. {
  16851. tempIndex = gun_index;
  16852. }
  16853. for (int index = 0; index < CCS_QUANTITY; index++)
  16854. {
  16855. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16856. {
  16857. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16858. }
  16859. }// End of for CCS_QUANTITY
  16860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16861. }
  16862. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16863. {
  16864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16865. {
  16866. tempIndex = ((gun_index==2) ? 1: 0);
  16867. }
  16868. else
  16869. {
  16870. tempIndex = gun_index;
  16871. }
  16872. for (int index = 0; index < GB_QUANTITY; index++)
  16873. {
  16874. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16875. {
  16876. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16877. }
  16878. }// End of for GB_QUANTITY
  16879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16880. }
  16881. else if(gunType[gun_index] == GUN_TYPE_DO)
  16882. {
  16883. tempIndex = gun_index;
  16884. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16885. {
  16886. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16887. {
  16888. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16889. }
  16890. }
  16891. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16892. }
  16893. else
  16894. {
  16895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16896. {
  16897. tempIndex = 2;
  16898. }
  16899. else
  16900. {
  16901. tempIndex = gun_index;
  16902. }
  16903. for (int index = 0; index < AC_QUANTITY; index++)
  16904. {
  16905. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16906. {
  16907. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16908. }
  16909. }// End of for AC_QUANTITY
  16910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16911. }
  16912. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16913. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16914. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16915. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16916. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16918. }
  16919. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16920. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16921. {
  16922. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16923. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16924. {
  16925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16926. {
  16927. tempIndex = ((gun_index==2) ? 1: 0);
  16928. }
  16929. else
  16930. {
  16931. tempIndex = gun_index;
  16932. }
  16933. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16934. {
  16935. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16936. {
  16937. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16938. }
  16939. }// END OF CHAdeMO_QUANTITY
  16940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16941. }
  16942. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16943. {
  16944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16945. {
  16946. tempIndex = ((gun_index==2) ? 1: 0);
  16947. }
  16948. else
  16949. {
  16950. tempIndex = gun_index;
  16951. }
  16952. for (int index = 0; index < CCS_QUANTITY; index++)
  16953. {
  16954. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16955. {
  16956. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16957. }
  16958. }// END OF CCS_QUANTITY
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16960. }
  16961. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16962. {
  16963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16964. {
  16965. tempIndex = ((gun_index==2) ? 1: 0);
  16966. }
  16967. else
  16968. {
  16969. tempIndex = gun_index;
  16970. }
  16971. for (int index = 0; index < GB_QUANTITY; index++)
  16972. {
  16973. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16974. {
  16975. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16976. }
  16977. }// END OF GB_QUANTITY
  16978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16979. }
  16980. else if(gunType[gun_index] == GUN_TYPE_DO)
  16981. {
  16982. tempIndex = gun_index;
  16983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16984. {
  16985. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16986. {
  16987. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16988. }
  16989. }
  16990. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16991. }
  16992. else
  16993. {
  16994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16995. {
  16996. tempIndex = 2;
  16997. }
  16998. else
  16999. {
  17000. tempIndex = gun_index;
  17001. }
  17002. for (int index = 0; index < AC_QUANTITY; index++)
  17003. {
  17004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17005. {
  17006. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17007. }
  17008. }// END OF AC_QUANTITY
  17009. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17010. }
  17011. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17012. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17014. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17017. }
  17018. //2.3====================================== Power.Active.Import =========================================
  17019. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17020. {
  17021. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17022. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17023. {
  17024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17025. {
  17026. tempIndex = ((gun_index==2) ? 1: 0);
  17027. }
  17028. else
  17029. {
  17030. tempIndex = gun_index;
  17031. }
  17032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17033. {
  17034. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17035. {
  17036. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17037. }
  17038. } // End for CHAdeMO_QUANTITY
  17039. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17040. }
  17041. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17042. {
  17043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17044. {
  17045. tempIndex = ((gun_index==2) ? 1: 0);
  17046. }
  17047. else
  17048. {
  17049. tempIndex = gun_index;
  17050. }
  17051. for (int index = 0; index < CCS_QUANTITY; index++)
  17052. {
  17053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17054. {
  17055. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17056. }
  17057. } // END for CCS_QUANTITY
  17058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17059. }
  17060. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17061. {
  17062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17063. {
  17064. tempIndex = ((gun_index==2) ? 1: 0);
  17065. }
  17066. else
  17067. {
  17068. tempIndex = gun_index;
  17069. }
  17070. for (int index = 0; index < GB_QUANTITY; index++)
  17071. {
  17072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17073. {
  17074. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17075. }
  17076. }// END for GB_QUANTITY
  17077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17078. }
  17079. else if(gunType[gun_index] == GUN_TYPE_DO)
  17080. {
  17081. tempIndex = gun_index;
  17082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17083. {
  17084. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17085. {
  17086. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17087. }
  17088. }
  17089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17090. }
  17091. else
  17092. {
  17093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17094. {
  17095. tempIndex = 2;
  17096. }
  17097. else
  17098. {
  17099. tempIndex = gun_index;
  17100. }
  17101. for (int index = 0; index < AC_QUANTITY; index++)
  17102. {
  17103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17104. {
  17105. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17106. }
  17107. } // END for AC_QUANTITY
  17108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17109. }
  17110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17113. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17116. }
  17117. //2.4====================================== Voltage L1 ====================================================
  17118. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17119. {
  17120. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17121. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17122. {
  17123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17124. {
  17125. tempIndex = ((gun_index==2) ? 1: 0);
  17126. }
  17127. else
  17128. {
  17129. tempIndex = gun_index;
  17130. }
  17131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17132. {
  17133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17134. {
  17135. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17136. }
  17137. } // END OF FOR CHAdeMO_QUANTITY
  17138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17139. }
  17140. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17141. {
  17142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17143. {
  17144. tempIndex = ((gun_index==2) ? 1: 0);
  17145. }
  17146. else
  17147. {
  17148. tempIndex = gun_index;
  17149. }
  17150. for (int index = 0; index < CCS_QUANTITY; index++)
  17151. {
  17152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17153. {
  17154. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17155. }
  17156. } // END OF FOR CCS_QUANTITY
  17157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17158. }
  17159. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17160. {
  17161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17162. {
  17163. tempIndex = ((gun_index==2) ? 1: 0);
  17164. }
  17165. else
  17166. {
  17167. tempIndex = gun_index;
  17168. }
  17169. for (int index = 0; index < GB_QUANTITY; index++)
  17170. {
  17171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17172. {
  17173. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17174. }
  17175. } // END OF FOR GB_QUANTITY
  17176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17177. }
  17178. else if(gunType[gun_index] == GUN_TYPE_DO)
  17179. {
  17180. tempIndex = gun_index;
  17181. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17182. {
  17183. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17184. {
  17185. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17186. }
  17187. }
  17188. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17189. }
  17190. else
  17191. {
  17192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17193. {
  17194. tempIndex = 2;
  17195. }
  17196. else
  17197. {
  17198. tempIndex = gun_index;
  17199. }
  17200. for (int index = 0; index < AC_QUANTITY; index++)
  17201. {
  17202. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17203. {
  17204. 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
  17205. }
  17206. } // END OF FOR AC_QUANTITY
  17207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17208. }
  17209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17212. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17215. }
  17216. //2.5============================================== End SoC =========================================================
  17217. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17218. {
  17219. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17220. 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))
  17221. {
  17222. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17223. {
  17224. tempIndex = ((gun_index==2) ? 1: 0);
  17225. }
  17226. else
  17227. {
  17228. tempIndex = gun_index;
  17229. }
  17230. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17231. {
  17232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17233. {
  17234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17235. {
  17236. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17237. }
  17238. }
  17239. }
  17240. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17241. {
  17242. for (int index = 0; index < CCS_QUANTITY; index++)
  17243. {
  17244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17245. {
  17246. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17247. }
  17248. }
  17249. }
  17250. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17251. {
  17252. for (int index = 0; index < GB_QUANTITY; index++)
  17253. {
  17254. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17255. {
  17256. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17257. }
  17258. }
  17259. }
  17260. else if(gunType[gun_index] == GUN_TYPE_DO)
  17261. {
  17262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17263. {
  17264. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17265. {
  17266. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17267. }
  17268. }
  17269. }
  17270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17276. } // END FOR DC CASE
  17277. }
  17278. //2.6====================================== Current.Import L2 ==============================================
  17279. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17280. {
  17281. // AC 3 phase L2 current
  17282. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17283. {
  17284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17285. {
  17286. tempIndex = 2;
  17287. }
  17288. else
  17289. {
  17290. tempIndex = gun_index;
  17291. }
  17292. for (int index = 0; index < AC_QUANTITY; index++)
  17293. {
  17294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17295. {
  17296. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17297. }
  17298. }// End of for AC_QUANTITY
  17299. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17300. }
  17301. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17306. }
  17307. //2.7====================================== Current.Import L3 ==============================================
  17308. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17309. {
  17310. // AC 3 phase L3 current
  17311. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17312. {
  17313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17314. {
  17315. tempIndex = 2;
  17316. }
  17317. else
  17318. {
  17319. tempIndex = gun_index;
  17320. }
  17321. for (int index = 0; index < AC_QUANTITY; index++)
  17322. {
  17323. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17324. {
  17325. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17326. }
  17327. }// End of for AC_QUANTITY
  17328. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17329. }
  17330. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17333. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17335. }
  17336. //2.9====================================== Voltage L2 ====================================================
  17337. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17338. {
  17339. // AC 3 phase L2 volatge
  17340. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17341. {
  17342. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17343. {
  17344. tempIndex = 2;
  17345. }
  17346. else
  17347. {
  17348. tempIndex = gun_index;
  17349. }
  17350. for (int index = 0; index < AC_QUANTITY; index++)
  17351. {
  17352. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17353. {
  17354. 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
  17355. }
  17356. } // END OF FOR AC_QUANTITY
  17357. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17358. }
  17359. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17364. }
  17365. //2.10====================================== Voltage L3 ====================================================
  17366. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17367. {
  17368. // AC 3 phase L3 volatge
  17369. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17370. {
  17371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17372. {
  17373. tempIndex = 2;
  17374. }
  17375. else
  17376. {
  17377. tempIndex = gun_index;
  17378. }
  17379. for (int index = 0; index < AC_QUANTITY; index++)
  17380. {
  17381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17382. {
  17383. 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
  17384. }
  17385. } // END OF FOR AC_QUANTITY
  17386. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17387. }
  17388. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17389. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17393. }
  17394. //====================== Start SoC ================================
  17395. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17396. {
  17397. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17398. 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))
  17399. {
  17400. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17401. {
  17402. tempIndex = ((gun_index==2) ? 1: 0);
  17403. }
  17404. else
  17405. {
  17406. tempIndex = gun_index;
  17407. }
  17408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17409. {
  17410. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17411. {
  17412. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17413. {
  17414. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17415. }
  17416. }
  17417. }
  17418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17419. {
  17420. for (int index = 0; index < CCS_QUANTITY; index++)
  17421. {
  17422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17423. {
  17424. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17425. }
  17426. }
  17427. }
  17428. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17429. {
  17430. for (int index = 0; index < GB_QUANTITY; index++)
  17431. {
  17432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17433. {
  17434. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17435. }
  17436. }
  17437. }
  17438. else if(gunType[gun_index] == GUN_TYPE_DO)
  17439. {
  17440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17441. {
  17442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17443. {
  17444. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17445. }
  17446. }
  17447. }
  17448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17449. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17451. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17454. } // END FOR DC CASE
  17455. }
  17456. //======================================== Message create ==============================================
  17457. json_object *StopTransaction = json_object_new_object();
  17458. json_object *transactionDatas = json_object_new_array();
  17459. json_object *sampledValues = json_object_new_array();
  17460. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17461. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17462. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17463. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17464. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17465. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17466. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17467. {
  17468. json_object *transactionData = json_object_new_object();
  17469. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17470. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17471. {
  17472. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17473. {
  17474. json_object *sampledValue = json_object_new_object();
  17475. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17476. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17477. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17478. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17479. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17480. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17481. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17482. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17483. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17484. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17485. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17486. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17487. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17488. json_object_array_add(sampledValues, sampledValue);
  17489. }
  17490. }
  17491. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17492. json_object_array_add(transactionDatas, transactionData);
  17493. }
  17494. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17495. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17496. ,MESSAGE_TYPE_CALL
  17497. ,guid
  17498. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17499. json_object_put(StopTransaction);
  17500. // Check File "TempStopTransaction" Exist
  17501. if((access(TempStopTransaction,F_OK))!=-1)
  17502. {
  17503. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17504. fclose(fopen(TempStopTransaction, "w"));
  17505. }
  17506. else
  17507. {
  17508. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17509. FILE *log = fopen(TempStopTransaction, "w+");
  17510. if(log == NULL)
  17511. {
  17512. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17513. return ;
  17514. }
  17515. else
  17516. {
  17517. fclose(log);
  17518. }
  17519. }
  17520. //Add TempStopTransaction | Update TempStopTransaction
  17521. // open file for writing
  17522. FILE *outfile;
  17523. outfile = fopen (TempStopTransaction, "a");
  17524. //DEBUG_INFO("data = %s\n", queuedata);
  17525. fputs(queuedata, outfile);
  17526. fputs("\n", outfile);
  17527. fclose (outfile);
  17528. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17529. }
  17530. void checkTempStopTransaction(int gun_index)
  17531. {
  17532. FILE *fptr1;
  17533. char ch;
  17534. char str[QUEUE_MESSAGE_LENGTH]={0};
  17535. char guid[37]={0};
  17536. char tempdata[65]={0};
  17537. char connectorStr[2]={0};
  17538. char TempStopTransaction[256];
  17539. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17540. fptr1 = fopen(TempStopTransaction, "r");
  17541. //TempStopTransaction格式: 槍號,StopTransaction封包
  17542. if (!fptr1)
  17543. {
  17544. //printf(" File not found or unable to open the input file!!\n");
  17545. return ;
  17546. }
  17547. ch=fgetc(fptr1);
  17548. //printf(" Now the content of the file %s is : \n",fname);
  17549. rewind(fptr1);
  17550. if(ch!=EOF)
  17551. {
  17552. // copy all contents to the temporary file except the specific line
  17553. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17554. {
  17555. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17556. if(str[0]=='\0')
  17557. {
  17558. break;
  17559. }
  17560. //TempStopTransaction格式: 槍號,StopTransaction封包
  17561. strncpy(connectorStr, str, 1);
  17562. if(atoi(connectorStr) != (gun_index+1))
  17563. {
  17564. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17565. fclose(fptr1);
  17566. return ;
  17567. }
  17568. //random_uuid(guid);
  17569. strncpy(guid, str+6, 36); //copy guid
  17570. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17571. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17572. {
  17573. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17574. }
  17575. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17576. OCPP_insert_transaction_msg(NO, str);
  17577. memset(str,0,ARRAY_SIZE(str));
  17578. }
  17579. }
  17580. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17581. fclose(fptr1);
  17582. remove(TempStopTransaction); // remove the original file
  17583. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17584. }
  17585. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17586. {
  17587. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17588. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17589. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17590. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17591. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17592. }
  17593. int GetWebSocketPingInterval(void)
  17594. {
  17595. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17596. }
  17597. int GetServerSign(void)
  17598. {
  17599. return server_sign;
  17600. }
  17601. uint8_t GetOcppSecurityProfile()
  17602. {
  17603. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17604. }
  17605. void GetOcppChargerBoxId(uint8_t *data)
  17606. {
  17607. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17608. }
  17609. void GetOcppSecurityPassword(uint8_t *data)
  17610. {
  17611. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17612. }
  17613. void SetOcppVersion(uint8_t *version)
  17614. {
  17615. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17616. DEBUG_INFO("ocpp version: %s\n", version);
  17617. if(strstr((char*)version, "ocpp1.6") != NULL)
  17618. {
  17619. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17620. }
  17621. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17622. {
  17623. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17624. system("pkill OcppBackend");
  17625. }
  17626. }
  17627. void SetServerSign(int value)
  17628. {
  17629. server_sign = value;
  17630. }
  17631. int GetBootNotificationInterval(void)
  17632. {
  17633. return BootNotificationInterval;
  17634. }
  17635. int GetInternetConn(void)
  17636. {
  17637. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17638. }
  17639. int GetBackendConnectionTimeout(void)
  17640. {
  17641. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17642. }
  17643. int isConnectorInitMode(int gun_index)
  17644. {
  17645. int tempIndex = 0;
  17646. int result = TRUE;
  17647. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17648. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  17659. {
  17660. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17661. {
  17662. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17663. } //end of the same index
  17664. }//end of for CHAdeMO_QUANTITY
  17665. }
  17666. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  17677. {
  17678. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17679. {
  17680. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17681. } //end of the same index
  17682. } // end of for CCS_QUANTITY
  17683. }
  17684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17685. {
  17686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17687. {
  17688. tempIndex = ((gun_index==2) ? 1: 0);
  17689. }
  17690. else
  17691. {
  17692. tempIndex = gun_index;
  17693. }
  17694. for (int index = 0; index < GB_QUANTITY; index++)
  17695. {
  17696. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17697. {
  17698. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17699. } //end of the same index
  17700. } // end of for GB_QUANTITY
  17701. }
  17702. else if(gunType[gun_index] == GUN_TYPE_DO)
  17703. {
  17704. tempIndex = gun_index;
  17705. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17706. {
  17707. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17708. {
  17709. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17710. } //end of the same index
  17711. }
  17712. }
  17713. else
  17714. {
  17715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17716. {
  17717. tempIndex = 2;
  17718. }
  17719. else
  17720. {
  17721. tempIndex = gun_index;
  17722. }
  17723. for (int index = 0; index < AC_QUANTITY; index++)
  17724. {
  17725. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17726. {
  17727. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17728. }//end of the same index
  17729. }//end of for AC_QUANTITY
  17730. }
  17731. return result;
  17732. }
  17733. void refreshProcDogTimer()
  17734. {
  17735. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17736. }
  17737. void InitialSystemValue(void)
  17738. {
  17739. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17740. locallistVersion=0;
  17741. BootNotificationInterval = 0;
  17742. authorizeRetryTimes = 0;
  17743. GunStatusInterval = 10;
  17744. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17745. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17746. //Hear Beat
  17747. HeartBeatWithNOResponse = 0;
  17748. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17749. FirstHeartBeat = 0;
  17750. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17751. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17752. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17753. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17754. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17755. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17756. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17757. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17758. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17759. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17760. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17761. //Status && ConnectorPlugIn Setting
  17762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17763. {
  17764. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17765. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17766. }
  17767. for (int index = 0; index < CCS_QUANTITY; index++)
  17768. {
  17769. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17770. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17771. }
  17772. for (int index = 0; index < GB_QUANTITY; index++)
  17773. {
  17774. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17775. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17776. }
  17777. for (int index = 0; index < AC_QUANTITY; index++)
  17778. {
  17779. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17780. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17781. }
  17782. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17783. {
  17784. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17785. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17786. }
  17787. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17788. {
  17789. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17790. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17791. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17792. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17793. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17794. }
  17795. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17796. refreshStartTimer(&clientTime.Heartbeat);
  17797. sleep(1);
  17798. }
  17799. void LWS_Send(char *str)
  17800. {
  17801. //=====================================================
  17802. // Check InternetConn 0: disconnected, 1: connected
  17803. //====================================================
  17804. if(GetOcppConnStatus() == 0)
  17805. {
  17806. DEBUG_INFO("offline now !!!\n");
  17807. return;
  17808. }
  17809. // Only disable isWebsocketSendable operation initiated by charger
  17810. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17811. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17812. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17813. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17814. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17815. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17816. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17817. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17818. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17819. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17820. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17821. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17822. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17823. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17824. {
  17825. isWebsocketSendable = 0;
  17826. }
  17827. pthread_mutex_lock(&lock_send);
  17828. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17829. sprintf((char *)SendBuffer, "%s", str);
  17830. SendBufLen = strlen(str);
  17831. pthread_mutex_unlock(&lock_send);
  17832. lws_callback_on_writable(wsi_client);
  17833. //lws_service(context, 0);
  17834. //sleep(1);
  17835. }
  17836. void LWS_SendNow(char *str)
  17837. {
  17838. //=====================================================
  17839. // Check InternetConn 0: disconnected, 1: connected
  17840. //====================================================
  17841. if(GetOcppConnStatus() == 0)
  17842. {
  17843. DEBUG_INFO("offline now !!!\n");
  17844. return;
  17845. }
  17846. // Only disable isWebsocketSendable operation initiated by charger
  17847. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17848. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17849. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17850. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17851. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17852. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17853. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17854. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17855. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17856. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17857. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17858. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17859. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17860. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17861. {
  17862. isWebsocketSendable = 0;
  17863. }
  17864. pthread_mutex_lock(&lock_send);
  17865. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17866. sprintf((char *)SendBuffer, "%s", str);
  17867. SendBufLen = strlen(str);
  17868. pthread_mutex_unlock(&lock_send);
  17869. lws_callback_on_writable(wsi_client);
  17870. lws_service(context, 0);
  17871. //sleep(1);
  17872. }