MessageHandler.c 907 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514
  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 YesCustomCallReader;
  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. //==========================================
  675. // Check time passed since today
  676. //==========================================
  677. long long DiffTimebWithNow(struct timeb ST)
  678. {
  679. //return milli-second
  680. struct timeb ET;
  681. long long StartTime,StopTime;
  682. ftime(&ET);
  683. StartTime=(long long)ST.time;
  684. StopTime=(long long)ET.time;
  685. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  686. }
  687. int getTimePassSinceToday(uint8_t gun_index)
  688. {
  689. int result = -1;
  690. static time_t lastTime[4];
  691. time_t t;
  692. struct tm *tmStartToday;
  693. struct timeb tbStartToday;
  694. t=time(NULL);
  695. if(difftime(t, lastTime[gun_index])>0)
  696. {
  697. tmStartToday=localtime(&t);
  698. tmStartToday->tm_hour = 0;
  699. tmStartToday->tm_min = 0;
  700. tmStartToday->tm_sec = 0;
  701. tbStartToday.time = mktime(tmStartToday);
  702. tbStartToday.millitm = 0;
  703. result = DiffTimebWithNow(tbStartToday)/1000;
  704. lastTime[gun_index] = t;
  705. }
  706. return result;
  707. }
  708. void getNowDatetime(uint8_t *data)
  709. {
  710. time_t t = time(NULL);
  711. struct tm tm = *localtime(&t);
  712. 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);
  713. }
  714. int syncDateTimeRTC(uint8_t *data)
  715. {
  716. struct ParsingResult
  717. {
  718. int result;
  719. int scanedElement;
  720. int year;
  721. int month;
  722. int mday;
  723. int hour;
  724. int min;
  725. int sec;
  726. int tz_hour;
  727. int tz_min;
  728. float minSec;
  729. }result;
  730. struct tm tmOrg;
  731. struct tm *tmTarget;
  732. struct timeb tbTarget;
  733. char buf[128];
  734. memset(&result, 0x00, sizeof(struct ParsingResult));
  735. result.result = PASS;
  736. if(strstr((char*)data, ".") != NULL)
  737. {
  738. // Original data with mini second
  739. if(strstr((char*)data, "Z") != NULL)
  740. {
  741. // Original data with Z
  742. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  743. &result.year,
  744. &result.month,
  745. &result.mday,
  746. &result.hour,
  747. &result.min,
  748. &result.sec,
  749. &result.minSec);
  750. }
  751. else
  752. {
  753. // Original data without Z
  754. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  755. &result.year,
  756. &result.month,
  757. &result.mday,
  758. &result.hour,
  759. &result.min,
  760. &result.sec,
  761. &result.minSec,
  762. &result.tz_hour,
  763. &result.tz_min);
  764. }
  765. }
  766. else
  767. {
  768. // Original data without mini second
  769. if(strstr((char*)data, "Z") != NULL)
  770. {
  771. // Original data with Z
  772. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  773. &result.year,
  774. &result.month,
  775. &result.mday,
  776. &result.hour,
  777. &result.min,
  778. &result.sec);
  779. }
  780. else
  781. {
  782. // Original data without Z
  783. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  784. &result.year,
  785. &result.month,
  786. &result.mday,
  787. &result.hour,
  788. &result.min,
  789. &result.sec,
  790. &result.tz_hour,
  791. &result.tz_min);
  792. }
  793. }
  794. tmOrg.tm_year = result.year - 1900;
  795. tmOrg.tm_mon = result.month - 1;
  796. tmOrg.tm_mday = result.mday;
  797. tmOrg.tm_hour = result.hour;
  798. tmOrg.tm_min = result.min;
  799. tmOrg.tm_sec = result.sec;
  800. tmOrg.tm_gmtoff = 0;
  801. tbTarget.time = mktime(&tmOrg);
  802. tbTarget.timezone = 0;
  803. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  804. tmTarget = gmtime(&tbTarget.time);
  805. 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);
  806. //DEBUG_INFO(" org date time: %s\n", data);
  807. //DEBUG_INFO("parse date time: %s\n", buf);
  808. system(buf);
  809. system("/sbin/hwclock -w --systohc");
  810. if(result.scanedElement < 6)
  811. result.result = FAIL;
  812. return result.result;
  813. }
  814. //==========================================
  815. // GetCompositeSchedule logic related function
  816. //==========================================
  817. int DiffTimebSec(struct timeb ST, struct timeb ET)
  818. {
  819. //return milli-second
  820. unsigned int StartTime,StopTime;
  821. StartTime=(unsigned int)ST.time;
  822. StopTime=(unsigned int)ET.time;
  823. return (StopTime-StartTime);
  824. }
  825. int DiffTimebWithNowSec(struct timeb ST)
  826. {
  827. //return milli-second
  828. struct timeb ET;
  829. unsigned int StartTime,StopTime;
  830. ftime(&ET);
  831. StartTime=(unsigned int)ST.time;
  832. StopTime=(unsigned int)ET.time;
  833. return (StopTime-StartTime);
  834. }
  835. int getStartStop(uint8_t *start, uint8_t *stop)
  836. {
  837. int result = -1;
  838. struct tm tmStart;
  839. struct timeb tbStart;
  840. struct tm tmStop;
  841. struct timeb tbStop;
  842. 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) &&
  843. (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))
  844. {
  845. //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);
  846. //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);
  847. tmStart.tm_year -= 1900;
  848. tmStart.tm_mon -= 1;
  849. tbStart.time = mktime(&tmStart);
  850. tbStart.millitm = 0;
  851. tmStop.tm_year -= 1900;
  852. tmStop.tm_mon -= 1;
  853. tbStop.time = mktime(&tmStop);
  854. tbStop.millitm = 0;
  855. result = DiffTimebSec(tbStart, tbStop);
  856. //DEBUG_INFO("getStartStop(): %d\n", result);
  857. }
  858. else
  859. {
  860. DEBUG_WARN("Start or stop date parsing error.\r\n");
  861. }
  862. return result;
  863. }
  864. int isOvertNow(uint8_t *start)
  865. {
  866. int result = NO;
  867. struct ParsingResult
  868. {
  869. int result;
  870. int scanedElement;
  871. int year;
  872. int month;
  873. int mday;
  874. int hour;
  875. int min;
  876. int sec;
  877. int tz_hour;
  878. int tz_min;
  879. float minSec;
  880. }parsingResult;
  881. struct tm tmStart;
  882. struct timeb tbStart;
  883. if(strstr((char*)start, ".") != NULL)
  884. {
  885. // Original data with mini second
  886. if(strstr((char*)start, "Z") != NULL)
  887. {
  888. // Original data with Z
  889. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  890. &parsingResult.year,
  891. &parsingResult.month,
  892. &parsingResult.mday,
  893. &parsingResult.hour,
  894. &parsingResult.min,
  895. &parsingResult.sec,
  896. &parsingResult.minSec);
  897. }
  898. else
  899. {
  900. // Original data without Z
  901. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  902. &parsingResult.year,
  903. &parsingResult.month,
  904. &parsingResult.mday,
  905. &parsingResult.hour,
  906. &parsingResult.min,
  907. &parsingResult.sec,
  908. &parsingResult.minSec,
  909. &parsingResult.tz_hour,
  910. &parsingResult.tz_min);
  911. }
  912. }
  913. else
  914. {
  915. // Original data without mini second
  916. if(strstr((char*)start, "Z") != NULL)
  917. {
  918. // Original data with Z
  919. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  920. &parsingResult.year,
  921. &parsingResult.month,
  922. &parsingResult.mday,
  923. &parsingResult.hour,
  924. &parsingResult.min,
  925. &parsingResult.sec);
  926. }
  927. else
  928. {
  929. // Original data without Z
  930. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  931. &parsingResult.year,
  932. &parsingResult.month,
  933. &parsingResult.mday,
  934. &parsingResult.hour,
  935. &parsingResult.min,
  936. &parsingResult.sec,
  937. &parsingResult.tz_hour,
  938. &parsingResult.tz_min);
  939. }
  940. }
  941. if(parsingResult.scanedElement >= 6)
  942. {
  943. tmStart.tm_year = parsingResult.year - 1900;
  944. tmStart.tm_mon = parsingResult.month - 1;
  945. tmStart.tm_mday = parsingResult.mday;
  946. tmStart.tm_hour = parsingResult.hour;
  947. tmStart.tm_min = parsingResult.min;
  948. tmStart.tm_sec = parsingResult.sec;
  949. tmStart.tm_gmtoff = 0;
  950. tbStart.time = mktime(&tmStart);
  951. tbStart.timezone = 0;
  952. tbStart.millitm = 0;
  953. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  954. if(DiffTimebWithNowSec(tbStart) <= 0)
  955. result = NO;
  956. else
  957. result = YES;
  958. }
  959. else
  960. {
  961. DEBUG_WARN("Start date parsing error.\n");
  962. }
  963. return result;
  964. }
  965. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  966. {
  967. int result = -1;
  968. struct tm tmStart;
  969. struct timeb tbStart;
  970. struct tm tmStop;
  971. struct timeb tbStop;
  972. 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) &&
  973. (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))
  974. {
  975. tmStart.tm_year -= 1900;
  976. tmStart.tm_mon -= 1;
  977. tbStart.time = mktime(&tmStart);
  978. tbStart.millitm = 0;
  979. tmStop.tm_year -= 1900;
  980. tmStop.tm_mon -= 1;
  981. tbStop.time = mktime(&tmStop);
  982. tbStop.millitm = 0;
  983. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  984. }
  985. return result;
  986. }
  987. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  988. {
  989. FILE *fp;
  990. char profileFileName[128];
  991. char *line = NULL;
  992. size_t len = 0;
  993. time_t CurrentTime;
  994. struct tm *tmComposite;
  995. struct StructChargingProfile maxProfile;
  996. uint8_t limitMax=0;
  997. int compositePeriodIdx = 0;
  998. CurrentTime = time(NULL);
  999. tmComposite=localtime(&CurrentTime);
  1000. 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);
  1001. if(isUnitA)
  1002. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1003. else
  1004. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1005. compositeProfile->ChargingSchedule.Duration = durationReq;
  1006. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1007. {
  1008. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1009. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1010. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1011. }
  1012. compositeProfile->ChargingProfileId = 0;
  1013. compositeProfile->StackLevel = 99 ;
  1014. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1015. maxProfile.ChargingProfileId = -1;
  1016. maxProfile.ChargingSchedule.Duration = -1;
  1017. system("rm -f /tmp/*.json");
  1018. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1019. // Search max profile
  1020. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1021. if((access(profileFileName, F_OK))!=-1)
  1022. {
  1023. fp = fopen(profileFileName, "r");
  1024. while(getline(&line, &len, fp) != -1)
  1025. {
  1026. json_object *obj = NULL;
  1027. obj = json_tokener_parse(line);
  1028. if(is_error(obj))
  1029. {
  1030. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1031. }
  1032. else
  1033. {
  1034. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1035. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1036. )
  1037. {
  1038. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1039. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1040. )
  1041. {
  1042. struct tm tmFrom, tmTo;
  1043. struct timeb tbFrom, tbTo;
  1044. 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) &&
  1045. (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))
  1046. {
  1047. tmFrom.tm_year -= 1900;
  1048. tmFrom.tm_mon -= 1;
  1049. tbFrom.time = mktime(&tmFrom);
  1050. tmTo.tm_year -= 1900;
  1051. tmTo.tm_mon -= 1;
  1052. tbTo.time = mktime(&tmTo);
  1053. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1054. {
  1055. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1056. {
  1057. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1059. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1060. }
  1061. maxProfile.ChargingProfileId = -1;
  1062. maxProfile.StackLevel = -1;
  1063. if(maxProfile.ChargingProfileId == -1)
  1064. DEBUG_INFO("MaxProfile found.\n");
  1065. else
  1066. DEBUG_INFO("MaxProfile updated.\n");
  1067. // Required item
  1068. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1069. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1070. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1071. if(isUnitA)
  1072. {
  1073. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1074. 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++)
  1075. {
  1076. 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"));
  1077. 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?
  1078. 3:
  1079. 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")));
  1080. 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")));
  1081. }
  1082. }
  1083. else
  1084. {
  1085. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1086. 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++)
  1087. {
  1088. 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"));
  1089. 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?
  1090. 3:
  1091. 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")));
  1092. 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));
  1093. }
  1094. }
  1095. // Optional item
  1096. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1097. {
  1098. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1099. }
  1100. else
  1101. {
  1102. sprintf((char*)maxProfile.ValidFrom, " ");
  1103. }
  1104. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1105. {
  1106. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1107. }
  1108. else
  1109. {
  1110. sprintf((char*)maxProfile.ValidTo, " ");
  1111. }
  1112. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1113. {
  1114. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1115. }
  1116. else
  1117. {
  1118. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1119. }
  1120. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1121. {
  1122. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1123. }
  1124. else
  1125. {
  1126. maxProfile.TransactionId = -1;
  1127. }
  1128. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1129. {
  1130. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1131. }
  1132. else
  1133. {
  1134. maxProfile.ChargingSchedule.Duration = 86400;
  1135. }
  1136. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1137. {
  1138. 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")));
  1139. }
  1140. else
  1141. {
  1142. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1143. }
  1144. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1145. {
  1146. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1147. }
  1148. else
  1149. {
  1150. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1151. }
  1152. }
  1153. }
  1154. }
  1155. else
  1156. {
  1157. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1158. {
  1159. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1160. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1161. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1162. }
  1163. maxProfile.ChargingProfileId = -1;
  1164. maxProfile.StackLevel = -1;
  1165. if(maxProfile.ChargingProfileId == -1)
  1166. DEBUG_INFO("MaxProfile found.\n");
  1167. else
  1168. DEBUG_INFO("MaxProfile updated.\n");
  1169. // Required item
  1170. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1171. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1172. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1173. if(isUnitA)
  1174. {
  1175. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1176. 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++)
  1177. {
  1178. 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"));
  1179. 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?
  1180. 3:
  1181. 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")));
  1182. 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")));
  1183. }
  1184. }
  1185. else
  1186. {
  1187. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1188. 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++)
  1189. {
  1190. 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"));
  1191. 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?
  1192. 3:
  1193. 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")));
  1194. 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));
  1195. }
  1196. }
  1197. // Optional item
  1198. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1199. {
  1200. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1201. }
  1202. else
  1203. {
  1204. sprintf((char*)maxProfile.ValidFrom, " ");
  1205. }
  1206. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1207. {
  1208. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1209. }
  1210. else
  1211. {
  1212. sprintf((char*)maxProfile.ValidTo, " ");
  1213. }
  1214. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1215. {
  1216. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1217. }
  1218. else
  1219. {
  1220. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1221. }
  1222. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1223. {
  1224. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1225. }
  1226. else
  1227. {
  1228. maxProfile.TransactionId = -1;
  1229. }
  1230. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1231. {
  1232. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1233. }
  1234. else
  1235. {
  1236. maxProfile.ChargingSchedule.Duration = 86400;
  1237. }
  1238. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1239. {
  1240. 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")));
  1241. }
  1242. else
  1243. {
  1244. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1245. }
  1246. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1247. {
  1248. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1249. }
  1250. else
  1251. {
  1252. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. json_object_put(obj);
  1258. }
  1259. fclose(fp);
  1260. /*
  1261. if(maxProfile.ChargingProfileId !=-1)
  1262. {
  1263. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1264. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1265. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1266. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1267. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1268. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1269. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1270. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1271. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1272. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1273. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1274. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1275. {
  1276. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1277. {
  1278. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1279. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1280. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1281. }
  1282. }
  1283. }
  1284. else
  1285. DEBUG_INFO("MaxProfile not found.\n");
  1286. DEBUG_INFO("------------------------------------\n");*/
  1287. }
  1288. if(maxProfile.ChargingProfileId != -1)
  1289. {
  1290. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1291. {
  1292. if(maxProfile.ChargingSchedule.Duration != -1)
  1293. {
  1294. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1295. 0:
  1296. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1297. }
  1298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1299. {
  1300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1303. 0:
  1304. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1305. if(idxPeriod > 0)
  1306. {
  1307. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1308. {
  1309. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1316. {
  1317. if(maxProfile.ChargingSchedule.Duration != -1)
  1318. {
  1319. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1320. }
  1321. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1322. {
  1323. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1324. {
  1325. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1326. if(idxPeriod > 0)
  1327. {
  1328. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1329. {
  1330. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. else
  1337. {
  1338. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1339. {
  1340. if(maxProfile.ChargingSchedule.Duration != -1)
  1341. {
  1342. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1343. 0:
  1344. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1345. }
  1346. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1347. {
  1348. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1349. {
  1350. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1351. 0:
  1352. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1353. if(idxPeriod > 0)
  1354. {
  1355. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1356. {
  1357. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1358. }
  1359. }
  1360. }
  1361. }
  1362. }
  1363. else
  1364. {
  1365. if(maxProfile.ChargingSchedule.Duration != -1)
  1366. {
  1367. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1368. 0:
  1369. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1370. }
  1371. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1372. {
  1373. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1374. {
  1375. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1376. 0:
  1377. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1378. if(idxPeriod > 0)
  1379. {
  1380. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1381. {
  1382. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1383. }
  1384. }
  1385. }
  1386. }
  1387. }
  1388. }
  1389. /*
  1390. DEBUG_INFO("MaxProfile after align.\n");
  1391. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1392. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1393. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1394. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1395. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1396. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1397. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1398. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1399. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1400. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1401. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1402. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1403. {
  1404. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1405. {
  1406. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1407. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1408. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1409. }
  1410. }
  1411. DEBUG_INFO("------------------------------------\n");*/
  1412. }
  1413. // Find each profile period quantity
  1414. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1415. {
  1416. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1417. limitMax = idx+1;
  1418. }
  1419. if(maxProfile.ChargingProfileId != -1)
  1420. {
  1421. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1422. {
  1423. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1424. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1425. (maxProfile.ChargingSchedule.Duration > 0))
  1426. {
  1427. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1428. {
  1429. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1430. compositePeriodIdx++;
  1431. }
  1432. else
  1433. {
  1434. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1435. }
  1436. }
  1437. }
  1438. }
  1439. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1440. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1441. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1442. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1443. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1444. {
  1445. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1446. {
  1447. compositeProfile->ChargingProfileId = 1;
  1448. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1449. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1450. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1451. }
  1452. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1453. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1454. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1455. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1456. }
  1457. if(line)
  1458. free(line);
  1459. }
  1460. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1461. {
  1462. FILE *fp;
  1463. char profileFileName[128];
  1464. char *line = NULL;
  1465. size_t len = 0;
  1466. time_t CurrentTime;
  1467. struct tm *tmComposite;
  1468. struct StructChargingProfile maxProfile;
  1469. struct StructChargingProfile defaultTxProfile;
  1470. struct StructChargingProfile txProfile;
  1471. struct StructChargingSchedulePeriod tmpPeriod;
  1472. uint8_t limitMax=0;
  1473. uint8_t limitDef=0;
  1474. uint8_t limitTx=0;
  1475. int compositePeriodIdx = 0;
  1476. CurrentTime = time(NULL);
  1477. tmComposite=localtime(&CurrentTime);
  1478. 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);
  1479. if(isUnitA)
  1480. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1481. else
  1482. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1483. compositeProfile->ChargingSchedule.Duration = durationReq;
  1484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1485. {
  1486. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1487. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1488. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1489. }
  1490. compositeProfile->ChargingProfileId = 0;
  1491. compositeProfile->StackLevel = 99 ;
  1492. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1493. maxProfile.ChargingProfileId = -1;
  1494. defaultTxProfile.ChargingProfileId = -1;
  1495. txProfile.ChargingProfileId = -1;
  1496. maxProfile.ChargingSchedule.Duration = -1;
  1497. defaultTxProfile.ChargingSchedule.Duration = -1;
  1498. txProfile.ChargingSchedule.Duration = -1;
  1499. system("rm -f /tmp/*.json");
  1500. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1501. /*
  1502. * Search valid charging profile
  1503. */
  1504. //DEBUG_INFO("====================================\n");
  1505. // Search tx profile
  1506. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1507. if((access(profileFileName, F_OK))!=-1)
  1508. {
  1509. fp = fopen(profileFileName, "r");
  1510. while(getline(&line, &len, fp) != -1)
  1511. {
  1512. json_object *obj = NULL;
  1513. obj = json_tokener_parse(line);
  1514. if(is_error(obj))
  1515. {
  1516. DEBUG_ERROR("Parse txProfile from file error.\n");
  1517. }
  1518. else
  1519. {
  1520. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1521. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1522. )
  1523. {
  1524. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1525. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1526. )
  1527. {
  1528. struct tm tmFrom, tmTo;
  1529. struct timeb tbFrom, tbTo;
  1530. 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) &&
  1531. (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))
  1532. {
  1533. tmFrom.tm_year -= 1900;
  1534. tmFrom.tm_mon -= 1;
  1535. tbFrom.time = mktime(&tmFrom);
  1536. tmTo.tm_year -= 1900;
  1537. tmTo.tm_mon -= 1;
  1538. tbTo.time = mktime(&tmTo);
  1539. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1540. {
  1541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1542. {
  1543. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1544. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1545. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1546. }
  1547. txProfile.ChargingProfileId = -1;
  1548. txProfile.StackLevel = -1;
  1549. if(txProfile.ChargingProfileId == -1)
  1550. DEBUG_INFO("TxProfile found.\n");
  1551. else
  1552. DEBUG_INFO("TxProfile updated.\n");
  1553. // Required item
  1554. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1555. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1556. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1557. if(isUnitA)
  1558. {
  1559. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1560. 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++)
  1561. {
  1562. 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"));
  1563. 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?
  1564. 3:
  1565. 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")));
  1566. 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")));
  1567. }
  1568. }
  1569. else
  1570. {
  1571. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1572. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1573. {
  1574. 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"));
  1575. 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?
  1576. 3:
  1577. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1578. 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));
  1579. }
  1580. }
  1581. // Optional item
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1583. {
  1584. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)txProfile.ValidFrom, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1591. {
  1592. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1593. }
  1594. else
  1595. {
  1596. sprintf((char*)txProfile.ValidTo, " ");
  1597. }
  1598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1599. {
  1600. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1601. }
  1602. else
  1603. {
  1604. sprintf((char*)txProfile.RecurrencyKind, " ");
  1605. }
  1606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1607. {
  1608. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1609. }
  1610. else
  1611. {
  1612. txProfile.TransactionId = -1;
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1615. {
  1616. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1617. }
  1618. else
  1619. {
  1620. txProfile.ChargingSchedule.Duration = 86400;
  1621. }
  1622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1623. {
  1624. 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")));
  1625. }
  1626. else
  1627. {
  1628. 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));
  1629. }
  1630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1631. {
  1632. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1633. }
  1634. else
  1635. {
  1636. txProfile.ChargingSchedule.MinChargingRate = -1;
  1637. }
  1638. }
  1639. }
  1640. }
  1641. else
  1642. {
  1643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1644. {
  1645. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1646. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1647. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1648. }
  1649. txProfile.ChargingProfileId = -1;
  1650. txProfile.StackLevel = -1;
  1651. if(txProfile.ChargingProfileId == -1)
  1652. DEBUG_INFO("TxProfile found.\n");
  1653. else
  1654. DEBUG_INFO("TxProfile updated.\n");
  1655. // Required item
  1656. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1657. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1658. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1659. if(isUnitA)
  1660. {
  1661. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1662. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1663. {
  1664. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1665. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1666. 3:
  1667. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1668. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(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")));
  1669. }
  1670. }
  1671. else
  1672. {
  1673. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1674. 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++)
  1675. {
  1676. 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"));
  1677. 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?
  1678. 3:
  1679. 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")));
  1680. 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));
  1681. }
  1682. }
  1683. // Optional item
  1684. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1685. {
  1686. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1687. }
  1688. else
  1689. {
  1690. sprintf((char*)txProfile.ValidFrom, " ");
  1691. }
  1692. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1693. {
  1694. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1695. }
  1696. else
  1697. {
  1698. sprintf((char*)txProfile.ValidTo, " ");
  1699. }
  1700. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1701. {
  1702. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1703. }
  1704. else
  1705. {
  1706. sprintf((char*)txProfile.RecurrencyKind, " ");
  1707. }
  1708. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1709. {
  1710. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1711. }
  1712. else
  1713. {
  1714. txProfile.TransactionId = -1;
  1715. }
  1716. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1717. {
  1718. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1719. }
  1720. else
  1721. {
  1722. txProfile.ChargingSchedule.Duration = 86400;
  1723. }
  1724. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1725. {
  1726. 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")));
  1727. }
  1728. else
  1729. {
  1730. 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));
  1731. }
  1732. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1733. {
  1734. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1735. }
  1736. else
  1737. {
  1738. txProfile.ChargingSchedule.MinChargingRate = -1;
  1739. }
  1740. }
  1741. }
  1742. }
  1743. json_object_put(obj);
  1744. }
  1745. fclose(fp);
  1746. /*
  1747. if(txProfile.ChargingProfileId != -1)
  1748. {
  1749. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1750. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1751. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1752. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1753. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1754. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1755. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1756. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1757. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1758. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1759. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1760. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1761. {
  1762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1763. {
  1764. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1765. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1766. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1767. }
  1768. }
  1769. }
  1770. else
  1771. DEBUG_INFO("TxProfile not found.\n");*/
  1772. }
  1773. // Search default tx profile
  1774. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1775. if((access(profileFileName, F_OK))==-1)
  1776. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1777. if((access(profileFileName, F_OK))!=-1)
  1778. {
  1779. fp = fopen(profileFileName, "r");
  1780. while(getline(&line, &len, fp) != -1)
  1781. {
  1782. json_object *obj = NULL;
  1783. obj = json_tokener_parse(line);
  1784. if(is_error(obj))
  1785. {
  1786. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1787. }
  1788. else
  1789. {
  1790. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1791. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1792. )
  1793. {
  1794. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1795. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1796. )
  1797. {
  1798. struct tm tmFrom, tmTo;
  1799. struct timeb tbFrom, tbTo;
  1800. 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) &&
  1801. (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))
  1802. {
  1803. tmFrom.tm_year -= 1900;
  1804. tmFrom.tm_mon -= 1;
  1805. tbFrom.time = mktime(&tmFrom);
  1806. tmTo.tm_year -= 1900;
  1807. tmTo.tm_mon -= 1;
  1808. tbTo.time = mktime(&tmTo);
  1809. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1810. {
  1811. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1812. {
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1814. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1815. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1816. }
  1817. defaultTxProfile.ChargingProfileId = -1;
  1818. defaultTxProfile.StackLevel = -1;
  1819. if(defaultTxProfile.ChargingProfileId == -1)
  1820. DEBUG_INFO("TxDefaultProfile found.\n");
  1821. else
  1822. DEBUG_INFO("TxDefaultProfile updated.\n");
  1823. // Required item
  1824. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1825. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1826. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1827. if(isUnitA)
  1828. {
  1829. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1830. 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++)
  1831. {
  1832. 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"));
  1833. 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?
  1834. 3:
  1835. 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")));
  1836. 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")));
  1837. }
  1838. }
  1839. else
  1840. {
  1841. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1842. 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++)
  1843. {
  1844. 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"));
  1845. 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?
  1846. 3:
  1847. 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")));
  1848. 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));
  1849. }
  1850. }
  1851. // Optional item
  1852. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1853. {
  1854. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1855. }
  1856. else
  1857. {
  1858. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1859. }
  1860. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1861. {
  1862. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1863. }
  1864. else
  1865. {
  1866. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1867. }
  1868. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1869. {
  1870. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1871. }
  1872. else
  1873. {
  1874. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1875. }
  1876. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1877. {
  1878. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1879. }
  1880. else
  1881. {
  1882. defaultTxProfile.TransactionId = -1;
  1883. }
  1884. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1885. {
  1886. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1887. }
  1888. else
  1889. {
  1890. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1891. }
  1892. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1893. {
  1894. 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")));
  1895. }
  1896. else
  1897. {
  1898. 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));
  1899. }
  1900. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1903. }
  1904. else
  1905. {
  1906. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1907. }
  1908. }
  1909. }
  1910. }
  1911. else
  1912. {
  1913. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1914. {
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1917. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1918. }
  1919. defaultTxProfile.ChargingProfileId = -1;
  1920. defaultTxProfile.StackLevel = -1;
  1921. if(defaultTxProfile.ChargingProfileId == -1)
  1922. DEBUG_INFO("TxDefaultProfile found.\n");
  1923. else
  1924. DEBUG_INFO("TxDefaultProfile updated.\n");
  1925. // Required item
  1926. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1927. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1928. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1929. if(isUnitA)
  1930. {
  1931. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1932. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1933. {
  1934. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1935. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1936. 3:
  1937. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1938. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(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")));
  1939. }
  1940. }
  1941. else
  1942. {
  1943. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1944. 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++)
  1945. {
  1946. 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"));
  1947. 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?
  1948. 3:
  1949. 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")));
  1950. 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));
  1951. }
  1952. }
  1953. // Optional item
  1954. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1955. {
  1956. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1957. }
  1958. else
  1959. {
  1960. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1961. }
  1962. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1963. {
  1964. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1965. }
  1966. else
  1967. {
  1968. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1969. }
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1971. {
  1972. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1973. }
  1974. else
  1975. {
  1976. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1977. }
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1979. {
  1980. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1981. }
  1982. else
  1983. {
  1984. defaultTxProfile.TransactionId = -1;
  1985. }
  1986. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1987. {
  1988. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1989. }
  1990. else
  1991. {
  1992. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1993. }
  1994. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1995. {
  1996. 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")));
  1997. }
  1998. else
  1999. {
  2000. 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));
  2001. }
  2002. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2003. {
  2004. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2005. }
  2006. else
  2007. {
  2008. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2009. }
  2010. }
  2011. }
  2012. }
  2013. json_object_put(obj);
  2014. }
  2015. fclose(fp);
  2016. /*
  2017. if(defaultTxProfile.ChargingProfileId != -1)
  2018. {
  2019. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2020. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2021. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2022. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2023. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2024. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2025. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2026. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2027. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2028. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2029. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2030. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2031. {
  2032. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2033. {
  2034. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2035. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2036. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2037. }
  2038. }
  2039. }
  2040. else
  2041. DEBUG_INFO("TxDefaultProfile not found.\n");
  2042. DEBUG_INFO("------------------------------------\n");*/
  2043. }
  2044. // Search max profile
  2045. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2046. if((access(profileFileName, F_OK))!=-1)
  2047. {
  2048. fp = fopen(profileFileName, "r");
  2049. while(getline(&line, &len, fp) != -1)
  2050. {
  2051. json_object *obj = NULL;
  2052. obj = json_tokener_parse(line);
  2053. if(is_error(obj))
  2054. {
  2055. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2056. }
  2057. else
  2058. {
  2059. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2060. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2061. )
  2062. {
  2063. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2064. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2065. )
  2066. {
  2067. struct tm tmFrom, tmTo;
  2068. struct timeb tbFrom, tbTo;
  2069. 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) &&
  2070. (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))
  2071. {
  2072. tmFrom.tm_year -= 1900;
  2073. tmFrom.tm_mon -= 1;
  2074. tbFrom.time = mktime(&tmFrom);
  2075. tmTo.tm_year -= 1900;
  2076. tmTo.tm_mon -= 1;
  2077. tbTo.time = mktime(&tmTo);
  2078. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2079. {
  2080. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2081. {
  2082. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2083. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2084. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2085. }
  2086. maxProfile.ChargingProfileId = -1;
  2087. maxProfile.StackLevel = -1;
  2088. if(maxProfile.ChargingProfileId == -1)
  2089. DEBUG_INFO("MaxProfile found.\n");
  2090. else
  2091. DEBUG_INFO("MaxProfile updated.\n");
  2092. // Required item
  2093. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2094. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2095. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2096. if(isUnitA)
  2097. {
  2098. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2099. 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++)
  2100. {
  2101. 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"));
  2102. 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?
  2103. 3:
  2104. 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")));
  2105. 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")));
  2106. }
  2107. }
  2108. else
  2109. {
  2110. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2111. 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++)
  2112. {
  2113. 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"));
  2114. 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?
  2115. 3:
  2116. 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")));
  2117. 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));
  2118. }
  2119. }
  2120. // Optional item
  2121. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2122. {
  2123. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2124. }
  2125. else
  2126. {
  2127. sprintf((char*)maxProfile.ValidFrom, " ");
  2128. }
  2129. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2130. {
  2131. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2132. }
  2133. else
  2134. {
  2135. sprintf((char*)maxProfile.ValidTo, " ");
  2136. }
  2137. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2138. {
  2139. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2140. }
  2141. else
  2142. {
  2143. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2144. }
  2145. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2146. {
  2147. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2148. }
  2149. else
  2150. {
  2151. maxProfile.TransactionId = -1;
  2152. }
  2153. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2154. {
  2155. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2156. }
  2157. else
  2158. {
  2159. maxProfile.ChargingSchedule.Duration = 86400;
  2160. }
  2161. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2162. {
  2163. 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")));
  2164. }
  2165. else
  2166. {
  2167. 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));
  2168. }
  2169. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2170. {
  2171. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2172. }
  2173. else
  2174. {
  2175. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2176. }
  2177. }
  2178. }
  2179. }
  2180. else
  2181. {
  2182. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2183. {
  2184. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2185. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2186. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2187. }
  2188. maxProfile.ChargingProfileId = -1;
  2189. maxProfile.StackLevel = -1;
  2190. if(maxProfile.ChargingProfileId == -1)
  2191. DEBUG_INFO("MaxProfile found.\n");
  2192. else
  2193. DEBUG_INFO("MaxProfile updated.\n");
  2194. // Required item
  2195. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2196. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2197. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2198. if(isUnitA)
  2199. {
  2200. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2201. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2202. {
  2203. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2204. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2205. 3:
  2206. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2207. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((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")));
  2208. }
  2209. }
  2210. else
  2211. {
  2212. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2213. 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++)
  2214. {
  2215. 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"));
  2216. 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?
  2217. 3:
  2218. 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")));
  2219. 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));
  2220. }
  2221. }
  2222. // Optional item
  2223. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2224. {
  2225. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2226. }
  2227. else
  2228. {
  2229. sprintf((char*)maxProfile.ValidFrom, " ");
  2230. }
  2231. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2232. {
  2233. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2234. }
  2235. else
  2236. {
  2237. sprintf((char*)maxProfile.ValidTo, " ");
  2238. }
  2239. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2240. {
  2241. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2242. }
  2243. else
  2244. {
  2245. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2246. }
  2247. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2248. {
  2249. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2250. }
  2251. else
  2252. {
  2253. maxProfile.TransactionId = -1;
  2254. }
  2255. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2256. {
  2257. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2258. }
  2259. else
  2260. {
  2261. maxProfile.ChargingSchedule.Duration = 86400;
  2262. }
  2263. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2264. {
  2265. 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")));
  2266. }
  2267. else
  2268. {
  2269. 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));
  2270. }
  2271. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2272. {
  2273. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2274. }
  2275. else
  2276. {
  2277. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2278. }
  2279. }
  2280. }
  2281. }
  2282. json_object_put(obj);
  2283. }
  2284. fclose(fp);
  2285. /*
  2286. if(maxProfile.ChargingProfileId !=-1)
  2287. {
  2288. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2289. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2290. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2291. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2292. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2293. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2294. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2295. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2296. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2297. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2298. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2300. {
  2301. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2302. {
  2303. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2304. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2305. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2306. }
  2307. }
  2308. }
  2309. else
  2310. DEBUG_INFO("MaxProfile not found.\n");
  2311. DEBUG_INFO("------------------------------------\n");*/
  2312. }
  2313. /*
  2314. * Align found profile start schedule & periods
  2315. */
  2316. //DEBUG_INFO("====================================\n");
  2317. /*
  2318. // For local test usage, force modify found profile start schedule info
  2319. 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);
  2320. 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);
  2321. 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);
  2322. */
  2323. if(txProfile.ChargingProfileId != -1)
  2324. {
  2325. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2326. {
  2327. if(txProfile.ChargingSchedule.Duration != -1)
  2328. {
  2329. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2330. 0:
  2331. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2332. }
  2333. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2334. {
  2335. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2336. {
  2337. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2338. 0:
  2339. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2340. if(idxPeriod > 0)
  2341. {
  2342. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2343. {
  2344. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2351. {
  2352. if(txProfile.ChargingSchedule.Duration != -1)
  2353. {
  2354. 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?
  2355. 0:
  2356. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2357. }
  2358. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2359. {
  2360. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2361. {
  2362. 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?
  2363. 0:
  2364. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2365. if(idxPeriod > 0)
  2366. {
  2367. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2368. {
  2369. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2370. }
  2371. }
  2372. }
  2373. }
  2374. }
  2375. else
  2376. {
  2377. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2378. {
  2379. if(txProfile.ChargingSchedule.Duration != -1)
  2380. {
  2381. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2382. 0:
  2383. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2384. }
  2385. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2386. {
  2387. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2388. {
  2389. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2390. 0:
  2391. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2392. if(idxPeriod > 0)
  2393. {
  2394. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2395. {
  2396. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2397. }
  2398. }
  2399. }
  2400. }
  2401. }
  2402. else
  2403. {
  2404. if(txProfile.ChargingSchedule.Duration != -1)
  2405. {
  2406. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2407. 0:
  2408. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2409. }
  2410. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2411. {
  2412. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2413. {
  2414. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2415. 0:
  2416. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2417. if(idxPeriod > 0)
  2418. {
  2419. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2420. {
  2421. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. /*
  2429. DEBUG_INFO("txProfile after align.\n");
  2430. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2431. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2432. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2433. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2434. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2435. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2436. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2437. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2438. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2439. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2440. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2441. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2442. {
  2443. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2444. {
  2445. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2446. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2447. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2448. }
  2449. }*/
  2450. }
  2451. if(defaultTxProfile.ChargingProfileId != -1)
  2452. {
  2453. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2454. {
  2455. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2456. {
  2457. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2458. 0:
  2459. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2460. }
  2461. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2462. {
  2463. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2464. {
  2465. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2466. 0:
  2467. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2468. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2469. {
  2470. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2471. }
  2472. if(idxPeriod > 0)
  2473. {
  2474. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2475. {
  2476. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2477. }
  2478. }
  2479. }
  2480. }
  2481. }
  2482. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2483. {
  2484. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2485. {
  2486. 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?
  2487. 0:
  2488. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2489. }
  2490. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2491. {
  2492. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2493. {
  2494. 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?
  2495. 0:
  2496. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2497. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2498. {
  2499. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2500. }
  2501. if(idxPeriod > 0)
  2502. {
  2503. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2504. {
  2505. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2506. }
  2507. }
  2508. }
  2509. }
  2510. }
  2511. else
  2512. {
  2513. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2514. {
  2515. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2516. {
  2517. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2518. 0:
  2519. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2520. }
  2521. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2522. {
  2523. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2524. {
  2525. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2526. 0:
  2527. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2528. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2529. {
  2530. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2531. }
  2532. if(idxPeriod > 0)
  2533. {
  2534. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2535. {
  2536. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2537. }
  2538. }
  2539. }
  2540. }
  2541. }
  2542. else
  2543. {
  2544. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2545. {
  2546. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2547. 0:
  2548. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2549. }
  2550. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2551. {
  2552. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2553. {
  2554. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2555. 0:
  2556. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2557. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2558. {
  2559. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2560. }
  2561. if(idxPeriod > 0)
  2562. {
  2563. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2564. {
  2565. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. }
  2572. /*
  2573. DEBUG_INFO("defaultTxProfile after align.\n");
  2574. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2575. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2576. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2577. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2578. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2579. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2580. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2581. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2582. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2583. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2584. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2585. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2586. {
  2587. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2588. {
  2589. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2590. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2591. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2592. }
  2593. }
  2594. DEBUG_INFO("------------------------------------\n");*/
  2595. }
  2596. if(maxProfile.ChargingProfileId != -1)
  2597. {
  2598. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2599. {
  2600. if(maxProfile.ChargingSchedule.Duration != -1)
  2601. {
  2602. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2603. 0:
  2604. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2605. }
  2606. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2607. {
  2608. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2609. {
  2610. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2611. 0:
  2612. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2613. if(idxPeriod > 0)
  2614. {
  2615. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2616. {
  2617. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2624. {
  2625. if(maxProfile.ChargingSchedule.Duration != -1)
  2626. {
  2627. 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?
  2628. 0:
  2629. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2630. }
  2631. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2632. {
  2633. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2634. {
  2635. 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?
  2636. 0:
  2637. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2638. if(idxPeriod > 0)
  2639. {
  2640. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2641. {
  2642. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2643. }
  2644. }
  2645. }
  2646. }
  2647. }
  2648. else
  2649. {
  2650. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2651. {
  2652. if(maxProfile.ChargingSchedule.Duration != -1)
  2653. {
  2654. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2655. 0:
  2656. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2657. }
  2658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2659. {
  2660. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2661. {
  2662. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2663. 0:
  2664. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2665. if(idxPeriod > 0)
  2666. {
  2667. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2668. {
  2669. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. else
  2676. {
  2677. if(maxProfile.ChargingSchedule.Duration != -1)
  2678. {
  2679. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2680. 0:
  2681. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2682. }
  2683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2684. {
  2685. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2686. {
  2687. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2688. 0:
  2689. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2690. if(idxPeriod > 0)
  2691. {
  2692. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2693. {
  2694. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2695. }
  2696. }
  2697. }
  2698. }
  2699. }
  2700. }
  2701. /*
  2702. DEBUG_INFO("MaxProfile after align.\n");
  2703. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2704. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2705. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2706. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2707. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2708. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2709. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2710. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2711. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2712. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2713. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2714. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2715. {
  2716. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2717. {
  2718. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2719. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2720. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2721. }
  2722. }
  2723. DEBUG_INFO("------------------------------------\n");*/
  2724. }
  2725. /*
  2726. * Merge to conposite schedule
  2727. */
  2728. //DEBUG_INFO("====================================\n");
  2729. // Find each profile period quantity
  2730. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2731. {
  2732. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2733. limitMax = idx+1;
  2734. }
  2735. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2736. {
  2737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2738. limitDef = idx+1;
  2739. }
  2740. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2741. {
  2742. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2743. limitTx = idx+1;
  2744. }
  2745. // TxProfile found, composite schedule based on it
  2746. if(txProfile.ChargingProfileId != -1)
  2747. {
  2748. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2749. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2750. {
  2751. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2752. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2753. (txProfile.ChargingSchedule.Duration > 0))
  2754. {
  2755. if(maxProfile.ChargingProfileId != -1)
  2756. {
  2757. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2758. {
  2759. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2760. {
  2761. if((maxProfile.ChargingSchedule.Duration > 0))
  2762. {
  2763. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2764. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2765. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2766. }
  2767. else
  2768. {
  2769. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2770. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2771. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2772. }
  2773. }
  2774. if(idxMaxPeriod == (limitMax-1))
  2775. {
  2776. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2777. {
  2778. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2779. {
  2780. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2781. compositePeriodIdx++;
  2782. }
  2783. else
  2784. {
  2785. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2786. }
  2787. }
  2788. }
  2789. }
  2790. }
  2791. else
  2792. {
  2793. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2794. {
  2795. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2796. compositePeriodIdx++;
  2797. }
  2798. else
  2799. {
  2800. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2801. }
  2802. }
  2803. }
  2804. if(idxTxPeriod == (limitTx-1))
  2805. {
  2806. if(defaultTxProfile.ChargingProfileId != -1)
  2807. {
  2808. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2809. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2810. {
  2811. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2812. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2813. (defaultTxProfile.ChargingSchedule.Duration>0))
  2814. {
  2815. if(maxProfile.ChargingProfileId != -1)
  2816. {
  2817. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2818. {
  2819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2820. {
  2821. if((maxProfile.ChargingSchedule.Duration > 0))
  2822. {
  2823. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2824. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2825. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2826. }
  2827. else
  2828. {
  2829. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2830. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2831. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2832. }
  2833. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2834. {
  2835. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2836. {
  2837. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2838. compositePeriodIdx++;
  2839. }
  2840. else
  2841. {
  2842. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2843. }
  2844. }
  2845. // Delete duplicate period
  2846. if(compositePeriodIdx > 1)
  2847. {
  2848. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2849. {
  2850. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2851. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2852. compositePeriodIdx -= 1;
  2853. }
  2854. }
  2855. }
  2856. else
  2857. {
  2858. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2859. {
  2860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2861. compositePeriodIdx++;
  2862. }
  2863. else
  2864. {
  2865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2866. }
  2867. break;
  2868. }
  2869. }
  2870. }
  2871. else
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2874. {
  2875. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2876. compositePeriodIdx++;
  2877. }
  2878. else
  2879. {
  2880. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2881. }
  2882. }
  2883. }
  2884. }
  2885. }
  2886. }
  2887. }
  2888. }
  2889. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2890. else if(defaultTxProfile.ChargingProfileId != -1)
  2891. {
  2892. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2893. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2894. {
  2895. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2896. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2897. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2898. {
  2899. if(maxProfile.ChargingProfileId != -1)
  2900. {
  2901. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2902. {
  2903. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2904. {
  2905. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2906. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2907. if((maxProfile.ChargingSchedule.Duration > 0))
  2908. {
  2909. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2910. }
  2911. else
  2912. {
  2913. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2914. }
  2915. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2916. {
  2917. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2918. {
  2919. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2920. compositePeriodIdx++;
  2921. }
  2922. else
  2923. {
  2924. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2925. }
  2926. }
  2927. // Delete duplicate period
  2928. if(compositePeriodIdx > 1)
  2929. {
  2930. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2931. {
  2932. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2933. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2934. compositePeriodIdx -= 1;
  2935. }
  2936. }
  2937. }
  2938. else
  2939. {
  2940. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2941. {
  2942. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2943. compositePeriodIdx++;
  2944. }
  2945. else
  2946. {
  2947. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2948. }
  2949. break;
  2950. }
  2951. }
  2952. }
  2953. else
  2954. {
  2955. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2956. {
  2957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2958. compositePeriodIdx++;
  2959. }
  2960. else
  2961. {
  2962. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2963. }
  2964. }
  2965. }
  2966. }
  2967. }
  2968. // Fill other period by MaxProfile
  2969. if(maxProfile.ChargingProfileId != -1)
  2970. {
  2971. if(compositePeriodIdx==0)
  2972. {
  2973. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2974. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2975. {
  2976. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2977. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2978. (maxProfile.ChargingSchedule.Duration > 0))
  2979. {
  2980. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2981. {
  2982. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2983. compositePeriodIdx++;
  2984. }
  2985. else
  2986. {
  2987. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2988. }
  2989. }
  2990. }
  2991. }
  2992. else
  2993. {
  2994. int lastCompositePeriodIdx = compositePeriodIdx;
  2995. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2996. {
  2997. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2998. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2999. (maxProfile.ChargingSchedule.Duration > 0))
  3000. {
  3001. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3002. {
  3003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3004. {
  3005. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3006. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3007. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3008. }
  3009. else
  3010. {
  3011. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3012. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3013. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3014. }
  3015. }
  3016. if(tmpPeriod.Limit != -1)
  3017. {
  3018. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3019. {
  3020. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3021. {
  3022. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3023. compositePeriodIdx++;
  3024. }
  3025. else
  3026. {
  3027. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3028. }
  3029. }
  3030. // Delete duplicate period
  3031. if(compositePeriodIdx > 1)
  3032. {
  3033. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3034. {
  3035. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3036. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3037. compositePeriodIdx -= 1;
  3038. }
  3039. }
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. compositeProfile->ChargingSchedule.Duration = durationReq;
  3046. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3047. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3048. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3049. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3050. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3051. {
  3052. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3053. {
  3054. compositeProfile->ChargingProfileId = 1;
  3055. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3056. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3057. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3058. }
  3059. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3060. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3061. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3062. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3063. }
  3064. if(line)
  3065. free(line);
  3066. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3067. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3068. }
  3069. //==========================================
  3070. // Init all share memory
  3071. //==========================================
  3072. int InitShareMemory()
  3073. {
  3074. int result = PASS;
  3075. int MeterSMId;
  3076. //creat ShmSysConfigAndInfo
  3077. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3078. {
  3079. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3080. result = FAIL;
  3081. }
  3082. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3083. {
  3084. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3085. result = FAIL;
  3086. }
  3087. else
  3088. {}
  3089. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3090. {
  3091. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3092. result = FAIL;
  3093. }
  3094. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3095. {
  3096. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3097. result = FAIL;
  3098. }
  3099. else
  3100. {}
  3101. //creat ShmPsuData
  3102. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3103. {
  3104. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3105. result = FAIL;
  3106. }
  3107. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3108. {
  3109. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3110. result = FAIL;
  3111. }
  3112. else
  3113. {}
  3114. //link ShmOCPP16Data
  3115. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3116. {
  3117. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3118. result = FAIL;
  3119. }
  3120. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3121. {
  3122. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3123. result = FAIL;
  3124. }
  3125. else
  3126. {}
  3127. //creat ShmOCPP16DataPH
  3128. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3129. {
  3130. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3131. result = FAIL;
  3132. }
  3133. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3134. {
  3135. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3136. result = FAIL;
  3137. }
  3138. else
  3139. {}
  3140. /****************************** For Initial Settings************************************************/
  3141. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3142. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3143. // allocate Configuration memory address
  3144. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3145. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3146. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3147. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3148. //offline MeterValue Interval
  3149. TempMeterValueInterval = 0;
  3150. return result;
  3151. }
  3152. int ProcessShareMemory()
  3153. {
  3154. int result = PASS;
  3155. if(InitShareMemory() == FAIL)
  3156. {
  3157. DEBUG_ERROR("InitShareMemory NG\n");
  3158. if(ShmStatusCodeData!=NULL)
  3159. {
  3160. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3161. }
  3162. result = FAIL;
  3163. }
  3164. // Model name parsing
  3165. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3166. {
  3167. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3168. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3169. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3170. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3171. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3172. ) // 'D' means DC
  3173. {
  3174. // DO series
  3175. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3176. {
  3177. SystemInitial += 1;
  3178. gunTotalNumber += 1;
  3179. gunType[gun_index] = GUN_TYPE_DO;
  3180. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3181. {
  3182. case Gun_Type_Chademo:
  3183. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3184. break;
  3185. case Gun_Type_CCS_2:
  3186. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3187. break;
  3188. case Gun_Type_GB:
  3189. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3190. break;
  3191. case Gun_Type_AC:
  3192. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3193. break;
  3194. default:
  3195. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3196. break;
  3197. }
  3198. }
  3199. }
  3200. else
  3201. {
  3202. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3203. {
  3204. SystemInitial += 1;
  3205. gunTotalNumber += 1;
  3206. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3207. {
  3208. case Gun_Type_Chademo:
  3209. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3210. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3211. break;
  3212. case Gun_Type_CCS_2:
  3213. gunType[gun_index] = GUN_TYPE_CCS;
  3214. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3215. break;
  3216. case Gun_Type_GB:
  3217. gunType[gun_index] = GUN_TYPE_GBT;
  3218. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3219. break;
  3220. case Gun_Type_AC:
  3221. gunType[gun_index] = GUN_TYPE_AC;
  3222. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3223. break;
  3224. default:
  3225. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3226. break;
  3227. }
  3228. }
  3229. }
  3230. }
  3231. else
  3232. {
  3233. DEBUG_ERROR("Model name parsing fail.\n");
  3234. result = FAIL;
  3235. }
  3236. if(result != PASS)sleep(5);
  3237. return result;
  3238. }
  3239. void checkRemoteStart(uint8_t connectorIdInt)
  3240. {
  3241. uint8_t tempIndex;
  3242. int result = PASS;
  3243. char cmdBuf[512];
  3244. //check Transaction active
  3245. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3246. {
  3247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3248. {
  3249. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3250. }
  3251. else
  3252. {
  3253. tempIndex = connectorIdInt -1;
  3254. }
  3255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3256. {
  3257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3258. {
  3259. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3260. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3261. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3262. {
  3263. //Reserved
  3264. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3265. }
  3266. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3267. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3268. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3269. {
  3270. //Reserved
  3271. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3272. result = FAIL;
  3273. goto end;
  3274. }
  3275. else
  3276. {
  3277. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3278. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3279. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3280. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3281. {
  3282. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3283. result = FAIL;
  3284. goto end;
  3285. }
  3286. }//END FOR ELSE
  3287. }
  3288. }// END FOR CHAdeMO_QUANTITY
  3289. }
  3290. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3291. {
  3292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3293. {
  3294. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3295. }
  3296. else
  3297. {
  3298. tempIndex = connectorIdInt -1;
  3299. }
  3300. for (int index = 0; index < CCS_QUANTITY; index++)
  3301. {
  3302. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3303. {
  3304. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3305. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3306. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3307. {
  3308. //Reserved
  3309. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3310. }
  3311. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3312. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3313. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3314. {
  3315. //Reserved
  3316. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3317. result = FAIL;
  3318. goto end;
  3319. }
  3320. else
  3321. {
  3322. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3323. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3324. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3325. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3326. {
  3327. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3328. result = FAIL;
  3329. goto end;
  3330. }
  3331. }// END FOR ELSE
  3332. }
  3333. }// END FOR CCS_QUANTITY
  3334. }
  3335. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3336. {
  3337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3338. {
  3339. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3340. }
  3341. else
  3342. {
  3343. tempIndex = connectorIdInt -1;
  3344. }
  3345. for (int index = 0; index < GB_QUANTITY; index++)
  3346. {
  3347. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3348. {
  3349. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3350. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3351. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3352. {
  3353. //Reserved
  3354. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3355. }
  3356. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3357. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3358. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3359. {
  3360. //Reserved
  3361. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3362. result = FAIL;
  3363. goto end;
  3364. }
  3365. else
  3366. {
  3367. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3368. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3369. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3370. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3371. {
  3372. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3373. result = FAIL;
  3374. goto end;
  3375. }
  3376. }// END FOR ELSE
  3377. }
  3378. } // END FOR GB_QUANTITY
  3379. }
  3380. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3381. {
  3382. tempIndex = connectorIdInt -1;
  3383. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3384. {
  3385. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3386. {
  3387. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3388. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3389. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3390. {
  3391. //Reserved
  3392. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3393. }
  3394. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3395. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3396. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3397. {
  3398. //Reserved
  3399. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3400. result = FAIL;
  3401. goto end;
  3402. }
  3403. else
  3404. {
  3405. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3406. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3407. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3408. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3409. {
  3410. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3411. result = FAIL;
  3412. goto end;
  3413. }
  3414. }// END FOR ELSE
  3415. }
  3416. } // END FOR GB_QUANTITY
  3417. }
  3418. else
  3419. {
  3420. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3421. {
  3422. tempIndex = 2;
  3423. }
  3424. else
  3425. {
  3426. tempIndex = connectorIdInt -1;
  3427. }
  3428. for (int index = 0; index < AC_QUANTITY; index++)
  3429. {
  3430. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3431. {
  3432. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3433. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3434. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3435. {
  3436. //Reserved
  3437. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3438. }
  3439. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3440. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3441. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3442. {
  3443. //Reserved
  3444. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3445. result = FAIL;
  3446. goto end;
  3447. }
  3448. else
  3449. {
  3450. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3451. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3452. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3453. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3454. {
  3455. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3456. result = FAIL;
  3457. goto end;
  3458. }
  3459. }//END FOR ELSE
  3460. }
  3461. }// END FOR AC_QUANTITY
  3462. }
  3463. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3464. {
  3465. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3466. {
  3467. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3468. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3469. {
  3470. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3471. system(cmdBuf);
  3472. }
  3473. }
  3474. else
  3475. {
  3476. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3477. result = FAIL;
  3478. }
  3479. }
  3480. end:
  3481. if(result == PASS)
  3482. {
  3483. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3484. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3485. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3486. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3488. }
  3489. }
  3490. void CheckSystemValue(void)
  3491. {
  3492. char filenmae[100]={0};
  3493. char str[100]={0};
  3494. int tempIndex = 0;
  3495. //===============================
  3496. // send Heartbeat
  3497. //===============================
  3498. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3499. {
  3500. //parameter for test
  3501. sendHeartbeatRequest(0);
  3502. //==============================================
  3503. // Reset Waiting Time
  3504. //==============================================
  3505. HeartBeatWithNOResponse += 2;
  3506. }
  3507. //===============================
  3508. // send YES CallReader
  3509. //===============================
  3510. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->YesCustomData.CallReaderReq == 1) && (getDiffSecNow(clientTime.YesCustomCallReader) >= 5))
  3511. {
  3512. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3513. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"call_reader");
  3514. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data," ");
  3515. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  3516. //ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
  3517. refreshStartTimer(&clientTime.YesCustomCallReader);
  3518. }
  3519. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3520. {
  3521. // ClockAlign MeterValue
  3522. 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))
  3523. {
  3524. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3525. {
  3526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3527. {
  3528. tempIndex = ((gun_index==2) ? 1: 0);
  3529. }
  3530. else
  3531. {
  3532. tempIndex = gun_index;
  3533. }
  3534. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3535. {
  3536. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3537. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3538. {
  3539. reqClockAlignMeter[gun_index] = 1;
  3540. }
  3541. }// End for CHAdeMO
  3542. }
  3543. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3544. {
  3545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3546. {
  3547. tempIndex = ((gun_index==2) ? 1: 0);
  3548. }
  3549. else
  3550. {
  3551. tempIndex = gun_index;
  3552. }
  3553. for (int index = 0; index < CCS_QUANTITY; index++)
  3554. {
  3555. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3556. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3557. {
  3558. reqClockAlignMeter[gun_index] = 1;
  3559. }
  3560. } // End for CCS
  3561. }
  3562. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3563. {
  3564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3565. {
  3566. tempIndex = ((gun_index==2) ? 1: 0);
  3567. }
  3568. else
  3569. {
  3570. tempIndex = gun_index;
  3571. }
  3572. for (int index = 0; index < GB_QUANTITY; index++)
  3573. {
  3574. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3575. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3576. {
  3577. reqClockAlignMeter[gun_index] = 1;
  3578. }
  3579. }// End for GB
  3580. }
  3581. else if(gunType[gun_index] == GUN_TYPE_DO)
  3582. {
  3583. tempIndex = gun_index;
  3584. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3585. {
  3586. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3587. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3588. {
  3589. reqClockAlignMeter[gun_index] = 1;
  3590. }
  3591. }
  3592. }
  3593. else
  3594. {
  3595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3596. {
  3597. tempIndex = 2;
  3598. }
  3599. else
  3600. {
  3601. tempIndex = gun_index;
  3602. }
  3603. for (int index = 0; index < AC_QUANTITY; index++)
  3604. {
  3605. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3606. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3607. {
  3608. reqClockAlignMeter[gun_index] = 1;
  3609. }
  3610. }//End for AC
  3611. }
  3612. }
  3613. }
  3614. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3615. {
  3616. //==========================================
  3617. // Check remote start without connector id
  3618. //==========================================
  3619. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3620. {
  3621. int connectorIdInt = -1;
  3622. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3623. {
  3624. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3625. {
  3626. connectorIdInt = (gun_index+1);
  3627. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3628. checkRemoteStart(connectorIdInt);
  3629. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3630. break;
  3631. }
  3632. }
  3633. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3634. {
  3635. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3636. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3637. }
  3638. }
  3639. //==========================================
  3640. // csu trigger DataTransferReq
  3641. //==========================================
  3642. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3643. {
  3644. sendDataTransferRequest(gun_index);
  3645. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3646. }
  3647. //===============================
  3648. // CSU Trigger Authorize Request
  3649. //===============================
  3650. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3651. {
  3652. sendAuthorizeRequest(0);
  3653. authorizeRetryTimes = authorizeRetryTimes + 1;
  3654. if(authorizeRetryTimes < 3)
  3655. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3656. }
  3657. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3658. {
  3659. authorizeRetryTimes = 0;
  3660. SetOcppConnStatus(FALSE);
  3661. server_sign = FALSE;
  3662. }
  3663. 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))
  3664. {
  3665. sendAuthorizeRequest(0);
  3666. }
  3667. //==============================================
  3668. // Charger start transaction
  3669. //==============================================
  3670. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3671. {
  3672. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3673. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3674. sendStartTransactionRequest(gun_index);
  3675. refreshStartTimer(&clientTime.StartTransaction);
  3676. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3677. //storeTempStopTransaction(gun_index);
  3678. }
  3679. //==============================================
  3680. // Charger stop transaction
  3681. //==============================================
  3682. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3683. {
  3684. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3685. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3686. sendStopTransactionRequest(gun_index);
  3687. refreshStartTimer(&clientTime.StopTransaction);
  3688. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3689. }
  3690. //==============================================
  3691. // Charger status report
  3692. //==============================================
  3693. //--- Check Mode Change ---//
  3694. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3695. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3696. {
  3697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3698. {
  3699. tempIndex = ((gun_index==2) ? 1: 0);
  3700. }
  3701. else
  3702. {
  3703. tempIndex = gun_index;
  3704. }
  3705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3706. {
  3707. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3708. {
  3709. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3710. {
  3711. // Sent unplug message for California pricing logic
  3712. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3713. {
  3714. uint8_t ts[20];
  3715. getNowDatetime(ts);
  3716. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3717. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3718. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3719. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3720. }
  3721. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3722. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3723. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3724. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3725. {
  3726. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3727. if((access(filenmae,F_OK))!=-1)
  3728. {
  3729. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3730. sprintf(str,"rm -f %s",filenmae);
  3731. system(str);
  3732. }
  3733. }
  3734. }
  3735. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3736. #if 1 // for TempStopTransaction
  3737. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3738. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3739. {
  3740. checkTempStopTransaction(gun_index);
  3741. }
  3742. #endif
  3743. }
  3744. }
  3745. }
  3746. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3747. {
  3748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3749. {
  3750. tempIndex = ((gun_index==2) ? 1: 0);
  3751. }
  3752. else
  3753. {
  3754. tempIndex = gun_index;
  3755. }
  3756. for (int index = 0; index < CCS_QUANTITY; index++)
  3757. {
  3758. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3759. {
  3760. 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]*/ )
  3761. {
  3762. // Sent unplug message for California pricing logic
  3763. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3764. {
  3765. uint8_t ts[20];
  3766. getNowDatetime(ts);
  3767. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3768. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3769. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3770. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3771. }
  3772. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3773. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3774. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3775. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3776. {
  3777. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3778. if((access(filenmae,F_OK))!=-1)
  3779. {
  3780. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3781. sprintf(str,"rm -f %s",filenmae);
  3782. system(str);
  3783. }
  3784. }
  3785. }
  3786. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3787. #if 1 // for TempStopTransaction
  3788. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3789. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3790. {
  3791. checkTempStopTransaction(gun_index);
  3792. }
  3793. #endif
  3794. }
  3795. }
  3796. }
  3797. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3798. {
  3799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3800. {
  3801. tempIndex = ((gun_index==2) ? 1: 0);
  3802. }
  3803. else
  3804. {
  3805. tempIndex = gun_index;
  3806. }
  3807. for (int index = 0; index < GB_QUANTITY; index++)
  3808. {
  3809. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3810. {
  3811. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3812. {
  3813. // Sent unplug message for California pricing logic
  3814. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3815. {
  3816. uint8_t ts[20];
  3817. getNowDatetime(ts);
  3818. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3819. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3820. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3821. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3822. }
  3823. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3824. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3825. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3826. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3827. {
  3828. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3829. if((access(filenmae,F_OK))!=-1)
  3830. {
  3831. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3832. sprintf(str,"rm -f %s",filenmae);
  3833. system(str);
  3834. }
  3835. }
  3836. }
  3837. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3838. #if 1 // for TempStopTransaction
  3839. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3840. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3841. {
  3842. checkTempStopTransaction(gun_index);
  3843. }
  3844. #endif
  3845. }
  3846. }
  3847. }
  3848. else if(gunType[gun_index] == GUN_TYPE_DO)
  3849. {
  3850. tempIndex = gun_index;
  3851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3852. {
  3853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3854. {
  3855. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3856. {
  3857. // Sent unplug message for California pricing logic
  3858. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3859. {
  3860. uint8_t ts[20];
  3861. getNowDatetime(ts);
  3862. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3863. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3864. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3865. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3866. }
  3867. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3868. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3869. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3870. 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
  3871. {
  3872. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3873. if((access(filenmae,F_OK))!=-1)
  3874. {
  3875. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3876. sprintf(str,"rm -f %s",filenmae);
  3877. system(str);
  3878. }
  3879. }
  3880. }
  3881. 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);
  3882. #if 1 // for TempStopTransaction
  3883. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3884. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3885. {
  3886. checkTempStopTransaction(gun_index);
  3887. }
  3888. #endif
  3889. }
  3890. }
  3891. }
  3892. else
  3893. {
  3894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3895. {
  3896. tempIndex = 2;
  3897. }
  3898. else
  3899. {
  3900. tempIndex = gun_index;
  3901. }
  3902. for (int index = 0; index < AC_QUANTITY; index++)
  3903. {
  3904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3905. {
  3906. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3907. {
  3908. // Sent unplug message for California pricing logic
  3909. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3910. {
  3911. uint8_t ts[20];
  3912. getNowDatetime(ts);
  3913. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3914. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3915. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3916. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3917. }
  3918. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3919. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3920. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3921. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3922. {
  3923. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3924. if((access(filenmae,F_OK))!=-1)
  3925. {
  3926. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3927. sprintf(str,"rm -f %s",filenmae);
  3928. system(str);
  3929. }
  3930. }
  3931. }
  3932. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3933. #if 1 // for TempStopTransaction
  3934. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3935. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3936. {
  3937. checkTempStopTransaction(gun_index);
  3938. }
  3939. #endif
  3940. }
  3941. }// END
  3942. }
  3943. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  3944. (
  3945. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3946. )
  3947. )
  3948. {
  3949. if(SystemInitial > 0)
  3950. SystemInitial -= 1;
  3951. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3952. sendStatusNotificationRequest(gun_index);
  3953. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3954. }
  3955. //==============================================
  3956. // CSU Trigger Smart Charging Profilw
  3957. //==============================================
  3958. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3959. {
  3960. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3961. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3962. }
  3963. //==============================================
  3964. // Meter report
  3965. //==============================================
  3966. // Trigger MeterValue
  3967. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3968. {
  3969. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3970. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3971. }
  3972. // Clock-aligned Meter value
  3973. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  3974. {
  3975. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3976. reqClockAlignMeter[gun_index] = 0;
  3977. }
  3978. // Sample period MeterValue
  3979. 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))))
  3980. {
  3981. //check Transaction active
  3982. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3983. {
  3984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3985. {
  3986. tempIndex = ((gun_index==2) ? 1: 0);
  3987. }
  3988. else
  3989. {
  3990. tempIndex = gun_index;
  3991. }
  3992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3993. {
  3994. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3995. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3996. {
  3997. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3998. {
  3999. reqSampleMeter[gun_index] = 1;
  4000. }
  4001. }
  4002. }// End for CHAdeMO
  4003. }
  4004. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4005. {
  4006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4007. {
  4008. tempIndex = ((gun_index==2) ? 1: 0);
  4009. }
  4010. else
  4011. {
  4012. tempIndex = gun_index;
  4013. }
  4014. for (int index = 0; index < CCS_QUANTITY; index++)
  4015. {
  4016. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4017. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4018. {
  4019. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4020. {
  4021. reqSampleMeter[gun_index] = 1;
  4022. }
  4023. }
  4024. } // End for CCS
  4025. }
  4026. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4027. {
  4028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4029. {
  4030. tempIndex = ((gun_index==2) ? 1: 0);
  4031. }
  4032. else
  4033. {
  4034. tempIndex = gun_index;
  4035. }
  4036. for (int index = 0; index < GB_QUANTITY; index++)
  4037. {
  4038. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4039. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4040. {
  4041. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4042. {
  4043. reqSampleMeter[gun_index] = 1;
  4044. }
  4045. }
  4046. }// End for GB
  4047. }
  4048. else if(gunType[gun_index] == GUN_TYPE_DO)
  4049. {
  4050. tempIndex = gun_index;
  4051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4052. {
  4053. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4054. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4055. {
  4056. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4057. {
  4058. reqSampleMeter[gun_index] = 1;
  4059. }
  4060. }
  4061. }
  4062. }
  4063. else
  4064. {
  4065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4066. {
  4067. tempIndex = 2;
  4068. }
  4069. else
  4070. {
  4071. tempIndex = gun_index;
  4072. }
  4073. for (int index = 0; index < AC_QUANTITY; index++)
  4074. {
  4075. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4076. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4077. {
  4078. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4079. {
  4080. reqSampleMeter[gun_index] = 1;
  4081. }
  4082. }
  4083. }//End for AC
  4084. }
  4085. if(reqSampleMeter[gun_index] == 1)
  4086. {
  4087. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4088. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4089. //storeTempStopTransaction(gun_index);
  4090. reqSampleMeter[gun_index] = 0;
  4091. }
  4092. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4093. }
  4094. //==============================================
  4095. // Check Connector reserved
  4096. //==============================================
  4097. //===============================
  4098. // Check if Reserve is expired
  4099. //===============================
  4100. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4101. {
  4102. double diff_t;
  4103. struct tm tp;
  4104. // current time
  4105. time_t t = time(NULL);
  4106. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4107. tp.tm_isdst = -1;
  4108. time_t utc = mktime(&tp);
  4109. diff_t = difftime(utc, t);
  4110. if(diff_t <= 0)
  4111. {
  4112. DEBUG_INFO("reserve expired.\n");
  4113. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4114. }
  4115. }//END OF Check if Reserve is expired
  4116. //==========================================
  4117. // csu trigger FirmwareStatusNotificationReq
  4118. //==========================================
  4119. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4120. {
  4121. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4122. }
  4123. //==========================================
  4124. // csu trigger DiagnosticsStatusNotificationReq
  4125. //==========================================
  4126. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4127. {
  4128. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4129. }
  4130. //==========================================
  4131. // csu trigger CancelReservationConf
  4132. //==========================================
  4133. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4134. {
  4135. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4136. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4137. }
  4138. //==========================================
  4139. // csu trigger ChangeAvailabilityConf
  4140. //==========================================
  4141. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4142. {
  4143. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4144. }
  4145. //==========================================
  4146. // csu trigger UnlockConnectorConf
  4147. //==========================================
  4148. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4149. {
  4150. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4151. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4152. }
  4153. //==========================================
  4154. // csu trigger ReserveNowConf
  4155. //==========================================
  4156. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4157. {
  4158. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4159. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4160. }
  4161. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4162. {
  4163. sendSignCertificateRequest();
  4164. }
  4165. }
  4166. }
  4167. //==========================================
  4168. // send request routine
  4169. //==========================================
  4170. int sendAuthorizeRequest(int gun_index)
  4171. {
  4172. mtrace();
  4173. int result = FAIL;
  4174. char message[100]={0};
  4175. char guid[37];
  4176. char tempdata[65]={0};
  4177. DEBUG_INFO("sendAuthorizeRequest...\n");
  4178. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4179. //Local Authorize
  4180. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4181. {
  4182. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4183. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4184. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4185. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4186. result = PASS;
  4187. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4188. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4189. authorizeRetryTimes = 0;
  4190. return result;
  4191. }
  4192. 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))||
  4193. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4194. {
  4195. // Query from cache
  4196. DEBUG_INFO("Authorize from cache.\n");
  4197. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4198. // Query from list
  4199. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4200. {
  4201. DEBUG_INFO("Authorize from list.\n");
  4202. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4203. }
  4204. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4205. {
  4206. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4207. {
  4208. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4209. }
  4210. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4211. {
  4212. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4213. }
  4214. if(!GetOcppConnStatus())
  4215. {
  4216. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4217. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4218. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4219. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4220. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4221. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4222. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4223. authorizeRetryTimes = 0;
  4224. return result;
  4225. }
  4226. }
  4227. else
  4228. {
  4229. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4230. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4231. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4232. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4233. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4234. else
  4235. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4236. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4237. result = PASS;
  4238. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4239. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4240. authorizeRetryTimes = 0;
  4241. return result;
  4242. }
  4243. }
  4244. //initialize struct Authorize
  4245. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4246. //get data from shared memory
  4247. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4248. random_uuid(guid);
  4249. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4250. LWS_Send(message);
  4251. sprintf(tempdata, "Authorize,%d", gun_index);
  4252. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4253. {
  4254. result = PASS;
  4255. DEBUG_INFO("Authorize mapItem pass\n");
  4256. }
  4257. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4258. return result;
  4259. }
  4260. int sendBootNotificationRequest(void)
  4261. {
  4262. mtrace();
  4263. int result = FAIL;
  4264. char message[500]={0}, payload[700]={0};
  4265. char guid[37]={0};
  4266. char tempdata[65]={0};
  4267. // Fill BootNotification fields
  4268. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4269. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4270. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4271. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4272. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4273. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4274. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4275. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4276. ShmOCPP16DataPH->ChargeBoxId
  4277. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4278. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4279. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4280. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4281. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4282. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4283. random_uuid(guid);
  4284. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4285. LWS_Send(message);
  4286. sprintf(tempdata, "BootNotification,0");
  4287. 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*/)
  4288. {
  4289. result = PASS;
  4290. }
  4291. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4292. strcpy(queuedata,message);
  4293. return result;
  4294. }
  4295. int sendDataTransferRequest(int gun_index)
  4296. {
  4297. mtrace();
  4298. char message[1000]={0};
  4299. char guid[37]={0};
  4300. char tempdata[65]={0};
  4301. int result = FAIL;
  4302. random_uuid(guid);
  4303. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4304. MESSAGE_TYPE_CALL,
  4305. guid,
  4306. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4307. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4308. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4309. LWS_Send(message);
  4310. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4311. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4312. {
  4313. result = PASS;
  4314. DEBUG_INFO("DataTransfer mapItem pass\n");
  4315. }
  4316. return result;
  4317. }
  4318. int sendDiagnosticsStatusNotificationRequest(char *status)
  4319. {
  4320. mtrace();
  4321. int result = FAIL;
  4322. char message[110]={0};
  4323. char guid[37]={0};
  4324. char tempdata[65]={0};
  4325. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4326. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4327. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4328. random_uuid(guid);
  4329. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4330. LWS_SendNow(message);
  4331. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4332. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4333. {
  4334. result = PASS;
  4335. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4336. }
  4337. //#ifdef SystemLogMessage
  4338. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4339. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4340. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4341. //#endif
  4342. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4343. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4344. //record status
  4345. if(strcmp(status,"Idle")==0)
  4346. {
  4347. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4348. }
  4349. else if(strcmp(status,"Uploaded")==0)
  4350. {
  4351. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4352. }
  4353. else if(strcmp(status,"UploadFailed")==0)
  4354. {
  4355. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4356. }
  4357. else if(strcmp(status,"Uploading")==0)
  4358. {
  4359. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4360. }
  4361. return result;
  4362. }
  4363. int sendFirmwareStatusNotificationRequest(char *status)
  4364. {
  4365. mtrace();
  4366. int result = FAIL;
  4367. char message[110]={0};
  4368. char guid[37]={0};
  4369. char tempdata[65]={0};
  4370. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4371. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4372. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4373. random_uuid(guid);
  4374. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4375. LWS_SendNow(message);
  4376. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4377. 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*/)
  4378. {
  4379. result = PASS;
  4380. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4381. }
  4382. //#ifdef SystemLogMessage
  4383. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4384. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4385. //#endif
  4386. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4387. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4388. //record status
  4389. if(strcmp(status,"Downloaded")==0)
  4390. {
  4391. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4392. }
  4393. else if(strcmp(status,"DownloadFailed")==0)
  4394. {
  4395. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4396. }
  4397. else if(strcmp(status,"Downloading")==0)
  4398. {
  4399. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4400. }
  4401. else if(strcmp(status,"Idle")==0)
  4402. {
  4403. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4404. }
  4405. else if(strcmp(status,"InstallationFailed")==0)
  4406. {
  4407. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4408. }
  4409. else if(strcmp(status,"Installing")==0)
  4410. {
  4411. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4412. }
  4413. else if(strcmp(status,"Installed")==0)
  4414. {
  4415. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4416. }
  4417. return result;
  4418. }
  4419. int sendHeartbeatRequest(int gun_index)
  4420. {
  4421. mtrace();
  4422. int result = FAIL;
  4423. char message[80]={0};
  4424. char guid[37]={0};
  4425. char tempdata[65]={0};
  4426. random_uuid(guid);
  4427. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4428. , MESSAGE_TYPE_CALL
  4429. , guid );
  4430. LWS_Send(message);
  4431. sprintf(tempdata, "Heartbeat,%d", 0);
  4432. 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*/)
  4433. {
  4434. result = PASS;
  4435. }
  4436. return result;
  4437. }
  4438. int sendStartTransactionRequest(int gun_index)
  4439. {
  4440. mtrace();
  4441. int result = FAIL;
  4442. char message[250]={0};
  4443. char guid[37]={0};
  4444. struct timeval tmnow;
  4445. struct tm *tm;
  4446. char buf[28];//, usec_buf[6];
  4447. char tempdata[65]={0};
  4448. int tempIndex = 0;
  4449. DEBUG_INFO("sendStartTransactionRequest...\n");
  4450. gettimeofday(&tmnow, NULL);
  4451. time_t t;
  4452. t = time(NULL);
  4453. /*UTC time and date*/
  4454. tm = gmtime(&t);
  4455. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4456. #if 0 // remove temporally
  4457. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4458. strcat(buf,".");
  4459. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4460. strcat(buf,usec_buf);
  4461. #endif
  4462. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4463. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4464. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4465. // clear StartTransaction Response
  4466. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4467. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4468. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4469. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4470. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4471. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4472. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4473. {
  4474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4475. {
  4476. tempIndex = ((gun_index==2) ? 1: 0);
  4477. }
  4478. else
  4479. {
  4480. tempIndex = gun_index;
  4481. }
  4482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4483. {
  4484. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4485. {
  4486. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4487. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4488. }
  4489. }
  4490. }
  4491. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4492. {
  4493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4494. {
  4495. tempIndex = ((gun_index==2) ? 1: 0);
  4496. }
  4497. else
  4498. {
  4499. tempIndex = gun_index;
  4500. }
  4501. for (int index = 0; index < CCS_QUANTITY; index++)
  4502. {
  4503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4504. {
  4505. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4506. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4507. }
  4508. }
  4509. }
  4510. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4511. {
  4512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4513. {
  4514. tempIndex = ((gun_index==2) ? 1: 0);
  4515. }
  4516. else
  4517. {
  4518. tempIndex = gun_index;
  4519. }
  4520. for (int index = 0; index < GB_QUANTITY; index++)
  4521. {
  4522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4523. {
  4524. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4525. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4526. }
  4527. }
  4528. }
  4529. else if(gunType[gun_index] == GUN_TYPE_DO)
  4530. {
  4531. tempIndex = gun_index;
  4532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4533. {
  4534. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4535. {
  4536. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4537. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4538. }
  4539. }
  4540. }
  4541. else
  4542. {
  4543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4544. {
  4545. tempIndex = 2;
  4546. }
  4547. else
  4548. {
  4549. tempIndex = gun_index;
  4550. }
  4551. for (int index = 0; index < AC_QUANTITY; index++)
  4552. {
  4553. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4554. {
  4555. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4556. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4557. }
  4558. }
  4559. }
  4560. random_uuid(guid);
  4561. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4562. {
  4563. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4564. , gun_index +1
  4565. , MESSAGE_TYPE_CALL
  4566. , guid
  4567. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4568. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4569. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4570. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4571. }
  4572. else
  4573. {
  4574. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4575. , gun_index +1
  4576. , MESSAGE_TYPE_CALL
  4577. , guid
  4578. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4579. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4580. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4581. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4582. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4583. }
  4584. #if 1
  4585. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4586. 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*/)
  4587. {
  4588. result = PASS;
  4589. }
  4590. #endif
  4591. strcpy(queuedata, message);
  4592. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4593. OCPP_insert_transaction_msg(YES, queuedata);
  4594. return result;
  4595. }
  4596. int sendStatusNotificationRequest(int gun_index)
  4597. {
  4598. mtrace();
  4599. int result = FAIL;
  4600. char message[600]={0};
  4601. char guid[37];
  4602. int currentStatus = 0;
  4603. struct timeval tmnow;
  4604. struct tm *tm;
  4605. char buf[28];//, usec_buf[6];
  4606. char tempdata[65]={0};
  4607. int tempIndex = 0;
  4608. uint8_t isStateChanged = TRUE;
  4609. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4610. gettimeofday(&tmnow, NULL);
  4611. time_t t;
  4612. t = time(NULL);
  4613. /*UTC time and date*/
  4614. tm = gmtime(&t);
  4615. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4616. #if 0 // remove temporally
  4617. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4618. strcat(buf,".");
  4619. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4620. strcat(buf,usec_buf);
  4621. #endif
  4622. //printf("%s",buf);
  4623. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4624. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4625. // it's option
  4626. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4627. /*
  4628. enum _SYSTEM_STATUS
  4629. {
  4630. S_BOOTING = 0,
  4631. S_IDLE, = 1
  4632. S_AUTHORIZING, =2
  4633. S_REASSIGN_CHECK, =3
  4634. S_REASSIGN, =4
  4635. S_PRECHARGE, =5
  4636. S_PREPARING_FOR_EV, =6
  4637. S_PREPARING_FOR_EVSE, =7
  4638. S_CHARGING, =8
  4639. S_TERMINATING, =9
  4640. S_COMPLETE, =10
  4641. S_ALARM, =11
  4642. S_FAULT =12
  4643. }
  4644. */
  4645. //check Transaction active
  4646. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4647. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4648. {
  4649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4650. {
  4651. tempIndex = ((gun_index==2) ? 1: 0);
  4652. }
  4653. else
  4654. {
  4655. tempIndex = gun_index;
  4656. }
  4657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4658. {
  4659. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4660. {
  4661. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4662. {
  4663. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4664. {
  4665. currentStatus = Preparing; //OCPP Status: Preparing
  4666. }
  4667. else
  4668. {
  4669. currentStatus = Available; //OCPP Status: Available
  4670. }
  4671. }
  4672. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4673. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4674. ) //S_PRECHARGE
  4675. {
  4676. currentStatus = Preparing; //OCPP Status: Preparing
  4677. }
  4678. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4679. {
  4680. currentStatus = Charging; //OCPP Status: Charging
  4681. }
  4682. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4683. {
  4684. currentStatus = Finishing; //OCPP Status: Finishing
  4685. }
  4686. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4687. {
  4688. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4689. }
  4690. 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
  4691. {
  4692. currentStatus = Unavailable; //OCPP Status: Unavailable
  4693. }
  4694. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4695. {
  4696. currentStatus = Faulted; //OCPP Status: Faulted
  4697. }
  4698. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4699. {
  4700. currentStatus = Reserved; //OCPP Status: Reserved
  4701. }
  4702. } //end of the same index
  4703. }//end of for CHAdeMO_QUANTITY
  4704. }
  4705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4706. {
  4707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4708. {
  4709. tempIndex = ((gun_index==2) ? 1: 0);
  4710. }
  4711. else
  4712. {
  4713. tempIndex = gun_index;
  4714. }
  4715. for (int index = 0; index < CCS_QUANTITY; index++)
  4716. {
  4717. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4718. {
  4719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4720. {
  4721. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4722. {
  4723. currentStatus = Preparing; //OCPP Status: Preparing
  4724. }
  4725. else
  4726. {
  4727. currentStatus = Available; //OCPP Status: Available
  4728. }
  4729. }
  4730. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4731. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4732. ) //S_PRECHARGE
  4733. {
  4734. currentStatus = Preparing; //OCPP Status: Preparing
  4735. }
  4736. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4737. {
  4738. currentStatus = Charging; //OCPP Status: Charging
  4739. }
  4740. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4741. {
  4742. currentStatus = Finishing; //OCPP Status: Finishing
  4743. }
  4744. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4745. {
  4746. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4747. }
  4748. 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
  4749. {
  4750. currentStatus = Unavailable; //OCPP Status : Unavailable
  4751. }
  4752. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4753. {
  4754. currentStatus = Faulted; //OCPP Status: Faulted
  4755. }
  4756. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4757. {
  4758. currentStatus = Reserved; //OCPP Status: Reserved
  4759. }
  4760. } //end of the same index
  4761. } // end of for CCS_QUANTITY
  4762. }
  4763. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4764. {
  4765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4766. {
  4767. tempIndex = ((gun_index==2) ? 1: 0);
  4768. }
  4769. else
  4770. {
  4771. tempIndex = gun_index;
  4772. }
  4773. for (int index = 0; index < GB_QUANTITY; index++)
  4774. {
  4775. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4776. {
  4777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4778. {
  4779. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4780. {
  4781. currentStatus = Preparing; //OCPP Status: Preparing
  4782. }
  4783. else
  4784. {
  4785. currentStatus = Available; //OCPP Status: Available
  4786. }
  4787. }
  4788. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4789. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4790. ) //S_PRECHARGE
  4791. {
  4792. currentStatus = Preparing; //OCPP Status: Preparing
  4793. }
  4794. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4795. {
  4796. currentStatus = Charging; //OCPP Status: Charging
  4797. }
  4798. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4799. {
  4800. currentStatus = Finishing; //OCPP Status: Finishing
  4801. }
  4802. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4803. {
  4804. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4805. }
  4806. 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
  4807. {
  4808. currentStatus = Unavailable; //OCPP Status: Unavailable
  4809. }
  4810. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4811. {
  4812. currentStatus = Faulted; //OCPP Status: Faulted
  4813. }
  4814. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4815. {
  4816. currentStatus = Reserved; //OCPP Status: Reserved
  4817. }
  4818. } //end of the same index
  4819. } // end of for GB_QUANTITY
  4820. }
  4821. else if(gunType[gun_index] == GUN_TYPE_DO)
  4822. {
  4823. tempIndex = gun_index;
  4824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4825. {
  4826. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4827. {
  4828. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4829. {
  4830. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4831. {
  4832. currentStatus = Preparing; //OCPP Status: Preparing
  4833. }
  4834. else
  4835. {
  4836. currentStatus = Available; //OCPP Status: Available
  4837. }
  4838. }
  4839. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4840. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4841. ) //S_PRECHARGE
  4842. {
  4843. currentStatus = Preparing; //OCPP Status: Preparing
  4844. }
  4845. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4846. {
  4847. currentStatus = Charging; //OCPP Status: Charging
  4848. }
  4849. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4850. {
  4851. currentStatus = Finishing; //OCPP Status: Finishing
  4852. }
  4853. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4854. {
  4855. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4856. }
  4857. 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
  4858. {
  4859. currentStatus = Unavailable; //OCPP Status: Unavailable
  4860. }
  4861. 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
  4862. {
  4863. currentStatus = Faulted; //OCPP Status: Faulted
  4864. }
  4865. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4866. {
  4867. currentStatus = Reserved; //OCPP Status: Reserved
  4868. }
  4869. } //end of the same index
  4870. }
  4871. }
  4872. else
  4873. {
  4874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4875. {
  4876. tempIndex = 2;
  4877. }
  4878. else
  4879. {
  4880. tempIndex = gun_index;
  4881. }
  4882. for (int index = 0; index < AC_QUANTITY; index++)
  4883. {
  4884. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4885. {
  4886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4887. {
  4888. 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))
  4889. {
  4890. currentStatus = Preparing; //OCPP Status: Preparing
  4891. }
  4892. else
  4893. {
  4894. currentStatus = Available; //OCPP Status: Available
  4895. }
  4896. }
  4897. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4898. {
  4899. currentStatus = Preparing; //OCPP Status: Preparing
  4900. }
  4901. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4902. {
  4903. currentStatus = Charging; //OCPP Status: Charging
  4904. }
  4905. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4906. {
  4907. currentStatus = Finishing; //OCPP Status: Finishing
  4908. }
  4909. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4910. {
  4911. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4912. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4913. else
  4914. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4915. }
  4916. 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
  4917. {
  4918. currentStatus = Unavailable; //OCPP Status: Unavailable
  4919. }
  4920. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4921. {
  4922. currentStatus = Faulted; //OCPP Status: Faulted
  4923. }
  4924. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4925. {
  4926. currentStatus = Reserved; //OCPP Status: Reserved
  4927. }
  4928. }//end of the same index
  4929. }//end of for AC_QUANTITY
  4930. }
  4931. //it's option
  4932. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4933. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4934. {
  4935. isStateChanged = FALSE;
  4936. }
  4937. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4938. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4939. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4940. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4941. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4942. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4943. random_uuid(guid);
  4944. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4945. , MESSAGE_TYPE_CALL
  4946. , guid
  4947. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4948. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4949. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4950. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4951. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4952. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4953. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4954. if((server_sign == TRUE) && isStateChanged)
  4955. {
  4956. LWS_Send(message);
  4957. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4958. 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*/)
  4959. {
  4960. //DEBUG_ERROR("statusNotification mapitem pass");
  4961. result = PASS;
  4962. }
  4963. }
  4964. else
  4965. {
  4966. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4967. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4968. result = PASS;
  4969. }
  4970. return result;
  4971. }
  4972. int sendStopTransactionRequest(int gun_index)
  4973. {
  4974. mtrace();
  4975. int result = FAIL;
  4976. //char message[1500]={0};
  4977. char guid[37]={0};
  4978. char tempdata[65]={0};
  4979. int tempIndex = 0;
  4980. char TempStopTransaction[256];
  4981. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4982. //int idx_sample=0;
  4983. DEBUG_INFO("sendStopTransactionRequest \n");
  4984. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4985. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4986. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4987. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4988. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4989. {
  4990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4991. {
  4992. tempIndex = ((gun_index==2) ? 1: 0);
  4993. }
  4994. else
  4995. {
  4996. tempIndex = gun_index;
  4997. }
  4998. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4999. {
  5000. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5001. {
  5002. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5003. }
  5004. }// END OF CHAdeMO_QUANTITY
  5005. }
  5006. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5007. {
  5008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5009. {
  5010. tempIndex = ((gun_index==2) ? 1: 0);
  5011. }
  5012. else
  5013. {
  5014. tempIndex = gun_index;
  5015. }
  5016. for (int index = 0; index < CCS_QUANTITY; index++)
  5017. {
  5018. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5019. {
  5020. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5021. }
  5022. }// END OF CCS_QUANTITY
  5023. }
  5024. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5025. {
  5026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5027. {
  5028. tempIndex = ((gun_index==2) ? 1: 0);
  5029. }
  5030. else
  5031. {
  5032. tempIndex = gun_index;
  5033. }
  5034. for (int index = 0; index < GB_QUANTITY; index++)
  5035. {
  5036. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5037. {
  5038. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5039. }
  5040. }// END OF GB_QUANTITY
  5041. }
  5042. else if(gunType[gun_index] == GUN_TYPE_DO)
  5043. {
  5044. tempIndex = gun_index;
  5045. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5046. {
  5047. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5048. {
  5049. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5050. }
  5051. }// END OF GB_QUANTITY
  5052. }
  5053. else
  5054. {
  5055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5056. {
  5057. tempIndex = 2;
  5058. }
  5059. else
  5060. {
  5061. tempIndex = gun_index;
  5062. }
  5063. for (int index = 0; index < AC_QUANTITY; index++)
  5064. {
  5065. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5066. {
  5067. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5068. }
  5069. }// END OF AC_QUANTITY
  5070. }
  5071. //====================================== Stop Transaction Time =====================================================
  5072. struct timeval tmnow;
  5073. struct tm *tm;
  5074. char buf[28];//, usec_buf[6];
  5075. gettimeofday(&tmnow, NULL);
  5076. time_t t;
  5077. t = time(NULL);
  5078. /*UTC time and date*/
  5079. tm = gmtime(&t);
  5080. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5082. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5083. random_uuid(guid);
  5084. /***********************************transactionData******************************************************/
  5085. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5087. //=================================
  5088. // Transaction_Begin
  5089. //=================================
  5090. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5091. {
  5092. //============================================ Energy.Active.Import.Interval ================================
  5093. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5096. 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*/]);
  5097. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5098. 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))
  5099. {
  5100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5101. }
  5102. else
  5103. {
  5104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5105. }
  5106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5108. }
  5109. //=================================
  5110. // Transaction_End
  5111. //=================================
  5112. // ================================= Current.Import L1 ===============================================
  5113. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5114. {
  5115. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5116. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5117. {
  5118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5119. {
  5120. tempIndex = ((gun_index==2) ? 1: 0);
  5121. }
  5122. else
  5123. {
  5124. tempIndex = gun_index;
  5125. }
  5126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5127. {
  5128. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5129. {
  5130. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5131. }
  5132. }// End of for CHAdeMO_QUANTITY
  5133. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5134. }
  5135. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5136. {
  5137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5138. {
  5139. tempIndex = ((gun_index==2) ? 1: 0);
  5140. }
  5141. else
  5142. {
  5143. tempIndex = gun_index;
  5144. }
  5145. for (int index = 0; index < CCS_QUANTITY; index++)
  5146. {
  5147. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5148. {
  5149. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5150. }
  5151. }// End of for CCS_QUANTITY
  5152. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5153. }
  5154. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5155. {
  5156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5157. {
  5158. tempIndex = ((gun_index==2) ? 1: 0);
  5159. }
  5160. else
  5161. {
  5162. tempIndex = gun_index;
  5163. }
  5164. for (int index = 0; index < GB_QUANTITY; index++)
  5165. {
  5166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5167. {
  5168. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5169. }
  5170. }// End of for GB_QUANTITY
  5171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5172. }
  5173. else if(gunType[gun_index] == GUN_TYPE_DO)
  5174. {
  5175. tempIndex = gun_index;
  5176. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5177. {
  5178. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5179. {
  5180. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5181. }
  5182. }
  5183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5184. }
  5185. else
  5186. {
  5187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5188. {
  5189. tempIndex = 2;
  5190. }
  5191. else
  5192. {
  5193. tempIndex = gun_index;
  5194. }
  5195. for (int index = 0; index < AC_QUANTITY; index++)
  5196. {
  5197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5198. {
  5199. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5200. }
  5201. }// End of for AC_QUANTITY
  5202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5203. }
  5204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5205. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5209. }
  5210. // ================================= Energy.Active.Import.Interval ==============================================
  5211. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5212. {
  5213. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5214. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5215. {
  5216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5217. {
  5218. tempIndex = ((gun_index==2) ? 1: 0);
  5219. }
  5220. else
  5221. {
  5222. tempIndex = gun_index;
  5223. }
  5224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5225. {
  5226. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5227. {
  5228. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5229. }
  5230. }// END OF CHAdeMO_QUANTITY
  5231. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5232. }
  5233. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5234. {
  5235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5236. {
  5237. tempIndex = ((gun_index==2) ? 1: 0);
  5238. }
  5239. else
  5240. {
  5241. tempIndex = gun_index;
  5242. }
  5243. for (int index = 0; index < CCS_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5248. }
  5249. }// END OF CCS_QUANTITY
  5250. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5251. }
  5252. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5253. {
  5254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5255. {
  5256. tempIndex = ((gun_index==2) ? 1: 0);
  5257. }
  5258. else
  5259. {
  5260. tempIndex = gun_index;
  5261. }
  5262. for (int index = 0; index < GB_QUANTITY; index++)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5265. {
  5266. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5267. }
  5268. }// END OF GB_QUANTITY
  5269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5270. }
  5271. else if(gunType[gun_index] == GUN_TYPE_DO)
  5272. {
  5273. tempIndex = gun_index;
  5274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5275. {
  5276. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5277. {
  5278. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5279. }
  5280. }
  5281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5282. }
  5283. else
  5284. {
  5285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5286. {
  5287. tempIndex = 2;
  5288. }
  5289. else
  5290. {
  5291. tempIndex = gun_index;
  5292. }
  5293. for (int index = 0; index < AC_QUANTITY; index++)
  5294. {
  5295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5296. {
  5297. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5298. }
  5299. }// END OF AC_QUANTITY
  5300. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5301. }
  5302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5307. }
  5308. //=================================== Power.Active.Import ==================================================
  5309. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5310. {
  5311. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5312. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5313. {
  5314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5315. {
  5316. tempIndex = ((gun_index==2) ? 1: 0);
  5317. }
  5318. else
  5319. {
  5320. tempIndex = gun_index;
  5321. }
  5322. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5323. {
  5324. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5325. {
  5326. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5327. }
  5328. } // End for CHAdeMO_QUANTITY
  5329. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5330. }
  5331. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5332. {
  5333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5334. {
  5335. tempIndex = ((gun_index==2) ? 1: 0);
  5336. }
  5337. else
  5338. {
  5339. tempIndex = gun_index;
  5340. }
  5341. for (int index = 0; index < CCS_QUANTITY; index++)
  5342. {
  5343. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5344. {
  5345. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5346. }
  5347. } // END for CCS_QUANTITY
  5348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5349. }
  5350. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5351. {
  5352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5353. {
  5354. tempIndex = ((gun_index==2) ? 1: 0);
  5355. }
  5356. else
  5357. {
  5358. tempIndex = gun_index;
  5359. }
  5360. for (int index = 0; index < GB_QUANTITY; index++)
  5361. {
  5362. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5363. {
  5364. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5365. }
  5366. }// END for GB_QUANTITY
  5367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5368. }
  5369. else if(gunType[gun_index] == GUN_TYPE_DO)
  5370. {
  5371. tempIndex = gun_index;
  5372. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5373. {
  5374. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5375. {
  5376. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5377. }
  5378. }
  5379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5380. }
  5381. else
  5382. {
  5383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5384. {
  5385. tempIndex = 2;
  5386. }
  5387. else
  5388. {
  5389. tempIndex = gun_index;
  5390. }
  5391. for (int index = 0; index < AC_QUANTITY; index++)
  5392. {
  5393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5394. {
  5395. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5396. }
  5397. } // END for AC_QUANTITY
  5398. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5399. }
  5400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5401. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5402. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5403. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5404. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5405. }
  5406. //============================ Voltage L1 ====================================
  5407. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5408. {
  5409. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5410. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5411. {
  5412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5413. {
  5414. tempIndex = ((gun_index==2) ? 1: 0);
  5415. }
  5416. else
  5417. {
  5418. tempIndex = gun_index;
  5419. }
  5420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5421. {
  5422. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5423. {
  5424. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5425. }
  5426. } // END OF FOR CHAdeMO_QUANTITY
  5427. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5428. }
  5429. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5430. {
  5431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5432. {
  5433. tempIndex = ((gun_index==2) ? 1: 0);
  5434. }
  5435. else
  5436. {
  5437. tempIndex = gun_index;
  5438. }
  5439. for (int index = 0; index < CCS_QUANTITY; index++)
  5440. {
  5441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5442. {
  5443. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5444. }
  5445. } // END OF FOR CCS_QUANTITY
  5446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5447. }
  5448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5449. {
  5450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5451. {
  5452. tempIndex = ((gun_index==2) ? 1: 0);
  5453. }
  5454. else
  5455. {
  5456. tempIndex = gun_index;
  5457. }
  5458. for (int index = 0; index < GB_QUANTITY; index++)
  5459. {
  5460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5461. {
  5462. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5463. }
  5464. } // END OF FOR GB_QUANTITY
  5465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5466. }
  5467. else if(gunType[gun_index] == GUN_TYPE_DO)
  5468. {
  5469. tempIndex = gun_index;
  5470. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5471. {
  5472. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5473. {
  5474. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5475. }
  5476. }
  5477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5478. }
  5479. else
  5480. {
  5481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5482. {
  5483. tempIndex = 2;
  5484. }
  5485. else
  5486. {
  5487. tempIndex = gun_index;
  5488. }
  5489. for (int index = 0; index < AC_QUANTITY; index++)
  5490. {
  5491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5492. {
  5493. 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
  5494. }
  5495. } // END OF FOR AC_QUANTITY
  5496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5497. }
  5498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5499. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5500. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5501. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5502. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5503. }
  5504. //====================== End SoC ================================
  5505. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5506. {
  5507. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5508. 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))
  5509. {
  5510. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5511. {
  5512. tempIndex = ((gun_index==2) ? 1: 0);
  5513. }
  5514. else
  5515. {
  5516. tempIndex = gun_index;
  5517. }
  5518. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5519. {
  5520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5521. {
  5522. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5523. {
  5524. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5525. }
  5526. }
  5527. }
  5528. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5529. {
  5530. for (int index = 0; index < CCS_QUANTITY; index++)
  5531. {
  5532. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5533. {
  5534. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5535. }
  5536. }
  5537. }
  5538. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5539. {
  5540. for (int index = 0; index < GB_QUANTITY; index++)
  5541. {
  5542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5543. {
  5544. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5545. }
  5546. }
  5547. }
  5548. else if(gunType[gun_index] == GUN_TYPE_DO)
  5549. {
  5550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5551. {
  5552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5553. {
  5554. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5555. }
  5556. }
  5557. }
  5558. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5562. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5564. } // END FOR DC CASE
  5565. }
  5566. // ================================= Current.Import L2 ===============================================
  5567. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5568. {
  5569. // AC 3 phse L2 current
  5570. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5571. {
  5572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5573. {
  5574. tempIndex = 2;
  5575. }
  5576. else
  5577. {
  5578. tempIndex = gun_index;
  5579. }
  5580. for (int index = 0; index < AC_QUANTITY; index++)
  5581. {
  5582. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5583. {
  5584. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5585. }
  5586. }// End of for AC_QUANTITY
  5587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5588. }
  5589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5590. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5591. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5592. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5593. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5594. }
  5595. // ================================= Current.Import L3 ===============================================
  5596. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5597. {
  5598. // AC 3 phse L3 current
  5599. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5600. {
  5601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5602. {
  5603. tempIndex = 2;
  5604. }
  5605. else
  5606. {
  5607. tempIndex = gun_index;
  5608. }
  5609. for (int index = 0; index < AC_QUANTITY; index++)
  5610. {
  5611. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5612. {
  5613. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5614. }
  5615. }// End of for AC_QUANTITY
  5616. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5617. }
  5618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5623. }
  5624. //============================ Voltage L2 ====================================
  5625. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5626. {
  5627. // AC 3 phse L2 voltage
  5628. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5631. {
  5632. tempIndex = 2;
  5633. }
  5634. else
  5635. {
  5636. tempIndex = gun_index;
  5637. }
  5638. for (int index = 0; index < AC_QUANTITY; index++)
  5639. {
  5640. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5641. {
  5642. 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
  5643. }
  5644. } // END OF FOR AC_QUANTITY
  5645. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5646. }
  5647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5648. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5652. }
  5653. //============================ Voltage L3 ====================================
  5654. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5655. {
  5656. // AC 3 phse L3 voltage
  5657. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5658. {
  5659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5660. {
  5661. tempIndex = 2;
  5662. }
  5663. else
  5664. {
  5665. tempIndex = gun_index;
  5666. }
  5667. for (int index = 0; index < AC_QUANTITY; index++)
  5668. {
  5669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5670. {
  5671. 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
  5672. }
  5673. } // END OF FOR AC_QUANTITY
  5674. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5675. }
  5676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5681. }
  5682. //====================== Start SoC ================================
  5683. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5684. {
  5685. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5686. 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))
  5687. {
  5688. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5689. {
  5690. tempIndex = ((gun_index==2) ? 1: 0);
  5691. }
  5692. else
  5693. {
  5694. tempIndex = gun_index;
  5695. }
  5696. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5697. {
  5698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5699. {
  5700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5701. {
  5702. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5703. }
  5704. }
  5705. }
  5706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5707. {
  5708. for (int index = 0; index < CCS_QUANTITY; index++)
  5709. {
  5710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5711. {
  5712. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5713. }
  5714. }
  5715. }
  5716. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5717. {
  5718. for (int index = 0; index < GB_QUANTITY; index++)
  5719. {
  5720. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5721. {
  5722. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5723. }
  5724. }
  5725. }
  5726. else if(gunType[gun_index] == GUN_TYPE_DO)
  5727. {
  5728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5729. {
  5730. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5731. {
  5732. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5733. }
  5734. }
  5735. }
  5736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5742. } // END FOR DC CASE
  5743. }
  5744. //================================================ Message create ====================================================
  5745. json_object *StopTransaction = json_object_new_object();
  5746. json_object *transactionDatas = json_object_new_array();
  5747. json_object *sampledValues = json_object_new_array();
  5748. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5749. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5750. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5751. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5752. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5753. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5754. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5755. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5756. {
  5757. json_object *transactionData = json_object_new_object();
  5758. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5759. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5760. {
  5761. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5762. {
  5763. json_object *sampledValue = json_object_new_object();
  5764. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5765. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5766. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5767. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5768. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5769. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5770. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5771. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5772. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5773. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5774. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5775. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5776. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5777. json_object_array_add(sampledValues, sampledValue);
  5778. }
  5779. }
  5780. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5781. json_object_array_add(transactionDatas, transactionData);
  5782. }
  5783. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5784. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5785. ,MESSAGE_TYPE_CALL
  5786. ,guid
  5787. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5788. json_object_put(StopTransaction);
  5789. #if 1 // for TempStopTransaction
  5790. //Delete TempStopTransaction
  5791. if((access(TempStopTransaction,F_OK))!=-1)
  5792. {
  5793. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5794. }
  5795. #endif
  5796. #if 1
  5797. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5798. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5799. {
  5800. result = PASS;
  5801. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5802. }
  5803. #endif
  5804. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5805. OCPP_insert_transaction_msg(NO, queuedata);
  5806. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5807. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5808. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5809. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5810. {
  5811. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5812. }
  5813. //for test
  5814. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5815. return result;
  5816. }
  5817. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5818. {
  5819. mtrace();
  5820. int result = FAIL;
  5821. char guid[37]={0};
  5822. char tempdata[65]={0};
  5823. int tempIndex = 0;
  5824. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5825. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5826. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5827. //set value
  5828. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5829. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5830. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5831. -1);
  5832. random_uuid(guid);
  5833. //UTC Date time
  5834. struct timeval tmnow;
  5835. struct tm *tm;
  5836. char buf[28];//, usec_buf[6];
  5837. gettimeofday(&tmnow, NULL);
  5838. time_t t;
  5839. t = time(NULL);
  5840. /*UTC time and date*/
  5841. tm = gmtime(&t);
  5842. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5843. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5844. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5845. //********************************(1)Current.Import L1************************************************/
  5846. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5847. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5848. (dataType == ReadingContext_Trigger))
  5849. {
  5850. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5851. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5852. {
  5853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5854. {
  5855. tempIndex = ((gun_index==2) ? 1: 0);
  5856. }
  5857. else
  5858. {
  5859. tempIndex = gun_index;
  5860. }
  5861. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5862. {
  5863. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5864. {
  5865. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5866. }
  5867. }
  5868. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5869. }
  5870. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5871. {
  5872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5873. {
  5874. tempIndex = ((gun_index==2) ? 1: 0);
  5875. }
  5876. else
  5877. {
  5878. tempIndex = gun_index;
  5879. }
  5880. for (int index = 0; index < CCS_QUANTITY; index++)
  5881. {
  5882. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5883. {
  5884. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5885. }
  5886. }
  5887. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5888. }
  5889. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5890. {
  5891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5892. {
  5893. tempIndex = ((gun_index==2) ? 1: 0);
  5894. }
  5895. else
  5896. {
  5897. tempIndex = gun_index;
  5898. }
  5899. for (int index = 0; index < GB_QUANTITY; index++)
  5900. {
  5901. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5902. {
  5903. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5904. }
  5905. }
  5906. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5907. }
  5908. else if(gunType[gun_index] == GUN_TYPE_DO)
  5909. {
  5910. tempIndex = gun_index;
  5911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5916. }
  5917. }
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5919. }
  5920. else
  5921. {
  5922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5923. {
  5924. tempIndex = 2;
  5925. }
  5926. else
  5927. {
  5928. tempIndex = gun_index;
  5929. }
  5930. for (int index = 0; index < AC_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5935. }
  5936. }
  5937. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5938. }
  5939. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5940. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5941. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5942. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5943. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5944. }
  5945. //********************************(2)Energy.Active.Import.Register ************************************************/
  5946. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5947. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5948. (dataType == ReadingContext_Trigger))
  5949. {
  5950. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5951. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5952. {
  5953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5954. {
  5955. tempIndex = ((gun_index==2) ? 1: 0);
  5956. }
  5957. else
  5958. {
  5959. tempIndex = gun_index;
  5960. }
  5961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5964. {
  5965. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5966. }
  5967. }
  5968. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5969. }
  5970. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5971. {
  5972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5973. {
  5974. tempIndex = ((gun_index==2) ? 1: 0);
  5975. }
  5976. else
  5977. {
  5978. tempIndex = gun_index;
  5979. }
  5980. for (int index = 0; index < CCS_QUANTITY; index++)
  5981. {
  5982. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5983. {
  5984. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5985. }
  5986. }
  5987. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5988. }
  5989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5990. {
  5991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5992. {
  5993. tempIndex = ((gun_index==2) ? 1: 0);
  5994. }
  5995. else
  5996. {
  5997. tempIndex = gun_index;
  5998. }
  5999. for (int index = 0; index < GB_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6002. {
  6003. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6004. }
  6005. }
  6006. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6007. }
  6008. else if(gunType[gun_index] == GUN_TYPE_DO)
  6009. {
  6010. tempIndex = gun_index;
  6011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6012. {
  6013. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6014. {
  6015. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6016. }
  6017. }
  6018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6019. }
  6020. else
  6021. {
  6022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6023. {
  6024. tempIndex = 2;
  6025. }
  6026. else
  6027. {
  6028. tempIndex = gun_index;
  6029. }
  6030. for (int index = 0; index < AC_QUANTITY; index++)
  6031. {
  6032. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6033. {
  6034. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6035. }
  6036. }
  6037. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6038. }
  6039. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6040. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6041. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6042. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6043. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6044. }
  6045. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6046. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6047. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6048. (dataType == ReadingContext_Trigger))
  6049. {
  6050. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6051. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6052. {
  6053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6054. {
  6055. tempIndex = ((gun_index==2) ? 1: 0);
  6056. }
  6057. else
  6058. {
  6059. tempIndex = gun_index;
  6060. }
  6061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6062. {
  6063. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6064. {
  6065. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6066. }
  6067. } // END OF FOR CHAdeMO_QUANTITY
  6068. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6069. }
  6070. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6071. {
  6072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6073. {
  6074. tempIndex = ((gun_index==2) ? 1: 0);
  6075. }
  6076. else
  6077. {
  6078. tempIndex = gun_index;
  6079. }
  6080. for (int index = 0; index < CCS_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6085. }
  6086. } // END OF CCS_QUANTITY
  6087. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6088. }
  6089. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6090. {
  6091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6092. {
  6093. tempIndex = ((gun_index==2) ? 1: 0);
  6094. }
  6095. else
  6096. {
  6097. tempIndex = gun_index;
  6098. }
  6099. for (int index = 0; index < GB_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6104. }
  6105. } // END OF GB_QUANTITY
  6106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6107. }
  6108. else if(gunType[gun_index] == GUN_TYPE_DO)
  6109. {
  6110. tempIndex = gun_index;
  6111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6112. {
  6113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6114. {
  6115. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6116. }
  6117. }
  6118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6119. }
  6120. else
  6121. {
  6122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6123. {
  6124. tempIndex = 2;
  6125. }
  6126. else
  6127. {
  6128. tempIndex = gun_index;
  6129. }
  6130. for (int index = 0; index < AC_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6133. {
  6134. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6135. }
  6136. }
  6137. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6138. }
  6139. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6140. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6141. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6142. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6143. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6144. }
  6145. //********************************(4)Power.Active.Import************************************************/
  6146. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6147. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6148. (dataType == ReadingContext_Trigger))
  6149. {
  6150. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6151. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6152. {
  6153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6154. {
  6155. tempIndex = ((gun_index==2) ? 1: 0);
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6164. {
  6165. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6166. }
  6167. } // END OF FOR
  6168. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6169. }
  6170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6171. {
  6172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6173. {
  6174. tempIndex = ((gun_index==2) ? 1: 0);
  6175. }
  6176. else
  6177. {
  6178. tempIndex = gun_index;
  6179. }
  6180. for (int index = 0; index < CCS_QUANTITY; index++)
  6181. {
  6182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6183. {
  6184. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6185. }
  6186. }
  6187. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6188. }
  6189. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6190. {
  6191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6192. {
  6193. tempIndex = ((gun_index==2) ? 1: 0);
  6194. }
  6195. else
  6196. {
  6197. tempIndex = gun_index;
  6198. }
  6199. for (int index = 0; index < GB_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6202. {
  6203. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6204. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6205. }
  6206. }
  6207. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6208. }
  6209. else if(gunType[gun_index] == GUN_TYPE_DO)
  6210. {
  6211. tempIndex = gun_index;
  6212. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6213. {
  6214. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6215. {
  6216. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6217. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6218. }
  6219. }
  6220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6221. }
  6222. else
  6223. {
  6224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6225. {
  6226. tempIndex = 2;
  6227. }
  6228. else
  6229. {
  6230. tempIndex = gun_index;
  6231. }
  6232. for (int index = 0; index < AC_QUANTITY; index++)
  6233. {
  6234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6235. {
  6236. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6237. }
  6238. }
  6239. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6240. }
  6241. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6242. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6243. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6244. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6245. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6246. }
  6247. //***********************************************(5)VOLTAGE L1******************************************************/
  6248. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6249. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6250. (dataType == ReadingContext_Trigger))
  6251. {
  6252. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6253. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6254. {
  6255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6256. {
  6257. tempIndex = ((gun_index==2) ? 1: 0);
  6258. }
  6259. else
  6260. {
  6261. tempIndex = gun_index;
  6262. }
  6263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6264. {
  6265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6266. {
  6267. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6268. }
  6269. }
  6270. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6271. }
  6272. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6273. {
  6274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6275. {
  6276. tempIndex = ((gun_index==2) ? 1: 0);
  6277. }
  6278. else
  6279. {
  6280. tempIndex = gun_index;
  6281. }
  6282. for (int index = 0; index < CCS_QUANTITY; index++)
  6283. {
  6284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6285. {
  6286. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6287. }
  6288. }
  6289. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6290. }
  6291. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6292. {
  6293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6294. {
  6295. tempIndex = ((gun_index==2) ? 1: 0);
  6296. }
  6297. else
  6298. {
  6299. tempIndex = gun_index;
  6300. }
  6301. for (int index = 0; index < GB_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6304. {
  6305. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6306. }
  6307. }
  6308. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6309. }
  6310. else if(gunType[gun_index] == GUN_TYPE_DO)
  6311. {
  6312. tempIndex = gun_index;
  6313. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6314. {
  6315. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6316. {
  6317. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6318. }
  6319. }
  6320. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6321. }
  6322. else
  6323. {
  6324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6325. {
  6326. tempIndex = 2;
  6327. }
  6328. else
  6329. {
  6330. tempIndex = gun_index;
  6331. }
  6332. for (int index = 0; index < AC_QUANTITY; index++)
  6333. {
  6334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6335. {
  6336. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6337. }
  6338. }
  6339. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6340. }
  6341. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6342. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6343. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6344. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6345. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6346. }
  6347. //***********************************************(6)SOC******************************************************/
  6348. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6349. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6350. (dataType == ReadingContext_Trigger))
  6351. {
  6352. 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))
  6353. {
  6354. //idx_sample=5;
  6355. //sampledValue = NULL;
  6356. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6357. {
  6358. tempIndex = ((gun_index==2) ? 1: 0);
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6365. {
  6366. //tempIndex = ((gun_index==2) ? 1: 0);
  6367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6370. {
  6371. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6372. }
  6373. }
  6374. }
  6375. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6376. {
  6377. //tempIndex = ((gun_index==2) ? 1: 0);
  6378. for (int index = 0; index < CCS_QUANTITY; index++)
  6379. {
  6380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6381. {
  6382. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6383. }
  6384. }
  6385. }
  6386. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6387. {
  6388. //tempIndex = ((gun_index==2) ? 1: 0);
  6389. for (int index = 0; index < GB_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6394. }
  6395. }
  6396. }
  6397. else if(gunType[gun_index] == GUN_TYPE_DO)
  6398. {
  6399. //tempIndex = ((gun_index==2) ? 1: 0);
  6400. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6401. {
  6402. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6403. {
  6404. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6405. }
  6406. }
  6407. }
  6408. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6409. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6410. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6412. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6413. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6414. }
  6415. }
  6416. //********************************(7)Current.Import L2************************************************/
  6417. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6418. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6419. (dataType == ReadingContext_Trigger))
  6420. {
  6421. // Only for AC 3 phase
  6422. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6423. {
  6424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6425. {
  6426. tempIndex = 2;
  6427. }
  6428. else
  6429. {
  6430. tempIndex = gun_index;
  6431. }
  6432. for (int index = 0; index < AC_QUANTITY; index++)
  6433. {
  6434. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6435. {
  6436. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6437. }
  6438. }
  6439. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6440. }
  6441. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6442. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6443. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6444. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6445. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6446. }
  6447. //********************************(8)Current.Import L3************************************************/
  6448. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6449. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6450. (dataType == ReadingContext_Trigger))
  6451. {
  6452. // Only for AC 3 phase
  6453. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6454. {
  6455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6456. {
  6457. tempIndex = 2;
  6458. }
  6459. else
  6460. {
  6461. tempIndex = gun_index;
  6462. }
  6463. for (int index = 0; index < AC_QUANTITY; index++)
  6464. {
  6465. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6466. {
  6467. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6468. }
  6469. }
  6470. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6471. }
  6472. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6473. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6474. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6476. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6477. }
  6478. //***********************************************(9)VOLTAGE L2******************************************************/
  6479. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6480. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6481. (dataType == ReadingContext_Trigger))
  6482. {
  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[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6498. }
  6499. }
  6500. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6501. }
  6502. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6503. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6504. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6507. }
  6508. //***********************************************(10)VOLTAGE L3******************************************************/
  6509. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6510. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6511. (dataType == ReadingContext_Trigger))
  6512. {
  6513. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6514. {
  6515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6516. {
  6517. tempIndex = 2;
  6518. }
  6519. else
  6520. {
  6521. tempIndex = gun_index;
  6522. }
  6523. for (int index = 0; index < AC_QUANTITY; index++)
  6524. {
  6525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6526. {
  6527. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6528. }
  6529. }
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6537. }
  6538. //***********************************************(11)Current.Offered******************************************************/
  6539. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6540. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6541. (dataType == ReadingContext_Trigger))
  6542. {
  6543. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6544. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6545. {
  6546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6547. {
  6548. tempIndex = ((gun_index==2) ? 1: 0);
  6549. }
  6550. else
  6551. {
  6552. tempIndex = gun_index;
  6553. }
  6554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6557. {
  6558. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6559. }
  6560. } // END OF FOR CHAdeMO_QUANTITY
  6561. }
  6562. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6563. {
  6564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6565. {
  6566. tempIndex = ((gun_index==2) ? 1: 0);
  6567. }
  6568. else
  6569. {
  6570. tempIndex = gun_index;
  6571. }
  6572. for (int index = 0; index < CCS_QUANTITY; index++)
  6573. {
  6574. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6575. {
  6576. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6577. }
  6578. } // END OF CCS_QUANTITY
  6579. }
  6580. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6581. {
  6582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6583. {
  6584. tempIndex = ((gun_index==2) ? 1: 0);
  6585. }
  6586. else
  6587. {
  6588. tempIndex = gun_index;
  6589. }
  6590. for (int index = 0; index < GB_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6593. {
  6594. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6595. }
  6596. } // END OF GB_QUANTITY
  6597. }
  6598. else if(gunType[gun_index] == GUN_TYPE_DO)
  6599. {
  6600. tempIndex = gun_index;
  6601. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6602. {
  6603. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6604. {
  6605. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6606. }
  6607. }
  6608. }
  6609. else
  6610. {
  6611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6612. {
  6613. tempIndex = 2;
  6614. }
  6615. else
  6616. {
  6617. tempIndex = gun_index;
  6618. }
  6619. for (int index = 0; index < AC_QUANTITY; index++)
  6620. {
  6621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6622. {
  6623. uint16_t currentOffer;
  6624. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6625. {
  6626. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6627. }
  6628. else
  6629. {
  6630. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6631. }
  6632. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6633. }
  6634. }
  6635. }
  6636. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6637. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6638. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6639. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6640. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6641. }
  6642. //***********************************************(12)Power.Offered******************************************************/
  6643. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6644. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6645. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6646. {
  6647. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6648. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6649. {
  6650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6651. {
  6652. tempIndex = ((gun_index==2) ? 1: 0);
  6653. }
  6654. else
  6655. {
  6656. tempIndex = gun_index;
  6657. }
  6658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6659. {
  6660. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6661. {
  6662. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6663. }
  6664. } // END OF FOR CHAdeMO_QUANTITY
  6665. }
  6666. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6667. {
  6668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6669. {
  6670. tempIndex = ((gun_index==2) ? 1: 0);
  6671. }
  6672. else
  6673. {
  6674. tempIndex = gun_index;
  6675. }
  6676. for (int index = 0; index < CCS_QUANTITY; index++)
  6677. {
  6678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6679. {
  6680. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6681. }
  6682. } // END OF CCS_QUANTITY
  6683. }
  6684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6685. {
  6686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6687. {
  6688. tempIndex = ((gun_index==2) ? 1: 0);
  6689. }
  6690. else
  6691. {
  6692. tempIndex = gun_index;
  6693. }
  6694. for (int index = 0; index < GB_QUANTITY; index++)
  6695. {
  6696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6697. {
  6698. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6699. }
  6700. } // END OF GB_QUANTITY
  6701. }
  6702. else if(gunType[gun_index] == GUN_TYPE_DO)
  6703. {
  6704. tempIndex = gun_index;
  6705. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6706. {
  6707. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6708. {
  6709. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6710. }
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6714. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6715. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6716. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6717. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6718. }
  6719. // Message create ====================================================================================================
  6720. if(TRUE)
  6721. {
  6722. json_object *MeterValueReq = json_object_new_object();
  6723. json_object *MeterValues = json_object_new_array();
  6724. json_object *sampledValues = json_object_new_array();
  6725. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6726. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6727. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6728. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6729. {
  6730. json_object *MeterValue = json_object_new_object();
  6731. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6732. {
  6733. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6734. {
  6735. json_object *sampledValue = json_object_new_object();
  6736. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6737. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6738. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6739. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6740. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6741. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6742. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6743. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6744. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6745. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6746. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6747. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6748. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6749. json_object_array_add(sampledValues, sampledValue);
  6750. }
  6751. }
  6752. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6753. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6754. json_object_array_add(MeterValues, MeterValue);
  6755. }
  6756. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6757. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6758. ,gun_index + 1
  6759. ,MESSAGE_TYPE_CALL
  6760. ,guid
  6761. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6762. json_object_put(MeterValueReq);
  6763. }
  6764. // Put request guid to hash map
  6765. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6766. 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*/)
  6767. {
  6768. result = PASS;
  6769. //DEBUG_INFO("MeterValues mapitem pass\n");
  6770. }
  6771. if((dataType != ReadingContext_Trigger) &&
  6772. (dataType != ReadingContext_Sample_Clock) &&
  6773. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6774. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6775. else
  6776. {
  6777. if(FirstHeartBeat)
  6778. LWS_Send(queuedata +2);
  6779. }
  6780. return result;
  6781. }
  6782. int sendLogStatusNotificationRequest(char *status)
  6783. {
  6784. mtrace();
  6785. int result = PASS;
  6786. char message[4096]={0};
  6787. char guid[37]={0};
  6788. char tempdata[128]={0};
  6789. json_object *LogStatusNotification = json_object_new_object();
  6790. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6791. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6792. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6793. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6794. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6795. random_uuid(guid);
  6796. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6797. json_object_put(LogStatusNotification);
  6798. LWS_Send(message);
  6799. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6801. {
  6802. result = PASS;
  6803. }
  6804. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6805. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6806. return result;
  6807. }
  6808. int sendSecurityEventNotificationRequest()
  6809. {
  6810. mtrace();
  6811. int result = PASS;
  6812. char message[4096]={0};
  6813. char guid[37]={0};
  6814. char tempdata[128]={0};
  6815. json_object *SecurityEventNotification = json_object_new_object();
  6816. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6817. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6818. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6819. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6820. random_uuid(guid);
  6821. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6822. json_object_put(SecurityEventNotification);
  6823. LWS_Send(message);
  6824. sprintf(tempdata, "SecurityEventNotification,0");
  6825. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6826. {
  6827. result = PASS;
  6828. }
  6829. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6830. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6831. return result;
  6832. }
  6833. int sendSignCertificateRequest()
  6834. {
  6835. mtrace();
  6836. int result = PASS;
  6837. char message[4096]={0};
  6838. char guid[37]={0};
  6839. char tempdata[128]={0};
  6840. json_object *SignCertificate = json_object_new_object();
  6841. DEBUG_INFO("sendSignCertificateRequest...\n");
  6842. // Read csr file content
  6843. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6844. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6845. char *line = NULL;
  6846. size_t len = 0;
  6847. while(getline(&line, &len, fp) != -1)
  6848. {
  6849. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6850. {
  6851. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6852. }
  6853. }
  6854. fclose(fp);
  6855. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6856. random_uuid(guid);
  6857. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6858. json_object_put(SignCertificate);
  6859. LWS_Send(message);
  6860. sprintf(tempdata, "SignCertificate,0");
  6861. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6862. {
  6863. result = PASS;
  6864. }
  6865. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6866. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6867. return result;
  6868. }
  6869. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6870. {
  6871. mtrace();
  6872. int result = PASS;
  6873. char message[110]={0};
  6874. char guid[37]={0};
  6875. char tempdata[65]={0};
  6876. json_object *FirmwareStatusNotification = json_object_new_object();
  6877. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6878. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6879. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6880. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6881. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6882. random_uuid(guid);
  6883. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6884. json_object_put(FirmwareStatusNotification);
  6885. LWS_Send(message);
  6886. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6887. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6888. {
  6889. result = PASS;
  6890. }
  6891. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6892. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6893. return result;
  6894. }
  6895. //==========================================
  6896. // send confirm routine
  6897. //==========================================
  6898. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6899. {
  6900. mtrace();
  6901. int result = FAIL;
  6902. char message[100]={0};
  6903. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6904. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6905. LWS_Send(message);
  6906. result = TRUE;
  6907. return result;
  6908. }
  6909. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6910. {
  6911. mtrace();
  6912. int result = FAIL;
  6913. char message[100]={0};
  6914. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6915. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6916. LWS_Send(message);
  6917. result = TRUE;
  6918. return result;
  6919. }
  6920. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6921. {
  6922. mtrace();
  6923. int result = FAIL;
  6924. char message[100]={0};
  6925. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6926. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6927. LWS_Send(message);
  6928. result = TRUE;
  6929. return result;
  6930. }
  6931. int sendClearCacheConfirmation(char *uuid,char *payload)
  6932. {
  6933. mtrace();
  6934. int result = FAIL;
  6935. char message[500]={0};
  6936. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6937. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6938. LWS_Send(message);
  6939. return result;
  6940. }
  6941. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6942. {
  6943. mtrace();
  6944. int result = FAIL;
  6945. char message[500]={0};
  6946. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6947. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6948. LWS_Send(message);
  6949. return result;
  6950. }
  6951. int sendDataTransferConfirmation(char *uuid,char *payload)
  6952. {
  6953. mtrace();
  6954. char statusStr[20]={0};
  6955. char dataStr[10]={0};
  6956. char sstr[20]={0};
  6957. int c = 0;
  6958. char *loc;
  6959. int result = FAIL;
  6960. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6961. /**********************status**************************/
  6962. loc = strstr(payload, "status");
  6963. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6964. c = 0;
  6965. while (loc[3+strlen("status")+c] != '\"')
  6966. {
  6967. sstr[c] = loc[3+strlen("status")+c];
  6968. c++;
  6969. }
  6970. sstr[c] = '\0';
  6971. strcpy(statusStr, sstr);
  6972. /**********************data**************************/
  6973. loc = strstr(payload, "data");
  6974. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6975. c = 0;
  6976. while (loc[3+strlen("data")+c] != '\"')
  6977. {
  6978. sstr[c] = loc[3+strlen("data")+c];
  6979. c++;
  6980. }
  6981. sstr[c] = '\0';
  6982. strcpy(dataStr, sstr);
  6983. return result;
  6984. }
  6985. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6986. {
  6987. mtrace();
  6988. int result = FAIL;
  6989. char message[1000]={0};
  6990. int CompositeScheduleIndex = 0;
  6991. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6992. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6993. if(nPeriod == 0)
  6994. {
  6995. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6996. {
  6997. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6998. ,MESSAGE_TYPE_CALLRESULT
  6999. ,uuid
  7000. ,payload
  7001. ,connectorIdInt);
  7002. }
  7003. else
  7004. {
  7005. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7006. ,MESSAGE_TYPE_CALLRESULT
  7007. ,uuid
  7008. ,payload
  7009. ,connectorIdInt
  7010. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7011. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7012. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7013. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7014. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7015. }
  7016. }
  7017. else
  7018. {
  7019. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7020. ,MESSAGE_TYPE_CALLRESULT
  7021. ,uuid
  7022. ,payload
  7023. ,connectorIdInt
  7024. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7025. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7026. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7027. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7028. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7029. {
  7030. if (idx_sample == 0)
  7031. {
  7032. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7033. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7034. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7035. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7036. }
  7037. else
  7038. {
  7039. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7040. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7041. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7042. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7043. }
  7044. }
  7045. sprintf(message + strlen(message), "]}}]");
  7046. }
  7047. LWS_Send(message);
  7048. result = TRUE;
  7049. return result;
  7050. }
  7051. int sendGetConfigurationConfirmation(char *uuid)
  7052. {
  7053. mtrace();
  7054. int result = FAIL;
  7055. int MaxKeySupported = 0;
  7056. int sentConfigurationNumber= 0;
  7057. int sentunConfigurationNumber= 0;
  7058. char message[1024*10]={0};
  7059. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7060. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7061. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7062. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7063. ,MESSAGE_TYPE_CALLRESULT
  7064. ,uuid );
  7065. //configuration key
  7066. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7067. {
  7068. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7069. {
  7070. if (sentConfigurationNumber == 0)
  7071. {
  7072. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7073. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7074. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7075. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7076. }
  7077. else
  7078. {
  7079. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7080. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7081. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7082. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7083. }
  7084. sentConfigurationNumber = sentConfigurationNumber + 1;
  7085. }
  7086. }
  7087. sprintf(message + strlen(message), "]");
  7088. if(UnknownKeynum != 0)
  7089. {
  7090. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7091. //unkown key
  7092. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7093. {
  7094. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7095. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7096. if(sentunConfigurationNumber == 0)
  7097. {
  7098. sprintf(message + strlen(message), "\"%s\""
  7099. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7100. }
  7101. else
  7102. {
  7103. sprintf(message + strlen(message), ",\"%s\""
  7104. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7105. }
  7106. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7107. }
  7108. sprintf(message + strlen(message), "]");
  7109. }
  7110. sprintf(message + strlen(message), "}]");
  7111. LWS_Send(message);
  7112. return result;
  7113. }
  7114. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7115. {
  7116. mtrace();
  7117. int result = FAIL;
  7118. char message[400]={0};
  7119. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7120. if(strcmp(payload,"")==0)
  7121. {
  7122. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7123. }
  7124. else
  7125. {
  7126. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7127. }
  7128. LWS_Send(message);
  7129. result = TRUE;
  7130. return result;
  7131. }
  7132. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7133. {
  7134. mtrace();
  7135. int result = FAIL;
  7136. char message[80]={0};
  7137. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7138. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7139. LWS_Send(message);
  7140. result = TRUE;
  7141. return result;
  7142. }
  7143. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7144. {
  7145. mtrace();
  7146. int result = FAIL;
  7147. char message[80]={0};
  7148. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7149. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7150. LWS_Send(message);
  7151. result = TRUE;
  7152. return result;
  7153. }
  7154. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7155. {
  7156. mtrace();
  7157. int result = FAIL;
  7158. char message[80]={0};
  7159. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7160. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7161. LWS_Send(message);
  7162. result = TRUE;
  7163. return result;
  7164. }
  7165. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7166. {
  7167. mtrace();
  7168. int result = FAIL;
  7169. char message[80]={0};
  7170. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7171. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7172. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7173. LWS_Send(message);
  7174. result = TRUE;
  7175. return result;
  7176. }
  7177. int sendResetConfirmation(char *uuid,char *payload)
  7178. {
  7179. mtrace();
  7180. int result = FAIL;
  7181. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7182. char message[80]={0};
  7183. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7184. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7185. LWS_Send(message);
  7186. result = TRUE;
  7187. return result;
  7188. }
  7189. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7190. {
  7191. mtrace();
  7192. int result = FAIL;
  7193. char message[500]={0};
  7194. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7195. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7196. LWS_Send(message);
  7197. result = TRUE;
  7198. return result;
  7199. }
  7200. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7201. {
  7202. mtrace();
  7203. int result = FAIL;
  7204. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7205. char message[80]={0};
  7206. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7207. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7208. LWS_Send(message);
  7209. result = TRUE;
  7210. return result;
  7211. }
  7212. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7213. {
  7214. mtrace();
  7215. int result = FAIL;
  7216. char message[80]={0};
  7217. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7218. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7219. LWS_Send(message);
  7220. result = TRUE;
  7221. return result;
  7222. }
  7223. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7224. {
  7225. mtrace();
  7226. int result = FAIL;
  7227. char message[80]={0};
  7228. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7229. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7230. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7231. LWS_Send(message);
  7232. result = TRUE;
  7233. return result;
  7234. }
  7235. int sendUpdateFirmwareConfirmation(char *uuid)
  7236. {
  7237. mtrace();
  7238. int result = FAIL;
  7239. char message[60]={0};
  7240. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7241. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7242. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7243. LWS_Send(message);
  7244. result = TRUE;
  7245. return result;
  7246. }
  7247. int sendCertificateSignedConfirmation(char *uuid)
  7248. {
  7249. mtrace();
  7250. int result = PASS;
  7251. char message[4096]={0};
  7252. json_object *CertificateSigned = json_object_new_object();
  7253. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7254. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7255. sprintf(message,"[%d,\"%s\",%s]"
  7256. ,MESSAGE_TYPE_CALLRESULT
  7257. ,uuid
  7258. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7259. json_object_put(CertificateSigned);
  7260. LWS_Send(message);
  7261. return result;
  7262. }
  7263. int sendDeleteCertificateConfirmation(char *uuid)
  7264. {
  7265. mtrace();
  7266. int result = PASS;
  7267. char message[4096]={0};
  7268. json_object *DeleteCertificate = json_object_new_object();
  7269. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7270. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7271. sprintf(message,"[%d,\"%s\",%s]"
  7272. ,MESSAGE_TYPE_CALLRESULT
  7273. ,uuid
  7274. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7275. json_object_put(DeleteCertificate);
  7276. LWS_Send(message);
  7277. return result;
  7278. }
  7279. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7280. {
  7281. mtrace();
  7282. int result = PASS;
  7283. char message[4096]={0};
  7284. json_object *ExtendedTriggerMessage = json_object_new_object();
  7285. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7286. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7287. sprintf(message,"[%d,\"%s\",%s]"
  7288. ,MESSAGE_TYPE_CALLRESULT
  7289. ,uuid
  7290. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7291. json_object_put(ExtendedTriggerMessage);
  7292. LWS_Send(message);
  7293. return result;
  7294. }
  7295. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7296. {
  7297. mtrace();
  7298. int result = PASS;
  7299. char message[4096]={0};
  7300. json_object *GetInstalledCertificateIds = json_object_new_object();
  7301. json_object *certificateHashDataDatas = json_object_new_array();
  7302. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7303. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7304. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7305. {
  7306. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7307. {
  7308. json_object *certificateHashData = json_object_new_object();
  7309. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7310. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7311. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7312. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7313. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7314. }
  7315. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7316. }
  7317. else
  7318. {
  7319. json_object_put(certificateHashDataDatas);
  7320. }
  7321. sprintf(message,"[%d,\"%s\",%s]"
  7322. ,MESSAGE_TYPE_CALLRESULT
  7323. ,uuid
  7324. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7325. json_object_put(GetInstalledCertificateIds);
  7326. LWS_Send(message);
  7327. return result;
  7328. }
  7329. int sendGetLogConfirmation(char *uuid)
  7330. {
  7331. mtrace();
  7332. int result = PASS;
  7333. char message[4096]={0};
  7334. json_object *GetLog = json_object_new_object();
  7335. DEBUG_INFO("sendGetLogConfirmation...\n");
  7336. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7337. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7338. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7339. sprintf(message,"[%d,\"%s\",%s]"
  7340. ,MESSAGE_TYPE_CALLRESULT
  7341. ,uuid
  7342. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7343. json_object_put(GetLog);
  7344. LWS_Send(message);
  7345. return result;
  7346. }
  7347. int sendInstallCertificateConfirmation(char *uuid)
  7348. {
  7349. mtrace();
  7350. int result = PASS;
  7351. char message[4096]={0};
  7352. json_object *InstallCertificate = json_object_new_object();
  7353. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7354. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7355. sprintf(message,"[%d,\"%s\",%s]"
  7356. ,MESSAGE_TYPE_CALLRESULT
  7357. ,uuid
  7358. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7359. json_object_put(InstallCertificate);
  7360. LWS_Send(message);
  7361. return result;
  7362. }
  7363. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7364. {
  7365. mtrace();
  7366. int result = PASS;
  7367. char message[4096]={0};
  7368. json_object *SignedUpdateFirmware = json_object_new_object();
  7369. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7370. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7371. sprintf(message,"[%d,\"%s\",%s]"
  7372. ,MESSAGE_TYPE_CALLRESULT
  7373. ,uuid
  7374. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7375. json_object_put(SignedUpdateFirmware);
  7376. LWS_Send(message);
  7377. return result;
  7378. }
  7379. int sendUnknownConfirmation(char *uuid)
  7380. {
  7381. mtrace();
  7382. int result = PASS;
  7383. char message[256]={0};
  7384. DEBUG_INFO("sendUnknownConfirmation...\n");
  7385. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7386. LWS_Send(message);
  7387. return result;
  7388. }
  7389. //==========================================
  7390. // Handle server request routine Start
  7391. //==========================================
  7392. int handleCancelReservationRequest(char *uuid, char *payload)
  7393. {
  7394. mtrace();
  7395. int result = FAIL;
  7396. int gunNO = 0;
  7397. int reservationIdInt = -1;
  7398. char comfirmstr[20];
  7399. DEBUG_INFO("handleCancelReservationRequest...\n");
  7400. json_object *CancelReservation;
  7401. CancelReservation = json_tokener_parse(payload);
  7402. if(!is_error(CancelReservation))
  7403. {
  7404. // Required data
  7405. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7406. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7407. }
  7408. json_object_put(CancelReservation);
  7409. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7410. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7411. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7412. if(reservationIdInt != -1)
  7413. {
  7414. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7415. //check Transaction active
  7416. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7417. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7418. {
  7419. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7420. {
  7421. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7422. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7423. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7424. {
  7425. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7426. }
  7427. else
  7428. {
  7429. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7430. }
  7431. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7432. goto end;
  7433. }
  7434. }
  7435. for (int index = 0; index < CCS_QUANTITY; index++)
  7436. {
  7437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7438. {
  7439. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7440. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7441. if(gunType[2] == GUN_TYPE_CCS)
  7442. {
  7443. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7444. }
  7445. else
  7446. {
  7447. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7448. }
  7449. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7450. goto end;
  7451. }
  7452. }
  7453. for (int index = 0; index < GB_QUANTITY; index++)
  7454. {
  7455. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7456. {
  7457. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7458. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7459. if(gunType[2] == GUN_TYPE_GBT)
  7460. {
  7461. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7462. }
  7463. else
  7464. {
  7465. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7466. }
  7467. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7468. goto end;
  7469. }
  7470. }
  7471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7472. {
  7473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7474. {
  7475. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7476. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7477. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7478. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7479. goto end;
  7480. }
  7481. }
  7482. for (int index = 0; index < AC_QUANTITY; index++)
  7483. {
  7484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7485. {
  7486. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7487. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7489. {
  7490. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7491. }
  7492. else
  7493. {
  7494. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7495. }
  7496. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7497. goto end;
  7498. }
  7499. }
  7500. }
  7501. //The reservationId does NOT match the reservationId
  7502. sendCancelReservationConfirmation(uuid, comfirmstr);
  7503. end:
  7504. // Fill in ocpp packet uuid
  7505. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7506. return result;
  7507. }
  7508. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7509. {
  7510. mtrace();
  7511. int result = FAIL;
  7512. int gunIndex = -1;
  7513. char typeStr[16]={0};
  7514. char comfirmstr[20];
  7515. int specificId = FALSE;
  7516. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7517. json_object *ChangeAvailability;
  7518. ChangeAvailability = json_tokener_parse(payload);
  7519. if(!is_error(ChangeAvailability))
  7520. {
  7521. // Required data
  7522. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7523. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7524. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7525. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7526. }
  7527. json_object_put(ChangeAvailability);
  7528. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7529. {
  7530. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7531. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7532. }
  7533. else if(gunIndex == 0)
  7534. {
  7535. for(int i=0; i < gunTotalNumber; i++)
  7536. {
  7537. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7538. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7539. }
  7540. }
  7541. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7543. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7544. {
  7545. specificId = TRUE;
  7546. }
  7547. if(specificId == FALSE)
  7548. goto end;
  7549. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7550. {
  7551. //----------------------gunIndex is 0 ------------------------------------------------//
  7552. if(gunIndex == 0)
  7553. {
  7554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7555. {
  7556. for(int i=0; i < gunTotalNumber; i++)
  7557. {
  7558. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7559. {
  7560. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7561. {
  7562. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7563. {
  7564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7565. goto end;
  7566. }
  7567. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7569. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7570. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7571. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7572. {
  7573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7574. goto end;
  7575. }
  7576. }
  7577. }//END FOR CHAdeMO_QUANTITY
  7578. for (int index = 0; index < CCS_QUANTITY; index++)
  7579. {
  7580. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7581. {
  7582. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7583. {
  7584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7585. goto end;
  7586. }
  7587. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7589. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7590. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7591. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7592. {
  7593. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7594. goto end;
  7595. }
  7596. }
  7597. }//END FOR CCS_QUANTITY
  7598. for (int index = 0; index < GB_QUANTITY; index++)
  7599. {
  7600. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7601. {
  7602. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7603. {
  7604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7605. goto end;
  7606. }
  7607. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7608. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7609. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7610. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7611. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7612. {
  7613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7614. goto end;
  7615. }
  7616. }
  7617. }// END FOR GB_QUANTITY
  7618. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7619. {
  7620. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7621. {
  7622. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7623. {
  7624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7625. goto end;
  7626. }
  7627. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7628. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7629. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7631. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7632. {
  7633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7634. goto end;
  7635. }
  7636. }
  7637. }// END FOR GENERAL_GUN_QUANTITY
  7638. for (int index = 0; index < AC_QUANTITY; index++)
  7639. {
  7640. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7641. {
  7642. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7643. {
  7644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7645. goto end;
  7646. }
  7647. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7648. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7652. {
  7653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7654. goto end;
  7655. }
  7656. }
  7657. }//END FOR AC_QUANTITY
  7658. }// END FOR gunTotalNumber
  7659. }
  7660. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7661. {
  7662. for(int i=0; i < gunTotalNumber; i++)
  7663. {
  7664. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7665. {
  7666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7667. goto end;
  7668. }
  7669. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7670. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7671. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7673. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7674. {
  7675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7676. goto end;
  7677. }
  7678. }
  7679. }
  7680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7681. goto end;
  7682. }
  7683. //----------------------gunIndex is not 0 ------------------------------------------------//
  7684. //check Transaction active
  7685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7686. {
  7687. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7688. {
  7689. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7690. {
  7691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7692. goto end;
  7693. }
  7694. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7695. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7696. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7697. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7698. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7699. {
  7700. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7701. goto end;
  7702. }
  7703. else
  7704. {
  7705. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7706. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7707. goto end;
  7708. }
  7709. }
  7710. }//END FOR CHAdeMO_QUANTITY
  7711. for (int index = 0; index < CCS_QUANTITY; index++)
  7712. {
  7713. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7714. {
  7715. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7716. {
  7717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7718. goto end;
  7719. }
  7720. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7721. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7722. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7723. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7724. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7725. {
  7726. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7727. goto end;
  7728. }
  7729. else
  7730. {
  7731. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7732. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7733. goto end;
  7734. }
  7735. }
  7736. }//END FOR CCS_QUANTITY
  7737. for (int index = 0; index < GB_QUANTITY; index++)
  7738. {
  7739. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7740. {
  7741. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7742. {
  7743. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7744. goto end;
  7745. }
  7746. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7747. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7748. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7749. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7750. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7751. {
  7752. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7753. goto end;
  7754. }
  7755. else
  7756. {
  7757. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7759. goto end;
  7760. }
  7761. }
  7762. }// END FOR GB_QUANTITY
  7763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7764. {
  7765. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7766. {
  7767. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7768. {
  7769. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7770. goto end;
  7771. }
  7772. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7773. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7774. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7775. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7776. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7777. {
  7778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7779. goto end;
  7780. }
  7781. else
  7782. {
  7783. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7784. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7785. goto end;
  7786. }
  7787. }
  7788. }// END FOR GENERAL_GUN_QUANTITY
  7789. for (int index = 0; index < AC_QUANTITY; index++)
  7790. {
  7791. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7792. {
  7793. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7794. {
  7795. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7796. goto end;
  7797. }
  7798. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7799. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7800. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7801. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7802. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7803. {
  7804. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7805. goto end;
  7806. }
  7807. else
  7808. {
  7809. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7811. goto end;
  7812. }
  7813. }
  7814. }//END FOR AC_QUANTITY
  7815. }//END FOR AvailabilityTypeStr[Inoperative]
  7816. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7817. {
  7818. //----------------------gunIndex is 0 ------------------------------------------------//
  7819. if(gunIndex == 0)
  7820. {
  7821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7822. {
  7823. for(int i=0; i < gunTotalNumber; i++)
  7824. {
  7825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7826. {
  7827. 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
  7828. {
  7829. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7830. goto end;
  7831. }
  7832. }//END FOR CHAdeMO_QUANTITY
  7833. for (int index = 0; index < CCS_QUANTITY; index++)
  7834. {
  7835. 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
  7836. {
  7837. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7838. goto end;
  7839. }
  7840. }//END FOR CCS_QUANTITY
  7841. for (int index = 0; index < GB_QUANTITY; index++)
  7842. {
  7843. 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
  7844. {
  7845. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7846. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7847. goto end;
  7848. }
  7849. }// END FOR GB_QUANTITY
  7850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7851. {
  7852. 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
  7853. {
  7854. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7855. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7856. goto end;
  7857. }
  7858. }// END FOR GENERAL_GUN_QUANTITY
  7859. for (int index = 0; index < AC_QUANTITY; index++)
  7860. {
  7861. 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
  7862. {
  7863. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7864. goto end;
  7865. }
  7866. }//END FOR CHAdeMO_QUANTITY
  7867. }// END FOR gunTotalNumber
  7868. }
  7869. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7870. {
  7871. for(int i=0; i < gunTotalNumber; i++)
  7872. {
  7873. for (int index = 0; index < AC_QUANTITY; index++)
  7874. {
  7875. 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
  7876. {
  7877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7878. goto end;
  7879. }
  7880. }//END FOR CHAdeMO_QUANTITY
  7881. } // END FOR gunTotalNumber
  7882. }
  7883. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7884. goto end;
  7885. }
  7886. //----------------------gunIndex is not 0 ------------------------------------------------//
  7887. //check Transaction active
  7888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7889. {
  7890. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7891. {
  7892. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7893. goto end;
  7894. }
  7895. }//END FOR CHAdeMO_QUANTITY
  7896. for (int index = 0; index < CCS_QUANTITY; index++)
  7897. {
  7898. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7899. {
  7900. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7901. goto end;
  7902. }
  7903. }//END FOR CCS_QUANTITY
  7904. for (int index = 0; index < GB_QUANTITY; index++)
  7905. {
  7906. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7907. {
  7908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7909. goto end;
  7910. }
  7911. }// END FOR GB_QUANTITY
  7912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7913. {
  7914. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7915. {
  7916. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7917. goto end;
  7918. }
  7919. }// END FOR GENERAL_GUN_QUANTITY
  7920. for (int index = 0; index < AC_QUANTITY; index++)
  7921. {
  7922. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7923. {
  7924. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7925. goto end;
  7926. }
  7927. }//END FOR AC_QUANTITY
  7928. }//END FOR AvailabilityTypeStr[Operative]
  7929. end:
  7930. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7931. {
  7932. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7933. }
  7934. else
  7935. {
  7936. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7937. }
  7938. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7939. {
  7940. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7941. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7942. }
  7943. else if(gunIndex == 0)
  7944. {
  7945. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7946. {
  7947. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7948. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7949. }
  7950. }
  7951. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7952. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7953. return result;
  7954. }
  7955. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7956. {
  7957. mtrace();
  7958. int valueInvalid = NO;
  7959. int result = FAIL;
  7960. char keystr[40]={0};
  7961. char valuestr[501]={0}; //value should be limited in 500 bytes
  7962. char comfirmstr[20]={0};
  7963. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7964. json_object *ChangeConfiguration;
  7965. ChangeConfiguration = json_tokener_parse(payload);
  7966. if(!is_error(ChangeConfiguration))
  7967. {
  7968. // Required data
  7969. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7970. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7971. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  7972. {
  7973. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7974. }
  7975. else
  7976. {
  7977. valueInvalid = YES;
  7978. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  7979. }
  7980. }
  7981. json_object_put(ChangeConfiguration);
  7982. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  7983. {
  7984. DEBUG_ERROR("Payload is null or not accepted.\n");
  7985. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7986. }
  7987. else
  7988. {
  7989. int status = setKeyValue(keystr, valuestr);
  7990. switch(status)
  7991. {
  7992. case ConfigurationStatus_Accepted:
  7993. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7994. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7995. StoreConfigurationTable();
  7996. break;
  7997. case RebootRequired:
  7998. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7999. StoreConfigurationTable();
  8000. break;
  8001. case NotSupported:
  8002. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8003. break;
  8004. case ConfigurationStatus_Rejected:
  8005. default:
  8006. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8007. break;
  8008. }
  8009. }
  8010. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8011. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8012. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8013. {
  8014. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8015. SetOcppConnStatus(FALSE);
  8016. }
  8017. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8018. {
  8019. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8020. }
  8021. return result;
  8022. }
  8023. int handleClearCacheRequest(char *uuid, char *payload)
  8024. {
  8025. mtrace();
  8026. int result = FAIL;
  8027. char comfirmstr[20];
  8028. char rmFileCmd[100]={0};
  8029. struct stat stats;
  8030. DEBUG_INFO("handleClearCacheRequest...\n");
  8031. stat("/Storage/OCPP_PH", &stats);
  8032. // Check for directory existence
  8033. if (S_ISDIR(stats.st_mode) == 1)
  8034. {}
  8035. else
  8036. {
  8037. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8038. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8039. system(rmFileCmd);
  8040. }
  8041. if(OCPP_cleanLocalCache())
  8042. {
  8043. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8044. }
  8045. else
  8046. {
  8047. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8048. }
  8049. sendClearCacheConfirmation(uuid, comfirmstr);
  8050. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8051. return result;
  8052. }
  8053. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8054. {
  8055. mtrace();
  8056. int result = FAIL;
  8057. int resultRename;
  8058. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8059. char chargingProfilePurposeStr[26]={0};
  8060. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8061. char tempchargingProfilePurposeStr[26]={0};
  8062. char str[100]={0};
  8063. char fname[200]={0};
  8064. char comfirmstr[20]={0};
  8065. char word[1600]={0};
  8066. int clearflag = FALSE;
  8067. int chargingProfileIdIsNULL = FALSE;
  8068. int connectorIsNULL = FALSE;
  8069. int chargingProfilePurposeIsNULL = FALSE;
  8070. int stackLevelIsNULL = FALSE;
  8071. //int GotoEnd = FALSE;
  8072. FILE *fptr1, *fptr2;
  8073. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8074. int n_chargingProfile=0;
  8075. int isEmptyFile = FALSE;
  8076. char sLineWord[1600]={0};
  8077. char chargingProfiles[10][100]={0};
  8078. int ChargeProfileCount = 0;
  8079. int ch;
  8080. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8081. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8082. json_object *ClearChargingProfile;
  8083. ClearChargingProfile = json_tokener_parse(payload);
  8084. if(!is_error(ClearChargingProfile))
  8085. {
  8086. // Optional data
  8087. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8088. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8089. else
  8090. chargingProfileIdIsNULL = TRUE;
  8091. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8092. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8093. else
  8094. connectorIsNULL = TRUE;
  8095. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8096. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8097. else
  8098. chargingProfilePurposeIsNULL = TRUE;
  8099. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8100. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8101. else
  8102. stackLevelIsNULL = TRUE;
  8103. }
  8104. json_object_put(ClearChargingProfile);
  8105. if(connectorIsNULL == FALSE)
  8106. {
  8107. switch(connectorIdInt)
  8108. {
  8109. case 0:
  8110. if(chargingProfilePurposeIsNULL == TRUE)
  8111. {
  8112. int l = 0;
  8113. strcpy(fname, ChargePointMaxProfile_JSON);
  8114. if((access(fname,F_OK))!=-1)
  8115. {
  8116. strcpy(chargingProfiles[l], fname);
  8117. l = l + 1;
  8118. }
  8119. strcpy(fname, TxDefaultProfile_0_JSON);
  8120. if((access(fname,F_OK))!=-1)
  8121. {
  8122. strcpy(chargingProfiles[l], fname);
  8123. l = l + 1;
  8124. }
  8125. ChargeProfileCount = l;
  8126. }
  8127. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8128. {
  8129. strcpy(fname, ChargePointMaxProfile_JSON);
  8130. if((access(fname,F_OK))!=-1)
  8131. {
  8132. strcpy(chargingProfiles[0], fname);
  8133. ChargeProfileCount = 1;
  8134. }
  8135. }
  8136. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8137. {
  8138. strcpy(fname, TxDefaultProfile_0_JSON);
  8139. if((access(fname,F_OK))!=-1)
  8140. {
  8141. strcpy(chargingProfiles[0], fname);
  8142. ChargeProfileCount = 1;
  8143. }
  8144. }
  8145. break;
  8146. default:
  8147. if(chargingProfilePurposeIsNULL == TRUE)
  8148. {
  8149. int m = 0;
  8150. memset(fname, 0, ARRAY_SIZE(fname));
  8151. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8152. if((access(fname,F_OK))!=-1)
  8153. {
  8154. strcpy(chargingProfiles[m], fname);
  8155. m = m + 1;
  8156. }
  8157. memset(fname, 0, ARRAY_SIZE(fname));
  8158. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8159. if((access(fname,F_OK))!=-1)
  8160. {
  8161. strcpy(chargingProfiles[m], fname);
  8162. m = m + 1;
  8163. }
  8164. ChargeProfileCount = m;
  8165. }
  8166. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8167. {
  8168. //strcpy(fname, TxDefaultProfile_1_JSON);
  8169. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8170. if((access(fname,F_OK))!=-1)
  8171. {
  8172. strcpy(chargingProfiles[0], fname);
  8173. ChargeProfileCount = 1;
  8174. }
  8175. }
  8176. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8177. {
  8178. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8179. if((access(fname,F_OK))!=-1)
  8180. {
  8181. strcpy(chargingProfiles[0], fname);
  8182. ChargeProfileCount = 1;
  8183. }
  8184. //strcpy(fname, TxProfile_1_JSON);
  8185. }
  8186. //strcpy(fname, ChargePointMaxProfile_JSON );
  8187. break;
  8188. }
  8189. }
  8190. else // Check all Charging Profiles
  8191. {
  8192. int i = 0;
  8193. char fnametemp[200]={0};
  8194. ChargeProfileCount = 0;
  8195. //Check ChargePointMaxProfile.json exit
  8196. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8197. {
  8198. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8199. i = i + 1;
  8200. }
  8201. //Check TxDefaultProfile_0.json exit
  8202. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8203. {
  8204. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8205. i = i + 1;
  8206. }
  8207. //Check TxDefaultProfile_%d.json
  8208. for(int j=1; j <= gunTotalNumber; j++)
  8209. {
  8210. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8211. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8212. if((access(fnametemp,F_OK))!=-1)
  8213. {
  8214. strcpy(chargingProfiles[i], fnametemp);
  8215. i = i + 1;
  8216. }
  8217. }
  8218. //Check TxProfile_%d.json
  8219. for(int j=1; j <= gunTotalNumber; j++)
  8220. {
  8221. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8222. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8223. if((access(fnametemp,F_OK))!=-1)
  8224. {
  8225. strcpy(chargingProfiles[i], fnametemp);
  8226. i = i + 1;
  8227. }
  8228. }
  8229. ChargeProfileCount = i;
  8230. }// End connectorIsNULL is TRUE
  8231. if(ChargeProfileCount == 0)
  8232. {
  8233. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8234. goto end;
  8235. }
  8236. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8237. {
  8238. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8239. goto end;
  8240. }
  8241. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8242. {
  8243. memset(str, 0, ARRAY_SIZE(str));
  8244. // clear temp file
  8245. sprintf(str,"rm -f %s",temp);
  8246. system(str);
  8247. for(int k=0; k < ChargeProfileCount; k++)
  8248. {
  8249. memset(str, 0, ARRAY_SIZE(str));
  8250. //clear file in C
  8251. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8252. system(str);
  8253. }
  8254. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8255. goto end;
  8256. }
  8257. else if(connectorIsNULL == TRUE)
  8258. {
  8259. for(int k=0; k < ChargeProfileCount; k++)
  8260. {
  8261. fptr1 = fopen(chargingProfiles[k], "r");
  8262. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8263. //Check Charging Profile Count
  8264. while(fscanf(fptr1, "%s", word) != EOF)
  8265. {
  8266. //DEBUG_INFO("word=%s\n",word);
  8267. if(strstr(word, "chargingProfileId")!= NULL)
  8268. {
  8269. //DEBUG_INFO("test chargingProfileId \n");
  8270. n_chargingProfile = n_chargingProfile + 1;
  8271. //DEBUG_INFO("chargingProfileId Found\n");
  8272. }
  8273. }
  8274. rewind(fptr1);
  8275. //search Charging Profile Element
  8276. //int i= 0;
  8277. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8278. {
  8279. json_object *tmpProfilee;
  8280. tmpProfilee = json_tokener_parse(sLineWord);
  8281. if(!is_error(tmpProfilee))
  8282. {
  8283. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8284. {
  8285. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8286. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8287. }
  8288. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8289. {
  8290. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8291. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8292. }
  8293. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8294. {
  8295. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8296. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8297. }
  8298. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8299. {
  8300. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8301. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8302. }
  8303. }
  8304. json_object_put(tmpProfilee);
  8305. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8306. {
  8307. //------- not write to fptr2-------//
  8308. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8309. //clearflag = TRUE;
  8310. }
  8311. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8312. {
  8313. //------- not write to fptr2-------//
  8314. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8315. }
  8316. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8317. {
  8318. //------- not write to fptr2-------//
  8319. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8320. }
  8321. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8322. {
  8323. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8324. }
  8325. else
  8326. {
  8327. fprintf(fptr2, sLineWord);//writing data into file
  8328. }
  8329. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8330. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8331. if(clearflag == TRUE)
  8332. {
  8333. fclose(fptr1);
  8334. fclose(fptr2);
  8335. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8336. system(str);
  8337. // clear temp file
  8338. sprintf(str,"rm -f %s",temp);
  8339. system(str);
  8340. }
  8341. else
  8342. {
  8343. fclose(fptr1);
  8344. fclose(fptr2);
  8345. memset(str, 0, ARRAY_SIZE(str));
  8346. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8347. system(str);
  8348. resultRename = rename(temp, chargingProfiles[k]);
  8349. if(resultRename == 0)
  8350. {
  8351. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8352. }
  8353. else
  8354. {
  8355. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8356. }
  8357. if(comfirmstr[0]== 0)
  8358. {
  8359. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8360. }
  8361. //Check chargingProfile is empty file
  8362. /*------ Read the file ----------------*/
  8363. fptr1=fopen(chargingProfiles[k],"r");
  8364. ch=fgetc(fptr1);
  8365. rewind(fptr1);
  8366. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8367. if(ch!=EOF)
  8368. {
  8369. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8370. {
  8371. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8372. if(sLineWord[0]=='\0')
  8373. {
  8374. isEmptyFile = TRUE;
  8375. break;
  8376. }
  8377. else
  8378. {
  8379. isEmptyFile = FALSE;
  8380. break;
  8381. }
  8382. }
  8383. }
  8384. else
  8385. isEmptyFile = TRUE;
  8386. fclose(fptr1);
  8387. if(isEmptyFile == TRUE)
  8388. {
  8389. memset(str, 0, ARRAY_SIZE(str));
  8390. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8391. system(str);
  8392. }
  8393. }
  8394. }// End of while(int k=0; k < ChargePointCount; k++)
  8395. }
  8396. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8397. {
  8398. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8399. for(int k=0; k < ChargeProfileCount; k++)
  8400. {
  8401. fptr1 = fopen(chargingProfiles[k], "r");
  8402. fptr2 = fopen(temp, "w+");
  8403. //Check Charging Profile Count
  8404. while(fscanf(fptr1, "%s", word) != EOF)
  8405. {
  8406. //DEBUG_INFO("word=%s\n",word);
  8407. if(strstr(word, "chargingProfileId")!= NULL)
  8408. {
  8409. n_chargingProfile = n_chargingProfile + 1;
  8410. }
  8411. }
  8412. rewind(fptr1);
  8413. //search Charging Profile Element
  8414. //int i= 0;
  8415. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8416. {
  8417. json_object *tmpProfilee;
  8418. tmpProfilee = json_tokener_parse(sLineWord);
  8419. if(!is_error(tmpProfilee))
  8420. {
  8421. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8422. {
  8423. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8424. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8425. }
  8426. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8427. {
  8428. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8429. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8430. }
  8431. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8432. {
  8433. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8434. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8435. }
  8436. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8437. {
  8438. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8439. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8440. }
  8441. }
  8442. json_object_put(tmpProfilee);
  8443. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8444. {
  8445. //------- not write to fptr2-------//
  8446. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8447. //clearflag = TRUE;
  8448. }
  8449. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8450. {
  8451. //------- not write to fptr2-------//
  8452. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8453. }
  8454. else if(stackLevelIsNULL == TRUE)
  8455. {
  8456. //Clear Whole File
  8457. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8458. clearflag = TRUE;
  8459. break;
  8460. }
  8461. else
  8462. {
  8463. fprintf(fptr2, sLineWord);//writing data into file
  8464. }
  8465. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8466. }
  8467. if(clearflag == TRUE)
  8468. {
  8469. fclose(fptr1);
  8470. fclose(fptr2);
  8471. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8472. system(str);
  8473. // clear temp file
  8474. sprintf(str,"rm -f %s",temp);
  8475. system(str);
  8476. }
  8477. else
  8478. {
  8479. fclose(fptr1);
  8480. fclose(fptr2);
  8481. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8482. system(str);
  8483. resultRename = rename(temp, chargingProfiles[k]);
  8484. if(resultRename == 0)
  8485. {
  8486. DEBUG_INFO("File ChargingProfile renamed successfully");
  8487. }
  8488. else
  8489. {
  8490. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8491. }
  8492. if(comfirmstr[0]== 0)
  8493. {
  8494. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8495. }
  8496. //Check chargingProfile is empty file
  8497. /*------ Read the file ----------------*/
  8498. fptr1=fopen(chargingProfiles[k],"r");
  8499. ch=fgetc(fptr1);
  8500. rewind(fptr1);
  8501. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8502. if(ch!=EOF)
  8503. {
  8504. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8505. {
  8506. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8507. if(sLineWord[0]=='\0')
  8508. {
  8509. isEmptyFile = TRUE;
  8510. break;
  8511. }
  8512. else
  8513. {
  8514. isEmptyFile = FALSE;
  8515. break;
  8516. }
  8517. }
  8518. }
  8519. else
  8520. isEmptyFile = TRUE;
  8521. fclose(fptr1);
  8522. if(isEmptyFile == TRUE)
  8523. {
  8524. memset(str, 0, ARRAY_SIZE(str));
  8525. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8526. system(str);
  8527. }
  8528. /*------- End of reading ---------------*/
  8529. }
  8530. } // while(int k=0; k < ChargeProfileCount; k++)
  8531. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8532. end:
  8533. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8534. {
  8535. if(connectorIdInt == 0)
  8536. {
  8537. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8538. {
  8539. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8540. }
  8541. }
  8542. else
  8543. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8544. }
  8545. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8546. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8547. return result;
  8548. }
  8549. void createFirmwareVersionByDataTransfer(void)
  8550. {
  8551. json_object *FirmwareDataTransfer = json_object_new_object();
  8552. // AC & DC model
  8553. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8554. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8555. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8556. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8557. // DC model
  8558. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8559. {
  8560. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8561. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8562. (gunType[3] != GUN_TYPE_UNKNOWN))
  8563. {
  8564. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8565. }
  8566. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8567. {
  8568. // DS DM DW
  8569. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8570. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8571. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8572. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8573. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8574. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8575. }
  8576. else
  8577. {
  8578. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8579. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8580. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8581. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8582. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8583. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8584. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8585. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8586. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8587. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8588. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8589. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8590. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8591. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8592. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8593. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8594. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8595. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8596. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8597. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8598. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8599. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8600. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8601. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8602. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8603. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8604. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8605. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8606. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8607. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8608. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8609. }
  8610. }
  8611. // 4G model
  8612. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8613. {
  8614. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8615. }
  8616. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8617. json_object_put(FirmwareDataTransfer);
  8618. }
  8619. int handleDataTransferRequest(char *uuid, char *payload)
  8620. {
  8621. mtrace();
  8622. json_object *response = json_object_new_object();
  8623. int result = FAIL;
  8624. char tempvendorId[255]={0};
  8625. char tempmessageId[50]={0};
  8626. char tempdata[512]={0};
  8627. char message[2048]={0};
  8628. DEBUG_INFO("handleDataTransferRequest...\n");
  8629. if((uuid != NULL) && (payload != NULL))
  8630. {
  8631. json_object *DataTransfer;
  8632. DataTransfer = json_tokener_parse(payload);
  8633. if(!is_error(DataTransfer))
  8634. {
  8635. // Required data
  8636. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8637. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8638. // Optional data
  8639. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8640. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8641. if(json_object_object_get(DataTransfer, "data") != NULL)
  8642. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8643. result = PASS;
  8644. }
  8645. json_object_put(DataTransfer);
  8646. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8647. {
  8648. // Send all moudle firmware version on EVSE
  8649. createFirmwareVersionByDataTransfer();
  8650. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8651. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8652. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8653. json_object_put(response);
  8654. }
  8655. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8656. {
  8657. system("/usr/bin/run_tmate_restart.sh &");
  8658. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8659. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8660. json_object_put(response);
  8661. }
  8662. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8663. {
  8664. json_object *data;
  8665. data = json_tokener_parse(tempdata);
  8666. if(!is_error(data))
  8667. {
  8668. 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))
  8669. {
  8670. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8671. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8672. if(json_object_object_get(data, "SOC") != NULL)
  8673. {
  8674. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8675. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8676. }
  8677. if(json_object_object_get(data, "Energy") != NULL)
  8678. {
  8679. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8680. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8681. }
  8682. if(json_object_object_get(data, "Duration") != NULL)
  8683. {
  8684. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8685. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8686. }
  8687. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8688. }
  8689. else
  8690. {
  8691. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8692. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8693. }
  8694. }
  8695. else
  8696. {
  8697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8698. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8699. }
  8700. json_object_put(data);
  8701. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8702. json_object_put(response);
  8703. }
  8704. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8705. {
  8706. json_object *data;
  8707. data = json_tokener_parse(tempdata);
  8708. if(!is_error(data))
  8709. {
  8710. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8711. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8712. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8713. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8714. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8715. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8716. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8717. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8718. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8719. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8720. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8721. }
  8722. else
  8723. {
  8724. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8725. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8726. }
  8727. json_object_put(data);
  8728. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8729. json_object_put(response);
  8730. }
  8731. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8732. {
  8733. json_object *data;
  8734. data = json_tokener_parse(tempdata);
  8735. if(!is_error(data))
  8736. {
  8737. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8738. if(json_object_object_get(data, "idToken") != NULL)
  8739. {
  8740. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8741. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8742. }
  8743. if(json_object_object_get(data, "price") != NULL)
  8744. {
  8745. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8746. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  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("Configuration content something wrong."));
  8754. }
  8755. json_object_put(data);
  8756. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8757. json_object_put(response);
  8758. }
  8759. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8760. {
  8761. json_object *data;
  8762. data = json_tokener_parse(tempdata);
  8763. if(!is_error(data))
  8764. {
  8765. if(json_object_object_get(data, "txId") != NULL)
  8766. {
  8767. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8768. for(int idx = 0;idx<gunTotalNumber;idx++)
  8769. {
  8770. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8771. {
  8772. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8773. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8774. if(json_object_object_get(data, "description") != NULL)
  8775. {
  8776. // California pricing V1.0
  8777. DEBUG_INFO("California pricing V1.0\n");
  8778. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8779. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8780. }
  8781. else
  8782. {
  8783. // California pricing V1.1
  8784. DEBUG_INFO("California pricing V1.1\n");
  8785. if(json_object_object_get(data, "timestamp") != NULL)
  8786. {
  8787. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8788. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8789. }
  8790. if(json_object_object_get(data, "meterValue") != NULL)
  8791. {
  8792. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8793. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8794. }
  8795. if(json_object_object_get(data, "cost") != NULL)
  8796. {
  8797. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8798. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8799. }
  8800. if(json_object_object_get(data, "state") != NULL)
  8801. {
  8802. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8803. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8804. }
  8805. if(json_object_object_get(data, "chargingPrice") != NULL)
  8806. {
  8807. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8808. {
  8809. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8810. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8811. }
  8812. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8813. {
  8814. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8815. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8816. }
  8817. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8818. {
  8819. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8820. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8821. }
  8822. }
  8823. if(json_object_object_get(data, "idlePrice") != NULL)
  8824. {
  8825. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8826. {
  8827. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8828. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8829. }
  8830. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8831. {
  8832. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8833. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8834. }
  8835. }
  8836. if(json_object_object_get(data, "nextPeriod") != NULL)
  8837. {
  8838. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8839. {
  8840. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8841. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8842. }
  8843. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8844. {
  8845. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8846. {
  8847. 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")));
  8848. 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"));
  8849. }
  8850. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8851. {
  8852. 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")));
  8853. 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"));
  8854. }
  8855. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8856. {
  8857. 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")));
  8858. 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"));
  8859. }
  8860. }
  8861. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8862. {
  8863. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8864. {
  8865. 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")));
  8866. 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"));
  8867. }
  8868. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8869. {
  8870. 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")));
  8871. 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"));
  8872. }
  8873. }
  8874. }
  8875. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8876. {
  8877. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8878. {
  8879. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8880. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8881. }
  8882. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8883. {
  8884. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8885. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8886. }
  8887. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8888. {
  8889. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8890. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8891. }
  8892. }
  8893. }
  8894. }
  8895. }
  8896. }
  8897. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8898. }
  8899. else
  8900. {
  8901. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8902. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8903. }
  8904. json_object_put(data);
  8905. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8906. json_object_put(response);
  8907. }
  8908. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8909. {
  8910. json_object *data;
  8911. data = json_tokener_parse(tempdata);
  8912. if(!is_error(data))
  8913. {
  8914. if(json_object_object_get(data, "txId") != NULL)
  8915. {
  8916. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8917. for(int idx = 0;idx<gunTotalNumber;idx++)
  8918. {
  8919. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8920. {
  8921. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8922. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8923. if(json_object_object_get(data, "description") != NULL)
  8924. {
  8925. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8926. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8927. }
  8928. }
  8929. }
  8930. }
  8931. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8932. }
  8933. else
  8934. {
  8935. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8936. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8937. }
  8938. json_object_put(data);
  8939. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8940. json_object_put(response);
  8941. }
  8942. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8943. {
  8944. json_object *data;
  8945. data = json_tokener_parse(tempdata);
  8946. if(!is_error(data))
  8947. {
  8948. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8949. if(json_object_object_get(data, "Content_Type") != NULL)
  8950. {
  8951. 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))
  8952. {
  8953. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8954. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8955. {
  8956. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8957. }
  8958. }
  8959. else
  8960. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8961. }
  8962. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8963. }
  8964. else
  8965. {
  8966. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8967. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8968. }
  8969. json_object_put(data);
  8970. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8971. json_object_put(response);
  8972. }
  8973. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8974. {
  8975. json_object *data;
  8976. data = json_tokener_parse(tempdata);
  8977. if(!is_error(data))
  8978. {
  8979. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8980. if(json_object_object_get(data, "Page_Index") != NULL)
  8981. {
  8982. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8983. }
  8984. if(json_object_object_get(data, "Duration") != NULL)
  8985. {
  8986. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8987. }
  8988. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8989. }
  8990. else
  8991. {
  8992. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8993. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8994. }
  8995. json_object_put(data);
  8996. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8997. json_object_put(response);
  8998. }
  8999. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9000. {
  9001. json_object *data;
  9002. data = json_tokener_parse(tempdata);
  9003. if(!is_error(data))
  9004. {
  9005. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9006. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9007. {
  9008. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9009. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9010. else
  9011. {
  9012. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9013. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9014. }
  9015. }
  9016. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9017. {
  9018. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9019. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9020. else
  9021. {
  9022. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9023. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9024. }
  9025. }
  9026. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9027. {
  9028. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9029. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9030. else
  9031. {
  9032. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9033. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9034. }
  9035. }
  9036. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9037. {
  9038. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9039. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9040. else
  9041. {
  9042. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9043. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9044. }
  9045. }
  9046. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9047. {
  9048. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9049. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9050. else
  9051. {
  9052. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9053. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9054. }
  9055. }
  9056. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9057. {
  9058. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9059. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9060. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9061. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9062. else
  9063. {
  9064. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9065. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9066. }
  9067. }
  9068. if(json_object_object_get(data, "isAuthentication") != NULL)
  9069. {
  9070. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9071. {
  9072. case 0:
  9073. case 1:
  9074. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9075. break;
  9076. default:
  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. break;
  9080. }
  9081. }
  9082. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9083. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9084. }
  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. json_object_put(data);
  9091. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9092. json_object_put(response);
  9093. }
  9094. else if(strstr(tempmessageId, "refund_status") != NULL)
  9095. {
  9096. json_object *data;
  9097. data = json_tokener_parse(tempdata);
  9098. if(!is_error(data))
  9099. {
  9100. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9101. if(json_object_object_get(data, "status") != NULL)
  9102. {
  9103. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9104. if(strcmp(json_object_get_string(json_object_object_get(data, "status")), "T") || strcmp(json_object_get_string(json_object_object_get(data, "status")), "F"))
  9105. {
  9106. sprintf((char*)ShmOCPP16DataPH->YesCustomData.RefundStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9107. }
  9108. else
  9109. {
  9110. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9111. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9112. }
  9113. }
  9114. else
  9115. {
  9116. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9117. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9118. }
  9119. if(json_object_object_get(data, "chargeDate") != NULL)
  9120. {
  9121. sprintf((char *)ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeDate, "%s", json_object_get_string(json_object_object_get(data,"chargeDate")));
  9122. }
  9123. else
  9124. {
  9125. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9126. json_object_object_add(response, "data", json_object_new_string("chargeDate data can not get."));
  9127. }
  9128. if(json_object_object_get(data, "holdAmt") != NULL)
  9129. {
  9130. if(json_object_get_int(json_object_object_get(data, "holdAmt")) >= 0)
  9131. ShmOCPP16DataPH->YesCustomData.RefundStatus.holdAmt = json_object_get_int(json_object_object_get(data, "holdAmt"));
  9132. else
  9133. {
  9134. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9135. json_object_object_add(response, "data", json_object_new_string("holdAmt data is invalid."));
  9136. }
  9137. }
  9138. else
  9139. {
  9140. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9141. json_object_object_add(response, "data", json_object_new_string("holdAmt data can not get."));
  9142. }
  9143. if(json_object_object_get(data, "chargeAmt") != NULL)
  9144. {
  9145. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9146. ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9147. else
  9148. {
  9149. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9150. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9151. }
  9152. }
  9153. else
  9154. {
  9155. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9156. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9157. }
  9158. if(json_object_object_get(data, "refundAmt") != NULL)
  9159. {
  9160. if(json_object_get_int(json_object_object_get(data, "refundAmt")) >= 0)
  9161. ShmOCPP16DataPH->YesCustomData.RefundStatus.refundAmt = json_object_get_int(json_object_object_get(data, "refundAmt"));
  9162. else
  9163. {
  9164. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9165. json_object_object_add(response, "data", json_object_new_string("refundAmt data is invalid."));
  9166. }
  9167. }
  9168. else
  9169. {
  9170. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9171. json_object_object_add(response, "data", json_object_new_string("refundAmt data can not get."));
  9172. }
  9173. if(json_object_object_get(data, "page") != NULL)
  9174. {
  9175. if(json_object_get_int(json_object_object_get(data, "page")) >= 0 && json_object_get_int(json_object_object_get(data, "page")) <= 3)
  9176. ShmOCPP16DataPH->YesCustomData.RefundStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9177. else
  9178. {
  9179. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9180. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9181. }
  9182. }
  9183. else
  9184. {
  9185. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9186. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9187. }
  9188. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9189. {
  9190. ShmOCPP16DataPH->YesCustomData.RefundStatusReq = 1;
  9191. DEBUG_INFO("<<< RefundStatus:{status:%s, chargeDate:%s, holdAmt:%d, chargeAmt:%d, refundAmt:%d, page:%d}\n",
  9192. ShmOCPP16DataPH->YesCustomData.RefundStatus.status,
  9193. ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeDate,
  9194. ShmOCPP16DataPH->YesCustomData.RefundStatus.holdAmt,
  9195. ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeAmt,
  9196. ShmOCPP16DataPH->YesCustomData.RefundStatus.refundAmt,
  9197. ShmOCPP16DataPH->YesCustomData.RefundStatus.page);
  9198. }
  9199. }
  9200. else
  9201. {
  9202. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9203. json_object_object_add(response, "data", json_object_new_string("refund_status content got something wrong."));
  9204. }
  9205. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9206. json_object_put(response);
  9207. }
  9208. else if(strstr(tempmessageId, "deduct_status") != NULL)
  9209. {
  9210. json_object *data;
  9211. data = json_tokener_parse(tempdata);
  9212. if(!is_error(data))
  9213. {
  9214. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9215. if(json_object_object_get(data, "status") != NULL)
  9216. {
  9217. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9218. if((strcmp(json_object_get_string(json_object_object_get(data, "status")), "T")==0) || (strcmp(json_object_get_string(json_object_object_get(data, "status")), "F")==0))
  9219. {
  9220. sprintf((char*)ShmOCPP16DataPH->YesCustomData.DeductStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9221. }
  9222. else
  9223. {
  9224. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9225. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9226. }
  9227. }
  9228. else
  9229. {
  9230. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9231. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9232. }
  9233. if(json_object_object_get(data, "autoLoadAmt") != NULL)
  9234. {
  9235. if(json_object_get_int(json_object_object_get(data, "autoLoadAmt")) >= 0)
  9236. ShmOCPP16DataPH->YesCustomData.DeductStatus.autoLoadAmt = json_object_get_int(json_object_object_get(data, "autoLoadAmt"));
  9237. else
  9238. {
  9239. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9240. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt is invalid."));
  9241. }
  9242. }
  9243. else
  9244. {
  9245. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9246. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt data can not get."));
  9247. }
  9248. if(json_object_object_get(data, "beforeAmt") != NULL)
  9249. {
  9250. if(json_object_get_int(json_object_object_get(data, "beforeAmt")) >= 0)
  9251. ShmOCPP16DataPH->YesCustomData.DeductStatus.beforeAmt = json_object_get_int(json_object_object_get(data, "beforeAmt"));
  9252. else
  9253. {
  9254. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9255. json_object_object_add(response, "data", json_object_new_string("beforeAmt data is invalid."));
  9256. }
  9257. }
  9258. else
  9259. {
  9260. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9261. json_object_object_add(response, "data", json_object_new_string("beforeAmt data can not get."));
  9262. }
  9263. if(json_object_object_get(data, "chargeAmt") != NULL)
  9264. {
  9265. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9266. ShmOCPP16DataPH->YesCustomData.DeductStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9267. else
  9268. {
  9269. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9270. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9271. }
  9272. }
  9273. else
  9274. {
  9275. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9276. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9277. }
  9278. if(json_object_object_get(data, "afterAmt") != NULL)
  9279. {
  9280. if(json_object_get_int(json_object_object_get(data, "afterAmt")) >= 0)
  9281. ShmOCPP16DataPH->YesCustomData.DeductStatus.afterAmt = json_object_get_int(json_object_object_get(data, "afterAmt"));
  9282. else
  9283. {
  9284. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9285. json_object_object_add(response, "data", json_object_new_string("afterAmt data is invalid."));
  9286. }
  9287. }
  9288. else
  9289. {
  9290. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9291. json_object_object_add(response, "data", json_object_new_string("afterAmt data can not get."));
  9292. }
  9293. if(json_object_object_get(data, "page") != NULL)
  9294. {
  9295. if(json_object_get_int(json_object_object_get(data, "page")) >= 0)
  9296. ShmOCPP16DataPH->YesCustomData.DeductStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9297. else
  9298. {
  9299. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9300. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9301. }
  9302. }
  9303. else
  9304. {
  9305. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9306. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9307. }
  9308. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9309. {
  9310. ShmOCPP16DataPH->YesCustomData.DeductStatusReq = 1;
  9311. DEBUG_INFO("<<< deduct_status:{status:%s, autoLoadAmt:%d, beforeAmt:%d, chargeAmt:%d, afterAmt:%d, page:%d}\n",
  9312. ShmOCPP16DataPH->YesCustomData.DeductStatus.status,
  9313. ShmOCPP16DataPH->YesCustomData.DeductStatus.autoLoadAmt,
  9314. ShmOCPP16DataPH->YesCustomData.DeductStatus.beforeAmt,
  9315. ShmOCPP16DataPH->YesCustomData.DeductStatus.chargeAmt,
  9316. ShmOCPP16DataPH->YesCustomData.DeductStatus.afterAmt,
  9317. ShmOCPP16DataPH->YesCustomData.DeductStatus.page);
  9318. }
  9319. }
  9320. else
  9321. {
  9322. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9323. json_object_object_add(response, "data", json_object_new_string("deduct_status content got something wrong."));
  9324. }
  9325. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9326. json_object_put(response);
  9327. }
  9328. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9329. {
  9330. json_object *data;
  9331. data = json_tokener_parse(tempdata);
  9332. if(!is_error(data))
  9333. {
  9334. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9335. if(json_object_object_get(data, "stationName") != NULL)
  9336. {
  9337. sprintf((char *)ShmOCPP16DataPH->YesCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9338. }
  9339. else
  9340. {
  9341. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9342. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9343. }
  9344. /*if(json_object_object_get(data, "station_id") != NULL)
  9345. {
  9346. sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_id, "%s", json_object_get_string(json_object_object_get(data,"station_id")));
  9347. }
  9348. else
  9349. {
  9350. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9351. json_object_object_add(response, "data", json_object_new_string("station_id data can not get."));
  9352. }
  9353. if(json_object_object_get(data, "charge_id") != NULL)
  9354. {
  9355. for(int idx=0;idx<json_object_array_length(json_object_object_get(data, "charge_id"));idx++)
  9356. {
  9357. sprintf((char*)ShmOCPP16Data->YesCustomData.ChargerInfo.charge_id[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(data, "charge_id"), idx)));
  9358. }
  9359. }
  9360. else
  9361. {
  9362. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9363. json_object_object_add(response, "data", json_object_new_string("charge_id data can not get."));
  9364. }*/
  9365. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9366. {
  9367. ShmOCPP16DataPH->YesCustomData.ChargerInfoReq = 1;
  9368. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9369. ShmOCPP16DataPH->YesCustomData.ChargerInfo.station_name);
  9370. }
  9371. }
  9372. else
  9373. {
  9374. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9375. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9376. }
  9377. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9378. json_object_put(response);
  9379. }
  9380. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9381. {
  9382. json_object *data;
  9383. data = json_tokener_parse(tempdata);
  9384. if(!is_error(data))
  9385. {
  9386. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9387. if(json_object_object_get(data, "weatherId") != NULL)
  9388. {
  9389. ShmOCPP16DataPH->YesCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9390. }
  9391. else
  9392. {
  9393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9394. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9395. }
  9396. if(json_object_object_get(data, "Temperature") != NULL)
  9397. {
  9398. ShmOCPP16DataPH->YesCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9399. }
  9400. else
  9401. {
  9402. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9403. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9404. }
  9405. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9406. {
  9407. ShmOCPP16DataPH->YesCustomData.WeatherInfoReq = 1;
  9408. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9409. ShmOCPP16DataPH->YesCustomData.WeatherInfo.weatherId,
  9410. ShmOCPP16DataPH->YesCustomData.WeatherInfo.temperature);
  9411. }
  9412. }
  9413. else
  9414. {
  9415. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9416. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9417. }
  9418. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9419. json_object_put(response);
  9420. }
  9421. else if(strstr(tempmessageId, "set_qrcode") != NULL)
  9422. {
  9423. json_object *data;
  9424. data = json_tokener_parse(tempdata);
  9425. if(!is_error(data))
  9426. {
  9427. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9428. if(json_object_object_get(data, "connectorId") != NULL)
  9429. {
  9430. if((json_object_get_int(json_object_object_get(data, "connectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "connectorId")) <= gunTotalNumber))
  9431. {
  9432. int idx = json_object_get_int(json_object_object_get(data, "connectorId"))-1;
  9433. if(json_object_object_get(data, "qrcode") != NULL)
  9434. {
  9435. sprintf((char *)ShmOCPP16DataPH->YesCustomData.QrCode[idx], "%s", json_object_get_string(json_object_object_get(data,"qrcode")));
  9436. ShmOCPP16DataPH->YesCustomData.SetQrCodeReq = 1;
  9437. DEBUG_INFO("<<< set_qrcode:{connectorId:%d, qrcode:%s}\n",
  9438. idx,
  9439. ShmOCPP16DataPH->YesCustomData.QrCode[idx]
  9440. );
  9441. }
  9442. else
  9443. {
  9444. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9445. json_object_object_add(response, "data", json_object_new_string("qrcode data can not get."));
  9446. }
  9447. }
  9448. else
  9449. {
  9450. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9451. json_object_object_add(response, "data", json_object_new_string("connectorId data is invalid."));
  9452. }
  9453. }
  9454. else
  9455. {
  9456. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9457. json_object_object_add(response, "data", json_object_new_string("connectorId data can not get."));
  9458. }
  9459. }
  9460. else
  9461. {
  9462. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9463. json_object_object_add(response, "data", json_object_new_string("set_qrcode content got something wrong."));
  9464. }
  9465. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9466. json_object_put(response);
  9467. }
  9468. else
  9469. {
  9470. // Can not find valid message id
  9471. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9472. }
  9473. }
  9474. else
  9475. {
  9476. // Payload is null
  9477. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9478. }
  9479. LWS_Send(message);
  9480. return result;
  9481. }
  9482. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9483. {
  9484. mtrace();
  9485. int result = FAIL;
  9486. int connectorIdInt, durationInt;
  9487. char chargingRateUnitStr[4]={0};
  9488. char comfirmstr[20];
  9489. int confirmPeriods = 0;
  9490. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9491. json_object *GetCompositeSchedule;
  9492. GetCompositeSchedule = json_tokener_parse(payload);
  9493. if(!is_error(GetCompositeSchedule))
  9494. {
  9495. // Required data
  9496. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9497. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9498. else
  9499. connectorIdInt = -1;
  9500. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9501. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9502. else
  9503. durationInt = 86400;
  9504. // Optional data
  9505. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9506. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9507. }
  9508. json_object_put(GetCompositeSchedule);
  9509. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9510. if((connectorIdInt == 0) ||
  9511. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9512. {
  9513. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9514. struct StructChargingProfile tmpProfile[1];
  9515. if(strstr(chargingRateUnitStr, "W") != NULL)
  9516. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9517. else
  9518. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9519. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9520. {
  9521. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9522. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9523. }
  9524. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9525. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9526. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9527. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9528. {
  9529. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9530. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9531. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9532. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9533. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9534. {
  9535. confirmPeriods = idx;
  9536. break;
  9537. }
  9538. }
  9539. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9540. {
  9541. confirmPeriods += 1;
  9542. }
  9543. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9544. }
  9545. else
  9546. {
  9547. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9548. }
  9549. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9550. return result;
  9551. }
  9552. int handleGetConfigurationRequest(char *uuid, char *payload)
  9553. {
  9554. mtrace();
  9555. int result = FAIL;
  9556. int MaxKeySupported = 0;
  9557. int n_keys = 0;
  9558. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9559. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9560. json_object *GetConfiguration;
  9561. GetConfiguration = json_tokener_parse(payload);
  9562. if(!is_error(GetConfiguration))
  9563. {
  9564. // Optional data
  9565. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9566. {
  9567. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9568. {
  9569. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9570. n_keys = idx + 1;
  9571. }
  9572. }
  9573. }
  9574. json_object_put(GetConfiguration);
  9575. UnknownKeynum = 0;
  9576. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9577. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9578. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9579. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9580. if(n_keys != 0)
  9581. {
  9582. for(int i=0;i<n_keys;i++)
  9583. {
  9584. getKeyValue(requestKey[i]);
  9585. }
  9586. }
  9587. else
  9588. {
  9589. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9590. getKeyValue("");
  9591. }
  9592. processUnkownKey();
  9593. sendGetConfigurationConfirmation(uuid);
  9594. return result;
  9595. }
  9596. static char fnamePlusPath[100]={0};
  9597. static char fnamePWithNoPath[60]={0};
  9598. void checkUploadLog(void)
  9599. {
  9600. FILE *fp;
  9601. /* Open the command for reading. */
  9602. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9603. if (fp == NULL) {
  9604. DEBUG_WARN("Failed to run command\n" );
  9605. exit(1);
  9606. }
  9607. int ftppathlen = 0;
  9608. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9609. int i = 0;
  9610. /* Read the output a line at a time - output it. */
  9611. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9612. if(i==0)
  9613. {
  9614. ftppathlen = strlen(fnamePlusPath);
  9615. DEBUG_INFO("%s\n", fnamePlusPath);
  9616. fnamePlusPath[ftppathlen]='\0';
  9617. break;
  9618. }
  9619. i= i+1;
  9620. }
  9621. /* close */
  9622. pclose(fp);
  9623. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9624. {
  9625. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9626. {
  9627. fnamePlusPath[k]='\0';
  9628. }
  9629. }
  9630. i=1;
  9631. //char fname[60]={0};
  9632. while(i < ftppathlen)
  9633. {
  9634. int len=ftppathlen-i;
  9635. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9636. {
  9637. DEBUG_INFO("compare '/' all right\n");
  9638. break;
  9639. }
  9640. i=i+1;
  9641. }
  9642. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9643. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9644. fnamePWithNoPath[i+1] = '\0';
  9645. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9646. {
  9647. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9648. {
  9649. fnamePWithNoPath[j]='\0';
  9650. }
  9651. }
  9652. FILE* fp1 = fopen(fnamePlusPath, "r");
  9653. if (fp1)
  9654. {
  9655. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9656. // file exists
  9657. fclose(fp1);
  9658. }
  9659. else
  9660. {
  9661. // file doesn't exist
  9662. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9663. }
  9664. }
  9665. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9666. {
  9667. mtrace();
  9668. int result = FAIL;
  9669. time_t CurrentTime;
  9670. struct tm *tm;
  9671. pthread_t th_Status;
  9672. CurrentTime = time(NULL);
  9673. tm = localtime(&CurrentTime);
  9674. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9675. 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);
  9676. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9677. if(!interLock.isGetDiagnosticGoing)
  9678. {
  9679. interLock.isGetDiagnosticGoing = 1;
  9680. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9681. sleep(1);
  9682. }
  9683. else
  9684. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9685. return result;
  9686. }
  9687. void* GetDiagnosticsProcess(void* data)
  9688. {
  9689. pthread_detach(pthread_self());
  9690. mtrace();
  9691. int retriesInt=0, retryIntervalInt=0;
  9692. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9693. 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};
  9694. int port=0;
  9695. int isSuccess = FALSE;
  9696. char ftpbuf[200]={0};
  9697. char cmdBuf[2048];
  9698. struct tm *tmNow;
  9699. time_t CurrentTime;
  9700. struct tm tmStart;
  9701. struct tm tmStop;
  9702. CurrentTime = time(NULL);
  9703. tmNow=localtime(&CurrentTime);
  9704. uint16_t targetYear, targetMonth;
  9705. json_object *GetDiagnostics;
  9706. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9707. GetDiagnostics = json_tokener_parse(data);
  9708. if(!is_error(GetDiagnostics))
  9709. {
  9710. // Required data
  9711. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9712. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9713. // Optional data
  9714. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9715. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9716. else
  9717. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9718. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9719. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9720. else
  9721. retryIntervalInt = 30;
  9722. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9723. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9724. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9725. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9726. }
  9727. json_object_put(GetDiagnostics);
  9728. // Pack log to compress file
  9729. 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) &&
  9730. (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))
  9731. {
  9732. // Pack system log
  9733. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9734. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9735. targetYear = tmStart.tm_year;
  9736. targetMonth = tmStart.tm_mon;
  9737. do
  9738. {
  9739. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9740. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9741. if(targetMonth+1>=13)
  9742. {
  9743. targetYear += 1;
  9744. targetMonth = 1;
  9745. }
  9746. else
  9747. {
  9748. targetMonth += 1;
  9749. }
  9750. }while((targetYear < (tmNow->tm_year+1900)) ||
  9751. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9752. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9753. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9754. system(cmdBuf);
  9755. // Pack charging & event log
  9756. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9757. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9758. targetYear = tmStart.tm_year;
  9759. targetMonth = tmStart.tm_mon;
  9760. do
  9761. {
  9762. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9763. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9764. if(targetMonth+1>=13)
  9765. {
  9766. targetYear += 1;
  9767. targetMonth = 1;
  9768. }
  9769. else
  9770. {
  9771. targetMonth += 1;
  9772. }
  9773. }while((targetYear < (tmNow->tm_year+1900)) ||
  9774. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9775. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9776. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9777. system(cmdBuf);
  9778. // Combine log file
  9779. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9780. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9781. }
  9782. else
  9783. {
  9784. system("exec /root/logPackTools 'log' 6");
  9785. }
  9786. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9787. system(cmdBuf);
  9788. checkUploadLog();
  9789. //****************location*******************/
  9790. if(strcmp(locationstr,"")==0)
  9791. {
  9792. DEBUG_INFO("location is <Empty>!\n");
  9793. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9794. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9795. goto end;
  9796. }
  9797. memset(protocol, 0, ARRAY_SIZE(protocol));
  9798. memset(user, 0, ARRAY_SIZE(user) );
  9799. memset(password, 0, ARRAY_SIZE(password));
  9800. memset(host, 0, ARRAY_SIZE(host));
  9801. memset(path, 0, ARRAY_SIZE(path));
  9802. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9803. memset(host1, 0, ARRAY_SIZE(host1));
  9804. memset(path1, 0, ARRAY_SIZE(path1));
  9805. /*location: ftp://user:password@host:port/path*/
  9806. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9807. if((access(fnamePlusPath,F_OK))!=-1)
  9808. {
  9809. DEBUG_INFO("fnamePlusPath exist.\n");
  9810. }
  9811. else
  9812. {
  9813. DEBUG_INFO("fnamePlusPath not exist!\n");
  9814. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9815. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9816. goto end;
  9817. }
  9818. if(strchr(locationstr,'@')==NULL)
  9819. {
  9820. sscanf(locationstr,
  9821. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9822. protocol, host, &port, path);
  9823. strcpy(user,"anonymous");
  9824. strcpy(password,"");
  9825. }
  9826. else
  9827. {
  9828. //DEBUG_INFO("pch=%s\n", pch);
  9829. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9830. protocol, user, password, host, &port, path);
  9831. }
  9832. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9833. {
  9834. DEBUG_INFO("protocol is not ftp/http ! \n");
  9835. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9836. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9837. goto end;
  9838. }
  9839. if(strncmp(locationstr,"http", 4) == 0)
  9840. {
  9841. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9842. sprintf(ftppath,"/%s", path);
  9843. do
  9844. {
  9845. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9846. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9847. sleep(3);
  9848. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9849. if(!isSuccess)
  9850. {
  9851. DEBUG_INFO("Diagnostics fail.\n");
  9852. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9853. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9854. sleep(retryIntervalInt);
  9855. }
  9856. else
  9857. {
  9858. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9859. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9860. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9861. }
  9862. retriesInt--;
  9863. }while((isSuccess == 0)&&(retriesInt >= 0));
  9864. }
  9865. else
  9866. {
  9867. sscanf(host,"%[^/]%s",host1, path1);
  9868. if(strlen(path) > 0)
  9869. sprintf(ftppath,"/%s", path);
  9870. else
  9871. sprintf(ftppath,"/%s", path1);
  9872. int ftppathlen=strlen(ftppath);
  9873. int i=1;
  9874. char filenametemp[50];
  9875. while(i < ftppathlen)
  9876. {
  9877. int len=ftppathlen-i;
  9878. if(ftppath[len]== 47) // '/' ascll code: 47
  9879. {
  9880. DEBUG_INFO("find '/' all right\n");
  9881. break;
  9882. }
  9883. i=i+1;
  9884. }
  9885. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9886. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9887. filenametemp[i+1] = 0;
  9888. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9889. if(port == 0)
  9890. port = 21;
  9891. do
  9892. {
  9893. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9894. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9895. sleep(3);
  9896. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9897. if(!isSuccess)
  9898. {
  9899. DEBUG_INFO("Diagnostics fail.\n");
  9900. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9901. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9902. sleep(retryIntervalInt);
  9903. }
  9904. else
  9905. {
  9906. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9907. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9908. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9909. }
  9910. retriesInt--;
  9911. }while((!isSuccess)&&(retriesInt >= 0));
  9912. }
  9913. end:
  9914. system("rm -f /mnt/*");
  9915. sleep(5);
  9916. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9917. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9918. interLock.isGetDiagnosticGoing = 0;
  9919. pthread_exit(NULL);
  9920. }
  9921. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9922. {
  9923. mtrace();
  9924. int result = FAIL;
  9925. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9926. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9927. {
  9928. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9929. locallistVersion = -1;
  9930. }
  9931. else
  9932. {
  9933. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9934. OCPP_getListVerion();
  9935. }
  9936. //from db.OCPP_getListVerion
  9937. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9938. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9939. sendGetLocalListVersionConfirmation(uuid,"");
  9940. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9941. return result;
  9942. }
  9943. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9944. {
  9945. mtrace();
  9946. int result = FAIL;
  9947. int connectorIdInt=-1;
  9948. int tempIndex = 0;
  9949. int connectorIdIsNULL, chargingProfileIsNULL;
  9950. char comfirmstr[20]={0};
  9951. char cmdBuf[512];
  9952. json_object *RemoteStartTransaction;
  9953. FILE *fp;
  9954. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9955. if(server_pending == TRUE)
  9956. {
  9957. return 0;
  9958. }
  9959. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9960. RemoteStartTransaction = json_tokener_parse(payload);
  9961. if(!is_error(RemoteStartTransaction))
  9962. {
  9963. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9964. {
  9965. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9966. }
  9967. else
  9968. {
  9969. connectorIdIsNULL = TRUE;
  9970. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9971. {
  9972. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9973. {
  9974. connectorIdIsNULL = FALSE;
  9975. connectorIdInt = (gun_index+1);
  9976. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9977. break;
  9978. }
  9979. }
  9980. }
  9981. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9982. {
  9983. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9984. // Required data
  9985. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9986. // Optional data
  9987. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9988. {
  9989. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9990. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9991. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9992. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9993. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9994. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9995. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9996. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9997. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9998. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9999. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10000. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10001. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10002. {
  10003. 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")));
  10004. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10005. 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"));
  10006. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10007. 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"));
  10008. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10009. 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")));
  10010. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10011. {
  10012. 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++)
  10013. {
  10014. 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"));
  10015. 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"));
  10016. 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)
  10017. 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"));
  10018. }
  10019. }
  10020. }
  10021. }
  10022. else
  10023. {
  10024. chargingProfileIsNULL = TRUE;
  10025. }
  10026. }
  10027. }
  10028. else
  10029. {
  10030. connectorIdIsNULL = TRUE;
  10031. }
  10032. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10033. {
  10034. DEBUG_WARN("Connector id is NULL\n.");
  10035. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10036. goto end;
  10037. }
  10038. /*
  10039. enum _SYSTEM_STATUS
  10040. {
  10041. S_BOOTING = 0,
  10042. S_IDLE, = 1
  10043. S_AUTHORIZING, = 2
  10044. S_REASSIGN_CHECK, = 3
  10045. S_REASSIGN, = 4
  10046. S_PRECHARGE, = 5
  10047. S_PREPARING_FOR_EV, = 6
  10048. S_PREPARING_FOR_EVSE, = 7
  10049. S_CHARGING, = 8
  10050. S_TERMINATING, = 9
  10051. S_COMPLETE, = 10
  10052. S_ALARM, = 11
  10053. S_FAULT = 12
  10054. }
  10055. */
  10056. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10057. {
  10058. //check Transaction active
  10059. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10060. {
  10061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10062. {
  10063. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10064. }
  10065. else
  10066. {
  10067. tempIndex = connectorIdInt -1;
  10068. }
  10069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10070. {
  10071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10072. {
  10073. 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))
  10074. {
  10075. //Reserved
  10076. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10077. }
  10078. 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))
  10079. {
  10080. //Reserved
  10081. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10082. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10083. goto end;
  10084. }
  10085. else
  10086. {
  10087. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10088. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10089. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10090. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10091. {
  10092. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10093. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10094. goto end;
  10095. }
  10096. }//END FOR ELSE
  10097. }
  10098. }// END FOR CHAdeMO_QUANTITY
  10099. }
  10100. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10101. {
  10102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10103. {
  10104. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10105. }
  10106. else
  10107. {
  10108. tempIndex = connectorIdInt -1;
  10109. }
  10110. for (int index = 0; index < CCS_QUANTITY; index++)
  10111. {
  10112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10113. {
  10114. 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))
  10115. {
  10116. //Reserved
  10117. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10118. }
  10119. 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))
  10120. {
  10121. //Reserved
  10122. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10124. goto end;
  10125. }
  10126. else
  10127. {
  10128. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10129. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10130. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10131. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10132. {
  10133. DEBUG_WARN("CCS connector not allow start\n.");
  10134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10135. goto end;
  10136. }
  10137. }// END FOR ELSE
  10138. }
  10139. }// END FOR CCS_QUANTITY
  10140. }
  10141. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10142. {
  10143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10144. {
  10145. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10146. }
  10147. else
  10148. {
  10149. tempIndex = connectorIdInt -1;
  10150. }
  10151. for (int index = 0; index < GB_QUANTITY; index++)
  10152. {
  10153. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10154. {
  10155. 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))
  10156. {
  10157. //Reserved
  10158. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10159. }
  10160. 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))
  10161. {
  10162. //Reserved
  10163. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10164. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10165. goto end;
  10166. }
  10167. else
  10168. {
  10169. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10170. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10171. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10172. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10173. {
  10174. DEBUG_WARN("GB connector not allow start\n.");
  10175. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10176. goto end;
  10177. }
  10178. }// END FOR ELSE
  10179. }
  10180. } // END FOR GB_QUANTITY
  10181. }
  10182. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10183. {
  10184. tempIndex = connectorIdInt -1;
  10185. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10186. {
  10187. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10188. {
  10189. 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))
  10190. {
  10191. //Reserved
  10192. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10193. }
  10194. 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))
  10195. {
  10196. //Reserved
  10197. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10198. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10199. goto end;
  10200. }
  10201. else
  10202. {
  10203. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10204. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10205. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10206. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10207. {
  10208. DEBUG_WARN("GB connector not allow start\n.");
  10209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10210. goto end;
  10211. }
  10212. }// END FOR ELSE
  10213. }
  10214. } // END FOR GB_QUANTITY
  10215. }
  10216. else
  10217. {
  10218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10219. {
  10220. tempIndex = 2;
  10221. }
  10222. else
  10223. {
  10224. tempIndex = connectorIdInt -1;
  10225. }
  10226. for (int index = 0; index < AC_QUANTITY; index++)
  10227. {
  10228. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10229. {
  10230. 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))
  10231. {
  10232. //Reserved
  10233. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10234. }
  10235. 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))
  10236. {
  10237. //Reserved
  10238. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10239. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10240. goto end;
  10241. }
  10242. else
  10243. {
  10244. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10245. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10246. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10247. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10248. {
  10249. DEBUG_WARN("AC connector not allow start\n.");
  10250. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10251. goto end;
  10252. }
  10253. }//END FOR ELSE
  10254. }
  10255. }// END FOR AC_QUANTITY
  10256. }
  10257. if(chargingProfileIsNULL == FALSE)
  10258. {
  10259. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10260. {
  10261. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10263. //memset idTag
  10264. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10265. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10266. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10268. // Save profile to file
  10269. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10270. system(cmdBuf);
  10271. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10272. fp = fopen(cmdBuf, "w");
  10273. 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));
  10274. fclose(fp);
  10275. }
  10276. else
  10277. {
  10278. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10279. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10280. }
  10281. }
  10282. else
  10283. {
  10284. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10286. //memset idTag
  10287. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10288. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10289. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10290. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10291. }
  10292. }
  10293. else
  10294. {
  10295. DEBUG_WARN("Connector id over\n.");
  10296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10297. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10298. }
  10299. end:
  10300. json_object_put(RemoteStartTransaction);
  10301. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10302. {
  10303. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10304. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10305. }
  10306. //OCPP send RemoteStartConfirmation by first.
  10307. sendRemoteStartConfirmation(uuid, comfirmstr);
  10308. return result;
  10309. }
  10310. int handleRemoteStartRequest(char *uuid, char *payload)
  10311. {
  10312. mtrace();
  10313. int result = PASS;
  10314. int connectorIdInt=-1;
  10315. int tempIndex = 0;
  10316. char comfirmstr[20]={0};
  10317. char cmdBuf[512];
  10318. json_object *RemoteStartTransaction;
  10319. FILE *fp;
  10320. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10321. if(server_pending == TRUE)
  10322. {
  10323. result = FAIL;
  10324. }
  10325. RemoteStartTransaction = json_tokener_parse(payload);
  10326. if(!is_error(RemoteStartTransaction))
  10327. {
  10328. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10329. {
  10330. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10331. }
  10332. else
  10333. {
  10334. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10335. {
  10336. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10337. {
  10338. connectorIdInt = (gun_index+1);
  10339. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10340. break;
  10341. }
  10342. }
  10343. }
  10344. if(connectorIdInt == 0)
  10345. {
  10346. DEBUG_WARN("Connector id shall not equal 0.\n");
  10347. result = FAIL;
  10348. }
  10349. else if(connectorIdInt == -1)
  10350. {
  10351. DEBUG_INFO("Connector id does not specific.\n");
  10352. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10353. {
  10354. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10355. // Required data
  10356. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10357. // Optional data
  10358. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10359. {
  10360. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10361. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10362. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10363. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10364. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10365. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10366. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10367. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10368. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10369. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10370. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10371. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10372. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10373. {
  10374. 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")));
  10375. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10376. 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"));
  10377. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10378. 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"));
  10379. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10380. 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")));
  10381. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10382. {
  10383. 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++)
  10384. {
  10385. 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"));
  10386. 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"));
  10387. 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)
  10388. 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"));
  10389. }
  10390. }
  10391. }
  10392. }
  10393. else
  10394. {
  10395. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10396. }
  10397. }
  10398. }
  10399. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10400. {
  10401. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10402. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10403. // Required data
  10404. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10405. // Optional data
  10406. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10407. {
  10408. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10409. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10410. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10411. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10412. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10413. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10414. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10415. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10416. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10417. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10418. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10419. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10420. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10421. {
  10422. 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")));
  10423. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10424. 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"));
  10425. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10426. 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"));
  10427. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10428. 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")));
  10429. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10430. {
  10431. 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++)
  10432. {
  10433. 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"));
  10434. 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"));
  10435. 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)
  10436. 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"));
  10437. }
  10438. }
  10439. }
  10440. }
  10441. else
  10442. {
  10443. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10444. }
  10445. }
  10446. else
  10447. {
  10448. DEBUG_WARN("Connector id is over maximun value.\n");
  10449. result = FAIL;
  10450. }
  10451. }
  10452. if(result == PASS)
  10453. {
  10454. if(connectorIdInt > 0)
  10455. {
  10456. //check Transaction active
  10457. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10458. {
  10459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10460. {
  10461. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10462. }
  10463. else
  10464. {
  10465. tempIndex = connectorIdInt -1;
  10466. }
  10467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10468. {
  10469. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10470. {
  10471. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10472. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10473. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10474. {
  10475. //Reserved
  10476. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10477. }
  10478. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10479. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10480. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10481. {
  10482. //Reserved
  10483. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10485. goto end;
  10486. }
  10487. else
  10488. {
  10489. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10490. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10491. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10492. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10493. {
  10494. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10495. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10496. goto end;
  10497. }
  10498. }//END FOR ELSE
  10499. }
  10500. }// END FOR CHAdeMO_QUANTITY
  10501. }
  10502. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10503. {
  10504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10505. {
  10506. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10507. }
  10508. else
  10509. {
  10510. tempIndex = connectorIdInt -1;
  10511. }
  10512. for (int index = 0; index < CCS_QUANTITY; index++)
  10513. {
  10514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10515. {
  10516. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10517. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10518. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10519. {
  10520. //Reserved
  10521. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10522. }
  10523. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10524. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10525. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10526. {
  10527. //Reserved
  10528. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10529. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10530. goto end;
  10531. }
  10532. else
  10533. {
  10534. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10535. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10536. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10537. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10538. {
  10539. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10540. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10541. goto end;
  10542. }
  10543. }// END FOR ELSE
  10544. }
  10545. }// END FOR CCS_QUANTITY
  10546. }
  10547. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10548. {
  10549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10550. {
  10551. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10552. }
  10553. else
  10554. {
  10555. tempIndex = connectorIdInt -1;
  10556. }
  10557. for (int index = 0; index < GB_QUANTITY; index++)
  10558. {
  10559. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10560. {
  10561. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10562. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10563. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10564. {
  10565. //Reserved
  10566. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10567. }
  10568. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10569. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10570. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10571. {
  10572. //Reserved
  10573. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10574. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10575. goto end;
  10576. }
  10577. else
  10578. {
  10579. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10580. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10581. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10582. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10583. {
  10584. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10585. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10586. goto end;
  10587. }
  10588. }// END FOR ELSE
  10589. }
  10590. } // END FOR GB_QUANTITY
  10591. }
  10592. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10593. {
  10594. tempIndex = connectorIdInt -1;
  10595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10596. {
  10597. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10598. {
  10599. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10600. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10601. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10602. {
  10603. //Reserved
  10604. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10605. }
  10606. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10608. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10609. {
  10610. //Reserved
  10611. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10613. goto end;
  10614. }
  10615. else
  10616. {
  10617. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10618. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10619. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10620. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10621. {
  10622. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10623. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10624. goto end;
  10625. }
  10626. }// END FOR ELSE
  10627. }
  10628. } // END FOR GB_QUANTITY
  10629. }
  10630. else
  10631. {
  10632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10633. {
  10634. tempIndex = 2;
  10635. }
  10636. else
  10637. {
  10638. tempIndex = connectorIdInt -1;
  10639. }
  10640. for (int index = 0; index < AC_QUANTITY; index++)
  10641. {
  10642. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10643. {
  10644. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10645. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10646. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10647. {
  10648. //Reserved
  10649. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10650. }
  10651. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10652. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10653. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10654. {
  10655. //Reserved
  10656. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10657. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10658. goto end;
  10659. }
  10660. else
  10661. {
  10662. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10663. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10664. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10665. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10666. {
  10667. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10668. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10669. goto end;
  10670. }
  10671. }//END FOR ELSE
  10672. }
  10673. }// END FOR AC_QUANTITY
  10674. }
  10675. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10676. {
  10677. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10678. {
  10679. // Save profile to file
  10680. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10681. system(cmdBuf);
  10682. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10683. fp = fopen(cmdBuf, "w");
  10684. 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));
  10685. fclose(fp);
  10686. }
  10687. else
  10688. {
  10689. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10691. goto end;
  10692. }
  10693. }
  10694. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10695. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10696. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10697. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10698. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10700. }
  10701. else
  10702. {
  10703. uint8_t isHasIdleConnector = FALSE;
  10704. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10705. {
  10706. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10707. {
  10708. isHasIdleConnector = TRUE;
  10709. break;
  10710. }
  10711. }
  10712. if(isHasIdleConnector == TRUE)
  10713. {
  10714. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10715. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10716. {
  10717. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10718. {
  10719. // Save profile to file
  10720. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10721. system(cmdBuf);
  10722. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10723. fp = fopen(cmdBuf, "w");
  10724. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10725. fclose(fp);
  10726. refreshStartTimer(&clientTime.RemoteStartWait);
  10727. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10728. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10729. }
  10730. else
  10731. {
  10732. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10733. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10734. }
  10735. }
  10736. else
  10737. {
  10738. refreshStartTimer(&clientTime.RemoteStartWait);
  10739. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10740. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10741. }
  10742. }
  10743. else
  10744. {
  10745. DEBUG_INFO("There is not any connector is idle.\n");
  10746. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10747. }
  10748. }
  10749. }
  10750. else
  10751. {
  10752. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10753. }
  10754. end:
  10755. json_object_put(RemoteStartTransaction);
  10756. sendRemoteStartConfirmation(uuid, comfirmstr);
  10757. return result;
  10758. }
  10759. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10760. {
  10761. mtrace();
  10762. int result = FAIL;
  10763. int match = FALSE;
  10764. int GunNO = 0;
  10765. int tempIndex = 0;
  10766. int transactionIdInt=0;
  10767. int transactionIdIsNULL= TRUE;
  10768. char comfirmstr[20];
  10769. json_object *RemoteStopTransaction;
  10770. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10771. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10772. if(server_pending == TRUE)
  10773. {
  10774. return 0;
  10775. }
  10776. RemoteStopTransaction = json_tokener_parse(payload);
  10777. if(!is_error(RemoteStopTransaction))
  10778. {
  10779. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10780. {
  10781. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10782. transactionIdIsNULL = FALSE;
  10783. }
  10784. }
  10785. json_object_put(RemoteStopTransaction);
  10786. if(transactionIdIsNULL == FALSE)
  10787. {
  10788. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10789. {
  10790. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10791. {
  10792. //check Transaction active
  10793. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10794. {
  10795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10796. {
  10797. tempIndex = ((gun_index==2) ? 1: 0);
  10798. }
  10799. else
  10800. {
  10801. tempIndex = gun_index;
  10802. }
  10803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10804. {
  10805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10806. {
  10807. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10808. {
  10809. match = TRUE;
  10810. GunNO = gun_index;
  10811. }
  10812. }
  10813. }// END FOR CHAdeMO_QUANTITY
  10814. }
  10815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10816. {
  10817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10818. {
  10819. tempIndex = ((gun_index==2) ? 1: 0);
  10820. }
  10821. else
  10822. {
  10823. tempIndex = gun_index;
  10824. }
  10825. for (int index = 0; index < CCS_QUANTITY; index++)
  10826. {
  10827. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10828. {
  10829. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10830. {
  10831. match = TRUE;
  10832. GunNO = gun_index;
  10833. }
  10834. }
  10835. }// END FOR CCS_QUANTITY
  10836. }
  10837. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10838. {
  10839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10840. {
  10841. tempIndex = ((gun_index==2) ? 1: 0);
  10842. }
  10843. else
  10844. {
  10845. tempIndex = gun_index;
  10846. }
  10847. for (int index = 0; index < GB_QUANTITY; index++)
  10848. {
  10849. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10850. {
  10851. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10852. {
  10853. match = TRUE;
  10854. GunNO = gun_index;
  10855. }
  10856. }
  10857. }// END FOR GB_QUANTITY
  10858. }
  10859. else if(gunType[gun_index] == GUN_TYPE_DO)
  10860. {
  10861. tempIndex = gun_index;
  10862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10863. {
  10864. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10865. {
  10866. 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
  10867. {
  10868. match = TRUE;
  10869. GunNO = gun_index;
  10870. }
  10871. }
  10872. }// END FOR GB_QUANTITY
  10873. }
  10874. else
  10875. {
  10876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10877. {
  10878. tempIndex = 2;
  10879. }
  10880. else
  10881. {
  10882. tempIndex = gun_index;
  10883. }
  10884. for (int index = 0; index < AC_QUANTITY; index++)
  10885. {
  10886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10887. {
  10888. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10889. {
  10890. match = TRUE;
  10891. GunNO = gun_index;
  10892. }
  10893. }
  10894. }// END FOR CHAdeMO_QUANTITY
  10895. } // END FOR AC ELSE
  10896. }// CHECK IF ResponseTransactionId == transactionIdInt
  10897. }//END FOR
  10898. if( match == TRUE)
  10899. {
  10900. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10901. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10902. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10903. }
  10904. else
  10905. {
  10906. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10907. }
  10908. }
  10909. else
  10910. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10911. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10912. return result;
  10913. }
  10914. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10915. {
  10916. mtrace();
  10917. int result = FAIL;
  10918. int connectorIdInt=0, reservationIdInt=0;
  10919. int tempIndex = 0;
  10920. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10921. char comfirmstr[20]={0};
  10922. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10923. int c = 0;
  10924. char *loc;
  10925. //char *ptr;
  10926. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10927. strcpy(sstrtemp, stringtrimspace(payload));
  10928. //***(1)connectorId ****/
  10929. c=0;
  10930. loc = strstr(sstrtemp, "connectorId");
  10931. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10932. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10933. {
  10934. sstr[c] = loc[strlen("connectorId")+2+c];
  10935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10936. c++;
  10937. }
  10938. sstr[c] = '\0';
  10939. connectorIdInt = atoi(sstr);
  10940. //***(2)expiryDate ****/
  10941. loc = strstr(sstrtemp, "expiryDate");
  10942. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10943. c = 0;
  10944. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10945. {
  10946. sstr[c] = loc[3+strlen("expiryDate")+c];
  10947. c++;
  10948. }
  10949. sstr[c] = '\0';
  10950. strcpy(expiryDatestr, sstr);
  10951. //***(3)idTag ****/
  10952. loc = strstr(sstrtemp, "idTag");
  10953. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10954. c = 0;
  10955. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10956. {
  10957. sstr[c] = loc[3+strlen("idTag")+c];
  10958. c++;
  10959. }
  10960. sstr[c] = '\0';
  10961. strcpy(idTagstr, sstr);
  10962. //***(4)parentIdTag ****/
  10963. loc = strstr(sstrtemp, "parentIdTag");
  10964. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10965. c = 0;
  10966. if(loc == NULL)
  10967. {
  10968. strcpy(parentIdTagstr, "");
  10969. }
  10970. else
  10971. {
  10972. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10973. {
  10974. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10975. c++;
  10976. }
  10977. sstr[c] = '\0';
  10978. strcpy(parentIdTagstr, sstr);
  10979. }
  10980. //***(5)reservationId ****/
  10981. c=0;
  10982. loc = strstr(sstrtemp, "reservationId");
  10983. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10984. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10985. {
  10986. sstr[c] = loc[strlen("reservationId")+2+c];
  10987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10988. c++;
  10989. }
  10990. sstr[c] = '\0';
  10991. reservationIdInt = atoi(sstr);
  10992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10993. /*
  10994. enum SYSTEM_STATUS
  10995. {
  10996. SYS_MODE_BOOTING = 0,
  10997. SYS_MODE_IDLE = 1,
  10998. SYS_MODE_AUTHORIZING = 2,
  10999. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11000. SYS_MODE_REASSIGN = 4,
  11001. SYS_MODE_PREPARING = 5,
  11002. SYS_MODE_PREPARE_FOR_EV = 6,
  11003. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11004. SYS_MODE_CHARGING = 8,
  11005. SYS_MODE_TERMINATING = 9,
  11006. SYS_MODE_COMPLETE = 10,
  11007. SYS_MODE_ALARM = 11,
  11008. SYS_MODE_FAULT = 12,
  11009. SYS_MODE_RESERVATION = 13,
  11010. SYS_MODE_BOOKING = 14,
  11011. SYS_MODE_MAINTAIN = 15,
  11012. SYS_MODE_DEBUG = 16,
  11013. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11014. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11015. SYS_MODE_UPDATE = 19
  11016. };
  11017. */
  11018. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11019. {
  11020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11021. goto end;
  11022. }
  11023. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11024. {
  11025. //check Transaction active
  11026. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11027. {
  11028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11029. {
  11030. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11031. }
  11032. else
  11033. {
  11034. tempIndex = connectorIdInt -1;
  11035. }
  11036. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11037. {
  11038. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11039. {
  11040. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11041. {
  11042. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11043. {
  11044. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11045. {
  11046. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11048. }
  11049. 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'))
  11050. {
  11051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11052. }
  11053. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11054. {
  11055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11056. }
  11057. else
  11058. {
  11059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11060. }
  11061. }
  11062. 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
  11063. {
  11064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11065. }
  11066. }
  11067. else
  11068. {
  11069. //replace reservation
  11070. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11072. }
  11073. }
  11074. } // END FOR CHAdeMO_QUANTITY
  11075. }
  11076. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11077. {
  11078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11079. {
  11080. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11081. }
  11082. else
  11083. {
  11084. tempIndex = connectorIdInt -1;
  11085. }
  11086. for (int index = 0; index < CCS_QUANTITY; index++)
  11087. {
  11088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11089. {
  11090. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11091. {
  11092. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11093. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11094. {
  11095. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11096. {
  11097. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11099. }
  11100. 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'))
  11101. {
  11102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11103. }
  11104. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11105. {
  11106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11107. }
  11108. else
  11109. {
  11110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11111. }
  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_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  11114. {
  11115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11116. }
  11117. }
  11118. else
  11119. {
  11120. //replace reservation
  11121. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11123. }
  11124. }
  11125. } // END FOR CCS_QUANTITY
  11126. }
  11127. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11128. {
  11129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11130. {
  11131. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11132. }
  11133. else
  11134. {
  11135. tempIndex = connectorIdInt -1;
  11136. }
  11137. for (int index = 0; index < GB_QUANTITY; index++)
  11138. {
  11139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11140. {
  11141. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11142. {
  11143. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11144. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11145. {
  11146. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11147. {
  11148. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11150. }
  11151. 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'))
  11152. {
  11153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11154. }
  11155. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11156. {
  11157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11158. }
  11159. else
  11160. {
  11161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11162. }
  11163. }
  11164. 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
  11165. {
  11166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11167. }
  11168. }
  11169. else
  11170. {
  11171. //replace reservation
  11172. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11174. }
  11175. }
  11176. }// END FOR GB_QUANTITY
  11177. }
  11178. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11179. {
  11180. tempIndex = connectorIdInt -1;
  11181. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11182. {
  11183. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11184. {
  11185. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11186. {
  11187. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11188. 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
  11189. {
  11190. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11191. {
  11192. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11194. }
  11195. 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'))
  11196. {
  11197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11198. }
  11199. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11200. {
  11201. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11202. }
  11203. else
  11204. {
  11205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11206. }
  11207. }
  11208. 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
  11209. {
  11210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11211. }
  11212. }
  11213. else
  11214. {
  11215. //replace reservation
  11216. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11218. }
  11219. }
  11220. }// END FOR GB_QUANTITY
  11221. }
  11222. else
  11223. {
  11224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11225. {
  11226. tempIndex = 2;
  11227. }
  11228. else
  11229. {
  11230. tempIndex = (connectorIdInt -1);
  11231. }
  11232. for (int index = 0; index < AC_QUANTITY; index++)
  11233. {
  11234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11235. {
  11236. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11237. {
  11238. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11239. {
  11240. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11241. {
  11242. 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))
  11243. {
  11244. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11245. }
  11246. else
  11247. {
  11248. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11249. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11250. }
  11251. }
  11252. 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'))
  11253. {
  11254. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11255. }
  11256. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11257. {
  11258. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11259. }
  11260. else
  11261. {
  11262. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11263. }
  11264. }
  11265. 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
  11266. {
  11267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11268. }
  11269. }
  11270. else
  11271. {
  11272. //replace reservation
  11273. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11275. }
  11276. }
  11277. } // END FOR AC_QUANTITY
  11278. }
  11279. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11280. }
  11281. else if(connectorIdInt == 0)
  11282. {
  11283. //check Transaction active
  11284. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11285. {
  11286. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11287. {
  11288. 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'))
  11289. {
  11290. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11291. goto end;
  11292. }
  11293. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11294. {
  11295. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11296. goto end;
  11297. }
  11298. 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
  11299. {
  11300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11301. goto end;
  11302. }
  11303. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11304. {
  11305. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11306. goto end;
  11307. }
  11308. }
  11309. }// END FOR CHAdeMO_QUANTITY
  11310. for (int index = 0; index < CCS_QUANTITY; index++)
  11311. {
  11312. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11313. {
  11314. 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'))
  11315. {
  11316. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11317. goto end;
  11318. }
  11319. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11320. {
  11321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11322. goto end;
  11323. }
  11324. 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
  11325. {
  11326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11327. goto end;
  11328. }
  11329. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11330. {
  11331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11332. goto end;
  11333. }
  11334. }
  11335. } // END FOR CCS_QUANTITY
  11336. for (int index = 0; index < GB_QUANTITY; index++)
  11337. {
  11338. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11339. {
  11340. 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'))
  11341. {
  11342. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11343. goto end;
  11344. }
  11345. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11346. {
  11347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11348. goto end;
  11349. }
  11350. 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
  11351. {
  11352. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11353. goto end;
  11354. }
  11355. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11356. {
  11357. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11358. goto end;
  11359. }
  11360. }
  11361. } // END FOR GB_QUANTITY
  11362. for (int index = 0; index < AC_QUANTITY; index++)
  11363. {
  11364. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11365. {
  11366. 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'))
  11367. {
  11368. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11369. goto end;
  11370. }
  11371. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11372. {
  11373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11374. goto end;
  11375. }
  11376. 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
  11377. {
  11378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11379. goto end;
  11380. }
  11381. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11382. {
  11383. 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))
  11384. {
  11385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11386. goto end;
  11387. }
  11388. }
  11389. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11390. {
  11391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11392. goto end;
  11393. }
  11394. }
  11395. }// END FOR AC_QUANTITY
  11396. //The connectorId is 0
  11397. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11399. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11400. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11401. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11402. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11403. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11404. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11405. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11406. result = TRUE;
  11407. return result;
  11408. }
  11409. else
  11410. {
  11411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11412. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11413. }
  11414. if(strcmp(comfirmstr,"Accepted") == 0)
  11415. {
  11416. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11417. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11418. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11419. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11420. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11421. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11422. result = TRUE;
  11423. return result;
  11424. }
  11425. end:
  11426. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11427. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11428. return result;
  11429. }
  11430. int handleResetRequest(char *uuid, char *payload)
  11431. {
  11432. mtrace();
  11433. int result = FAIL;
  11434. char sstr[10]={0},sstrtemp[30]={ 0 };
  11435. char typestr[10]={0};
  11436. char comfirmstr[20]={0};
  11437. int c = 0;
  11438. char *loc;
  11439. DEBUG_INFO("handleResetRequest...\n");
  11440. strcpy(sstrtemp, stringtrimspace(payload));
  11441. loc = strstr(sstrtemp, "type");
  11442. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11443. c = 0;
  11444. while (loc[3+strlen("type")+c] != '\"')
  11445. {
  11446. sstr[c] = loc[3+strlen("type")+c];
  11447. c++;
  11448. }
  11449. sstr[c] = '\0';
  11450. strcpy(typestr,sstr);
  11451. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11452. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11453. {
  11454. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11455. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11456. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11457. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11458. }
  11459. else
  11460. {
  11461. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11462. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11463. result = PASS;
  11464. }
  11465. sendResetConfirmation(uuid, comfirmstr);
  11466. return result;
  11467. }
  11468. int handleSendLocalListRequest(char *uuid, char *payload)
  11469. {
  11470. mtrace();
  11471. int result = FAIL;
  11472. char comfirmstr[20];
  11473. int checkState_Faulted = FALSE;
  11474. json_object *SendLocalList;
  11475. DEBUG_INFO("handleSendLocalListRequest...\n");
  11476. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11477. {
  11478. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11479. goto end;
  11480. }
  11481. //check Charge Point state
  11482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11483. {
  11484. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11485. {
  11486. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11487. }
  11488. }
  11489. for (int index = 0; index < CCS_QUANTITY; index++)
  11490. {
  11491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11492. {
  11493. checkState_Faulted = TRUE; //OCPP Status
  11494. }
  11495. }
  11496. for (int index = 0; index < GB_QUANTITY; index++)
  11497. {
  11498. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11499. {
  11500. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11501. }
  11502. }
  11503. //check Charge Point state
  11504. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11505. {
  11506. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11507. {
  11508. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11509. }
  11510. }
  11511. //check Charge Point state
  11512. for (int index = 0; index < AC_QUANTITY; index++)
  11513. {
  11514. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11515. {
  11516. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11517. }
  11518. }
  11519. if(checkState_Faulted == TRUE)
  11520. {
  11521. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11522. goto end;
  11523. }
  11524. // Parsing payload
  11525. SendLocalList = json_tokener_parse(payload);
  11526. if(!is_error(SendLocalList))
  11527. {
  11528. // Required data
  11529. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11530. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11531. // Optional data
  11532. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11533. {
  11534. //Check UpdateType
  11535. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11536. {
  11537. //Local list full update
  11538. DEBUG_INFO("Local list full update.\n");
  11539. OCPP_getListVerion();
  11540. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11541. {
  11542. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11543. goto end;
  11544. }
  11545. OCPP_cleanLocalList();
  11546. }
  11547. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11548. {
  11549. //Local list different update
  11550. DEBUG_INFO("Local list different update.\n");
  11551. OCPP_getListVerion();
  11552. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11553. {
  11554. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11555. goto end;
  11556. }
  11557. }
  11558. else
  11559. {
  11560. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11561. goto end;
  11562. }
  11563. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11564. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11565. {
  11566. 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")));
  11567. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11568. {
  11569. 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")));
  11570. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11571. 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")));
  11572. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11573. 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")));
  11574. }
  11575. // Add to db
  11576. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11577. {
  11578. //Local list full update
  11579. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11580. idx,
  11581. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11582. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11583. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11584. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11585. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11586. // update list
  11587. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11588. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11589. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11590. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11591. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11592. }
  11593. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11594. {
  11595. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11596. idx,
  11597. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11598. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11599. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11600. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11601. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11602. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11603. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11604. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11605. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11606. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11607. }
  11608. }
  11609. }
  11610. else
  11611. {
  11612. //Check UpdateType
  11613. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11614. {
  11615. //Local list full update
  11616. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11617. OCPP_cleanLocalList();
  11618. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11619. goto end;
  11620. }
  11621. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11622. {
  11623. //Local list different update
  11624. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11625. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11626. goto end;
  11627. }
  11628. }
  11629. result = PASS;
  11630. }
  11631. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11632. end:
  11633. json_object_put(SendLocalList);
  11634. sendSendLocalListConfirmation(uuid, comfirmstr);
  11635. return result;
  11636. }
  11637. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11638. {
  11639. mtrace();
  11640. int result = FAIL;
  11641. struct StructSetChargingProfile SetProfileReq = {0};
  11642. int tempchargingProfileIdInt;
  11643. int chargingSchedulePeriodCount = 0;
  11644. char comfirmstr[20]={0};
  11645. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11646. char rmFileCmd[128]={0};
  11647. int profileQuantity = 0;
  11648. json_object *SetChargingProfile;
  11649. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11650. SetChargingProfile = json_tokener_parse(payload);
  11651. if(!is_error(SetChargingProfile))
  11652. {
  11653. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11654. {
  11655. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11656. }
  11657. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11658. {
  11659. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11660. {
  11661. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11662. }
  11663. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11664. {
  11665. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11666. }
  11667. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11668. {
  11669. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11670. }
  11671. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11672. {
  11673. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11674. }
  11675. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11676. {
  11677. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11678. }
  11679. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11680. {
  11681. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11682. }
  11683. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11684. {
  11685. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11686. }
  11687. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11688. {
  11689. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11690. }
  11691. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11692. {
  11693. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11694. {
  11695. 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")));
  11696. }
  11697. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11698. {
  11699. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11700. }
  11701. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11702. {
  11703. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11704. }
  11705. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11706. {
  11707. 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")));
  11708. }
  11709. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11710. {
  11711. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11712. if(chargingSchedulePeriodCount <= 10)
  11713. {
  11714. 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++)
  11715. {
  11716. 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)
  11717. {
  11718. 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"));
  11719. }
  11720. 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)
  11721. {
  11722. 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"));
  11723. }
  11724. 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)
  11725. {
  11726. 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"));
  11727. }
  11728. }
  11729. }
  11730. }
  11731. }
  11732. }
  11733. }
  11734. // Profile periods quantity check
  11735. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11736. {
  11737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11738. goto end;
  11739. }
  11740. // Check invalid limit
  11741. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11742. {
  11743. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11744. {
  11745. 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)))) ||
  11746. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11747. {
  11748. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11749. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11750. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11751. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11752. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11753. goto end;
  11754. }
  11755. }
  11756. }
  11757. else
  11758. {
  11759. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11760. {
  11761. 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))
  11762. {
  11763. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11764. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11765. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11766. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11767. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11768. goto end;
  11769. }
  11770. }
  11771. }
  11772. // Profile purpose info check
  11773. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11774. {
  11775. FILE *fp;
  11776. char dataLine[4096]={0};
  11777. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11778. if(SetProfileReq.ConnectorId != 0)
  11779. {
  11780. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11781. goto end;
  11782. }
  11783. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11784. if (!fp)
  11785. {
  11786. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11787. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11788. }
  11789. else
  11790. {
  11791. while(fscanf(fp, "%s", dataLine) != EOF)
  11792. {
  11793. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11794. {
  11795. profileQuantity += 1;
  11796. }
  11797. }
  11798. }
  11799. fclose(fp);
  11800. }
  11801. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11802. {
  11803. FILE *fp;
  11804. char dataLine[4096]={0};
  11805. char filename[128]={0};
  11806. int tmpProfileQuantity;
  11807. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11808. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11809. {
  11810. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11811. goto end;
  11812. }
  11813. if(SetProfileReq.ConnectorId == 0)
  11814. {
  11815. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11816. {
  11817. tmpProfileQuantity = 0;
  11818. memset(filename, 0, ARRAY_SIZE(filename));
  11819. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11820. fp = fopen(filename, "r");
  11821. if (!fp)
  11822. {
  11823. DEBUG_INFO("%s does not create.\n", filename);
  11824. fp = fopen(filename, "w+");
  11825. }
  11826. else
  11827. {
  11828. while(fscanf(fp, "%s", dataLine) != EOF)
  11829. {
  11830. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11831. {
  11832. tmpProfileQuantity += 1;
  11833. }
  11834. }
  11835. }
  11836. fclose(fp);
  11837. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11838. }
  11839. }
  11840. else
  11841. {
  11842. memset(filename, 0, ARRAY_SIZE(filename));
  11843. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11844. fp = fopen(filename, "r");
  11845. if (!fp)
  11846. {
  11847. DEBUG_INFO("%s does not create.\n", filename);
  11848. fp = fopen(filename, "w+");
  11849. }
  11850. else
  11851. {
  11852. while(fscanf(fp, "%s", dataLine) != EOF)
  11853. {
  11854. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11855. {
  11856. profileQuantity += 1;
  11857. }
  11858. }
  11859. }
  11860. fclose(fp);
  11861. }
  11862. }
  11863. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11864. {
  11865. int isMatchTransactiodId= FALSE;
  11866. FILE *fp;
  11867. char dataLine[4096]={0};
  11868. char filename[128]={0};
  11869. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11870. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11871. if(SetProfileReq.ConnectorId == 0)
  11872. {
  11873. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11874. goto end;
  11875. }
  11876. int tempIndex = 0;
  11877. //check Transaction active
  11878. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11879. {
  11880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11881. {
  11882. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11883. }
  11884. else
  11885. {
  11886. tempIndex = SetProfileReq.ConnectorId -1;
  11887. }
  11888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11889. {
  11890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11891. {
  11892. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11893. {
  11894. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11895. {
  11896. isMatchTransactiodId = TRUE;
  11897. break;
  11898. }
  11899. }
  11900. }
  11901. }
  11902. }
  11903. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11904. {
  11905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11906. {
  11907. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11908. }
  11909. else
  11910. {
  11911. tempIndex = SetProfileReq.ConnectorId -1;
  11912. }
  11913. for (int index = 0; index < CCS_QUANTITY; index++)
  11914. {
  11915. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11916. {
  11917. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11918. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11919. {
  11920. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11921. {
  11922. isMatchTransactiodId = TRUE;
  11923. break;
  11924. }
  11925. }
  11926. }
  11927. }
  11928. }
  11929. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11930. {
  11931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11932. {
  11933. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11934. }
  11935. else
  11936. {
  11937. tempIndex = SetProfileReq.ConnectorId -1;
  11938. }
  11939. for (int index = 0; index < GB_QUANTITY; index++)
  11940. {
  11941. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11942. {
  11943. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11944. {
  11945. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11946. {
  11947. isMatchTransactiodId = TRUE;
  11948. break;
  11949. }
  11950. }
  11951. }
  11952. }
  11953. }
  11954. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11955. {
  11956. tempIndex = SetProfileReq.ConnectorId -1;
  11957. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11958. {
  11959. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11960. {
  11961. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11962. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11963. {
  11964. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11965. {
  11966. isMatchTransactiodId = TRUE;
  11967. break;
  11968. }
  11969. }
  11970. }
  11971. }
  11972. }
  11973. else
  11974. {
  11975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11976. {
  11977. tempIndex = 2;
  11978. }
  11979. else
  11980. {
  11981. tempIndex = (SetProfileReq.ConnectorId -1);
  11982. }
  11983. for (int index = 0; index < AC_QUANTITY; index++)
  11984. {
  11985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11986. {
  11987. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11988. {
  11989. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11990. {
  11991. isMatchTransactiodId = TRUE;
  11992. break;
  11993. }
  11994. }
  11995. }
  11996. }
  11997. }
  11998. //check Transaction active
  11999. if(isMatchTransactiodId == FALSE)
  12000. {
  12001. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12002. goto end;
  12003. }
  12004. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12005. {
  12006. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12007. goto end;
  12008. }
  12009. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12010. fp = fopen(filename, "r");
  12011. if (!fp)
  12012. {
  12013. DEBUG_INFO("%s does not create.\n", filename);
  12014. fp = fopen(filename, "w+");
  12015. }
  12016. else
  12017. {
  12018. //Check Charging Profile Count
  12019. while(fscanf(fp, "%s", dataLine) != EOF)
  12020. {
  12021. //DEBUG_INFO("word=%s\n",word);
  12022. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12023. {
  12024. profileQuantity += 1;
  12025. }
  12026. }
  12027. }
  12028. fclose(fp);
  12029. }
  12030. // Check ChargeProfileMaxStackLevel
  12031. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12032. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12033. {
  12034. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12035. goto end;
  12036. }
  12037. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12038. {
  12039. FILE *fp;
  12040. char dataLine[4096]={0};
  12041. char fnametemp[128]={0};
  12042. int tmpProfileQuantity;
  12043. //Check ChargePointMaxProfile.json exit
  12044. profileQuantity = 0;
  12045. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12046. {
  12047. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12048. //Check Charging Profile Count
  12049. tmpProfileQuantity = 0;
  12050. while(fscanf(fp, "%s", dataLine) != EOF)
  12051. {
  12052. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12053. {
  12054. profileQuantity += 1;
  12055. tmpProfileQuantity += 1;
  12056. }
  12057. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12058. }
  12059. fclose(fp);
  12060. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12061. }
  12062. //Check TxDefaultProfile_%d.json
  12063. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12064. {
  12065. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12066. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12067. if((access(fnametemp,F_OK))!=-1)
  12068. {
  12069. fp = fopen(fnametemp, "r");
  12070. //Check Charging Profile Count
  12071. tmpProfileQuantity = 0;
  12072. while(fscanf(fp, "%s", dataLine) != EOF)
  12073. {
  12074. //DEBUG_INFO("word=%s\n",word);
  12075. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12076. {
  12077. profileQuantity += 1;
  12078. tmpProfileQuantity += 1;
  12079. }
  12080. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12081. }
  12082. fclose(fp);
  12083. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12084. }
  12085. }
  12086. //Check TxProfile_%d.json
  12087. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12088. {
  12089. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12090. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12091. if((access(fnametemp,F_OK))!=-1)
  12092. {
  12093. fp = fopen(fnametemp, "r");
  12094. //Check Charging Profile Count
  12095. tmpProfileQuantity = 0;
  12096. while(fscanf(fp, "%s", dataLine) != EOF)
  12097. {
  12098. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12099. {
  12100. profileQuantity += 1;
  12101. tmpProfileQuantity += 1;
  12102. }
  12103. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12104. }
  12105. fclose(fp);
  12106. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12107. }
  12108. }
  12109. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12110. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12111. {
  12112. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12113. goto end;
  12114. }
  12115. }
  12116. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12117. //**********************************Write to File********************************************************/
  12118. {
  12119. FILE *infile;
  12120. FILE *outfile;
  12121. char dataLine[4096]={0};
  12122. char filename[128]={0};
  12123. int chkChar=0;
  12124. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12125. {
  12126. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12127. {
  12128. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12129. }
  12130. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12131. {
  12132. if(SetProfileReq.ConnectorId==0)
  12133. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12134. else
  12135. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12136. }
  12137. else
  12138. {
  12139. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12140. }
  12141. infile = fopen (filename, "r");
  12142. outfile = fopen (tempfile, "w");
  12143. chkChar = fgetc(infile);
  12144. rewind(infile);
  12145. if(chkChar == EOF)
  12146. {
  12147. // Profile is empty
  12148. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12149. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12150. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12151. fclose(infile);
  12152. fclose(outfile);
  12153. sprintf(rmFileCmd,"rm -f %s",filename);
  12154. system(rmFileCmd);
  12155. rename(tempfile, filename);
  12156. }
  12157. else
  12158. {
  12159. // Profile is not empty
  12160. int ChargingProfileAdded = FALSE;
  12161. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12162. {
  12163. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12164. json_object *tmpChargingProfile;
  12165. tmpChargingProfile = json_tokener_parse(dataLine);
  12166. if(!is_error(SetChargingProfile))
  12167. {
  12168. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12169. {
  12170. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12171. {
  12172. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12173. }
  12174. }
  12175. }
  12176. json_object_put(tmpChargingProfile);
  12177. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12178. {
  12179. if(ChargingProfileAdded == FALSE)
  12180. {
  12181. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12182. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12183. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12184. ChargingProfileAdded = TRUE;
  12185. }
  12186. }
  12187. else
  12188. {
  12189. fprintf(outfile,"%s\n",dataLine);
  12190. if(ChargingProfileAdded == FALSE)
  12191. {
  12192. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12193. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12194. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12195. ChargingProfileAdded = TRUE;
  12196. }
  12197. }
  12198. } // end of while loop
  12199. fclose(infile);
  12200. fclose(outfile);
  12201. sprintf(rmFileCmd,"rm -f %s",filename);
  12202. system(rmFileCmd);
  12203. rename(tempfile, filename);
  12204. }
  12205. }
  12206. sleep(1);
  12207. result = TRUE;
  12208. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12209. }
  12210. end:
  12211. json_object_put(SetChargingProfile);
  12212. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12213. {
  12214. if(SetProfileReq.ConnectorId == 0)
  12215. {
  12216. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12217. {
  12218. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12219. }
  12220. }
  12221. else
  12222. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12223. }
  12224. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12225. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12226. return result;
  12227. }
  12228. int handleTriggerMessageRequest(char *uuid, char *payload)
  12229. {
  12230. mtrace();
  12231. int result = FAIL;
  12232. int connectorIdIsNULL = FALSE;
  12233. int connectorIdInt =0;
  12234. char sstr[40]={0},sstrtemp[100]={ 0 };
  12235. char requestedMessagestr[40]={0};
  12236. char comfirmstr[20]={0};
  12237. int c = 0;
  12238. char *loc;
  12239. DEBUG_INFO("handleTriggerMessageRequest\n");
  12240. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12241. strcpy(sstrtemp, stringtrimspace(payload));
  12242. c = 0;
  12243. loc = strstr(sstrtemp, "requestedMessage");
  12244. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12245. {
  12246. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12247. c++;
  12248. }
  12249. sstr[c] = '\0';
  12250. strcpy(requestedMessagestr, sstr);
  12251. c = 0;
  12252. loc = strstr(sstrtemp, "connectorId");
  12253. if(loc == NULL)
  12254. {
  12255. connectorIdIsNULL = TRUE;
  12256. }
  12257. else
  12258. {
  12259. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12260. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12261. {
  12262. sstr[c] = loc[strlen("connectorId")+2+c];
  12263. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12264. c++;
  12265. }
  12266. sstr[c] = '\0';
  12267. connectorIdInt = atoi(sstr);
  12268. }
  12269. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12270. {
  12271. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12272. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12273. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12274. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12275. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12276. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12277. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12278. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12279. {
  12280. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12281. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12282. return TRUE;
  12283. }
  12284. else
  12285. {
  12286. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12287. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12288. }
  12289. }
  12290. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12291. {
  12292. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12293. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12294. return TRUE;
  12295. }
  12296. //==========================
  12297. // Trigger message
  12298. //==========================
  12299. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12300. {
  12301. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12302. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12303. {
  12304. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12305. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12306. }
  12307. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12308. }
  12309. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12310. {
  12311. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12312. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12313. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12314. }
  12315. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12316. {
  12317. //sendBootNotificationRequest();
  12318. server_sign = FALSE;
  12319. }
  12320. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12321. {
  12322. refreshStartTimer(&clientTime.Heartbeat);
  12323. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12324. }
  12325. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12326. {
  12327. if(connectorIdIsNULL == FALSE)
  12328. {
  12329. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12330. {
  12331. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12332. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12333. }
  12334. }
  12335. else
  12336. {
  12337. for(int idx=0;idx< gunTotalNumber;idx++)
  12338. {
  12339. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12340. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12341. }
  12342. }
  12343. }
  12344. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12345. {
  12346. if(connectorIdIsNULL == FALSE)
  12347. {
  12348. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12349. {
  12350. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12351. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12352. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12353. }
  12354. }
  12355. else
  12356. {
  12357. for(int idx=0;idx< gunTotalNumber;idx++)
  12358. {
  12359. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12360. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12361. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12362. }
  12363. }
  12364. }
  12365. return result;
  12366. }
  12367. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12368. {
  12369. mtrace();
  12370. int result = FAIL;
  12371. int connectorIdInt =0;
  12372. char comfirmstr[20]={0};
  12373. int tempIndex = 0;
  12374. json_object *UnlockConnector;
  12375. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12376. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12377. UnlockConnector = json_tokener_parse(payload);
  12378. if(!is_error(UnlockConnector))
  12379. {
  12380. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12381. {
  12382. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12383. }
  12384. }
  12385. json_object_put(UnlockConnector);
  12386. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12387. if(gunTotalNumber == 0)
  12388. {
  12389. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12390. goto end;
  12391. }
  12392. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12393. {
  12394. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12395. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12396. goto end;
  12397. }
  12398. else
  12399. {
  12400. //check Transaction active
  12401. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12402. {
  12403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12404. {
  12405. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12406. }
  12407. else
  12408. {
  12409. tempIndex = connectorIdInt -1;
  12410. }
  12411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12412. {
  12413. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12414. {
  12415. //stop Transaction
  12416. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12417. }
  12418. }
  12419. }
  12420. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12421. {
  12422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12423. {
  12424. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12425. }
  12426. else
  12427. {
  12428. tempIndex = connectorIdInt -1;
  12429. }
  12430. for (int index = 0; index < CCS_QUANTITY; index++)
  12431. {
  12432. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12433. {
  12434. //stop Transaction
  12435. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12436. }
  12437. }
  12438. }
  12439. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12440. {
  12441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12442. {
  12443. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12444. }
  12445. else
  12446. {
  12447. tempIndex = connectorIdInt -1;
  12448. }
  12449. for (int index = 0; index < GB_QUANTITY; index++)
  12450. {
  12451. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12452. {
  12453. //stop Transaction
  12454. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12455. }
  12456. }
  12457. }
  12458. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12459. {
  12460. tempIndex = connectorIdInt -1;
  12461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12462. {
  12463. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12464. {
  12465. //stop Transaction
  12466. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12467. }
  12468. }
  12469. }
  12470. else
  12471. {
  12472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12473. {
  12474. tempIndex = 2;
  12475. }
  12476. else
  12477. {
  12478. tempIndex = connectorIdInt-1;
  12479. }
  12480. for (int index = 0; index < AC_QUANTITY; index++)
  12481. {
  12482. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12483. {
  12484. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12485. }
  12486. }
  12487. }
  12488. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12489. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12490. result = TRUE;
  12491. return result;
  12492. }
  12493. end:
  12494. //json_object_put(obj); --- remove temporally
  12495. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12496. return result;
  12497. }
  12498. static char UpdateFirmwarepayloadData[300]={0};
  12499. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12500. {
  12501. mtrace();
  12502. int result = FAIL;
  12503. pthread_t t;
  12504. sendUpdateFirmwareConfirmation(uuid);
  12505. memset(UpdateFirmwarepayloadData, 0, 300);
  12506. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12507. if(!interLock.isUpdateFirmwareGoing)
  12508. {
  12509. interLock.isUpdateFirmwareGoing = 1;
  12510. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12511. sleep(1);
  12512. }
  12513. else
  12514. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12515. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12516. return result;
  12517. }
  12518. void *UpdateFirmwareProcess(void *data)
  12519. {
  12520. pthread_detach(pthread_self());
  12521. mtrace();
  12522. int retriesInt =0, retryIntervalInt=0;
  12523. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12524. int port=0;
  12525. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12526. int isSuccess = 0;
  12527. char ftpbuf[512];
  12528. char temp[100];
  12529. char * pch;
  12530. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12531. json_object *UpdateFirmware;
  12532. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12533. if(!is_error(UpdateFirmware))
  12534. {
  12535. // Required data
  12536. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12537. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12538. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12539. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12540. // Optional data
  12541. if(json_object_object_get(UpdateFirmware, "retries"))
  12542. {
  12543. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12544. }
  12545. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12546. {
  12547. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12548. }
  12549. }
  12550. json_object_put(UpdateFirmware);
  12551. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12552. memset(path, 0, ARRAY_SIZE(path));
  12553. // Wait retrieveData
  12554. if(strlen(retrieveDatestr) > 10)
  12555. {
  12556. do
  12557. {
  12558. sleep(1);
  12559. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12560. }
  12561. // Ready to download
  12562. system("rm -f /mnt/*");
  12563. if(strncmp(locationstr,"http", 4) == 0)
  12564. {
  12565. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12566. sprintf(ftppath,"/%s", path);
  12567. DEBUG_INFO("locationstr: %s\n", locationstr);
  12568. DEBUG_INFO("protocol: %s\n",protocol);
  12569. DEBUG_INFO("host: %s\n",host);
  12570. DEBUG_INFO("path: %s\n",path);
  12571. DEBUG_INFO("ftppath: %s\n",ftppath);
  12572. int ftppathlen=strlen(ftppath);
  12573. int i=1;
  12574. char filenametemp[50];
  12575. while(i < ftppathlen)
  12576. {
  12577. int len=ftppathlen-i;
  12578. if(ftppath[len]== 47) // '/' ascll code: 47
  12579. {
  12580. DEBUG_INFO("compare '/' all right\n");
  12581. break;
  12582. }
  12583. i=i+1;
  12584. }
  12585. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12586. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12587. filenametemp[i+1] = 0;
  12588. do
  12589. {
  12590. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12591. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12592. sleep(1);
  12593. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12594. if(!isSuccess)
  12595. {
  12596. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12597. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12598. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12599. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12600. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12601. }
  12602. else
  12603. {
  12604. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12605. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12606. }
  12607. retriesInt--;
  12608. }while((isSuccess == 0)&&(retriesInt >= 0));
  12609. }
  12610. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12611. {
  12612. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12613. memset(temp, 0, ARRAY_SIZE(temp));
  12614. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12615. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12616. int ftppathlen=strlen(ftpbuf);
  12617. int i=1;
  12618. char filenametemp[50];
  12619. while(i < ftppathlen)
  12620. {
  12621. int len=ftppathlen-i;
  12622. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12623. {
  12624. DEBUG_INFO(" compare '/' all right\n");
  12625. break;
  12626. }
  12627. i=i+1;
  12628. }
  12629. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12630. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12631. filenametemp[i+1] = 0;
  12632. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12633. pch=strchr(temp,'@');
  12634. if(pch==NULL)
  12635. {
  12636. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12637. protocol, host, &port, path);
  12638. strcpy(user,"anonymous");
  12639. strcpy(password,"");
  12640. }
  12641. else
  12642. {
  12643. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12644. protocol, user, password, host, &port, path);
  12645. }
  12646. sscanf(host,"%[^/]%s",host1, path1);
  12647. sprintf(ftppath,"%s", path1);
  12648. //DEBUG_INFO("protocol =%s\n",protocol);
  12649. //DEBUG_INFO("user =%s\n",user);
  12650. //DEBUG_INFO("password =%s\n",password);
  12651. //DEBUG_INFO("host1 =%s\n",host1);
  12652. //DEBUG_INFO("port =%d\n",port);
  12653. //DEBUG_INFO("path1 =%s\n",path1);
  12654. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12655. //ftpFile(host, user, password, port, ftppath, fname);
  12656. //download firmware pthred
  12657. if(port == 0)
  12658. {
  12659. port = 21;
  12660. }
  12661. do
  12662. {
  12663. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12664. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12665. sleep(1);
  12666. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12667. if(!isSuccess)
  12668. {
  12669. //BulldogUtil.sleepMs(interval*1000);
  12670. DEBUG_INFO("Update firmware request and download file fail.\n");
  12671. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12672. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12673. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12674. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12675. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12676. }
  12677. else
  12678. {
  12679. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12680. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12681. }
  12682. retriesInt--;
  12683. }while((!isSuccess)&&(retriesInt >= 0));
  12684. }
  12685. else
  12686. {
  12687. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12688. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12689. sleep(1);
  12690. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12691. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12692. }
  12693. // OCPPPH only, must announce CSU upgrade firmware
  12694. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12695. interLock.isUpdateFirmwareGoing = 0;
  12696. pthread_exit(NULL);
  12697. }
  12698. int handleCertificateSignedRequest(char *uuid, char *payload)
  12699. {
  12700. mtrace();
  12701. int result = PASS;
  12702. json_object *CertificateSigned;
  12703. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12704. CertificateSigned = json_tokener_parse(payload);
  12705. if(!is_error(CertificateSigned))
  12706. {
  12707. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12708. }
  12709. json_object_put(CertificateSigned);
  12710. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12711. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12712. fclose(fp);
  12713. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12714. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12715. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12716. sendCertificateSignedConfirmation(uuid);
  12717. return result;
  12718. }
  12719. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12720. {
  12721. mtrace();
  12722. int result = PASS;
  12723. json_object *DeleteCertificate;
  12724. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12725. DeleteCertificate = json_tokener_parse(payload);
  12726. if(!is_error(DeleteCertificate))
  12727. {
  12728. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12729. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12730. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12731. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12732. }
  12733. json_object_put(DeleteCertificate);
  12734. /*
  12735. * TODO: Delete certificateSigned process
  12736. */
  12737. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12738. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12739. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12740. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12741. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12742. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12743. sendDeleteCertificateConfirmation(uuid);
  12744. return result;
  12745. }
  12746. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12747. {
  12748. mtrace();
  12749. int result = PASS;
  12750. json_object *ExtendedTriggerMessage;
  12751. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12752. ExtendedTriggerMessage = json_tokener_parse(payload);
  12753. if(!is_error(ExtendedTriggerMessage))
  12754. {
  12755. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12756. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12757. {
  12758. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12759. }
  12760. else
  12761. {
  12762. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12763. }
  12764. }
  12765. json_object_put(ExtendedTriggerMessage);
  12766. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12767. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12768. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12769. {
  12770. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12771. }
  12772. else
  12773. {
  12774. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12775. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12776. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12777. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12778. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12779. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12780. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12781. {
  12782. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12783. }
  12784. else
  12785. {
  12786. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12787. }
  12788. }
  12789. sendExtendedTriggerMessageConfirmation(uuid);
  12790. //==========================
  12791. // Trigger message
  12792. //==========================
  12793. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12794. {
  12795. //sendBootNotificationRequest();
  12796. server_sign = FALSE;
  12797. }
  12798. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12799. {
  12800. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12801. }
  12802. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12803. {
  12804. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12805. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12806. {
  12807. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12808. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12809. }
  12810. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12811. }
  12812. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12813. {
  12814. refreshStartTimer(&clientTime.Heartbeat);
  12815. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12816. }
  12817. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12818. {
  12819. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12820. {
  12821. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12822. }
  12823. else
  12824. {
  12825. for(int idx=0;idx< gunTotalNumber;idx++)
  12826. {
  12827. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12828. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12829. }
  12830. }
  12831. }
  12832. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12833. {
  12834. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12835. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12836. {
  12837. 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\" &");
  12838. }
  12839. }
  12840. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12841. {
  12842. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12843. {
  12844. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12845. }
  12846. else
  12847. {
  12848. for(int idx=0;idx< gunTotalNumber;idx++)
  12849. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12850. }
  12851. }
  12852. return result;
  12853. }
  12854. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12855. {
  12856. mtrace();
  12857. int result = PASS;
  12858. json_object *GetInstalledCertificateIds;
  12859. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12860. GetInstalledCertificateIds = json_tokener_parse(payload);
  12861. if(!is_error(GetInstalledCertificateIds))
  12862. {
  12863. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12864. }
  12865. json_object_put(GetInstalledCertificateIds);
  12866. /*
  12867. * TODO: Return installed certificate process
  12868. */
  12869. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12870. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12871. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12872. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12873. sendGetInstalledCertificateIdsConfirmation(uuid);
  12874. return result;
  12875. }
  12876. int handleGetLogRequest(char *uuid, char *payload)
  12877. {
  12878. mtrace();
  12879. int result = PASS;
  12880. json_object *GetLog;
  12881. DEBUG_INFO("handleGetLogRequest...\n");
  12882. GetLog = json_tokener_parse(payload);
  12883. if(!is_error(GetLog))
  12884. {
  12885. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12886. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12887. if(json_object_object_get(GetLog, "retries") != NULL)
  12888. {
  12889. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12890. }
  12891. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12892. {
  12893. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12894. }
  12895. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12896. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12897. {
  12898. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12899. }
  12900. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12901. {
  12902. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12903. }
  12904. }
  12905. json_object_put(GetLog);
  12906. /*
  12907. * TODO: Upload log process
  12908. */
  12909. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12910. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12911. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12912. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12913. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12914. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12915. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12916. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12917. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12918. sendGetLogConfirmation(uuid);
  12919. return result;
  12920. }
  12921. int handleInstallCertificateRequest(char *uuid, char *payload)
  12922. {
  12923. mtrace();
  12924. int result = PASS;
  12925. json_object *InstallCertificate;
  12926. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12927. InstallCertificate = json_tokener_parse(payload);
  12928. if(!is_error(InstallCertificate))
  12929. {
  12930. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12931. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12932. /*
  12933. * TODO: Install certificate process
  12934. */
  12935. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12936. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12937. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12938. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12939. sendInstallCertificateConfirmation(uuid);
  12940. }
  12941. json_object_put(InstallCertificate);
  12942. return result;
  12943. }
  12944. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12945. {
  12946. mtrace();
  12947. int result = PASS;
  12948. json_object *SignedUpdateFirmware;
  12949. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12950. SignedUpdateFirmware = json_tokener_parse(payload);
  12951. if(!is_error(SignedUpdateFirmware))
  12952. {
  12953. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12954. {
  12955. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12956. }
  12957. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12958. {
  12959. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12960. }
  12961. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12962. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12963. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12964. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12965. {
  12966. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12967. }
  12968. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12969. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12970. }
  12971. json_object_put(SignedUpdateFirmware);
  12972. /*
  12973. * TODO: Upgrade firmware process
  12974. */
  12975. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12976. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12977. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12978. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12979. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12980. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12981. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12982. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12983. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12984. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12985. sendInstallCertificateConfirmation(uuid);
  12986. return result;
  12987. }
  12988. int handleUnknownRequest(char *uuid, char *payload)
  12989. {
  12990. mtrace();
  12991. int result = PASS;
  12992. DEBUG_INFO("handleUnknownRequest...\n");
  12993. sendUnknownConfirmation(uuid);
  12994. result = PASS;
  12995. return result;
  12996. }
  12997. //==========================================
  12998. // Handle server response routine
  12999. //==========================================
  13000. void handleAuthorizeResponse(char *payload, int gun_index)
  13001. {
  13002. mtrace();
  13003. char expiryDatestr[30]={0};
  13004. char parentIdTagstr[20]={0};
  13005. char statusstr[20]={0};
  13006. int expiryDateISNULL=FALSE;
  13007. int parentIdTagISNULL=FALSE;
  13008. DEBUG_INFO("handleAuthorizeResponse...\n");
  13009. json_object *Authorize;
  13010. Authorize = json_tokener_parse(payload);
  13011. if(!is_error(Authorize))
  13012. {
  13013. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13014. {
  13015. // Required data
  13016. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13017. // Optional data
  13018. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13019. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13020. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13021. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13022. }
  13023. }
  13024. json_object_put(Authorize);
  13025. if(expiryDateISNULL == FALSE)
  13026. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13027. if(parentIdTagISNULL == FALSE)
  13028. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13029. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13030. //Update idTag information to authorization cache if supproted
  13031. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13032. {
  13033. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13034. }
  13035. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13036. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13037. authorizeRetryTimes = 0;
  13038. }
  13039. void handleBootNotificationResponse(char *payload, int gun_index)
  13040. {
  13041. mtrace();
  13042. char statusStr[12]={0};
  13043. char currentTimeStr[30]={0};
  13044. int intervalInt = 0;
  13045. DEBUG_INFO("handleBootNotificationResponse...\n");
  13046. json_object *BootNotification;
  13047. BootNotification = json_tokener_parse(payload);
  13048. if(!is_error(BootNotification))
  13049. {
  13050. // Required data
  13051. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13052. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13053. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13054. }
  13055. json_object_put(BootNotification);
  13056. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13057. BootNotificationInterval = intervalInt;
  13058. HeartBeatWaitTime = intervalInt;
  13059. //write back to ShmOCPP16DataPH->BootNotification
  13060. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13061. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13062. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13063. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13064. {
  13065. if((intervalInt == 0) || (intervalInt >= 10))
  13066. {
  13067. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13068. HeartBeatWaitTime = intervalInt;
  13069. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13070. }
  13071. server_sign = TRUE;
  13072. server_pending =FALSE;
  13073. }
  13074. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13075. {
  13076. server_pending = TRUE;
  13077. }
  13078. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13079. srand(time(NULL));
  13080. refreshStartTimer(&clientTime.Heartbeat);
  13081. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13082. SetOcppConnStatus(TRUE);
  13083. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13084. }
  13085. void handleDataTransferResponse(char *payload, int gun_index)
  13086. {
  13087. json_object *DataTransfer = json_tokener_parse(payload);
  13088. char status[32];
  13089. if(!is_error(DataTransfer))
  13090. {
  13091. // Required data
  13092. sprintf(status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13093. DEBUG_INFO("Status: %s.\n", status);
  13094. // Optional data
  13095. if(json_object_object_get(DataTransfer, "data") != NULL)
  13096. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13097. // YES call_reader message confirm
  13098. if(ShmOCPP16DataPH->YesCustomData.CallReaderReq == 1)
  13099. {
  13100. sprintf((char *)ShmOCPP16DataPH->YesCustomData.CallReaderStatus, "%s",status);
  13101. ShmOCPP16DataPH->YesCustomData.CallReaderConf = 1;
  13102. ShmOCPP16DataPH->YesCustomData.CallReaderReq = 0;
  13103. DEBUG_INFO("Report CallReader status to CSU: %s\n",ShmOCPP16DataPH->YesCustomData.CallReaderStatus);
  13104. }
  13105. }
  13106. }
  13107. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13108. {
  13109. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13110. //struct json_object *obj;
  13111. // obj = json_tokener_parse(payload);
  13112. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13113. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13114. //No fields are defined.
  13115. }
  13116. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13117. {
  13118. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13119. //struct json_object *obj;
  13120. // obj = json_tokener_parse(payload);
  13121. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13122. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13123. //No fields are defined.
  13124. }
  13125. void handleHeartbeatResponse(char *payload, int gun_index)
  13126. {
  13127. mtrace();
  13128. DEBUG_INFO("handleHeartbeatResponse...\n");
  13129. json_object *Heartbeat;
  13130. Heartbeat = json_tokener_parse(payload);
  13131. if(!is_error(Heartbeat))
  13132. {
  13133. // Required data
  13134. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13135. }
  13136. json_object_put(Heartbeat);
  13137. if(FirstHeartBeat == 0)
  13138. {
  13139. FirstHeartBeat = 1;
  13140. DEBUG_INFO("FirstHeartBeat \n");
  13141. }
  13142. HeartBeatWithNOResponse = 0;
  13143. refreshStartTimer(&clientTime.Heartbeat);
  13144. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13145. }
  13146. void handleMeterValuesResponse(char *payload, int gun_index)
  13147. {
  13148. mtrace();
  13149. DEBUG_INFO("handleMeterValuesResponse...\n");
  13150. isQueueSendable = 1;
  13151. }
  13152. void handleStartTransactionResponse(char *payload, int gun_index)
  13153. {
  13154. mtrace();
  13155. //int transactionIdInt = 0;
  13156. FILE *outfile;
  13157. char data[100]={0};
  13158. DEBUG_INFO("handleStartTransactionResponse...\n");
  13159. json_object *StartTransaction;
  13160. StartTransaction = json_tokener_parse(payload);
  13161. if(!is_error(StartTransaction))
  13162. {
  13163. // Required data
  13164. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13165. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13166. // Optional data
  13167. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13168. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13169. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13170. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13171. }
  13172. json_object_put(StartTransaction);
  13173. isQueueSendable = 1;
  13174. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13175. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13176. //-----------Start : write to the Queue TransactionId file -----------------//
  13177. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13178. {}
  13179. else
  13180. {
  13181. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13182. if(log == NULL)
  13183. {
  13184. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13185. return ;
  13186. }
  13187. else
  13188. {
  13189. fclose(log);
  13190. }
  13191. }
  13192. // open file for writing
  13193. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13194. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13195. {
  13196. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13197. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13198. fputs(data, outfile);
  13199. fclose (outfile);
  13200. }
  13201. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13202. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13203. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13204. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13205. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13206. }
  13207. void handleStatusNotificationResponse(char *payload, int gun_index)
  13208. {
  13209. mtrace();
  13210. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13211. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13213. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13214. }
  13215. void handleStopTransactionnResponse(char *payload, int gun_index)
  13216. {
  13217. mtrace();
  13218. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13219. json_object *StopTransaction;
  13220. StopTransaction = json_tokener_parse(payload);
  13221. if(!is_error(StopTransaction))
  13222. {
  13223. // Optional data
  13224. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13225. {
  13226. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13227. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13228. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13229. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13230. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13231. }
  13232. }
  13233. json_object_put(StopTransaction);
  13234. isQueueSendable = 1;
  13235. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13236. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13237. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13238. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13239. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13240. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13241. }
  13242. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13243. {
  13244. mtrace();
  13245. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13246. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13247. }
  13248. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13249. {
  13250. mtrace();
  13251. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13252. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13253. }
  13254. void handleSignCertificateResponse(char *payload, int gun_index)
  13255. {
  13256. mtrace();
  13257. DEBUG_INFO("handleSignCertificateResponse...\n");
  13258. json_object *SignCertificate;
  13259. SignCertificate = json_tokener_parse(payload);
  13260. if(!is_error(SignCertificate))
  13261. {
  13262. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13263. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13264. }
  13265. json_object_put(SignCertificate);
  13266. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13267. }
  13268. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13269. {
  13270. mtrace();
  13271. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13272. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13273. }
  13274. //==========================================
  13275. // Handle Error routine
  13276. //==========================================
  13277. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13278. {
  13279. mtrace();
  13280. #ifdef SystemLogMessage
  13281. DEBUG_INFO("errorCode: %s\n", errorCode);
  13282. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13283. DEBUG_INFO("errorDetails: %s\n", payload);
  13284. #endif
  13285. }
  13286. //===============================================
  13287. // Common routine
  13288. //===============================================
  13289. int initialConfigurationTable(void)
  13290. {
  13291. //clock_t start_t, end_t, total_t;
  13292. FILE *fp;
  13293. FILE *outfile;
  13294. char str[512]={0};
  13295. char sstr[256]={0};
  13296. int c = 0;
  13297. char *loc;
  13298. int confVersion = 11;
  13299. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13300. //start_t = clock();
  13301. //printf("Starting of the program, start_t = %ld\n", start_t);
  13302. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13303. // Check configuration file size is correct
  13304. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13305. {
  13306. struct stat st;
  13307. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13308. if(st.st_size < 3100)
  13309. {
  13310. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13311. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13312. }
  13313. }
  13314. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13315. {
  13316. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13317. if(outfile == NULL)
  13318. {
  13319. DEBUG_INFO("Error opening file\n");
  13320. return FALSE;
  13321. }
  13322. /*Core Profile*/
  13323. //AllowOfflineTxForUnknownId
  13324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13328. //AuthorizationCacheEnabled
  13329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13333. //AuthorizeRemoteTxRequests
  13334. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13338. //BlinkRepeat
  13339. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13343. //ClockAlignedDataInterval
  13344. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13345. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13348. //ConnectionTimeOut
  13349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13353. //GetConfigurationMaxKeys
  13354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13356. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13358. // HeartbeatInterval
  13359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13363. // LightIntensity
  13364. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13365. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13368. // LocalAuthorizeOffline
  13369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13373. // LocalPreAuthorize
  13374. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13378. // MaxEnergyOnInvalidId
  13379. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13383. // MeterValuesAlignedData
  13384. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13387. 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" );
  13388. else
  13389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13391. // MeterValuesAlignedDataMaxLength
  13392. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13396. else
  13397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13399. // MeterValuesSampledData
  13400. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13403. 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" );
  13404. else
  13405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13407. // MeterValuesSampledDataMaxLength
  13408. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13412. else
  13413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13415. // MeterValueSampleInterval
  13416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13420. // MinimumStatusDuration
  13421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13424. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13426. // NumberOfConnectors
  13427. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13430. {
  13431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13432. }
  13433. else
  13434. {
  13435. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13436. }
  13437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13438. // ResetRetries
  13439. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13440. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13443. // ConnectorPhaseRotation
  13444. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13445. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13446. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13448. // ConnectorPhaseRotationMaxLength
  13449. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13450. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13451. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13453. // StopTransactionOnEVSideDisconnect
  13454. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13455. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13458. // StopTransactionOnInvalidId
  13459. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13460. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13461. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13463. // StopTxnAlignedData
  13464. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13465. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13466. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13468. // StopTxnAlignedDataMaxLength
  13469. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13470. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13473. // StopTxnSampledData
  13474. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13475. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13478. else
  13479. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13481. // StopTxnSampledDataMaxLength
  13482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13485. {
  13486. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13487. }
  13488. else
  13489. {
  13490. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13491. }
  13492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13493. // SupportedFeatureProfiles
  13494. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13496. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13498. // SupportedFeatureProfilesMaxLength
  13499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13500. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13501. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13503. // TransactionMessageAttempts
  13504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13506. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13507. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13509. // TransactionMessageRetryInterval
  13510. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13513. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13515. // UnlockConnectorOnEVSideDisconnect
  13516. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13517. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13520. // WebSocketPingInterval
  13521. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13523. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13525. // QueueOffLineMeterValues
  13526. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13530. // AuthorizationKey
  13531. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13532. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13535. // SecurityProfile
  13536. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13537. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13540. // DefaultPrice
  13541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13545. // CustomDisplayCostAndPrice
  13546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13550. // CustomIdleFeeAfterStop
  13551. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13552. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13553. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13555. // SystemUptimeSec
  13556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13557. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13560. // FreeVend
  13561. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13562. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13565. // OcppServer
  13566. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13568. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13570. // MaintainServer
  13571. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13573. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13575. // Configuration Version
  13576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13580. //* Local Auth List Management Profile*/
  13581. #if 0
  13582. //For OCTT Test Case
  13583. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13586. #endif
  13587. #if 1
  13588. //LocalAuthListEnabled
  13589. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13593. #endif
  13594. //LocalAuthListMaxLength
  13595. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13599. //SendLocalListMaxLength
  13600. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13604. //ReserveConnectorZeroSupported
  13605. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13609. //* Smart Charging Profile */
  13610. //ChargeProfileMaxStackLevel
  13611. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13615. // ChargingScheduleAllowedChargingRateUnit
  13616. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13617. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13620. // ChargingScheduleMaxPeriods
  13621. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13625. // ConnectorSwitch3to1PhaseSupported
  13626. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13630. // MaxChargingProfilesInstalled
  13631. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13632. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13635. fclose(outfile);
  13636. }
  13637. else
  13638. {
  13639. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13640. char keystr[60]={0};
  13641. char readonlystr[10]={0};
  13642. char valuestr[256]={0};
  13643. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13644. if(fp == NULL) {
  13645. DEBUG_INFO("Error opening file");
  13646. return FALSE;
  13647. }
  13648. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13649. {
  13650. //DEBUG_INFO("Get Configuration \n");
  13651. if(strlen(str) > 0)
  13652. {
  13653. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13654. //*************************key*********************************/
  13655. if(strstr(str, "key") != NULL)
  13656. {
  13657. loc = strstr(str, "key");
  13658. c = 0;
  13659. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13660. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13661. {
  13662. sstr[c] = loc[strlen("key")+3+c];
  13663. c++;
  13664. }
  13665. sstr[c] = '\0';
  13666. strcpy(keystr,sstr);
  13667. }
  13668. //*************************readonly*********************************/
  13669. if(strstr(str, "readonly") != NULL)
  13670. {
  13671. loc = strstr(str, "readonly");
  13672. c = 0;
  13673. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13674. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13675. {
  13676. sstr[c] = loc[strlen("readonly")+2+c];
  13677. c++;
  13678. }
  13679. sstr[c] = '\0';
  13680. strcpy(readonlystr,sstr);
  13681. }
  13682. //*************************value*********************************/
  13683. if(strstr(str, "value") != NULL)
  13684. {
  13685. loc = strstr(str, "value");
  13686. c = 0;
  13687. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13688. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13689. {
  13690. sstr[c] = loc[strlen("value")+3+c];
  13691. c++;
  13692. }
  13693. sstr[c] = '\0';
  13694. strcpy(valuestr,sstr);
  13695. }
  13696. // DEBUG_INFO("keystr=%s\n",keystr);
  13697. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13698. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13699. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13700. {
  13701. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13702. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13704. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13705. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13706. }
  13707. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13708. {
  13709. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13710. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13711. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13712. }
  13713. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13714. {
  13715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13717. }
  13718. if(strcmp(keystr, "BlinkRepeat") == 0)
  13719. {
  13720. //Charger.BlinkRepeat = Integer.parseInt(value);
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13722. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13723. }
  13724. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13725. {
  13726. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13727. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13728. }
  13729. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13730. {
  13731. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13732. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13733. }
  13734. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13735. {
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13738. }
  13739. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13740. {
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13743. HeartBeatWaitTime = atoi(valuestr);
  13744. }
  13745. if(strcmp(keystr, "LightIntensity") == 0)
  13746. {
  13747. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13749. }
  13750. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13751. {
  13752. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13754. }
  13755. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13756. {
  13757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13758. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13759. }
  13760. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13761. {
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13764. }
  13765. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13766. {
  13767. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13768. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13769. }
  13770. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13771. {
  13772. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13774. }
  13775. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13776. {
  13777. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13778. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13779. }
  13780. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13781. {
  13782. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13784. }
  13785. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13786. {
  13787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13789. }
  13790. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13791. {
  13792. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13794. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13795. }
  13796. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13797. {
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13799. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13800. }
  13801. if(strcmp(keystr, "ResetRetries") == 0)
  13802. {
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13804. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13805. }
  13806. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13807. {
  13808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13809. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13810. }
  13811. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13812. {
  13813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13814. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13815. }
  13816. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13817. {
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13820. }
  13821. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13822. {
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13824. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13825. }
  13826. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13827. {
  13828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13829. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13830. }
  13831. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13832. {
  13833. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13835. }
  13836. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13837. {
  13838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13839. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13840. }
  13841. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13842. {
  13843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13845. }
  13846. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13847. {
  13848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13850. }
  13851. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13852. {
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13854. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13855. }
  13856. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13857. {
  13858. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13859. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13860. TransactionMessageAttemptsValue = atoi(valuestr);
  13861. }
  13862. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13863. {
  13864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13865. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13866. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13867. }
  13868. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13869. {
  13870. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13871. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13872. }
  13873. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13874. {
  13875. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13877. }
  13878. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13879. {
  13880. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13881. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13882. }
  13883. if(strcmp(keystr, "AuthorizationKey") == 0)
  13884. {
  13885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13886. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13887. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13888. }
  13889. if(strcmp(keystr, "SecurityProfile") == 0)
  13890. {
  13891. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13892. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13894. }
  13895. if(strcmp(keystr, "DefaultPrice") == 0)
  13896. {
  13897. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13898. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13899. }
  13900. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13901. {
  13902. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13903. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13904. }
  13905. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13906. {
  13907. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13908. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13909. }
  13910. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13911. {
  13912. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13914. }
  13915. if(strcmp(keystr, "FreeVend") == 0)
  13916. {
  13917. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13918. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13919. }
  13920. if(strcmp(keystr, "OcppServer") == 0)
  13921. {
  13922. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13923. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13924. }
  13925. if(strcmp(keystr, "MaintainServer") == 0)
  13926. {
  13927. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13928. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13929. }
  13930. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13931. {
  13932. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13933. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13934. }
  13935. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13936. {
  13937. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13938. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13939. }
  13940. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13941. {
  13942. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13943. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13944. }
  13945. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13946. {
  13947. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13948. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13949. }
  13950. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13951. {
  13952. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13953. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13954. }
  13955. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13956. {
  13957. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13959. }
  13960. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13961. {
  13962. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13963. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13964. }
  13965. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13966. {
  13967. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13968. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13969. }
  13970. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13971. {
  13972. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13973. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13974. }
  13975. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13976. {
  13977. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13978. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13979. }
  13980. }
  13981. }
  13982. fclose(fp);
  13983. }
  13984. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13985. {
  13986. return PASS;
  13987. }
  13988. else
  13989. {
  13990. return FAIL;
  13991. }
  13992. }
  13993. void StoreConfigurationTable(void)
  13994. {
  13995. FILE *outfile;
  13996. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13997. if(outfile == NULL)
  13998. {
  13999. DEBUG_INFO("Error opening file");
  14000. return ;
  14001. }
  14002. /*Core Profile*/
  14003. //AllowOfflineTxForUnknownId
  14004. /*
  14005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14006. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14009. */
  14010. //DEBUG_INFO("data=%s\n",data);
  14011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14012. //AuthorizationCacheEnabled
  14013. /*
  14014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14017. */
  14018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14019. //AuthorizeRemoteTxRequests
  14020. /*
  14021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14024. */
  14025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14026. //BlinkRepeat
  14027. /*
  14028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14031. */
  14032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14033. //ClockAlignedDataInterval
  14034. /*
  14035. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14038. */
  14039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14040. //ConnectionTimeOut
  14041. /*
  14042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14045. */
  14046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14047. //GetConfigurationMaxKeys
  14048. /*
  14049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14052. */
  14053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14054. // HeartbeatInterval
  14055. /*
  14056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14059. */
  14060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14061. // LightIntensity
  14062. /*
  14063. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14066. */
  14067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14068. // LocalAuthorizeOffline
  14069. /*
  14070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14073. */
  14074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14075. // LocalPreAuthorize
  14076. /*
  14077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14080. */
  14081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14082. // MaxEnergyOnInvalidId
  14083. /*
  14084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14087. */
  14088. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14090. // MeterValuesAlignedData
  14091. /*
  14092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14095. */
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14097. // MeterValuesAlignedDataMaxLength
  14098. /*
  14099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14102. */
  14103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14104. // MeterValuesSampledData
  14105. /*
  14106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14109. */
  14110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14111. // MeterValuesSampledDataMaxLength
  14112. /*
  14113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14116. */
  14117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14118. // MeterValueSampleInterval
  14119. /*
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14123. */
  14124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14125. // MinimumStatusDuration
  14126. /*
  14127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14130. */
  14131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14132. // NumberOfConnectors
  14133. /*
  14134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14137. {
  14138. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14139. }
  14140. else
  14141. {
  14142. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14143. }
  14144. */
  14145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14146. // ResetRetries
  14147. /*
  14148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14151. */
  14152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14153. // ConnectorPhaseRotation
  14154. /*
  14155. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14158. */
  14159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14160. // ConnectorPhaseRotationMaxLength
  14161. /*
  14162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14165. */
  14166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14167. // StopTransactionOnEVSideDisconnect
  14168. /*
  14169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14172. */
  14173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14174. // StopTransactionOnInvalidId
  14175. /*
  14176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14179. */
  14180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14181. // StopTxnAlignedData
  14182. /*
  14183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14186. */
  14187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14188. // StopTxnAlignedDataMaxLength
  14189. /*
  14190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14193. */
  14194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14195. // StopTxnSampledData
  14196. /*
  14197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14200. */
  14201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14202. // StopTxnSampledDataMaxLength
  14203. /*
  14204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14207. */
  14208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14209. // SupportedFeatureProfiles
  14210. /*
  14211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14214. */
  14215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14216. // SupportedFeatureProfilesMaxLength
  14217. /*
  14218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14221. */
  14222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14223. // TransactionMessageAttempts
  14224. /*
  14225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14228. */
  14229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14230. // TransactionMessageRetryInterval
  14231. /*
  14232. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14235. */
  14236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14237. // UnlockConnectorOnEVSideDisconnect
  14238. /*
  14239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14242. */
  14243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14244. // WebSocketPingInterval
  14245. /*
  14246. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14249. */
  14250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14251. // QueueOffLineMeterValues
  14252. /*
  14253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14256. */
  14257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14258. // AuthorizationKey
  14259. /*
  14260. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14263. */
  14264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14265. // SecurityProfile
  14266. /*
  14267. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14270. */
  14271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14272. // DefaultPrice
  14273. /*
  14274. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14277. */
  14278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14279. // CustomDisplayCostAndPrice
  14280. /*
  14281. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14284. */
  14285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14286. // CustomIdleFeeAfterStop
  14287. /*
  14288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14291. */
  14292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14293. // SystemUptimeSec
  14294. /*
  14295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14298. */
  14299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14300. // FreeVend
  14301. /*
  14302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14305. */
  14306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14307. // OcppServer
  14308. /*
  14309. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14312. */
  14313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14314. // MaintainServer
  14315. /*
  14316. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14319. */
  14320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14321. // ConfigurationVersion
  14322. /*
  14323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14326. */
  14327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14328. //* Local Auth List Management Profile*/
  14329. //LocalAuthListEnabled
  14330. /*
  14331. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14334. */
  14335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14336. //LocalAuthListMaxLength
  14337. /*
  14338. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14341. */
  14342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14343. //SendLocalListMaxLength
  14344. /*
  14345. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14348. */
  14349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14350. //ReserveConnectorZeroSupported
  14351. /*
  14352. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14355. */
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14357. //* Smart Charging Profile */
  14358. //ChargeProfileMaxStackLevel
  14359. /*
  14360. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14363. */
  14364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14365. // ChargingScheduleAllowedChargingRateUnit
  14366. /*
  14367. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14370. */
  14371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14372. // ChargingScheduleMaxPeriods
  14373. /*
  14374. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14377. */
  14378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14379. // ConnectorSwitch3to1PhaseSupported
  14380. /*
  14381. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14384. */
  14385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14386. // MaxChargingProfilesInstalled
  14387. /*
  14388. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14391. */
  14392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14393. fclose(outfile);
  14394. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14395. }
  14396. void getKeyValue(char *keyReq)
  14397. {
  14398. int isEmpty = FALSE;
  14399. int isKnowKey = FALSE;
  14400. DEBUG_INFO("keyReq = %s\n", keyReq);
  14401. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14402. isEmpty = TRUE;
  14403. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14404. {
  14405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14407. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14408. {
  14409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14410. }
  14411. else
  14412. {
  14413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14414. }
  14415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14416. isKnowKey = TRUE;
  14417. }
  14418. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14419. {
  14420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14423. {
  14424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14425. }
  14426. else
  14427. {
  14428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14429. }
  14430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14431. isKnowKey = TRUE;
  14432. }
  14433. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14434. {
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14437. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14438. {
  14439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14440. }
  14441. else
  14442. {
  14443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14444. }
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14446. isKnowKey = TRUE;
  14447. }
  14448. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14449. {
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14453. {
  14454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14455. }
  14456. else
  14457. {
  14458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14459. }
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14461. isKnowKey = TRUE;
  14462. }
  14463. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14464. {
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14467. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14468. {
  14469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14470. }
  14471. else
  14472. {
  14473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14474. }
  14475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14476. isKnowKey = TRUE;
  14477. }
  14478. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14479. {
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14482. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14483. {
  14484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14485. }
  14486. else
  14487. {
  14488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14489. }
  14490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14491. isKnowKey = TRUE;
  14492. }
  14493. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14494. {
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14497. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14498. {
  14499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14500. }
  14501. else
  14502. {
  14503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14504. }
  14505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14506. isKnowKey = TRUE;
  14507. }
  14508. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14509. {
  14510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14512. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14513. {
  14514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14515. }
  14516. else
  14517. {
  14518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14519. }
  14520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14521. isKnowKey = TRUE;
  14522. }
  14523. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14524. {
  14525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14527. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14528. {
  14529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14530. }
  14531. else
  14532. {
  14533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14534. }
  14535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14536. isKnowKey = TRUE;
  14537. }
  14538. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14539. {
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14543. {
  14544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14545. }
  14546. else
  14547. {
  14548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14549. }
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14551. isKnowKey = TRUE;
  14552. }
  14553. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14554. {
  14555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14557. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14558. {
  14559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14560. }
  14561. else
  14562. {
  14563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14564. }
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14566. isKnowKey = TRUE;
  14567. }
  14568. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14569. {
  14570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14572. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14573. {
  14574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14575. }
  14576. else
  14577. {
  14578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14579. }
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14581. isKnowKey = TRUE;
  14582. }
  14583. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14584. {
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14587. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14588. {
  14589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14590. }
  14591. else
  14592. {
  14593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14594. }
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14596. isKnowKey = TRUE;
  14597. }
  14598. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14599. {
  14600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14603. {
  14604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14605. }
  14606. else
  14607. {
  14608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14609. }
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14611. isKnowKey = TRUE;
  14612. }
  14613. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14614. {
  14615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14617. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14618. {
  14619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14620. }
  14621. else
  14622. {
  14623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14624. }
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14626. isKnowKey = TRUE;
  14627. }
  14628. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14629. {
  14630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14632. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14633. {
  14634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14635. }
  14636. else
  14637. {
  14638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14639. }
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14641. isKnowKey = TRUE;
  14642. }
  14643. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14644. {
  14645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14648. {
  14649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14650. }
  14651. else
  14652. {
  14653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14654. }
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14656. isKnowKey = TRUE;
  14657. }
  14658. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14659. {
  14660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14662. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14663. {
  14664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14665. }
  14666. else
  14667. {
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14669. }
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14671. isKnowKey = TRUE;
  14672. }
  14673. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14674. {
  14675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14677. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14678. {
  14679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14680. }
  14681. else
  14682. {
  14683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14684. }
  14685. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14687. isKnowKey = TRUE;
  14688. }
  14689. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14690. {
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14693. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14694. {
  14695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14696. }
  14697. else
  14698. {
  14699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14700. }
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14702. isKnowKey = TRUE;
  14703. }
  14704. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14705. {
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14708. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14709. {
  14710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14711. }
  14712. else
  14713. {
  14714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14715. }
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14717. isKnowKey = TRUE;
  14718. }
  14719. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14723. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14724. {
  14725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14726. }
  14727. else
  14728. {
  14729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14730. }
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14732. isKnowKey = TRUE;
  14733. }
  14734. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14738. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14739. {
  14740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14741. }
  14742. else
  14743. {
  14744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14745. }
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14747. isKnowKey = TRUE;
  14748. }
  14749. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14750. {
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14753. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14754. {
  14755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14756. }
  14757. else
  14758. {
  14759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14760. }
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14762. isKnowKey = TRUE;
  14763. }
  14764. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14765. {
  14766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14768. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14769. {
  14770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14771. }
  14772. else
  14773. {
  14774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14775. }
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14777. isKnowKey = TRUE;
  14778. }
  14779. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14780. {
  14781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14783. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14784. {
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14786. }
  14787. else
  14788. {
  14789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14790. }
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14792. isKnowKey = TRUE;
  14793. }
  14794. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14795. {
  14796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14798. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14799. {
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14801. }
  14802. else
  14803. {
  14804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14805. }
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14807. isKnowKey = TRUE;
  14808. }
  14809. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14810. {
  14811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14813. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14814. {
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14816. }
  14817. else
  14818. {
  14819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14820. }
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14822. isKnowKey = TRUE;
  14823. }
  14824. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14825. {
  14826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14828. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14829. {
  14830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14831. }
  14832. else
  14833. {
  14834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14835. }
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14837. isKnowKey = TRUE;
  14838. }
  14839. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14840. {
  14841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14843. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14844. {
  14845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14846. }
  14847. else
  14848. {
  14849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14850. }
  14851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14852. isKnowKey = TRUE;
  14853. }
  14854. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14855. {
  14856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14858. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14859. {
  14860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14861. }
  14862. else
  14863. {
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14865. }
  14866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14867. isKnowKey = TRUE;
  14868. }
  14869. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14870. {
  14871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14873. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14874. {
  14875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14876. }
  14877. else
  14878. {
  14879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14880. }
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14882. isKnowKey = TRUE;
  14883. }
  14884. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14885. {
  14886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14888. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14889. {
  14890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14891. }
  14892. else
  14893. {
  14894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14895. }
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14897. isKnowKey = TRUE;
  14898. }
  14899. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14900. {
  14901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14903. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14904. {
  14905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14906. }
  14907. else
  14908. {
  14909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14910. }
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14912. isKnowKey = TRUE;
  14913. }
  14914. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14915. {
  14916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14918. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14919. {
  14920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14921. }
  14922. else
  14923. {
  14924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14925. }
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14927. isKnowKey = TRUE;
  14928. }
  14929. /*
  14930. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14931. {
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14934. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14935. {
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14937. }
  14938. else
  14939. {
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14941. }
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14943. isKnowKey = TRUE;
  14944. }*/
  14945. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14946. {
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14949. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14950. {
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14952. }
  14953. else
  14954. {
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14956. }
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14958. isKnowKey = TRUE;
  14959. }
  14960. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14961. {
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14964. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14965. {
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14967. }
  14968. else
  14969. {
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14971. }
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14973. isKnowKey = TRUE;
  14974. }
  14975. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14979. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14980. {
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14982. }
  14983. else
  14984. {
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14986. }
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14988. isKnowKey = TRUE;
  14989. }
  14990. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14991. {
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14994. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14995. {
  14996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14997. }
  14998. else
  14999. {
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15001. }
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15003. isKnowKey = TRUE;
  15004. }
  15005. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15006. {
  15007. struct sysinfo s_info;
  15008. int error = sysinfo(&s_info);
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15011. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15012. {
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15014. }
  15015. else
  15016. {
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15018. }
  15019. if(error != 0)
  15020. {
  15021. DEBUG_WARN("System uptime get error: %d\n", error);
  15022. }
  15023. else
  15024. {
  15025. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15026. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15027. }
  15028. isKnowKey = TRUE;
  15029. }
  15030. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15031. {
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15034. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15035. {
  15036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15037. }
  15038. else
  15039. {
  15040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15041. }
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15043. isKnowKey = TRUE;
  15044. }
  15045. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15046. {
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15052. }
  15053. else
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15056. }
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15058. isKnowKey = TRUE;
  15059. }
  15060. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15061. {
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15067. }
  15068. else
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15071. }
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15073. isKnowKey = TRUE;
  15074. }
  15075. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15076. {
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15079. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15080. {
  15081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15082. }
  15083. else
  15084. {
  15085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15086. }
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15088. isKnowKey = TRUE;
  15089. }
  15090. #if 1
  15091. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15092. {
  15093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15095. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15096. {
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15098. }
  15099. else
  15100. {
  15101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15102. }
  15103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15104. isKnowKey = TRUE;
  15105. }
  15106. #endif
  15107. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15108. {
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15111. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15112. {
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15114. }
  15115. else
  15116. {
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15118. }
  15119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15120. isKnowKey = TRUE;
  15121. }
  15122. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15123. {
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15126. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15127. {
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15129. }
  15130. else
  15131. {
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15133. }
  15134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15135. isKnowKey = TRUE;
  15136. }
  15137. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15138. {
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15141. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15142. {
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15144. }
  15145. else
  15146. {
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15148. }
  15149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15150. isKnowKey = TRUE;
  15151. }
  15152. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15153. {
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15156. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15157. {
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15159. }
  15160. else
  15161. {
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15163. }
  15164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15165. isKnowKey = TRUE;
  15166. }
  15167. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15168. {
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15171. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15172. {
  15173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15174. }
  15175. else
  15176. {
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15178. }
  15179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15180. isKnowKey = TRUE;
  15181. }
  15182. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15183. {
  15184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15186. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15187. {
  15188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15189. }
  15190. else
  15191. {
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15193. }
  15194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15195. isKnowKey = TRUE;
  15196. }
  15197. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15198. {
  15199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15201. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15202. {
  15203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15204. }
  15205. else
  15206. {
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15208. }
  15209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15210. isKnowKey = TRUE;
  15211. }
  15212. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15213. {
  15214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15216. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15217. {
  15218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15219. }
  15220. else
  15221. {
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15223. }
  15224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15225. isKnowKey = TRUE;
  15226. }
  15227. //=========================================================
  15228. if(!isEmpty && !isKnowKey)
  15229. {
  15230. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15231. strcpy(unknownkey[UnknownKeynum], keyReq);
  15232. UnknownKeynum = UnknownKeynum + 1;
  15233. }
  15234. }
  15235. void processUnkownKey(void)
  15236. {
  15237. DEBUG_INFO("processUnkownKey...\n");
  15238. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15239. for(int index=0; index < UnknownKeynum; index++)
  15240. {
  15241. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15242. {
  15243. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15244. }
  15245. }
  15246. }
  15247. int setKeyValue(char *key, char *value)
  15248. {
  15249. int isSuccess = NotSupported;
  15250. int check_ascii=0;
  15251. char str[501]={0};
  15252. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15253. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15254. {
  15255. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15256. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15257. {
  15258. strcpy(str, (const char*)value);
  15259. for(int i = 0; str[i]; i++){
  15260. str[i] = tolower(str[i]);
  15261. }
  15262. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15263. isSuccess = ConfigurationStatus_Accepted;
  15264. }
  15265. else
  15266. {
  15267. isSuccess = ConfigurationStatus_Rejected;
  15268. }
  15269. }
  15270. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15271. {
  15272. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15273. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15274. {
  15275. strcpy(str, (const char*)value);
  15276. for(int i = 0; str[i]; i++){
  15277. str[i] = tolower(str[i]);
  15278. }
  15279. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15280. isSuccess = ConfigurationStatus_Accepted;
  15281. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15282. }
  15283. else
  15284. {
  15285. isSuccess = ConfigurationStatus_Rejected;
  15286. }
  15287. }
  15288. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15289. {
  15290. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15291. {
  15292. strcpy(str, (const char*)value);
  15293. for(int i = 0; str[i]; i++)
  15294. {
  15295. str[i] = tolower(str[i]);
  15296. }
  15297. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15298. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15299. isSuccess = ConfigurationStatus_Accepted;
  15300. }
  15301. else
  15302. {
  15303. isSuccess = ConfigurationStatus_Rejected;
  15304. }
  15305. }
  15306. if(strcmp(key, "BlinkRepeat") == 0)
  15307. {
  15308. //Charger.BlinkRepeat = Integer.parseInt(value);
  15309. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15310. {
  15311. check_ascii = value[0];
  15312. if( (check_ascii < 48) || (check_ascii > 57) )
  15313. {
  15314. isSuccess = ConfigurationStatus_Rejected;
  15315. }
  15316. else
  15317. {
  15318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15319. isSuccess = ConfigurationStatus_Accepted;
  15320. }
  15321. }
  15322. else
  15323. {
  15324. isSuccess = ConfigurationStatus_Rejected;
  15325. }
  15326. }
  15327. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15328. {
  15329. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15330. {
  15331. check_ascii = value[0];
  15332. if( (check_ascii < 48) || (check_ascii > 57) )
  15333. {
  15334. isSuccess = ConfigurationStatus_Rejected;
  15335. }
  15336. else
  15337. {
  15338. if((atoi(value) == 0) || (atoi(value) >= 5))
  15339. {
  15340. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15342. isSuccess = ConfigurationStatus_Accepted;
  15343. }
  15344. else
  15345. isSuccess = ConfigurationStatus_Rejected;
  15346. }
  15347. }
  15348. else
  15349. {
  15350. isSuccess = ConfigurationStatus_Rejected;
  15351. }
  15352. }
  15353. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15354. {
  15355. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15356. {
  15357. check_ascii = value[0];
  15358. if( (check_ascii < 48) || (check_ascii > 57) )
  15359. {
  15360. isSuccess = ConfigurationStatus_Rejected;
  15361. }
  15362. else
  15363. {
  15364. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15365. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15366. isSuccess = ConfigurationStatus_Accepted;
  15367. }
  15368. }
  15369. else
  15370. {
  15371. isSuccess = ConfigurationStatus_Rejected;
  15372. }
  15373. }
  15374. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15375. {
  15376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15377. {
  15378. check_ascii = value[0];
  15379. if( (check_ascii < 48) || (check_ascii > 57) )
  15380. {
  15381. isSuccess = ConfigurationStatus_Rejected;
  15382. }
  15383. else
  15384. {
  15385. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15387. isSuccess = ConfigurationStatus_Accepted;
  15388. }
  15389. }
  15390. else
  15391. {
  15392. isSuccess = ConfigurationStatus_Rejected;
  15393. }
  15394. }
  15395. if(strcmp(key, "HeartbeatInterval") == 0)
  15396. {
  15397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15398. {
  15399. check_ascii = value[0];
  15400. if( (check_ascii < 48) || (check_ascii > 57) )
  15401. {
  15402. isSuccess = ConfigurationStatus_Rejected;
  15403. }
  15404. else
  15405. {
  15406. if((atoi(value) == 0) || (atoi(value) >= 10))
  15407. {
  15408. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15409. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15410. HeartBeatWaitTime = atoi(value);
  15411. isSuccess = ConfigurationStatus_Accepted;
  15412. }
  15413. else
  15414. {
  15415. isSuccess = ConfigurationStatus_Rejected;
  15416. }
  15417. }
  15418. }
  15419. else
  15420. {
  15421. isSuccess = ConfigurationStatus_Rejected;
  15422. }
  15423. }
  15424. if(strcmp(key, "LightIntensity") == 0)
  15425. {
  15426. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15427. {
  15428. check_ascii = value[0];
  15429. if( (check_ascii < 48) || (check_ascii > 57) )
  15430. {
  15431. isSuccess = ConfigurationStatus_Rejected;
  15432. }
  15433. else
  15434. {
  15435. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15436. isSuccess = ConfigurationStatus_Accepted;
  15437. }
  15438. }
  15439. else
  15440. {
  15441. isSuccess = ConfigurationStatus_Rejected;
  15442. }
  15443. }
  15444. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15445. {
  15446. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15447. {
  15448. strcpy(str, (const char*)value);
  15449. for(int i = 0; str[i]; i++)
  15450. {
  15451. str[i] = tolower(str[i]);
  15452. }
  15453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15454. isSuccess = ConfigurationStatus_Accepted;
  15455. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15456. }
  15457. else
  15458. {
  15459. isSuccess = ConfigurationStatus_Rejected;
  15460. }
  15461. }
  15462. if(strcmp(key, "LocalPreAuthorize") == 0)
  15463. {
  15464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15465. {
  15466. strcpy(str, (const char*)value);
  15467. for(int i = 0; str[i]; i++)
  15468. {
  15469. str[i] = tolower(str[i]);
  15470. }
  15471. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15472. isSuccess = ConfigurationStatus_Accepted;
  15473. }
  15474. else
  15475. {
  15476. isSuccess = ConfigurationStatus_Rejected;
  15477. }
  15478. }
  15479. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15480. {
  15481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15482. {
  15483. check_ascii = value[0];
  15484. if( (check_ascii < 48) || (check_ascii > 57) )
  15485. {
  15486. isSuccess = ConfigurationStatus_Rejected;
  15487. }
  15488. else
  15489. {
  15490. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15491. isSuccess = ConfigurationStatus_Accepted;
  15492. }
  15493. }
  15494. else
  15495. {
  15496. isSuccess = ConfigurationStatus_Rejected;
  15497. }
  15498. }
  15499. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15500. {
  15501. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15502. {
  15503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15504. isSuccess = ConfigurationStatus_Accepted;
  15505. }
  15506. else
  15507. {
  15508. isSuccess = ConfigurationStatus_Rejected;
  15509. }
  15510. }
  15511. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15512. {
  15513. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15514. {
  15515. check_ascii = value[0];
  15516. if( (check_ascii < 48) || (check_ascii > 57) )
  15517. {
  15518. isSuccess = ConfigurationStatus_Rejected;
  15519. }
  15520. else
  15521. {
  15522. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15523. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15524. isSuccess = ConfigurationStatus_Accepted;
  15525. }
  15526. }
  15527. else
  15528. {
  15529. isSuccess = ConfigurationStatus_Rejected;
  15530. }
  15531. }
  15532. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15533. {
  15534. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15535. {
  15536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15537. isSuccess = ConfigurationStatus_Accepted;
  15538. }
  15539. else
  15540. {
  15541. isSuccess = ConfigurationStatus_Rejected;
  15542. }
  15543. }
  15544. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15545. {
  15546. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15547. {
  15548. check_ascii = value[0];
  15549. if( (check_ascii < 48) || (check_ascii > 57) )
  15550. {
  15551. isSuccess = ConfigurationStatus_Rejected;
  15552. }
  15553. else
  15554. {
  15555. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15557. isSuccess = ConfigurationStatus_Accepted;
  15558. }
  15559. }
  15560. else
  15561. {
  15562. isSuccess = ConfigurationStatus_Rejected;
  15563. }
  15564. }
  15565. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15566. {
  15567. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15568. {
  15569. check_ascii = value[0];
  15570. if( (check_ascii < 48) || (check_ascii > 57) )
  15571. {
  15572. isSuccess = ConfigurationStatus_Rejected;
  15573. }
  15574. else
  15575. {
  15576. if((atoi(value) == 0) || (atoi(value) >= 3))
  15577. {
  15578. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15579. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15580. isSuccess = ConfigurationStatus_Accepted;
  15581. }
  15582. else
  15583. {
  15584. isSuccess = ConfigurationStatus_Rejected;
  15585. }
  15586. }
  15587. }
  15588. else
  15589. {
  15590. isSuccess = ConfigurationStatus_Rejected;
  15591. }
  15592. }
  15593. if(strcmp(key, "MinimumStatusDuration") == 0)
  15594. {
  15595. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15596. {
  15597. check_ascii = value[0];
  15598. if( (check_ascii < 48) || (check_ascii > 57) )
  15599. {
  15600. isSuccess = ConfigurationStatus_Rejected;
  15601. }
  15602. else
  15603. {
  15604. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15605. {
  15606. isSuccess = ConfigurationStatus_Rejected;
  15607. }
  15608. else
  15609. {
  15610. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15612. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15613. isSuccess = ConfigurationStatus_Accepted;
  15614. }
  15615. }
  15616. }
  15617. else
  15618. {
  15619. isSuccess = ConfigurationStatus_Rejected;
  15620. }
  15621. }
  15622. if(strcmp(key, "NumberOfConnectors") == 0)
  15623. {
  15624. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15625. {
  15626. check_ascii = value[0];
  15627. if( (check_ascii < 48) || (check_ascii > 57) )
  15628. {
  15629. isSuccess = ConfigurationStatus_Rejected;
  15630. }
  15631. else
  15632. {
  15633. //Charger.ResetRetries = Integer.parseInt(value);
  15634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15635. isSuccess = ConfigurationStatus_Accepted;
  15636. }
  15637. }
  15638. else
  15639. {
  15640. isSuccess = ConfigurationStatus_Rejected;
  15641. }
  15642. }
  15643. if(strcmp(key, "ResetRetries") == 0)
  15644. {
  15645. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15646. {
  15647. check_ascii = value[0];
  15648. if( (check_ascii < 48) || (check_ascii > 57) )
  15649. {
  15650. isSuccess = ConfigurationStatus_Rejected;
  15651. }
  15652. else
  15653. {
  15654. //Charger.ResetRetries = Integer.parseInt(value);
  15655. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15656. isSuccess = ConfigurationStatus_Accepted;
  15657. }
  15658. }
  15659. else
  15660. {
  15661. isSuccess = ConfigurationStatus_Rejected;
  15662. }
  15663. }
  15664. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15665. {
  15666. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15667. {
  15668. strcpy(str, (const char*)value);
  15669. for(int i = 0; str[i]; i++)
  15670. {
  15671. str[i] = tolower(str[i]);
  15672. }
  15673. if(strcmp(str, "notapplicable")== 0)
  15674. {
  15675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15676. isSuccess = ConfigurationStatus_Accepted;
  15677. }
  15678. else if(strcmp(str, "unknown")== 0)
  15679. {
  15680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15681. isSuccess = ConfigurationStatus_Accepted;
  15682. }
  15683. else if(strcmp(str, "rst")== 0)
  15684. {
  15685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15686. isSuccess = ConfigurationStatus_Accepted;
  15687. }
  15688. else if(strcmp(str, "rts")== 0)
  15689. {
  15690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15691. isSuccess = ConfigurationStatus_Accepted;
  15692. }
  15693. else if(strcmp(str, "srt")== 0)
  15694. {
  15695. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15696. isSuccess = ConfigurationStatus_Accepted;
  15697. }
  15698. else if(strcmp(str, "str")== 0)
  15699. {
  15700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15701. isSuccess = ConfigurationStatus_Accepted;
  15702. }
  15703. else if(strcmp(str, "trs")== 0)
  15704. {
  15705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15706. isSuccess = ConfigurationStatus_Accepted;
  15707. }
  15708. else if(strcmp(str, "tsr")== 0)
  15709. {
  15710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15711. isSuccess = ConfigurationStatus_Accepted;
  15712. }
  15713. else
  15714. {
  15715. isSuccess = ConfigurationStatus_Rejected;
  15716. }
  15717. }
  15718. else
  15719. {
  15720. isSuccess = ConfigurationStatus_Rejected;
  15721. }
  15722. }
  15723. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15724. {
  15725. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15726. {
  15727. check_ascii = value[0];
  15728. if( (check_ascii < 48) || (check_ascii > 57) )
  15729. {
  15730. isSuccess = ConfigurationStatus_Rejected;
  15731. }
  15732. else
  15733. {
  15734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15735. isSuccess = ConfigurationStatus_Accepted;
  15736. }
  15737. }
  15738. else
  15739. {
  15740. isSuccess = ConfigurationStatus_Rejected;
  15741. }
  15742. }
  15743. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15744. {
  15745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15746. {
  15747. strcpy(str, (const char*)value);
  15748. for(int i = 0; str[i]; i++)
  15749. {
  15750. str[i] = tolower(str[i]);
  15751. }
  15752. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15754. isSuccess = ConfigurationStatus_Accepted;
  15755. }
  15756. else
  15757. {
  15758. isSuccess = ConfigurationStatus_Rejected;
  15759. }
  15760. }
  15761. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15762. {
  15763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15764. {
  15765. strcpy(str, (const char*)value);
  15766. for(int i = 0; str[i]; i++)
  15767. {
  15768. str[i] = tolower(str[i]);
  15769. }
  15770. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15772. isSuccess = ConfigurationStatus_Accepted;
  15773. }
  15774. else
  15775. {
  15776. isSuccess = ConfigurationStatus_Rejected;
  15777. }
  15778. }
  15779. if(strcmp(key, "StopTxnAlignedData") == 0)
  15780. {
  15781. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15782. {
  15783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15784. isSuccess = ConfigurationStatus_Accepted;
  15785. }
  15786. else
  15787. {
  15788. isSuccess = ConfigurationStatus_Rejected;
  15789. }
  15790. }
  15791. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15792. {
  15793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15794. {
  15795. check_ascii = value[0];
  15796. if( (check_ascii < 48) || (check_ascii > 57) )
  15797. {
  15798. isSuccess = ConfigurationStatus_Rejected;
  15799. }
  15800. else
  15801. {
  15802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15803. isSuccess = ConfigurationStatus_Accepted;
  15804. }
  15805. }
  15806. else
  15807. {
  15808. isSuccess = ConfigurationStatus_Rejected;
  15809. }
  15810. }
  15811. if(strcmp(key, "StopTxnSampledData") == 0)
  15812. {
  15813. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15814. {
  15815. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15816. isSuccess = ConfigurationStatus_Accepted;
  15817. }
  15818. else
  15819. {
  15820. isSuccess = ConfigurationStatus_Rejected;
  15821. }
  15822. }
  15823. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15824. {
  15825. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15826. {
  15827. check_ascii = value[0];
  15828. if( (check_ascii < 48) || (check_ascii > 57) )
  15829. {
  15830. isSuccess = ConfigurationStatus_Rejected;
  15831. }
  15832. else
  15833. {
  15834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15835. isSuccess = ConfigurationStatus_Accepted;
  15836. }
  15837. }
  15838. else
  15839. {
  15840. isSuccess = ConfigurationStatus_Rejected;
  15841. }
  15842. }
  15843. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15844. {
  15845. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15846. {
  15847. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15848. isSuccess = ConfigurationStatus_Accepted;
  15849. }
  15850. else
  15851. {
  15852. isSuccess = ConfigurationStatus_Rejected;
  15853. }
  15854. }
  15855. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15856. {
  15857. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15858. {
  15859. check_ascii = value[0];
  15860. if( (check_ascii < 48) || (check_ascii > 57) )
  15861. {
  15862. isSuccess = ConfigurationStatus_Rejected;
  15863. }
  15864. else
  15865. {
  15866. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15867. isSuccess = ConfigurationStatus_Accepted;
  15868. }
  15869. }
  15870. else
  15871. {
  15872. isSuccess = ConfigurationStatus_Rejected;
  15873. }
  15874. }
  15875. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15876. {
  15877. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15878. {
  15879. check_ascii = value[0];
  15880. if( (check_ascii < 48) || (check_ascii > 57) )
  15881. {
  15882. isSuccess = ConfigurationStatus_Rejected;
  15883. }
  15884. else
  15885. {
  15886. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15887. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15888. TransactionMessageAttemptsValue = atoi(value);
  15889. isSuccess = ConfigurationStatus_Accepted;
  15890. }
  15891. }
  15892. else
  15893. {
  15894. isSuccess = ConfigurationStatus_Rejected;
  15895. }
  15896. }
  15897. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15898. {
  15899. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15900. {
  15901. check_ascii = value[0];
  15902. if( (check_ascii < 48) || (check_ascii > 57) )
  15903. {
  15904. isSuccess = ConfigurationStatus_Rejected;
  15905. }
  15906. else
  15907. {
  15908. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15909. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15910. TransactionMessageRetryIntervalValue = atoi(value);
  15911. isSuccess = ConfigurationStatus_Accepted;
  15912. }
  15913. }
  15914. else
  15915. {
  15916. isSuccess = ConfigurationStatus_Rejected;
  15917. }
  15918. }
  15919. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15920. {
  15921. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15922. {
  15923. strcpy(str, (const char*)value);
  15924. for(int i = 0; str[i]; i++)
  15925. {
  15926. str[i] = tolower(str[i]);
  15927. }
  15928. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15929. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15930. isSuccess = ConfigurationStatus_Accepted;
  15931. }
  15932. else
  15933. {
  15934. isSuccess = ConfigurationStatus_Rejected;
  15935. }
  15936. }
  15937. if(strcmp(key, "WebSocketPingInterval") == 0)
  15938. {
  15939. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15940. {
  15941. check_ascii = value[0];
  15942. if( (check_ascii < 48) || (check_ascii > 57) )
  15943. {
  15944. isSuccess = ConfigurationStatus_Rejected;
  15945. }
  15946. else
  15947. {
  15948. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15949. isSuccess = ConfigurationStatus_Accepted;
  15950. if((atoi(value) == 0) || (atoi(value) >= 10))
  15951. {
  15952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15953. isSuccess = ConfigurationStatus_Accepted;
  15954. }
  15955. else
  15956. isSuccess = ConfigurationStatus_Rejected;
  15957. }
  15958. }
  15959. else
  15960. {
  15961. isSuccess = ConfigurationStatus_Rejected;
  15962. }
  15963. }
  15964. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15965. {
  15966. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15967. {
  15968. strcpy(str, (const char*)value);
  15969. for(int i = 0; str[i]; i++)
  15970. {
  15971. str[i] = tolower(str[i]);
  15972. }
  15973. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15974. isSuccess = ConfigurationStatus_Accepted;
  15975. }
  15976. else
  15977. {
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. if(strcmp(key, "AuthorizationKey") == 0)
  15982. {
  15983. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15984. {
  15985. strcpy(str, (const char*)value);
  15986. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15987. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15988. isSuccess = ConfigurationStatus_Accepted;
  15989. }
  15990. else
  15991. {
  15992. isSuccess = ConfigurationStatus_Rejected;
  15993. }
  15994. }
  15995. if(strcmp(key, "SecurityProfile") == 0)
  15996. {
  15997. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15998. {
  15999. check_ascii = value[0];
  16000. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16001. {
  16002. isSuccess = ConfigurationStatus_Rejected;
  16003. }
  16004. else if(check_ascii == 0x33)
  16005. {
  16006. isSuccess = NotSupported;
  16007. }
  16008. else
  16009. {
  16010. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16011. {
  16012. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16013. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16014. isSuccess = ConfigurationStatus_Accepted;
  16015. }
  16016. else
  16017. isSuccess = ConfigurationStatus_Rejected;
  16018. }
  16019. }
  16020. else
  16021. {
  16022. isSuccess = ConfigurationStatus_Rejected;
  16023. }
  16024. }
  16025. if(strcmp(key, "DefaultPrice") == 0)
  16026. {
  16027. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16028. {
  16029. strcpy(str, (const char*)value);
  16030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16031. isSuccess = ConfigurationStatus_Accepted;
  16032. }
  16033. else
  16034. {
  16035. isSuccess = ConfigurationStatus_Rejected;
  16036. }
  16037. }
  16038. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16039. {
  16040. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16041. {
  16042. strcpy(str, (const char*)value);
  16043. for(int i = 0; str[i]; i++)
  16044. {
  16045. str[i] = tolower(str[i]);
  16046. }
  16047. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16048. isSuccess = ConfigurationStatus_Accepted;
  16049. }
  16050. else
  16051. {
  16052. isSuccess = ConfigurationStatus_Rejected;
  16053. }
  16054. }
  16055. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16056. {
  16057. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16058. {
  16059. strcpy(str, (const char*)value);
  16060. for(int i = 0; str[i]; i++)
  16061. {
  16062. str[i] = tolower(str[i]);
  16063. }
  16064. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16065. isSuccess = ConfigurationStatus_Accepted;
  16066. }
  16067. else
  16068. {
  16069. isSuccess = ConfigurationStatus_Rejected;
  16070. }
  16071. }
  16072. if(strcmp(key, "SystemUptimeSec") == 0)
  16073. {
  16074. isSuccess = NotSupported;
  16075. }
  16076. if(strcmp(key, "FreeVend") == 0)
  16077. {
  16078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16079. {
  16080. strcpy(str, (const char*)value);
  16081. for(int i = 0; str[i]; i++)
  16082. {
  16083. str[i] = tolower(str[i]);
  16084. }
  16085. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16087. isSuccess = ConfigurationStatus_Accepted;
  16088. }
  16089. else
  16090. {
  16091. isSuccess = ConfigurationStatus_Rejected;
  16092. }
  16093. }
  16094. if(strcmp(key, "OcppServer") == 0)
  16095. {
  16096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16097. {
  16098. strcpy(str, (const char*)value);
  16099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16100. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16101. isSuccess = ConfigurationStatus_Accepted;
  16102. }
  16103. else
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. }
  16108. if(strcmp(key, "MaintainServer") == 0)
  16109. {
  16110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16111. {
  16112. strcpy(str, (const char*)value);
  16113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16114. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16115. isSuccess = ConfigurationStatus_Accepted;
  16116. }
  16117. else
  16118. {
  16119. isSuccess = ConfigurationStatus_Rejected;
  16120. }
  16121. }
  16122. #if 0
  16123. //For OCPP Test Case
  16124. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16125. {
  16126. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16127. {
  16128. strcpy(str, (const char*)value);
  16129. for(int i = 0; str[i]; i++)
  16130. {
  16131. str[i] = tolower(str[i]);
  16132. }
  16133. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16134. isSuccess = ConfigurationStatus_Accepted;
  16135. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16136. }
  16137. else
  16138. {
  16139. isSuccess = ConfigurationStatus_Rejected;
  16140. }
  16141. }
  16142. #endif
  16143. #if 1
  16144. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16145. {
  16146. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16147. {
  16148. strcpy(str, (const char*)value);
  16149. for(int i = 0; str[i]; i++)
  16150. {
  16151. str[i] = tolower(str[i]);
  16152. }
  16153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16154. isSuccess = ConfigurationStatus_Accepted;
  16155. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16156. }
  16157. else
  16158. {
  16159. isSuccess = ConfigurationStatus_Rejected;
  16160. }
  16161. }
  16162. #endif
  16163. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16164. {
  16165. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16166. {
  16167. check_ascii = value[0];
  16168. if( (check_ascii < 48) || (check_ascii > 57) )
  16169. {
  16170. isSuccess = ConfigurationStatus_Rejected;
  16171. }
  16172. else
  16173. {
  16174. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16175. isSuccess = ConfigurationStatus_Accepted;
  16176. }
  16177. }
  16178. else
  16179. {
  16180. isSuccess = ConfigurationStatus_Rejected;
  16181. }
  16182. }
  16183. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16184. {
  16185. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16186. {
  16187. check_ascii = value[0];
  16188. if( (check_ascii < 48) || (check_ascii > 57) )
  16189. {
  16190. isSuccess = ConfigurationStatus_Rejected;
  16191. }
  16192. else
  16193. {
  16194. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16195. isSuccess = ConfigurationStatus_Accepted;
  16196. }
  16197. }
  16198. else
  16199. {
  16200. isSuccess = ConfigurationStatus_Rejected;
  16201. }
  16202. }
  16203. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16204. {
  16205. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16206. {
  16207. strcpy(str, (const char*)value);
  16208. for(int i = 0; str[i]; i++)
  16209. {
  16210. str[i] = tolower(str[i]);
  16211. }
  16212. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16213. isSuccess = ConfigurationStatus_Accepted;
  16214. }
  16215. else
  16216. {
  16217. isSuccess = ConfigurationStatus_Rejected;
  16218. }
  16219. }
  16220. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16221. {
  16222. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16223. {
  16224. check_ascii = value[0];
  16225. if( (check_ascii < 48) || (check_ascii > 57) )
  16226. {
  16227. isSuccess = ConfigurationStatus_Rejected;
  16228. }
  16229. else
  16230. {
  16231. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16232. isSuccess = ConfigurationStatus_Accepted;
  16233. }
  16234. }
  16235. else
  16236. {
  16237. isSuccess = ConfigurationStatus_Rejected;
  16238. }
  16239. }
  16240. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16241. {
  16242. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16243. {
  16244. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16245. isSuccess = ConfigurationStatus_Accepted;
  16246. }
  16247. else
  16248. {
  16249. isSuccess = ConfigurationStatus_Rejected;
  16250. }
  16251. }
  16252. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16253. {
  16254. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16255. {
  16256. check_ascii = value[0];
  16257. if( (check_ascii < 48) || (check_ascii > 57) )
  16258. {
  16259. isSuccess = ConfigurationStatus_Rejected;
  16260. }
  16261. else
  16262. {
  16263. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16264. isSuccess = ConfigurationStatus_Accepted;
  16265. }
  16266. }
  16267. else
  16268. {
  16269. isSuccess = ConfigurationStatus_Rejected;
  16270. }
  16271. }
  16272. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16273. {
  16274. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16275. {
  16276. strcpy(str, (const char*)value);
  16277. for(int i = 0; str[i]; i++)
  16278. {
  16279. str[i] = tolower(str[i]);
  16280. }
  16281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16282. isSuccess = ConfigurationStatus_Accepted;
  16283. }
  16284. else
  16285. {
  16286. isSuccess = ConfigurationStatus_Rejected;
  16287. }
  16288. }
  16289. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16290. {
  16291. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16292. {
  16293. check_ascii = value[0];
  16294. if( (check_ascii < 48) || (check_ascii > 57) )
  16295. {
  16296. isSuccess = ConfigurationStatus_Rejected;
  16297. }
  16298. else
  16299. {
  16300. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16301. isSuccess = ConfigurationStatus_Accepted;
  16302. }
  16303. }
  16304. else
  16305. {
  16306. isSuccess = ConfigurationStatus_Rejected;
  16307. }
  16308. }
  16309. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16310. return isSuccess;
  16311. }
  16312. int TransactionMessageAttemptsGet(void)
  16313. {
  16314. return TransactionMessageAttemptsValue;
  16315. }
  16316. int FirstHeartBeatResponse(void)
  16317. {
  16318. return FirstHeartBeat;
  16319. }
  16320. int TransactionMessageRetryIntervalGet(void)
  16321. {
  16322. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16323. }
  16324. int ReadHttpStatus(int sock)
  16325. {
  16326. //char c;
  16327. char buff[1024]="",*ptr=buff+1;
  16328. int bytes_received, status;
  16329. DEBUG_INFO("Begin Response ..\n");
  16330. while((bytes_received = recv(sock, ptr, 1, 0))){
  16331. if(bytes_received==-1){
  16332. perror("ReadHttpStatus");
  16333. exit(1);
  16334. }
  16335. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16336. ptr++;
  16337. }
  16338. *ptr=0;
  16339. ptr=buff+1;
  16340. sscanf(ptr,"%*s %d ", &status);
  16341. DEBUG_INFO("%s\n",ptr);
  16342. DEBUG_INFO("status=%d\n",status);
  16343. DEBUG_INFO("End Response ..\n");
  16344. return (bytes_received>0)?status:0;
  16345. }
  16346. //the only filed that it parsed is 'Content-Length'
  16347. int ParseHeader(int sock)
  16348. {
  16349. //char c;
  16350. char buff[1024]="",*ptr=buff+4;
  16351. int bytes_received;
  16352. DEBUG_INFO("Begin HEADER ..\n");
  16353. while((bytes_received = recv(sock, ptr, 1, 0))){
  16354. if(bytes_received==-1){
  16355. perror("Parse Header");
  16356. exit(1);
  16357. }
  16358. if(
  16359. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16360. (ptr[-1]=='\r') && (*ptr=='\n' )
  16361. ) break;
  16362. ptr++;
  16363. }
  16364. *ptr=0;
  16365. ptr=buff+4;
  16366. //printf("%s",ptr);
  16367. if(bytes_received){
  16368. ptr=strstr(ptr,"Content-Length:");
  16369. if(ptr){
  16370. sscanf(ptr,"%*s %d",&bytes_received);
  16371. }else
  16372. bytes_received=-1; //unknown size
  16373. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16374. }
  16375. DEBUG_INFO("End HEADER ..\n");
  16376. return bytes_received ;
  16377. }
  16378. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16379. {
  16380. int result = TRUE;
  16381. char rmFileCmd[100]={0};
  16382. char FilePath[100]={0};
  16383. char ftpbuf[200];
  16384. int systemresult;
  16385. sprintf(FilePath,"/mnt/%s",filename);
  16386. system("ping 8.8.8.8 &");
  16387. if((access(FilePath,F_OK))!=-1)
  16388. {
  16389. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16390. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16391. system(rmFileCmd);
  16392. }
  16393. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16394. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16395. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16396. systemresult = system(ftpbuf);
  16397. if(systemresult != 0)
  16398. {
  16399. DEBUG_INFO("http DownLoad error!\n");
  16400. result = FALSE;
  16401. }
  16402. system("pkill ping");
  16403. return result;
  16404. }
  16405. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16406. {
  16407. int result = TRUE;
  16408. char rmFileCmd[100]={0};
  16409. char FilePath[100]={0};
  16410. char ftpbuf[200];
  16411. int systemresult;
  16412. sprintf(FilePath,"/mnt/%s",filename);
  16413. system("ping 8.8.8.8 &");
  16414. if((access(FilePath,F_OK))!=-1)
  16415. {
  16416. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16417. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16418. system(rmFileCmd);
  16419. }
  16420. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16421. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16422. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16423. systemresult = system(ftpbuf);
  16424. if(systemresult != 0)
  16425. {
  16426. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16427. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16428. systemresult = system(ftpbuf);
  16429. if(systemresult != 0)
  16430. {
  16431. DEBUG_WARN("wget error!\n");
  16432. result = FALSE;
  16433. }
  16434. }
  16435. system("pkill ping");
  16436. return result;
  16437. }
  16438. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16439. {
  16440. char rmFileCmd[100]={0};
  16441. char FilePath[100]={0};
  16442. char buf[512];
  16443. int systemresult = 0;
  16444. //DEBUG_INFO("filename=%s\n",filename);
  16445. //DEBUG_INFO("url=%s\n",url);
  16446. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16447. if((access(FilePath,F_OK))!=-1)
  16448. {
  16449. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16450. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16451. system(rmFileCmd);
  16452. }
  16453. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16454. if(fp == NULL)
  16455. {
  16456. DEBUG_INFO("log is NULL\n");
  16457. return FALSE;
  16458. }
  16459. else
  16460. {
  16461. fprintf(fp, "%s\n", url);
  16462. fprintf(fp, "%s\n", filename);
  16463. fclose(fp);
  16464. }
  16465. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16466. if(phpFP == NULL)
  16467. {
  16468. DEBUG_INFO("PHP upload fail.\n");
  16469. return FALSE;
  16470. }
  16471. else
  16472. {
  16473. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16474. {
  16475. if(strstr(buf, "result") != NULL)
  16476. {
  16477. sscanf(buf, "result: %d", &systemresult);
  16478. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16479. }
  16480. }
  16481. pclose(phpFP);
  16482. }
  16483. if(systemresult != 1)
  16484. {
  16485. DEBUG_INFO("HTTP upload error!\n");
  16486. return FALSE;
  16487. }
  16488. return TRUE;
  16489. }
  16490. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16491. {
  16492. int result = FALSE;
  16493. char ftpbuf[200];
  16494. int systemresult;
  16495. /*
  16496. // Domaind name transfer to IP address
  16497. struct hostent* server;
  16498. char *IPbuffer;
  16499. server = gethostbyname(location);
  16500. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16501. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16502. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16503. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16504. systemresult = system(ftpbuf);
  16505. if(systemresult != 0)
  16506. {
  16507. DEBUG_INFO("ftpput error!\n");
  16508. }
  16509. else
  16510. {
  16511. result = TRUE;
  16512. DEBUG_INFO("ftpput OK!\n");
  16513. }
  16514. return result;
  16515. }
  16516. int GetOcppServerURL()
  16517. {
  16518. int result = FALSE;
  16519. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16520. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16521. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16522. struct yuarel url;
  16523. char urlStr[512];
  16524. // OCPPPH only
  16525. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16526. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16527. {
  16528. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16529. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16530. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16531. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16532. if(yuarel_parse(&url, urlStr) != -1)
  16533. {
  16534. sprintf(OcppProtocol, "%s", url.scheme);
  16535. sprintf(OcppHost, "%s", url.host);
  16536. if(url.path == NULL)
  16537. OcppTempPath[0] = '\0';
  16538. else
  16539. sprintf(OcppTempPath, "%s", url.path);
  16540. if(url.port == 0)
  16541. {
  16542. if(strcmp(OcppProtocol, "wss") == 0)
  16543. OcppPort = 443;
  16544. else
  16545. OcppPort = 80;
  16546. }
  16547. else
  16548. OcppPort = url.port;
  16549. result = TRUE;
  16550. }
  16551. }
  16552. else
  16553. {
  16554. strcpy(OcppHost,"");
  16555. }
  16556. return result;
  16557. }
  16558. int GetOcppPath()
  16559. {
  16560. int result = FALSE;
  16561. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16562. {
  16563. if(OcppTempPath == NULL)
  16564. {
  16565. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16566. }
  16567. else
  16568. {
  16569. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16570. }
  16571. result = TRUE;
  16572. goto End;
  16573. }
  16574. else
  16575. {
  16576. strcpy(OcppPath,"");
  16577. }
  16578. End:
  16579. return result;
  16580. }
  16581. int GetOcppPort()
  16582. {
  16583. return OcppPort;
  16584. }
  16585. int GetOcppConnStatus(void)
  16586. {
  16587. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16588. }
  16589. void SetOcppConnStatus(uint8_t status)
  16590. {
  16591. ShmOCPP16DataPH->OcppConnStatus = status;
  16592. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16593. }
  16594. int GetHeartBeatWithNOResponse(void)
  16595. {
  16596. return HeartBeatWithNOResponse;
  16597. }
  16598. void SetHeartBeatWithNOResponse(void)
  16599. {
  16600. HeartBeatWithNOResponse = 0;
  16601. }
  16602. void GetStartTransactionIdTag(int gun_index)
  16603. {
  16604. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16605. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16606. }
  16607. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16608. {
  16609. char ch;
  16610. FILE *fptr1;
  16611. int temptransactionId;
  16612. char str[100]={0};
  16613. temptransactionId = 0;
  16614. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16615. {
  16616. DEBUG_INFO("IdTag is empty.\n");
  16617. return temptransactionId;
  16618. }
  16619. /*------ Read the file ----------------*/
  16620. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16621. if (!fptr1)
  16622. {
  16623. DEBUG_INFO("QueueTransactionId file open error.\n");
  16624. //printf(" File not found or unable to open the input file!!\n");
  16625. return temptransactionId;
  16626. }
  16627. ch=fgetc(fptr1);
  16628. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16629. rewind(fptr1);
  16630. if(ch!=EOF)
  16631. {
  16632. // printf("%c",ch);
  16633. while (fgets(str, 100, fptr1) != NULL)
  16634. {
  16635. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16636. if(str[0]=='\0')
  16637. {
  16638. break;
  16639. }
  16640. char *revbuf[8] = {0}; // Variable store string split
  16641. int num = 0;// Quantity after string split
  16642. DEBUG_INFO("Transaction queue data= %s\n", str);
  16643. splitstring(str,",",revbuf,&num); // String split
  16644. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16645. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16646. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16647. DEBUG_INFO("------------------------------\n");
  16648. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16649. {
  16650. if(isStopTransaction)
  16651. {
  16652. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16653. {
  16654. temptransactionId = atoi(revbuf[2]);
  16655. //break;
  16656. }
  16657. }
  16658. else
  16659. {
  16660. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16661. {
  16662. temptransactionId = atoi(revbuf[2]);
  16663. //break;
  16664. }
  16665. }
  16666. }
  16667. }
  16668. }
  16669. else
  16670. DEBUG_INFO("EOF\n");
  16671. fclose(fptr1);
  16672. /*------- End of reading ---------------*/
  16673. return temptransactionId;
  16674. }
  16675. void SetTransactionIdZero(int transactionId)
  16676. {
  16677. char ch;
  16678. FILE *fptr1, *fptr2;
  16679. int temptransactionId = 0;
  16680. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16681. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16682. if (!fptr1)
  16683. {
  16684. //printf(" File not found or unable to open the input file!!\n");
  16685. return ;
  16686. }
  16687. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16688. if (!fptr2)
  16689. {
  16690. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16691. fclose(fptr1);
  16692. return ;
  16693. }
  16694. ch=fgetc(fptr1);
  16695. rewind(fptr1);
  16696. if(ch!=EOF)
  16697. {
  16698. // copy all contents to the temporary file except the specific line
  16699. while (fgets(str, 100, fptr1) != NULL)
  16700. {
  16701. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16702. if(str[0]=='\0')
  16703. {
  16704. break;
  16705. }
  16706. char *revbuf[8] = {0};
  16707. int num = 0;
  16708. strcpy(strtemp, str);
  16709. splitstring(str,",",revbuf,&num);
  16710. if(revbuf[2][0] != '\0')
  16711. {
  16712. temptransactionId = atoi(revbuf[2]);
  16713. if(transactionId != temptransactionId)
  16714. {
  16715. fprintf(fptr2, "%s\n", strtemp);
  16716. }
  16717. }
  16718. }
  16719. }
  16720. fclose(fptr1);
  16721. fclose(fptr2);
  16722. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16723. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16724. /*------ Read the file ----------------*/
  16725. }
  16726. int InternetDisconnect(void)
  16727. {
  16728. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16729. }
  16730. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16731. void storeTempStopTransaction(int gun_index)
  16732. {
  16733. char guid[37]={0};
  16734. int tempIndex = 0;
  16735. char TempStopTransaction[256];
  16736. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16737. DEBUG_INFO("storeTempStopTransaction...\n");
  16738. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16739. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16740. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16741. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16742. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16743. {
  16744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16745. {
  16746. tempIndex = ((gun_index==2) ? 1: 0);
  16747. }
  16748. else
  16749. {
  16750. tempIndex = gun_index;
  16751. }
  16752. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16753. {
  16754. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16755. {
  16756. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16757. }
  16758. }// END OF CHAdeMO_QUANTITY
  16759. }
  16760. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16761. {
  16762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16763. {
  16764. tempIndex = ((gun_index==2) ? 1: 0);
  16765. }
  16766. else
  16767. {
  16768. tempIndex = gun_index;
  16769. }
  16770. for (int index = 0; index < CCS_QUANTITY; index++)
  16771. {
  16772. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16773. {
  16774. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16775. }
  16776. }// END OF CCS_QUANTITY
  16777. }
  16778. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16779. {
  16780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16781. {
  16782. tempIndex = ((gun_index==2) ? 1: 0);
  16783. }
  16784. else
  16785. {
  16786. tempIndex = gun_index;
  16787. }
  16788. for (int index = 0; index < GB_QUANTITY; index++)
  16789. {
  16790. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16791. {
  16792. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16793. }
  16794. }// END OF GB_QUANTITY
  16795. }
  16796. else if(gunType[gun_index] == GUN_TYPE_DO)
  16797. {
  16798. tempIndex = gun_index;
  16799. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16800. {
  16801. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16802. {
  16803. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16804. }
  16805. }
  16806. }
  16807. else
  16808. {
  16809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16810. {
  16811. tempIndex = 2;
  16812. }
  16813. else
  16814. {
  16815. tempIndex = gun_index;
  16816. }
  16817. for (int index = 0; index < AC_QUANTITY; index++)
  16818. {
  16819. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16820. {
  16821. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16822. }
  16823. }// END OF AC_QUANTITY
  16824. }
  16825. //Stop Transaction Time
  16826. struct timeval tmnow;
  16827. struct tm *tm;
  16828. char buf[28];//, usec_buf[6];
  16829. gettimeofday(&tmnow, NULL);
  16830. time_t t;
  16831. t = time(NULL);
  16832. /*UTC time and date*/
  16833. tm = gmtime(&t);
  16834. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16835. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16836. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16837. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16838. random_uuid(guid);
  16839. /***********************************transactionData******************************************************/
  16840. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16842. //=================================
  16843. //1. Transaction_Begin
  16844. //=================================
  16845. //============================== Energy.Active.Import.Interval ===========================================
  16846. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16847. {
  16848. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16849. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16850. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16851. 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*/]);
  16852. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16853. 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))
  16854. {
  16855. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16856. }
  16857. else
  16858. {
  16859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16860. }
  16861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16863. }
  16864. //=================================
  16865. //2. Transaction_End
  16866. //=================================
  16867. //2.1====================================== Current.Import L1 ==============================================
  16868. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16869. {
  16870. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16871. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16872. {
  16873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16874. {
  16875. tempIndex = ((gun_index==2) ? 1: 0);
  16876. }
  16877. else
  16878. {
  16879. tempIndex = gun_index;
  16880. }
  16881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16882. {
  16883. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16884. {
  16885. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16886. }
  16887. }// End of for CHAdeMO_QUANTITY
  16888. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16889. }
  16890. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16891. {
  16892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16893. {
  16894. tempIndex = ((gun_index==2) ? 1: 0);
  16895. }
  16896. else
  16897. {
  16898. tempIndex = gun_index;
  16899. }
  16900. for (int index = 0; index < CCS_QUANTITY; index++)
  16901. {
  16902. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16903. {
  16904. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16905. }
  16906. }// End of for CCS_QUANTITY
  16907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16908. }
  16909. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16910. {
  16911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16912. {
  16913. tempIndex = ((gun_index==2) ? 1: 0);
  16914. }
  16915. else
  16916. {
  16917. tempIndex = gun_index;
  16918. }
  16919. for (int index = 0; index < GB_QUANTITY; index++)
  16920. {
  16921. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16922. {
  16923. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16924. }
  16925. }// End of for GB_QUANTITY
  16926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16927. }
  16928. else if(gunType[gun_index] == GUN_TYPE_DO)
  16929. {
  16930. tempIndex = gun_index;
  16931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16932. {
  16933. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16934. {
  16935. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16936. }
  16937. }
  16938. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16939. }
  16940. else
  16941. {
  16942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16943. {
  16944. tempIndex = 2;
  16945. }
  16946. else
  16947. {
  16948. tempIndex = gun_index;
  16949. }
  16950. for (int index = 0; index < AC_QUANTITY; index++)
  16951. {
  16952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16953. {
  16954. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16955. }
  16956. }// End of for AC_QUANTITY
  16957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16958. }
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16961. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16962. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16963. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16965. }
  16966. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16967. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16968. {
  16969. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16971. {
  16972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16973. {
  16974. tempIndex = ((gun_index==2) ? 1: 0);
  16975. }
  16976. else
  16977. {
  16978. tempIndex = gun_index;
  16979. }
  16980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16981. {
  16982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16983. {
  16984. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16985. }
  16986. }// END OF CHAdeMO_QUANTITY
  16987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16988. }
  16989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16990. {
  16991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16992. {
  16993. tempIndex = ((gun_index==2) ? 1: 0);
  16994. }
  16995. else
  16996. {
  16997. tempIndex = gun_index;
  16998. }
  16999. for (int index = 0; index < CCS_QUANTITY; index++)
  17000. {
  17001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17002. {
  17003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17004. }
  17005. }// END OF CCS_QUANTITY
  17006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17007. }
  17008. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17009. {
  17010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17011. {
  17012. tempIndex = ((gun_index==2) ? 1: 0);
  17013. }
  17014. else
  17015. {
  17016. tempIndex = gun_index;
  17017. }
  17018. for (int index = 0; index < GB_QUANTITY; index++)
  17019. {
  17020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17021. {
  17022. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17023. }
  17024. }// END OF GB_QUANTITY
  17025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17026. }
  17027. else if(gunType[gun_index] == GUN_TYPE_DO)
  17028. {
  17029. tempIndex = gun_index;
  17030. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17031. {
  17032. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17033. {
  17034. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17035. }
  17036. }
  17037. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17038. }
  17039. else
  17040. {
  17041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17042. {
  17043. tempIndex = 2;
  17044. }
  17045. else
  17046. {
  17047. tempIndex = gun_index;
  17048. }
  17049. for (int index = 0; index < AC_QUANTITY; index++)
  17050. {
  17051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17052. {
  17053. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17054. }
  17055. }// END OF AC_QUANTITY
  17056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17057. }
  17058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17061. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17064. }
  17065. //2.3====================================== Power.Active.Import =========================================
  17066. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17067. {
  17068. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17069. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17070. {
  17071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17072. {
  17073. tempIndex = ((gun_index==2) ? 1: 0);
  17074. }
  17075. else
  17076. {
  17077. tempIndex = gun_index;
  17078. }
  17079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17080. {
  17081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17082. {
  17083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17084. }
  17085. } // End for CHAdeMO_QUANTITY
  17086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17087. }
  17088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17089. {
  17090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17091. {
  17092. tempIndex = ((gun_index==2) ? 1: 0);
  17093. }
  17094. else
  17095. {
  17096. tempIndex = gun_index;
  17097. }
  17098. for (int index = 0; index < CCS_QUANTITY; index++)
  17099. {
  17100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17101. {
  17102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17103. }
  17104. } // END for CCS_QUANTITY
  17105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17106. }
  17107. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17108. {
  17109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17110. {
  17111. tempIndex = ((gun_index==2) ? 1: 0);
  17112. }
  17113. else
  17114. {
  17115. tempIndex = gun_index;
  17116. }
  17117. for (int index = 0; index < GB_QUANTITY; index++)
  17118. {
  17119. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17120. {
  17121. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17122. }
  17123. }// END for GB_QUANTITY
  17124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17125. }
  17126. else if(gunType[gun_index] == GUN_TYPE_DO)
  17127. {
  17128. tempIndex = gun_index;
  17129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17130. {
  17131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17132. {
  17133. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17134. }
  17135. }
  17136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17137. }
  17138. else
  17139. {
  17140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17141. {
  17142. tempIndex = 2;
  17143. }
  17144. else
  17145. {
  17146. tempIndex = gun_index;
  17147. }
  17148. for (int index = 0; index < AC_QUANTITY; index++)
  17149. {
  17150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17151. {
  17152. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17153. }
  17154. } // END for AC_QUANTITY
  17155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17156. }
  17157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17160. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17163. }
  17164. //2.4====================================== Voltage L1 ====================================================
  17165. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17166. {
  17167. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17168. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17169. {
  17170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17171. {
  17172. tempIndex = ((gun_index==2) ? 1: 0);
  17173. }
  17174. else
  17175. {
  17176. tempIndex = gun_index;
  17177. }
  17178. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17179. {
  17180. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17181. {
  17182. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17183. }
  17184. } // END OF FOR CHAdeMO_QUANTITY
  17185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17186. }
  17187. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17188. {
  17189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17190. {
  17191. tempIndex = ((gun_index==2) ? 1: 0);
  17192. }
  17193. else
  17194. {
  17195. tempIndex = gun_index;
  17196. }
  17197. for (int index = 0; index < CCS_QUANTITY; index++)
  17198. {
  17199. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17200. {
  17201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17202. }
  17203. } // END OF FOR CCS_QUANTITY
  17204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17205. }
  17206. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17207. {
  17208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17209. {
  17210. tempIndex = ((gun_index==2) ? 1: 0);
  17211. }
  17212. else
  17213. {
  17214. tempIndex = gun_index;
  17215. }
  17216. for (int index = 0; index < GB_QUANTITY; index++)
  17217. {
  17218. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17219. {
  17220. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17221. }
  17222. } // END OF FOR GB_QUANTITY
  17223. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17224. }
  17225. else if(gunType[gun_index] == GUN_TYPE_DO)
  17226. {
  17227. tempIndex = gun_index;
  17228. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17229. {
  17230. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17231. {
  17232. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17233. }
  17234. }
  17235. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17236. }
  17237. else
  17238. {
  17239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17240. {
  17241. tempIndex = 2;
  17242. }
  17243. else
  17244. {
  17245. tempIndex = gun_index;
  17246. }
  17247. for (int index = 0; index < AC_QUANTITY; index++)
  17248. {
  17249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17250. {
  17251. 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
  17252. }
  17253. } // END OF FOR AC_QUANTITY
  17254. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17255. }
  17256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17259. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17262. }
  17263. //2.5============================================== End SoC =========================================================
  17264. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17265. {
  17266. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17267. 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))
  17268. {
  17269. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17270. {
  17271. tempIndex = ((gun_index==2) ? 1: 0);
  17272. }
  17273. else
  17274. {
  17275. tempIndex = gun_index;
  17276. }
  17277. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17278. {
  17279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17280. {
  17281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17282. {
  17283. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17284. }
  17285. }
  17286. }
  17287. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17288. {
  17289. for (int index = 0; index < CCS_QUANTITY; index++)
  17290. {
  17291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17292. {
  17293. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17294. }
  17295. }
  17296. }
  17297. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17298. {
  17299. for (int index = 0; index < GB_QUANTITY; index++)
  17300. {
  17301. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17302. {
  17303. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17304. }
  17305. }
  17306. }
  17307. else if(gunType[gun_index] == GUN_TYPE_DO)
  17308. {
  17309. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17310. {
  17311. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17312. {
  17313. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17314. }
  17315. }
  17316. }
  17317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17318. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17320. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17321. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17322. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17323. } // END FOR DC CASE
  17324. }
  17325. //2.6====================================== Current.Import L2 ==============================================
  17326. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17327. {
  17328. // AC 3 phase L2 current
  17329. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17330. {
  17331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17332. {
  17333. tempIndex = 2;
  17334. }
  17335. else
  17336. {
  17337. tempIndex = gun_index;
  17338. }
  17339. for (int index = 0; index < AC_QUANTITY; index++)
  17340. {
  17341. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17342. {
  17343. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17344. }
  17345. }// End of for AC_QUANTITY
  17346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17347. }
  17348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17349. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17350. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17351. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17352. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17353. }
  17354. //2.7====================================== Current.Import L3 ==============================================
  17355. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17356. {
  17357. // AC 3 phase L3 current
  17358. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17359. {
  17360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17361. {
  17362. tempIndex = 2;
  17363. }
  17364. else
  17365. {
  17366. tempIndex = gun_index;
  17367. }
  17368. for (int index = 0; index < AC_QUANTITY; index++)
  17369. {
  17370. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17371. {
  17372. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17373. }
  17374. }// End of for AC_QUANTITY
  17375. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17376. }
  17377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17382. }
  17383. //2.9====================================== Voltage L2 ====================================================
  17384. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17385. {
  17386. // AC 3 phase L2 volatge
  17387. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17388. {
  17389. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17390. {
  17391. tempIndex = 2;
  17392. }
  17393. else
  17394. {
  17395. tempIndex = gun_index;
  17396. }
  17397. for (int index = 0; index < AC_QUANTITY; index++)
  17398. {
  17399. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17400. {
  17401. 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
  17402. }
  17403. } // END OF FOR AC_QUANTITY
  17404. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17405. }
  17406. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17411. }
  17412. //2.10====================================== Voltage L3 ====================================================
  17413. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17414. {
  17415. // AC 3 phase L3 volatge
  17416. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17417. {
  17418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17419. {
  17420. tempIndex = 2;
  17421. }
  17422. else
  17423. {
  17424. tempIndex = gun_index;
  17425. }
  17426. for (int index = 0; index < AC_QUANTITY; index++)
  17427. {
  17428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17429. {
  17430. 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
  17431. }
  17432. } // END OF FOR AC_QUANTITY
  17433. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17434. }
  17435. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17436. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17437. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17438. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17439. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17440. }
  17441. //====================== Start SoC ================================
  17442. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17443. {
  17444. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17445. 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))
  17446. {
  17447. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17448. {
  17449. tempIndex = ((gun_index==2) ? 1: 0);
  17450. }
  17451. else
  17452. {
  17453. tempIndex = gun_index;
  17454. }
  17455. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17456. {
  17457. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17458. {
  17459. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17460. {
  17461. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17462. }
  17463. }
  17464. }
  17465. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17466. {
  17467. for (int index = 0; index < CCS_QUANTITY; index++)
  17468. {
  17469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17470. {
  17471. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17472. }
  17473. }
  17474. }
  17475. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17476. {
  17477. for (int index = 0; index < GB_QUANTITY; index++)
  17478. {
  17479. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17480. {
  17481. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17482. }
  17483. }
  17484. }
  17485. else if(gunType[gun_index] == GUN_TYPE_DO)
  17486. {
  17487. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17488. {
  17489. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17490. {
  17491. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17492. }
  17493. }
  17494. }
  17495. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17499. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17500. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17501. } // END FOR DC CASE
  17502. }
  17503. //======================================== Message create ==============================================
  17504. json_object *StopTransaction = json_object_new_object();
  17505. json_object *transactionDatas = json_object_new_array();
  17506. json_object *sampledValues = json_object_new_array();
  17507. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17508. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17509. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17510. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17511. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17512. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17513. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17514. {
  17515. json_object *transactionData = json_object_new_object();
  17516. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17517. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17518. {
  17519. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17520. {
  17521. json_object *sampledValue = json_object_new_object();
  17522. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17523. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17524. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17525. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17526. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17527. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17528. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17529. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17530. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17531. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17532. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17533. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17534. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17535. json_object_array_add(sampledValues, sampledValue);
  17536. }
  17537. }
  17538. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17539. json_object_array_add(transactionDatas, transactionData);
  17540. }
  17541. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17542. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17543. ,MESSAGE_TYPE_CALL
  17544. ,guid
  17545. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17546. json_object_put(StopTransaction);
  17547. // Check File "TempStopTransaction" Exist
  17548. if((access(TempStopTransaction,F_OK))!=-1)
  17549. {
  17550. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17551. fclose(fopen(TempStopTransaction, "w"));
  17552. }
  17553. else
  17554. {
  17555. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17556. FILE *log = fopen(TempStopTransaction, "w+");
  17557. if(log == NULL)
  17558. {
  17559. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17560. return ;
  17561. }
  17562. else
  17563. {
  17564. fclose(log);
  17565. }
  17566. }
  17567. //Add TempStopTransaction | Update TempStopTransaction
  17568. // open file for writing
  17569. FILE *outfile;
  17570. outfile = fopen (TempStopTransaction, "a");
  17571. //DEBUG_INFO("data = %s\n", queuedata);
  17572. fputs(queuedata, outfile);
  17573. fputs("\n", outfile);
  17574. fclose (outfile);
  17575. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17576. }
  17577. void checkTempStopTransaction(int gun_index)
  17578. {
  17579. FILE *fptr1;
  17580. char ch;
  17581. char str[QUEUE_MESSAGE_LENGTH]={0};
  17582. char guid[37]={0};
  17583. char tempdata[65]={0};
  17584. char connectorStr[2]={0};
  17585. char TempStopTransaction[256];
  17586. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17587. fptr1 = fopen(TempStopTransaction, "r");
  17588. //TempStopTransaction格式: 槍號,StopTransaction封包
  17589. if (!fptr1)
  17590. {
  17591. //printf(" File not found or unable to open the input file!!\n");
  17592. return ;
  17593. }
  17594. ch=fgetc(fptr1);
  17595. //printf(" Now the content of the file %s is : \n",fname);
  17596. rewind(fptr1);
  17597. if(ch!=EOF)
  17598. {
  17599. // copy all contents to the temporary file except the specific line
  17600. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17601. {
  17602. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17603. if(str[0]=='\0')
  17604. {
  17605. break;
  17606. }
  17607. //TempStopTransaction格式: 槍號,StopTransaction封包
  17608. strncpy(connectorStr, str, 1);
  17609. if(atoi(connectorStr) != (gun_index+1))
  17610. {
  17611. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17612. fclose(fptr1);
  17613. return ;
  17614. }
  17615. //random_uuid(guid);
  17616. strncpy(guid, str+6, 36); //copy guid
  17617. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17618. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17619. {
  17620. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17621. }
  17622. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17623. OCPP_insert_transaction_msg(NO, str);
  17624. memset(str,0,ARRAY_SIZE(str));
  17625. }
  17626. }
  17627. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17628. fclose(fptr1);
  17629. remove(TempStopTransaction); // remove the original file
  17630. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17631. }
  17632. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17633. {
  17634. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17635. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17636. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17637. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17638. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17639. }
  17640. int GetWebSocketPingInterval(void)
  17641. {
  17642. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17643. }
  17644. int GetServerSign(void)
  17645. {
  17646. return server_sign;
  17647. }
  17648. uint8_t GetOcppSecurityProfile()
  17649. {
  17650. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17651. }
  17652. void GetOcppChargerBoxId(uint8_t *data)
  17653. {
  17654. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17655. }
  17656. void GetOcppSecurityPassword(uint8_t *data)
  17657. {
  17658. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17659. }
  17660. void SetOcppVersion(uint8_t *version)
  17661. {
  17662. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17663. DEBUG_INFO("ocpp version: %s\n", version);
  17664. if(strstr((char*)version, "ocpp1.6") != NULL)
  17665. {
  17666. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17667. }
  17668. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17669. {
  17670. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17671. system("pkill OcppBackend");
  17672. }
  17673. }
  17674. void SetServerSign(int value)
  17675. {
  17676. server_sign = value;
  17677. }
  17678. int GetBootNotificationInterval(void)
  17679. {
  17680. return BootNotificationInterval;
  17681. }
  17682. int GetInternetConn(void)
  17683. {
  17684. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17685. }
  17686. int GetBackendConnectionTimeout(void)
  17687. {
  17688. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17689. }
  17690. int isConnectorInitMode(int gun_index)
  17691. {
  17692. int tempIndex = 0;
  17693. int result = TRUE;
  17694. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17695. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17696. {
  17697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17698. {
  17699. tempIndex = ((gun_index==2) ? 1: 0);
  17700. }
  17701. else
  17702. {
  17703. tempIndex = gun_index;
  17704. }
  17705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17706. {
  17707. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17708. {
  17709. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17710. } //end of the same index
  17711. }//end of for CHAdeMO_QUANTITY
  17712. }
  17713. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17714. {
  17715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17716. {
  17717. tempIndex = ((gun_index==2) ? 1: 0);
  17718. }
  17719. else
  17720. {
  17721. tempIndex = gun_index;
  17722. }
  17723. for (int index = 0; index < CCS_QUANTITY; index++)
  17724. {
  17725. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17726. {
  17727. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17728. } //end of the same index
  17729. } // end of for CCS_QUANTITY
  17730. }
  17731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17732. {
  17733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17734. {
  17735. tempIndex = ((gun_index==2) ? 1: 0);
  17736. }
  17737. else
  17738. {
  17739. tempIndex = gun_index;
  17740. }
  17741. for (int index = 0; index < GB_QUANTITY; index++)
  17742. {
  17743. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17744. {
  17745. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17746. } //end of the same index
  17747. } // end of for GB_QUANTITY
  17748. }
  17749. else if(gunType[gun_index] == GUN_TYPE_DO)
  17750. {
  17751. tempIndex = gun_index;
  17752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17753. {
  17754. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17755. {
  17756. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17757. } //end of the same index
  17758. }
  17759. }
  17760. else
  17761. {
  17762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17763. {
  17764. tempIndex = 2;
  17765. }
  17766. else
  17767. {
  17768. tempIndex = gun_index;
  17769. }
  17770. for (int index = 0; index < AC_QUANTITY; index++)
  17771. {
  17772. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17773. {
  17774. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17775. }//end of the same index
  17776. }//end of for AC_QUANTITY
  17777. }
  17778. return result;
  17779. }
  17780. void refreshProcDogTimer()
  17781. {
  17782. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17783. }
  17784. void InitialSystemValue(void)
  17785. {
  17786. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17787. locallistVersion=0;
  17788. BootNotificationInterval = 0;
  17789. authorizeRetryTimes = 0;
  17790. GunStatusInterval = 10;
  17791. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17792. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17793. //Hear Beat
  17794. HeartBeatWithNOResponse = 0;
  17795. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17796. FirstHeartBeat = 0;
  17797. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17798. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17799. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17800. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17801. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17802. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17803. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17804. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17805. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17806. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17807. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17808. //Status && ConnectorPlugIn Setting
  17809. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17810. {
  17811. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17812. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17813. }
  17814. for (int index = 0; index < CCS_QUANTITY; index++)
  17815. {
  17816. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17817. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17818. }
  17819. for (int index = 0; index < GB_QUANTITY; index++)
  17820. {
  17821. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17822. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17823. }
  17824. for (int index = 0; index < AC_QUANTITY; index++)
  17825. {
  17826. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17827. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17828. }
  17829. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17830. {
  17831. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17832. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17833. }
  17834. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17835. {
  17836. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17837. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17838. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17839. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17840. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17841. }
  17842. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17843. refreshStartTimer(&clientTime.Heartbeat);
  17844. sleep(1);
  17845. }
  17846. void LWS_Send(char *str)
  17847. {
  17848. //=====================================================
  17849. // Check InternetConn 0: disconnected, 1: connected
  17850. //====================================================
  17851. if(GetOcppConnStatus() == 0)
  17852. {
  17853. DEBUG_INFO("offline now !!!\n");
  17854. return;
  17855. }
  17856. // Only disable isWebsocketSendable operation initiated by charger
  17857. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17858. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17859. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17860. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17861. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17862. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17863. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17864. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17865. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17866. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17867. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17868. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17869. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17870. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17871. {
  17872. isWebsocketSendable = 0;
  17873. }
  17874. pthread_mutex_lock(&lock_send);
  17875. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17876. sprintf((char *)SendBuffer, "%s", str);
  17877. SendBufLen = strlen(str);
  17878. pthread_mutex_unlock(&lock_send);
  17879. lws_callback_on_writable(wsi_client);
  17880. //lws_service(context, 0);
  17881. //sleep(1);
  17882. }
  17883. void LWS_SendNow(char *str)
  17884. {
  17885. //=====================================================
  17886. // Check InternetConn 0: disconnected, 1: connected
  17887. //====================================================
  17888. if(GetOcppConnStatus() == 0)
  17889. {
  17890. DEBUG_INFO("offline now !!!\n");
  17891. return;
  17892. }
  17893. // Only disable isWebsocketSendable operation initiated by charger
  17894. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17895. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17896. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17897. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17898. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17899. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17900. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17901. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17902. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17903. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17904. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17905. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17906. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17907. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17908. {
  17909. isWebsocketSendable = 0;
  17910. }
  17911. pthread_mutex_lock(&lock_send);
  17912. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17913. sprintf((char *)SendBuffer, "%s", str);
  17914. SendBufLen = strlen(str);
  17915. pthread_mutex_unlock(&lock_send);
  17916. lws_callback_on_writable(wsi_client);
  17917. lws_service(context, 0);
  17918. //sleep(1);
  17919. }