MessageHandler.c 914 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639
  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. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  3947. )
  3948. )
  3949. {
  3950. if(SystemInitial > 0)
  3951. SystemInitial -= 1;
  3952. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3953. sendStatusNotificationRequest(gun_index);
  3954. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3955. }
  3956. //==============================================
  3957. // CSU Trigger Smart Charging Profilw
  3958. //==============================================
  3959. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3960. {
  3961. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3962. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3963. }
  3964. //==============================================
  3965. // Meter report
  3966. //==============================================
  3967. // Trigger MeterValue
  3968. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3969. {
  3970. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3971. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3972. }
  3973. // Clock-aligned Meter value
  3974. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  3975. {
  3976. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3977. reqClockAlignMeter[gun_index] = 0;
  3978. }
  3979. // Sample period MeterValue
  3980. 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))))
  3981. {
  3982. //check Transaction active
  3983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3984. {
  3985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3986. {
  3987. tempIndex = ((gun_index==2) ? 1: 0);
  3988. }
  3989. else
  3990. {
  3991. tempIndex = gun_index;
  3992. }
  3993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3994. {
  3995. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3996. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3997. {
  3998. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3999. {
  4000. reqSampleMeter[gun_index] = 1;
  4001. }
  4002. }
  4003. }// End for CHAdeMO
  4004. }
  4005. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4006. {
  4007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4008. {
  4009. tempIndex = ((gun_index==2) ? 1: 0);
  4010. }
  4011. else
  4012. {
  4013. tempIndex = gun_index;
  4014. }
  4015. for (int index = 0; index < CCS_QUANTITY; index++)
  4016. {
  4017. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4018. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4019. {
  4020. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4021. {
  4022. reqSampleMeter[gun_index] = 1;
  4023. }
  4024. }
  4025. } // End for CCS
  4026. }
  4027. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4028. {
  4029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4030. {
  4031. tempIndex = ((gun_index==2) ? 1: 0);
  4032. }
  4033. else
  4034. {
  4035. tempIndex = gun_index;
  4036. }
  4037. for (int index = 0; index < GB_QUANTITY; index++)
  4038. {
  4039. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4040. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4041. {
  4042. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4043. {
  4044. reqSampleMeter[gun_index] = 1;
  4045. }
  4046. }
  4047. }// End for GB
  4048. }
  4049. else if(gunType[gun_index] == GUN_TYPE_DO)
  4050. {
  4051. tempIndex = gun_index;
  4052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4053. {
  4054. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4055. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4056. {
  4057. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4058. {
  4059. reqSampleMeter[gun_index] = 1;
  4060. }
  4061. }
  4062. }
  4063. }
  4064. else
  4065. {
  4066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4067. {
  4068. tempIndex = 2;
  4069. }
  4070. else
  4071. {
  4072. tempIndex = gun_index;
  4073. }
  4074. for (int index = 0; index < AC_QUANTITY; index++)
  4075. {
  4076. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4077. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4078. {
  4079. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4080. {
  4081. reqSampleMeter[gun_index] = 1;
  4082. }
  4083. }
  4084. }//End for AC
  4085. }
  4086. if(reqSampleMeter[gun_index] == 1)
  4087. {
  4088. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4089. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4090. //storeTempStopTransaction(gun_index);
  4091. reqSampleMeter[gun_index] = 0;
  4092. }
  4093. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4094. }
  4095. //==============================================
  4096. // Check Connector reserved
  4097. //==============================================
  4098. //===============================
  4099. // Check if Reserve is expired
  4100. //===============================
  4101. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4102. {
  4103. double diff_t;
  4104. struct tm tp;
  4105. // current time
  4106. time_t t = time(NULL);
  4107. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4108. tp.tm_isdst = -1;
  4109. time_t utc = mktime(&tp);
  4110. diff_t = difftime(utc, t);
  4111. if(diff_t <= 0)
  4112. {
  4113. DEBUG_INFO("reserve expired.\n");
  4114. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4115. }
  4116. }//END OF Check if Reserve is expired
  4117. //==========================================
  4118. // csu trigger FirmwareStatusNotificationReq
  4119. //==========================================
  4120. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4121. {
  4122. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4123. }
  4124. //==========================================
  4125. // csu trigger DiagnosticsStatusNotificationReq
  4126. //==========================================
  4127. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4128. {
  4129. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4130. }
  4131. //==========================================
  4132. // csu trigger CancelReservationConf
  4133. //==========================================
  4134. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4135. {
  4136. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4137. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4138. }
  4139. //==========================================
  4140. // csu trigger ChangeAvailabilityConf
  4141. //==========================================
  4142. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4143. {
  4144. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4145. }
  4146. //==========================================
  4147. // csu trigger UnlockConnectorConf
  4148. //==========================================
  4149. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4150. {
  4151. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4152. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4153. }
  4154. //==========================================
  4155. // csu trigger ReserveNowConf
  4156. //==========================================
  4157. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4158. {
  4159. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4160. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4161. }
  4162. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4163. {
  4164. sendSignCertificateRequest();
  4165. }
  4166. }
  4167. }
  4168. //==========================================
  4169. // send request routine
  4170. //==========================================
  4171. int sendAuthorizeRequest(int gun_index)
  4172. {
  4173. mtrace();
  4174. int result = FAIL;
  4175. char message[100]={0};
  4176. char guid[37];
  4177. char tempdata[65]={0};
  4178. DEBUG_INFO("sendAuthorizeRequest...\n");
  4179. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4180. //Local Authorize
  4181. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4182. {
  4183. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4184. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4185. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4186. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4187. result = PASS;
  4188. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4189. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4190. authorizeRetryTimes = 0;
  4191. return result;
  4192. }
  4193. 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))||
  4194. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4195. {
  4196. // Query from cache
  4197. DEBUG_INFO("Authorize from cache.\n");
  4198. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4199. // Query from list
  4200. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4201. {
  4202. DEBUG_INFO("Authorize from list.\n");
  4203. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4204. }
  4205. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4206. {
  4207. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4208. {
  4209. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4210. }
  4211. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4212. {
  4213. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4214. }
  4215. if(!GetOcppConnStatus())
  4216. {
  4217. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4218. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4219. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4220. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4221. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4222. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4223. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4224. authorizeRetryTimes = 0;
  4225. return result;
  4226. }
  4227. }
  4228. else
  4229. {
  4230. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4231. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4232. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4233. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4234. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4235. else
  4236. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4237. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4238. result = PASS;
  4239. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4240. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4241. authorizeRetryTimes = 0;
  4242. return result;
  4243. }
  4244. }
  4245. //initialize struct Authorize
  4246. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4247. //get data from shared memory
  4248. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4249. random_uuid(guid);
  4250. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4251. LWS_Send(message);
  4252. sprintf(tempdata, "Authorize,%d", gun_index);
  4253. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4254. {
  4255. result = PASS;
  4256. DEBUG_INFO("Authorize mapItem pass\n");
  4257. }
  4258. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4259. return result;
  4260. }
  4261. int sendBootNotificationRequest(void)
  4262. {
  4263. mtrace();
  4264. int result = FAIL;
  4265. char message[500]={0}, payload[700]={0};
  4266. char guid[37]={0};
  4267. char tempdata[65]={0};
  4268. // Fill BootNotification fields
  4269. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4270. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4271. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4272. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4273. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4274. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4275. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4276. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4277. ShmOCPP16DataPH->ChargeBoxId
  4278. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4279. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4280. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4281. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4282. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4283. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4284. random_uuid(guid);
  4285. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4286. LWS_Send(message);
  4287. sprintf(tempdata, "BootNotification,0");
  4288. 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*/)
  4289. {
  4290. result = PASS;
  4291. }
  4292. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4293. strcpy(queuedata,message);
  4294. return result;
  4295. }
  4296. int sendDataTransferRequest(int gun_index)
  4297. {
  4298. mtrace();
  4299. char message[1000]={0};
  4300. char guid[37]={0};
  4301. char tempdata[65]={0};
  4302. int result = FAIL;
  4303. random_uuid(guid);
  4304. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4305. MESSAGE_TYPE_CALL,
  4306. guid,
  4307. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4308. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4309. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4310. LWS_Send(message);
  4311. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4312. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4313. {
  4314. result = PASS;
  4315. DEBUG_INFO("DataTransfer mapItem pass\n");
  4316. }
  4317. return result;
  4318. }
  4319. int sendDiagnosticsStatusNotificationRequest(char *status)
  4320. {
  4321. mtrace();
  4322. int result = FAIL;
  4323. char message[110]={0};
  4324. char guid[37]={0};
  4325. char tempdata[65]={0};
  4326. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4327. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4328. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4329. random_uuid(guid);
  4330. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4331. LWS_SendNow(message);
  4332. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4333. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4334. {
  4335. result = PASS;
  4336. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4337. }
  4338. //#ifdef SystemLogMessage
  4339. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4340. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4341. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4342. //#endif
  4343. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4344. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4345. //record status
  4346. if(strcmp(status,"Idle")==0)
  4347. {
  4348. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4349. }
  4350. else if(strcmp(status,"Uploaded")==0)
  4351. {
  4352. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4353. }
  4354. else if(strcmp(status,"UploadFailed")==0)
  4355. {
  4356. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4357. }
  4358. else if(strcmp(status,"Uploading")==0)
  4359. {
  4360. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4361. }
  4362. return result;
  4363. }
  4364. int sendFirmwareStatusNotificationRequest(char *status)
  4365. {
  4366. mtrace();
  4367. int result = FAIL;
  4368. char message[110]={0};
  4369. char guid[37]={0};
  4370. char tempdata[65]={0};
  4371. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4372. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4373. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4374. random_uuid(guid);
  4375. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4376. LWS_SendNow(message);
  4377. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4378. 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*/)
  4379. {
  4380. result = PASS;
  4381. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4382. }
  4383. //#ifdef SystemLogMessage
  4384. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4385. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4386. //#endif
  4387. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4388. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4389. //record status
  4390. if(strcmp(status,"Downloaded")==0)
  4391. {
  4392. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4393. }
  4394. else if(strcmp(status,"DownloadFailed")==0)
  4395. {
  4396. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4397. }
  4398. else if(strcmp(status,"Downloading")==0)
  4399. {
  4400. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4401. }
  4402. else if(strcmp(status,"Idle")==0)
  4403. {
  4404. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4405. }
  4406. else if(strcmp(status,"InstallationFailed")==0)
  4407. {
  4408. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4409. }
  4410. else if(strcmp(status,"Installing")==0)
  4411. {
  4412. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4413. }
  4414. else if(strcmp(status,"Installed")==0)
  4415. {
  4416. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4417. }
  4418. return result;
  4419. }
  4420. int sendHeartbeatRequest(int gun_index)
  4421. {
  4422. mtrace();
  4423. int result = FAIL;
  4424. char message[80]={0};
  4425. char guid[37]={0};
  4426. char tempdata[65]={0};
  4427. random_uuid(guid);
  4428. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4429. , MESSAGE_TYPE_CALL
  4430. , guid );
  4431. LWS_Send(message);
  4432. sprintf(tempdata, "Heartbeat,%d", 0);
  4433. 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*/)
  4434. {
  4435. result = PASS;
  4436. }
  4437. return result;
  4438. }
  4439. int sendStartTransactionRequest(int gun_index)
  4440. {
  4441. mtrace();
  4442. int result = FAIL;
  4443. char message[250]={0};
  4444. char guid[37]={0};
  4445. struct timeval tmnow;
  4446. struct tm *tm;
  4447. char buf[28];//, usec_buf[6];
  4448. char tempdata[65]={0};
  4449. int tempIndex = 0;
  4450. DEBUG_INFO("sendStartTransactionRequest...\n");
  4451. gettimeofday(&tmnow, NULL);
  4452. time_t t;
  4453. t = time(NULL);
  4454. /*UTC time and date*/
  4455. tm = gmtime(&t);
  4456. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4457. #if 0 // remove temporally
  4458. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4459. strcat(buf,".");
  4460. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4461. strcat(buf,usec_buf);
  4462. #endif
  4463. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4464. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4465. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4466. // clear StartTransaction Response
  4467. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4468. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4469. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4470. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4471. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4472. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4474. {
  4475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4476. {
  4477. tempIndex = ((gun_index==2) ? 1: 0);
  4478. }
  4479. else
  4480. {
  4481. tempIndex = gun_index;
  4482. }
  4483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4484. {
  4485. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4486. {
  4487. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4488. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4489. }
  4490. }
  4491. }
  4492. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4493. {
  4494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4495. {
  4496. tempIndex = ((gun_index==2) ? 1: 0);
  4497. }
  4498. else
  4499. {
  4500. tempIndex = gun_index;
  4501. }
  4502. for (int index = 0; index < CCS_QUANTITY; index++)
  4503. {
  4504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4505. {
  4506. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4507. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4508. }
  4509. }
  4510. }
  4511. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4512. {
  4513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4514. {
  4515. tempIndex = ((gun_index==2) ? 1: 0);
  4516. }
  4517. else
  4518. {
  4519. tempIndex = gun_index;
  4520. }
  4521. for (int index = 0; index < GB_QUANTITY; index++)
  4522. {
  4523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4524. {
  4525. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4526. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4527. }
  4528. }
  4529. }
  4530. else if(gunType[gun_index] == GUN_TYPE_DO)
  4531. {
  4532. tempIndex = gun_index;
  4533. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4534. {
  4535. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4536. {
  4537. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4538. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4539. }
  4540. }
  4541. }
  4542. else
  4543. {
  4544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4545. {
  4546. tempIndex = 2;
  4547. }
  4548. else
  4549. {
  4550. tempIndex = gun_index;
  4551. }
  4552. for (int index = 0; index < AC_QUANTITY; index++)
  4553. {
  4554. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4555. {
  4556. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4557. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4558. }
  4559. }
  4560. }
  4561. random_uuid(guid);
  4562. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4563. {
  4564. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4565. , gun_index +1
  4566. , MESSAGE_TYPE_CALL
  4567. , guid
  4568. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4569. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4570. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4571. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4572. }
  4573. else
  4574. {
  4575. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4576. , gun_index +1
  4577. , MESSAGE_TYPE_CALL
  4578. , guid
  4579. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4580. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4581. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4582. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4583. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4584. }
  4585. #if 1
  4586. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4587. 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*/)
  4588. {
  4589. result = PASS;
  4590. }
  4591. #endif
  4592. strcpy(queuedata, message);
  4593. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4594. OCPP_insert_transaction_msg(YES, queuedata);
  4595. return result;
  4596. }
  4597. int sendStatusNotificationRequest(int gun_index)
  4598. {
  4599. mtrace();
  4600. int result = FAIL;
  4601. char message[600]={0};
  4602. char guid[37];
  4603. int currentStatus = 0;
  4604. struct timeval tmnow;
  4605. struct tm *tm;
  4606. char buf[28];//, usec_buf[6];
  4607. char tempdata[65]={0};
  4608. int tempIndex = 0;
  4609. uint8_t isStateChanged = TRUE;
  4610. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4611. gettimeofday(&tmnow, NULL);
  4612. time_t t;
  4613. t = time(NULL);
  4614. /*UTC time and date*/
  4615. tm = gmtime(&t);
  4616. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4617. #if 0 // remove temporally
  4618. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4619. strcat(buf,".");
  4620. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4621. strcat(buf,usec_buf);
  4622. #endif
  4623. //printf("%s",buf);
  4624. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4625. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4626. // it's option
  4627. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4628. /*
  4629. enum _SYSTEM_STATUS
  4630. {
  4631. S_BOOTING = 0,
  4632. S_IDLE, = 1
  4633. S_AUTHORIZING, =2
  4634. S_REASSIGN_CHECK, =3
  4635. S_REASSIGN, =4
  4636. S_PRECHARGE, =5
  4637. S_PREPARING_FOR_EV, =6
  4638. S_PREPARING_FOR_EVSE, =7
  4639. S_CHARGING, =8
  4640. S_TERMINATING, =9
  4641. S_COMPLETE, =10
  4642. S_ALARM, =11
  4643. S_FAULT =12
  4644. }
  4645. */
  4646. //check Transaction active
  4647. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4648. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4649. {
  4650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4651. {
  4652. tempIndex = ((gun_index==2) ? 1: 0);
  4653. }
  4654. else
  4655. {
  4656. tempIndex = gun_index;
  4657. }
  4658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4659. {
  4660. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4661. {
  4662. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4663. {
  4664. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4665. {
  4666. currentStatus = Preparing; //OCPP Status: Preparing
  4667. }
  4668. else
  4669. {
  4670. currentStatus = Available; //OCPP Status: Available
  4671. }
  4672. }
  4673. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4674. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4675. ) //S_PRECHARGE
  4676. {
  4677. currentStatus = Preparing; //OCPP Status: Preparing
  4678. }
  4679. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4680. {
  4681. currentStatus = Charging; //OCPP Status: Charging
  4682. }
  4683. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4684. {
  4685. currentStatus = Finishing; //OCPP Status: Finishing
  4686. }
  4687. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4688. {
  4689. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4690. }
  4691. 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
  4692. {
  4693. currentStatus = Unavailable; //OCPP Status: Unavailable
  4694. }
  4695. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4696. {
  4697. currentStatus = Faulted; //OCPP Status: Faulted
  4698. }
  4699. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4700. {
  4701. currentStatus = Reserved; //OCPP Status: Reserved
  4702. }
  4703. } //end of the same index
  4704. }//end of for CHAdeMO_QUANTITY
  4705. }
  4706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4707. {
  4708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4709. {
  4710. tempIndex = ((gun_index==2) ? 1: 0);
  4711. }
  4712. else
  4713. {
  4714. tempIndex = gun_index;
  4715. }
  4716. for (int index = 0; index < CCS_QUANTITY; index++)
  4717. {
  4718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4719. {
  4720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4721. {
  4722. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4723. {
  4724. currentStatus = Preparing; //OCPP Status: Preparing
  4725. }
  4726. else
  4727. {
  4728. currentStatus = Available; //OCPP Status: Available
  4729. }
  4730. }
  4731. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4732. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4733. ) //S_PRECHARGE
  4734. {
  4735. currentStatus = Preparing; //OCPP Status: Preparing
  4736. }
  4737. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4738. {
  4739. currentStatus = Charging; //OCPP Status: Charging
  4740. }
  4741. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4742. {
  4743. currentStatus = Finishing; //OCPP Status: Finishing
  4744. }
  4745. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4746. {
  4747. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4748. }
  4749. 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
  4750. {
  4751. currentStatus = Unavailable; //OCPP Status : Unavailable
  4752. }
  4753. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4754. {
  4755. currentStatus = Faulted; //OCPP Status: Faulted
  4756. }
  4757. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4758. {
  4759. currentStatus = Reserved; //OCPP Status: Reserved
  4760. }
  4761. } //end of the same index
  4762. } // end of for CCS_QUANTITY
  4763. }
  4764. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4765. {
  4766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4767. {
  4768. tempIndex = ((gun_index==2) ? 1: 0);
  4769. }
  4770. else
  4771. {
  4772. tempIndex = gun_index;
  4773. }
  4774. for (int index = 0; index < GB_QUANTITY; index++)
  4775. {
  4776. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4777. {
  4778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4779. {
  4780. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4781. {
  4782. currentStatus = Preparing; //OCPP Status: Preparing
  4783. }
  4784. else
  4785. {
  4786. currentStatus = Available; //OCPP Status: Available
  4787. }
  4788. }
  4789. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4790. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4791. ) //S_PRECHARGE
  4792. {
  4793. currentStatus = Preparing; //OCPP Status: Preparing
  4794. }
  4795. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4796. {
  4797. currentStatus = Charging; //OCPP Status: Charging
  4798. }
  4799. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4800. {
  4801. currentStatus = Finishing; //OCPP Status: Finishing
  4802. }
  4803. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4804. {
  4805. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4806. }
  4807. 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
  4808. {
  4809. currentStatus = Unavailable; //OCPP Status: Unavailable
  4810. }
  4811. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4812. {
  4813. currentStatus = Faulted; //OCPP Status: Faulted
  4814. }
  4815. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4816. {
  4817. currentStatus = Reserved; //OCPP Status: Reserved
  4818. }
  4819. } //end of the same index
  4820. } // end of for GB_QUANTITY
  4821. }
  4822. else if(gunType[gun_index] == GUN_TYPE_DO)
  4823. {
  4824. tempIndex = gun_index;
  4825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4826. {
  4827. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4828. {
  4829. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4830. {
  4831. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4832. {
  4833. currentStatus = Preparing; //OCPP Status: Preparing
  4834. }
  4835. else
  4836. {
  4837. currentStatus = Available; //OCPP Status: Available
  4838. }
  4839. }
  4840. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4841. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4842. ) //S_PRECHARGE
  4843. {
  4844. currentStatus = Preparing; //OCPP Status: Preparing
  4845. }
  4846. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4847. {
  4848. currentStatus = Charging; //OCPP Status: Charging
  4849. }
  4850. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4851. {
  4852. currentStatus = Finishing; //OCPP Status: Finishing
  4853. }
  4854. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4855. {
  4856. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4857. }
  4858. 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
  4859. {
  4860. currentStatus = Unavailable; //OCPP Status: Unavailable
  4861. }
  4862. 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
  4863. {
  4864. currentStatus = Faulted; //OCPP Status: Faulted
  4865. }
  4866. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4867. {
  4868. currentStatus = Reserved; //OCPP Status: Reserved
  4869. }
  4870. } //end of the same index
  4871. }
  4872. }
  4873. else
  4874. {
  4875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4876. {
  4877. tempIndex = 2;
  4878. }
  4879. else
  4880. {
  4881. tempIndex = gun_index;
  4882. }
  4883. for (int index = 0; index < AC_QUANTITY; index++)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4886. {
  4887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4888. {
  4889. 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))
  4890. {
  4891. currentStatus = Preparing; //OCPP Status: Preparing
  4892. }
  4893. else
  4894. {
  4895. currentStatus = Available; //OCPP Status: Available
  4896. }
  4897. }
  4898. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4899. {
  4900. currentStatus = Preparing; //OCPP Status: Preparing
  4901. }
  4902. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4903. {
  4904. currentStatus = Charging; //OCPP Status: Charging
  4905. }
  4906. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4907. {
  4908. currentStatus = Finishing; //OCPP Status: Finishing
  4909. }
  4910. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4911. {
  4912. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4913. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4914. else
  4915. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4916. }
  4917. 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
  4918. {
  4919. currentStatus = Unavailable; //OCPP Status: Unavailable
  4920. }
  4921. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4922. {
  4923. currentStatus = Faulted; //OCPP Status: Faulted
  4924. }
  4925. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4926. {
  4927. currentStatus = Reserved; //OCPP Status: Reserved
  4928. }
  4929. }//end of the same index
  4930. }//end of for AC_QUANTITY
  4931. }
  4932. //it's option
  4933. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4934. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  4935. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  4936. {
  4937. isStateChanged = FALSE;
  4938. }
  4939. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4940. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4941. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4942. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4943. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4944. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4945. random_uuid(guid);
  4946. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4947. , MESSAGE_TYPE_CALL
  4948. , guid
  4949. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4950. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4951. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4952. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4953. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4954. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4955. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4956. if((server_sign == TRUE) && isStateChanged)
  4957. {
  4958. LWS_Send(message);
  4959. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4960. 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*/)
  4961. {
  4962. //DEBUG_ERROR("statusNotification mapitem pass");
  4963. result = PASS;
  4964. }
  4965. }
  4966. else
  4967. {
  4968. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4969. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4970. result = PASS;
  4971. }
  4972. return result;
  4973. }
  4974. int sendStopTransactionRequest(int gun_index)
  4975. {
  4976. mtrace();
  4977. int result = FAIL;
  4978. //char message[1500]={0};
  4979. char guid[37]={0};
  4980. char tempdata[65]={0};
  4981. int tempIndex = 0;
  4982. char TempStopTransaction[256];
  4983. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4984. //int idx_sample=0;
  4985. DEBUG_INFO("sendStopTransactionRequest \n");
  4986. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4987. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4988. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4989. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4990. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4991. {
  4992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4993. {
  4994. tempIndex = ((gun_index==2) ? 1: 0);
  4995. }
  4996. else
  4997. {
  4998. tempIndex = gun_index;
  4999. }
  5000. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5001. {
  5002. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5003. {
  5004. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5005. }
  5006. }// END OF CHAdeMO_QUANTITY
  5007. }
  5008. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5009. {
  5010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5011. {
  5012. tempIndex = ((gun_index==2) ? 1: 0);
  5013. }
  5014. else
  5015. {
  5016. tempIndex = gun_index;
  5017. }
  5018. for (int index = 0; index < CCS_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5021. {
  5022. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5023. }
  5024. }// END OF CCS_QUANTITY
  5025. }
  5026. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5027. {
  5028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5029. {
  5030. tempIndex = ((gun_index==2) ? 1: 0);
  5031. }
  5032. else
  5033. {
  5034. tempIndex = gun_index;
  5035. }
  5036. for (int index = 0; index < GB_QUANTITY; index++)
  5037. {
  5038. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5039. {
  5040. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5041. }
  5042. }// END OF GB_QUANTITY
  5043. }
  5044. else if(gunType[gun_index] == GUN_TYPE_DO)
  5045. {
  5046. tempIndex = gun_index;
  5047. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5048. {
  5049. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5050. {
  5051. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5052. }
  5053. }// END OF GB_QUANTITY
  5054. }
  5055. else
  5056. {
  5057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5058. {
  5059. tempIndex = 2;
  5060. }
  5061. else
  5062. {
  5063. tempIndex = gun_index;
  5064. }
  5065. for (int index = 0; index < AC_QUANTITY; index++)
  5066. {
  5067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5068. {
  5069. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5070. }
  5071. }// END OF AC_QUANTITY
  5072. }
  5073. //====================================== Stop Transaction Time =====================================================
  5074. struct timeval tmnow;
  5075. struct tm *tm;
  5076. char buf[28];//, usec_buf[6];
  5077. gettimeofday(&tmnow, NULL);
  5078. time_t t;
  5079. t = time(NULL);
  5080. /*UTC time and date*/
  5081. tm = gmtime(&t);
  5082. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5084. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5085. random_uuid(guid);
  5086. /***********************************transactionData******************************************************/
  5087. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5089. //=================================
  5090. // Transaction_Begin
  5091. //=================================
  5092. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5093. {
  5094. //============================================ Energy.Active.Import.Interval ================================
  5095. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5096. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5098. 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*/]);
  5099. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5100. 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))
  5101. {
  5102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5103. }
  5104. else
  5105. {
  5106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5107. }
  5108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5109. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5110. }
  5111. //=================================
  5112. // Transaction_End
  5113. //=================================
  5114. // ================================= Current.Import L1 ===============================================
  5115. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5116. {
  5117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5119. {
  5120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5121. {
  5122. tempIndex = ((gun_index==2) ? 1: 0);
  5123. }
  5124. else
  5125. {
  5126. tempIndex = gun_index;
  5127. }
  5128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5129. {
  5130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5131. {
  5132. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5133. }
  5134. }// End of for CHAdeMO_QUANTITY
  5135. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5136. }
  5137. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5138. {
  5139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5140. {
  5141. tempIndex = ((gun_index==2) ? 1: 0);
  5142. }
  5143. else
  5144. {
  5145. tempIndex = gun_index;
  5146. }
  5147. for (int index = 0; index < CCS_QUANTITY; index++)
  5148. {
  5149. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5150. {
  5151. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5152. }
  5153. }// End of for CCS_QUANTITY
  5154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5155. }
  5156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5157. {
  5158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5159. {
  5160. tempIndex = ((gun_index==2) ? 1: 0);
  5161. }
  5162. else
  5163. {
  5164. tempIndex = gun_index;
  5165. }
  5166. for (int index = 0; index < GB_QUANTITY; index++)
  5167. {
  5168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5169. {
  5170. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5171. }
  5172. }// End of for GB_QUANTITY
  5173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5174. }
  5175. else if(gunType[gun_index] == GUN_TYPE_DO)
  5176. {
  5177. tempIndex = gun_index;
  5178. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5179. {
  5180. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5181. {
  5182. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5183. }
  5184. }
  5185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5186. }
  5187. else
  5188. {
  5189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5190. {
  5191. tempIndex = 2;
  5192. }
  5193. else
  5194. {
  5195. tempIndex = gun_index;
  5196. }
  5197. for (int index = 0; index < AC_QUANTITY; index++)
  5198. {
  5199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5200. {
  5201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5202. }
  5203. }// End of for AC_QUANTITY
  5204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5205. }
  5206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5211. }
  5212. // ================================= Energy.Active.Import.Interval ==============================================
  5213. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5214. {
  5215. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5216. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5217. {
  5218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5219. {
  5220. tempIndex = ((gun_index==2) ? 1: 0);
  5221. }
  5222. else
  5223. {
  5224. tempIndex = gun_index;
  5225. }
  5226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5227. {
  5228. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5229. {
  5230. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5231. }
  5232. }// END OF CHAdeMO_QUANTITY
  5233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5234. }
  5235. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5236. {
  5237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5238. {
  5239. tempIndex = ((gun_index==2) ? 1: 0);
  5240. }
  5241. else
  5242. {
  5243. tempIndex = gun_index;
  5244. }
  5245. for (int index = 0; index < CCS_QUANTITY; index++)
  5246. {
  5247. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5248. {
  5249. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5250. }
  5251. }// END OF CCS_QUANTITY
  5252. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5253. }
  5254. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5255. {
  5256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5257. {
  5258. tempIndex = ((gun_index==2) ? 1: 0);
  5259. }
  5260. else
  5261. {
  5262. tempIndex = gun_index;
  5263. }
  5264. for (int index = 0; index < GB_QUANTITY; index++)
  5265. {
  5266. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5267. {
  5268. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5269. }
  5270. }// END OF GB_QUANTITY
  5271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5272. }
  5273. else if(gunType[gun_index] == GUN_TYPE_DO)
  5274. {
  5275. tempIndex = gun_index;
  5276. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5277. {
  5278. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5279. {
  5280. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5281. }
  5282. }
  5283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5284. }
  5285. else
  5286. {
  5287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5288. {
  5289. tempIndex = 2;
  5290. }
  5291. else
  5292. {
  5293. tempIndex = gun_index;
  5294. }
  5295. for (int index = 0; index < AC_QUANTITY; index++)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5298. {
  5299. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5300. }
  5301. }// END OF AC_QUANTITY
  5302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5303. }
  5304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5309. }
  5310. //=================================== Power.Active.Import ==================================================
  5311. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5312. {
  5313. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5314. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5315. {
  5316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5317. {
  5318. tempIndex = ((gun_index==2) ? 1: 0);
  5319. }
  5320. else
  5321. {
  5322. tempIndex = gun_index;
  5323. }
  5324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5325. {
  5326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5327. {
  5328. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5329. }
  5330. } // End for CHAdeMO_QUANTITY
  5331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5332. }
  5333. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5334. {
  5335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5336. {
  5337. tempIndex = ((gun_index==2) ? 1: 0);
  5338. }
  5339. else
  5340. {
  5341. tempIndex = gun_index;
  5342. }
  5343. for (int index = 0; index < CCS_QUANTITY; index++)
  5344. {
  5345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5346. {
  5347. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5348. }
  5349. } // END for CCS_QUANTITY
  5350. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5351. }
  5352. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5353. {
  5354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5355. {
  5356. tempIndex = ((gun_index==2) ? 1: 0);
  5357. }
  5358. else
  5359. {
  5360. tempIndex = gun_index;
  5361. }
  5362. for (int index = 0; index < GB_QUANTITY; index++)
  5363. {
  5364. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5365. {
  5366. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5367. }
  5368. }// END for GB_QUANTITY
  5369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5370. }
  5371. else if(gunType[gun_index] == GUN_TYPE_DO)
  5372. {
  5373. tempIndex = gun_index;
  5374. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5375. {
  5376. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5377. {
  5378. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5379. }
  5380. }
  5381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5382. }
  5383. else
  5384. {
  5385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5386. {
  5387. tempIndex = 2;
  5388. }
  5389. else
  5390. {
  5391. tempIndex = gun_index;
  5392. }
  5393. for (int index = 0; index < AC_QUANTITY; index++)
  5394. {
  5395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5396. {
  5397. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5398. }
  5399. } // END for AC_QUANTITY
  5400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5401. }
  5402. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5403. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5404. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5405. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5406. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5407. }
  5408. //============================ Voltage L1 ====================================
  5409. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5410. {
  5411. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5412. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5413. {
  5414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5415. {
  5416. tempIndex = ((gun_index==2) ? 1: 0);
  5417. }
  5418. else
  5419. {
  5420. tempIndex = gun_index;
  5421. }
  5422. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5423. {
  5424. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5425. {
  5426. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5427. }
  5428. } // END OF FOR CHAdeMO_QUANTITY
  5429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5430. }
  5431. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5432. {
  5433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5434. {
  5435. tempIndex = ((gun_index==2) ? 1: 0);
  5436. }
  5437. else
  5438. {
  5439. tempIndex = gun_index;
  5440. }
  5441. for (int index = 0; index < CCS_QUANTITY; index++)
  5442. {
  5443. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5444. {
  5445. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5446. }
  5447. } // END OF FOR CCS_QUANTITY
  5448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5449. }
  5450. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5451. {
  5452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5453. {
  5454. tempIndex = ((gun_index==2) ? 1: 0);
  5455. }
  5456. else
  5457. {
  5458. tempIndex = gun_index;
  5459. }
  5460. for (int index = 0; index < GB_QUANTITY; index++)
  5461. {
  5462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5463. {
  5464. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5465. }
  5466. } // END OF FOR GB_QUANTITY
  5467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5468. }
  5469. else if(gunType[gun_index] == GUN_TYPE_DO)
  5470. {
  5471. tempIndex = gun_index;
  5472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5473. {
  5474. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5475. {
  5476. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5477. }
  5478. }
  5479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5480. }
  5481. else
  5482. {
  5483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5484. {
  5485. tempIndex = 2;
  5486. }
  5487. else
  5488. {
  5489. tempIndex = gun_index;
  5490. }
  5491. for (int index = 0; index < AC_QUANTITY; index++)
  5492. {
  5493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5494. {
  5495. 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
  5496. }
  5497. } // END OF FOR AC_QUANTITY
  5498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5499. }
  5500. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5501. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5502. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5503. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5504. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5505. }
  5506. //====================== End SoC ================================
  5507. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5508. {
  5509. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5510. 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))
  5511. {
  5512. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5513. {
  5514. tempIndex = ((gun_index==2) ? 1: 0);
  5515. }
  5516. else
  5517. {
  5518. tempIndex = gun_index;
  5519. }
  5520. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5521. {
  5522. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5523. {
  5524. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5525. {
  5526. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5527. }
  5528. }
  5529. }
  5530. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5531. {
  5532. for (int index = 0; index < CCS_QUANTITY; index++)
  5533. {
  5534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5535. {
  5536. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5537. }
  5538. }
  5539. }
  5540. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5541. {
  5542. for (int index = 0; index < GB_QUANTITY; index++)
  5543. {
  5544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5545. {
  5546. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5547. }
  5548. }
  5549. }
  5550. else if(gunType[gun_index] == GUN_TYPE_DO)
  5551. {
  5552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5553. {
  5554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5555. {
  5556. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5557. }
  5558. }
  5559. }
  5560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5562. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5566. } // END FOR DC CASE
  5567. }
  5568. // ================================= Current.Import L2 ===============================================
  5569. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5570. {
  5571. // AC 3 phse L2 current
  5572. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5573. {
  5574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5575. {
  5576. tempIndex = 2;
  5577. }
  5578. else
  5579. {
  5580. tempIndex = gun_index;
  5581. }
  5582. for (int index = 0; index < AC_QUANTITY; index++)
  5583. {
  5584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5585. {
  5586. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5587. }
  5588. }// End of for AC_QUANTITY
  5589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5590. }
  5591. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5592. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5593. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5596. }
  5597. // ================================= Current.Import L3 ===============================================
  5598. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5599. {
  5600. // AC 3 phse L3 current
  5601. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5602. {
  5603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5604. {
  5605. tempIndex = 2;
  5606. }
  5607. else
  5608. {
  5609. tempIndex = gun_index;
  5610. }
  5611. for (int index = 0; index < AC_QUANTITY; index++)
  5612. {
  5613. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5614. {
  5615. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5616. }
  5617. }// End of for AC_QUANTITY
  5618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5619. }
  5620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5625. }
  5626. //============================ Voltage L2 ====================================
  5627. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5628. {
  5629. // AC 3 phse L2 voltage
  5630. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5631. {
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5633. {
  5634. tempIndex = 2;
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. for (int index = 0; index < AC_QUANTITY; index++)
  5641. {
  5642. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5643. {
  5644. 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
  5645. }
  5646. } // END OF FOR AC_QUANTITY
  5647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5648. }
  5649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5654. }
  5655. //============================ Voltage L3 ====================================
  5656. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5657. {
  5658. // AC 3 phse L3 voltage
  5659. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5662. {
  5663. tempIndex = 2;
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < AC_QUANTITY; index++)
  5670. {
  5671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5672. {
  5673. 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
  5674. }
  5675. } // END OF FOR AC_QUANTITY
  5676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5677. }
  5678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5683. }
  5684. //====================== Start SoC ================================
  5685. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5686. {
  5687. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5688. 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))
  5689. {
  5690. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5691. {
  5692. tempIndex = ((gun_index==2) ? 1: 0);
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5699. {
  5700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5701. {
  5702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5703. {
  5704. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5705. }
  5706. }
  5707. }
  5708. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5709. {
  5710. for (int index = 0; index < CCS_QUANTITY; index++)
  5711. {
  5712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5713. {
  5714. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5715. }
  5716. }
  5717. }
  5718. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5719. {
  5720. for (int index = 0; index < GB_QUANTITY; index++)
  5721. {
  5722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5723. {
  5724. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5725. }
  5726. }
  5727. }
  5728. else if(gunType[gun_index] == GUN_TYPE_DO)
  5729. {
  5730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5731. {
  5732. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5733. {
  5734. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5735. }
  5736. }
  5737. }
  5738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5744. } // END FOR DC CASE
  5745. }
  5746. //================================================ Message create ====================================================
  5747. json_object *StopTransaction = json_object_new_object();
  5748. json_object *transactionDatas = json_object_new_array();
  5749. json_object *sampledValues = json_object_new_array();
  5750. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5751. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5752. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5753. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5754. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5755. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5756. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5757. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5758. {
  5759. json_object *transactionData = json_object_new_object();
  5760. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5761. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5762. {
  5763. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5764. {
  5765. json_object *sampledValue = json_object_new_object();
  5766. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5767. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5768. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5769. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5770. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5771. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5772. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5773. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5774. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5775. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5776. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5777. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5778. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5779. json_object_array_add(sampledValues, sampledValue);
  5780. }
  5781. }
  5782. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5783. json_object_array_add(transactionDatas, transactionData);
  5784. }
  5785. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5786. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5787. ,MESSAGE_TYPE_CALL
  5788. ,guid
  5789. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5790. json_object_put(StopTransaction);
  5791. #if 1 // for TempStopTransaction
  5792. //Delete TempStopTransaction
  5793. if((access(TempStopTransaction,F_OK))!=-1)
  5794. {
  5795. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5796. }
  5797. #endif
  5798. #if 1
  5799. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5801. {
  5802. result = PASS;
  5803. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5804. }
  5805. #endif
  5806. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5807. OCPP_insert_transaction_msg(NO, queuedata);
  5808. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5809. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5810. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5811. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5812. {
  5813. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5814. }
  5815. //for test
  5816. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5817. return result;
  5818. }
  5819. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5820. {
  5821. mtrace();
  5822. int result = FAIL;
  5823. char guid[37]={0};
  5824. char tempdata[65]={0};
  5825. int tempIndex = 0;
  5826. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5827. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5828. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5829. //set value
  5830. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5831. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5832. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5833. -1);
  5834. random_uuid(guid);
  5835. //UTC Date time
  5836. struct timeval tmnow;
  5837. struct tm *tm;
  5838. char buf[28];//, usec_buf[6];
  5839. gettimeofday(&tmnow, NULL);
  5840. time_t t;
  5841. t = time(NULL);
  5842. /*UTC time and date*/
  5843. tm = gmtime(&t);
  5844. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5845. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5846. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5847. //********************************(1)Current.Import L1************************************************/
  5848. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5849. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5850. (dataType == ReadingContext_Trigger))
  5851. {
  5852. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5853. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5854. {
  5855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5856. {
  5857. tempIndex = ((gun_index==2) ? 1: 0);
  5858. }
  5859. else
  5860. {
  5861. tempIndex = gun_index;
  5862. }
  5863. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5864. {
  5865. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5866. {
  5867. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5868. }
  5869. }
  5870. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5871. }
  5872. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5873. {
  5874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5875. {
  5876. tempIndex = ((gun_index==2) ? 1: 0);
  5877. }
  5878. else
  5879. {
  5880. tempIndex = gun_index;
  5881. }
  5882. for (int index = 0; index < CCS_QUANTITY; index++)
  5883. {
  5884. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5885. {
  5886. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5887. }
  5888. }
  5889. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5890. }
  5891. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5892. {
  5893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5894. {
  5895. tempIndex = ((gun_index==2) ? 1: 0);
  5896. }
  5897. else
  5898. {
  5899. tempIndex = gun_index;
  5900. }
  5901. for (int index = 0; index < GB_QUANTITY; index++)
  5902. {
  5903. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5904. {
  5905. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5906. }
  5907. }
  5908. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5909. }
  5910. else if(gunType[gun_index] == GUN_TYPE_DO)
  5911. {
  5912. tempIndex = gun_index;
  5913. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5914. {
  5915. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5916. {
  5917. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5918. }
  5919. }
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5921. }
  5922. else
  5923. {
  5924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5925. {
  5926. tempIndex = 2;
  5927. }
  5928. else
  5929. {
  5930. tempIndex = gun_index;
  5931. }
  5932. for (int index = 0; index < AC_QUANTITY; index++)
  5933. {
  5934. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5935. {
  5936. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5937. }
  5938. }
  5939. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5940. }
  5941. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5942. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5943. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5944. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5945. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5946. }
  5947. //********************************(2)Energy.Active.Import.Register ************************************************/
  5948. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5949. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5950. (dataType == ReadingContext_Trigger))
  5951. {
  5952. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5953. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5954. {
  5955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5956. {
  5957. tempIndex = ((gun_index==2) ? 1: 0);
  5958. }
  5959. else
  5960. {
  5961. tempIndex = gun_index;
  5962. }
  5963. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5964. {
  5965. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5966. {
  5967. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5968. }
  5969. }
  5970. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5971. }
  5972. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5973. {
  5974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5975. {
  5976. tempIndex = ((gun_index==2) ? 1: 0);
  5977. }
  5978. else
  5979. {
  5980. tempIndex = gun_index;
  5981. }
  5982. for (int index = 0; index < CCS_QUANTITY; index++)
  5983. {
  5984. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5985. {
  5986. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5987. }
  5988. }
  5989. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5990. }
  5991. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5992. {
  5993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5994. {
  5995. tempIndex = ((gun_index==2) ? 1: 0);
  5996. }
  5997. else
  5998. {
  5999. tempIndex = gun_index;
  6000. }
  6001. for (int index = 0; index < GB_QUANTITY; index++)
  6002. {
  6003. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6004. {
  6005. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6006. }
  6007. }
  6008. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6009. }
  6010. else if(gunType[gun_index] == GUN_TYPE_DO)
  6011. {
  6012. tempIndex = gun_index;
  6013. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6014. {
  6015. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6016. {
  6017. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6018. }
  6019. }
  6020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6021. }
  6022. else
  6023. {
  6024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6025. {
  6026. tempIndex = 2;
  6027. }
  6028. else
  6029. {
  6030. tempIndex = gun_index;
  6031. }
  6032. for (int index = 0; index < AC_QUANTITY; index++)
  6033. {
  6034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6035. {
  6036. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6037. }
  6038. }
  6039. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6040. }
  6041. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6042. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6043. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6044. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6045. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6046. }
  6047. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6048. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6049. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6050. (dataType == ReadingContext_Trigger))
  6051. {
  6052. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6053. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6054. {
  6055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6056. {
  6057. tempIndex = ((gun_index==2) ? 1: 0);
  6058. }
  6059. else
  6060. {
  6061. tempIndex = gun_index;
  6062. }
  6063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6064. {
  6065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6066. {
  6067. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6068. }
  6069. } // END OF FOR CHAdeMO_QUANTITY
  6070. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6071. }
  6072. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6073. {
  6074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6075. {
  6076. tempIndex = ((gun_index==2) ? 1: 0);
  6077. }
  6078. else
  6079. {
  6080. tempIndex = gun_index;
  6081. }
  6082. for (int index = 0; index < CCS_QUANTITY; index++)
  6083. {
  6084. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6085. {
  6086. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6087. }
  6088. } // END OF CCS_QUANTITY
  6089. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6090. }
  6091. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6092. {
  6093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6094. {
  6095. tempIndex = ((gun_index==2) ? 1: 0);
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. for (int index = 0; index < GB_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6106. }
  6107. } // END OF GB_QUANTITY
  6108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6109. }
  6110. else if(gunType[gun_index] == GUN_TYPE_DO)
  6111. {
  6112. tempIndex = gun_index;
  6113. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6114. {
  6115. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6116. {
  6117. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6118. }
  6119. }
  6120. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6121. }
  6122. else
  6123. {
  6124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6125. {
  6126. tempIndex = 2;
  6127. }
  6128. else
  6129. {
  6130. tempIndex = gun_index;
  6131. }
  6132. for (int index = 0; index < AC_QUANTITY; index++)
  6133. {
  6134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6135. {
  6136. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6137. }
  6138. }
  6139. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6140. }
  6141. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6142. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6143. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6144. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6145. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6146. }
  6147. //********************************(4)Power.Active.Import************************************************/
  6148. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6149. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6150. (dataType == ReadingContext_Trigger))
  6151. {
  6152. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6153. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6154. {
  6155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6156. {
  6157. tempIndex = ((gun_index==2) ? 1: 0);
  6158. }
  6159. else
  6160. {
  6161. tempIndex = gun_index;
  6162. }
  6163. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6166. {
  6167. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6168. }
  6169. } // END OF FOR
  6170. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6171. }
  6172. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6173. {
  6174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6175. {
  6176. tempIndex = ((gun_index==2) ? 1: 0);
  6177. }
  6178. else
  6179. {
  6180. tempIndex = gun_index;
  6181. }
  6182. for (int index = 0; index < CCS_QUANTITY; index++)
  6183. {
  6184. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6185. {
  6186. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6187. }
  6188. }
  6189. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6190. }
  6191. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6192. {
  6193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6194. {
  6195. tempIndex = ((gun_index==2) ? 1: 0);
  6196. }
  6197. else
  6198. {
  6199. tempIndex = gun_index;
  6200. }
  6201. for (int index = 0; index < GB_QUANTITY; index++)
  6202. {
  6203. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6204. {
  6205. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6206. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6207. }
  6208. }
  6209. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6210. }
  6211. else if(gunType[gun_index] == GUN_TYPE_DO)
  6212. {
  6213. tempIndex = gun_index;
  6214. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6215. {
  6216. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6217. {
  6218. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6219. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6220. }
  6221. }
  6222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6223. }
  6224. else
  6225. {
  6226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6227. {
  6228. tempIndex = 2;
  6229. }
  6230. else
  6231. {
  6232. tempIndex = gun_index;
  6233. }
  6234. for (int index = 0; index < AC_QUANTITY; index++)
  6235. {
  6236. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6237. {
  6238. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6239. }
  6240. }
  6241. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6242. }
  6243. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6244. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6245. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6248. }
  6249. //***********************************************(5)VOLTAGE L1******************************************************/
  6250. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6251. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6252. (dataType == ReadingContext_Trigger))
  6253. {
  6254. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6255. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6256. {
  6257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6258. {
  6259. tempIndex = ((gun_index==2) ? 1: 0);
  6260. }
  6261. else
  6262. {
  6263. tempIndex = gun_index;
  6264. }
  6265. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6266. {
  6267. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6268. {
  6269. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6270. }
  6271. }
  6272. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6273. }
  6274. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6275. {
  6276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6277. {
  6278. tempIndex = ((gun_index==2) ? 1: 0);
  6279. }
  6280. else
  6281. {
  6282. tempIndex = gun_index;
  6283. }
  6284. for (int index = 0; index < CCS_QUANTITY; index++)
  6285. {
  6286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6287. {
  6288. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6289. }
  6290. }
  6291. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6292. }
  6293. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6294. {
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6296. {
  6297. tempIndex = ((gun_index==2) ? 1: 0);
  6298. }
  6299. else
  6300. {
  6301. tempIndex = gun_index;
  6302. }
  6303. for (int index = 0; index < GB_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6306. {
  6307. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6308. }
  6309. }
  6310. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6311. }
  6312. else if(gunType[gun_index] == GUN_TYPE_DO)
  6313. {
  6314. tempIndex = gun_index;
  6315. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6316. {
  6317. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6318. {
  6319. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6320. }
  6321. }
  6322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6323. }
  6324. else
  6325. {
  6326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6327. {
  6328. tempIndex = 2;
  6329. }
  6330. else
  6331. {
  6332. tempIndex = gun_index;
  6333. }
  6334. for (int index = 0; index < AC_QUANTITY; index++)
  6335. {
  6336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6337. {
  6338. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6339. }
  6340. }
  6341. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6342. }
  6343. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6344. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6345. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6346. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6347. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6348. }
  6349. //***********************************************(6)SOC******************************************************/
  6350. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6351. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6352. (dataType == ReadingContext_Trigger))
  6353. {
  6354. 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))
  6355. {
  6356. //idx_sample=5;
  6357. //sampledValue = NULL;
  6358. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6359. {
  6360. tempIndex = ((gun_index==2) ? 1: 0);
  6361. }
  6362. else
  6363. {
  6364. tempIndex = gun_index;
  6365. }
  6366. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6367. {
  6368. //tempIndex = ((gun_index==2) ? 1: 0);
  6369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6370. {
  6371. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6372. {
  6373. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6374. }
  6375. }
  6376. }
  6377. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6378. {
  6379. //tempIndex = ((gun_index==2) ? 1: 0);
  6380. for (int index = 0; index < CCS_QUANTITY; index++)
  6381. {
  6382. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6383. {
  6384. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6385. }
  6386. }
  6387. }
  6388. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6389. {
  6390. //tempIndex = ((gun_index==2) ? 1: 0);
  6391. for (int index = 0; index < GB_QUANTITY; index++)
  6392. {
  6393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6394. {
  6395. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6396. }
  6397. }
  6398. }
  6399. else if(gunType[gun_index] == GUN_TYPE_DO)
  6400. {
  6401. //tempIndex = ((gun_index==2) ? 1: 0);
  6402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6403. {
  6404. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6405. {
  6406. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6407. }
  6408. }
  6409. }
  6410. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6412. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6413. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6414. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6415. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6416. }
  6417. }
  6418. //********************************(7)Current.Import L2************************************************/
  6419. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6420. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6421. (dataType == ReadingContext_Trigger))
  6422. {
  6423. // Only for AC 3 phase
  6424. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6425. {
  6426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6427. {
  6428. tempIndex = 2;
  6429. }
  6430. else
  6431. {
  6432. tempIndex = gun_index;
  6433. }
  6434. for (int index = 0; index < AC_QUANTITY; index++)
  6435. {
  6436. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6437. {
  6438. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6439. }
  6440. }
  6441. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6442. }
  6443. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6444. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6445. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6446. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6447. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6448. }
  6449. //********************************(8)Current.Import L3************************************************/
  6450. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6451. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6452. (dataType == ReadingContext_Trigger))
  6453. {
  6454. // Only for AC 3 phase
  6455. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6456. {
  6457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6458. {
  6459. tempIndex = 2;
  6460. }
  6461. else
  6462. {
  6463. tempIndex = gun_index;
  6464. }
  6465. for (int index = 0; index < AC_QUANTITY; index++)
  6466. {
  6467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6468. {
  6469. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6470. }
  6471. }
  6472. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6473. }
  6474. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6476. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6478. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6479. }
  6480. //***********************************************(9)VOLTAGE L2******************************************************/
  6481. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6482. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6483. (dataType == ReadingContext_Trigger))
  6484. {
  6485. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6486. {
  6487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6488. {
  6489. tempIndex = 2;
  6490. }
  6491. else
  6492. {
  6493. tempIndex = gun_index;
  6494. }
  6495. for (int index = 0; index < AC_QUANTITY; index++)
  6496. {
  6497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6498. {
  6499. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6500. }
  6501. }
  6502. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6503. }
  6504. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6507. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6508. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6509. }
  6510. //***********************************************(10)VOLTAGE L3******************************************************/
  6511. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6512. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6513. (dataType == ReadingContext_Trigger))
  6514. {
  6515. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6516. {
  6517. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6518. {
  6519. tempIndex = 2;
  6520. }
  6521. else
  6522. {
  6523. tempIndex = gun_index;
  6524. }
  6525. for (int index = 0; index < AC_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6528. {
  6529. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6530. }
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6533. }
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6538. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6539. }
  6540. //***********************************************(11)Current.Offered******************************************************/
  6541. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6542. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6543. (dataType == ReadingContext_Trigger))
  6544. {
  6545. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6546. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6547. {
  6548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6549. {
  6550. tempIndex = ((gun_index==2) ? 1: 0);
  6551. }
  6552. else
  6553. {
  6554. tempIndex = gun_index;
  6555. }
  6556. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6557. {
  6558. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6559. {
  6560. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6561. }
  6562. } // END OF FOR CHAdeMO_QUANTITY
  6563. }
  6564. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6565. {
  6566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6567. {
  6568. tempIndex = ((gun_index==2) ? 1: 0);
  6569. }
  6570. else
  6571. {
  6572. tempIndex = gun_index;
  6573. }
  6574. for (int index = 0; index < CCS_QUANTITY; index++)
  6575. {
  6576. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6577. {
  6578. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6579. }
  6580. } // END OF CCS_QUANTITY
  6581. }
  6582. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6583. {
  6584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6585. {
  6586. tempIndex = ((gun_index==2) ? 1: 0);
  6587. }
  6588. else
  6589. {
  6590. tempIndex = gun_index;
  6591. }
  6592. for (int index = 0; index < GB_QUANTITY; index++)
  6593. {
  6594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6595. {
  6596. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6597. }
  6598. } // END OF GB_QUANTITY
  6599. }
  6600. else if(gunType[gun_index] == GUN_TYPE_DO)
  6601. {
  6602. tempIndex = gun_index;
  6603. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6604. {
  6605. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6606. {
  6607. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6608. }
  6609. }
  6610. }
  6611. else
  6612. {
  6613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6614. {
  6615. tempIndex = 2;
  6616. }
  6617. else
  6618. {
  6619. tempIndex = gun_index;
  6620. }
  6621. for (int index = 0; index < AC_QUANTITY; index++)
  6622. {
  6623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6624. {
  6625. uint16_t currentOffer;
  6626. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6627. {
  6628. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6629. }
  6630. else
  6631. {
  6632. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6633. }
  6634. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6635. }
  6636. }
  6637. }
  6638. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6639. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6640. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6641. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6642. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6643. }
  6644. //***********************************************(12)Power.Offered******************************************************/
  6645. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6646. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6647. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6648. {
  6649. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6650. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6651. {
  6652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6653. {
  6654. tempIndex = ((gun_index==2) ? 1: 0);
  6655. }
  6656. else
  6657. {
  6658. tempIndex = gun_index;
  6659. }
  6660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6661. {
  6662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6663. {
  6664. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6665. }
  6666. } // END OF FOR CHAdeMO_QUANTITY
  6667. }
  6668. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6669. {
  6670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6671. {
  6672. tempIndex = ((gun_index==2) ? 1: 0);
  6673. }
  6674. else
  6675. {
  6676. tempIndex = gun_index;
  6677. }
  6678. for (int index = 0; index < CCS_QUANTITY; index++)
  6679. {
  6680. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6681. {
  6682. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6683. }
  6684. } // END OF CCS_QUANTITY
  6685. }
  6686. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6687. {
  6688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6689. {
  6690. tempIndex = ((gun_index==2) ? 1: 0);
  6691. }
  6692. else
  6693. {
  6694. tempIndex = gun_index;
  6695. }
  6696. for (int index = 0; index < GB_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6699. {
  6700. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6701. }
  6702. } // END OF GB_QUANTITY
  6703. }
  6704. else if(gunType[gun_index] == GUN_TYPE_DO)
  6705. {
  6706. tempIndex = gun_index;
  6707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6708. {
  6709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6710. {
  6711. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6712. }
  6713. }
  6714. }
  6715. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6716. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6717. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6718. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6720. }
  6721. // Message create ====================================================================================================
  6722. if(TRUE)
  6723. {
  6724. json_object *MeterValueReq = json_object_new_object();
  6725. json_object *MeterValues = json_object_new_array();
  6726. json_object *sampledValues = json_object_new_array();
  6727. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6728. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6729. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6730. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6731. {
  6732. json_object *MeterValue = json_object_new_object();
  6733. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6734. {
  6735. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6736. {
  6737. json_object *sampledValue = json_object_new_object();
  6738. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6739. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6740. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6741. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6742. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6743. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6744. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6745. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6746. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6747. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6748. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6749. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6750. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6751. json_object_array_add(sampledValues, sampledValue);
  6752. }
  6753. }
  6754. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6755. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6756. json_object_array_add(MeterValues, MeterValue);
  6757. }
  6758. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6759. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6760. ,gun_index + 1
  6761. ,MESSAGE_TYPE_CALL
  6762. ,guid
  6763. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6764. json_object_put(MeterValueReq);
  6765. }
  6766. // Put request guid to hash map
  6767. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6768. 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*/)
  6769. {
  6770. result = PASS;
  6771. //DEBUG_INFO("MeterValues mapitem pass\n");
  6772. }
  6773. if((dataType != ReadingContext_Trigger) &&
  6774. (dataType != ReadingContext_Sample_Clock) &&
  6775. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6776. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6777. else
  6778. {
  6779. if(FirstHeartBeat)
  6780. LWS_Send(queuedata +2);
  6781. }
  6782. return result;
  6783. }
  6784. int sendLogStatusNotificationRequest(char *status)
  6785. {
  6786. mtrace();
  6787. int result = PASS;
  6788. char message[4096]={0};
  6789. char guid[37]={0};
  6790. char tempdata[128]={0};
  6791. json_object *LogStatusNotification = json_object_new_object();
  6792. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6793. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6794. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6795. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6796. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6797. random_uuid(guid);
  6798. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6799. json_object_put(LogStatusNotification);
  6800. LWS_Send(message);
  6801. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6802. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6803. {
  6804. result = PASS;
  6805. }
  6806. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6807. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6808. return result;
  6809. }
  6810. int sendSecurityEventNotificationRequest()
  6811. {
  6812. mtrace();
  6813. int result = PASS;
  6814. char message[4096]={0};
  6815. char guid[37]={0};
  6816. char tempdata[128]={0};
  6817. json_object *SecurityEventNotification = json_object_new_object();
  6818. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6819. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6820. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6821. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6822. random_uuid(guid);
  6823. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6824. json_object_put(SecurityEventNotification);
  6825. LWS_Send(message);
  6826. sprintf(tempdata, "SecurityEventNotification,0");
  6827. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6828. {
  6829. result = PASS;
  6830. }
  6831. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6832. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6833. return result;
  6834. }
  6835. int sendSignCertificateRequest()
  6836. {
  6837. mtrace();
  6838. int result = PASS;
  6839. char message[4096]={0};
  6840. char guid[37]={0};
  6841. char tempdata[128]={0};
  6842. json_object *SignCertificate = json_object_new_object();
  6843. DEBUG_INFO("sendSignCertificateRequest...\n");
  6844. // Read csr file content
  6845. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6846. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6847. char *line = NULL;
  6848. size_t len = 0;
  6849. while(getline(&line, &len, fp) != -1)
  6850. {
  6851. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6852. {
  6853. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6854. }
  6855. }
  6856. fclose(fp);
  6857. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6858. random_uuid(guid);
  6859. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6860. json_object_put(SignCertificate);
  6861. LWS_Send(message);
  6862. sprintf(tempdata, "SignCertificate,0");
  6863. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6864. {
  6865. result = PASS;
  6866. }
  6867. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6868. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6869. return result;
  6870. }
  6871. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6872. {
  6873. mtrace();
  6874. int result = PASS;
  6875. char message[110]={0};
  6876. char guid[37]={0};
  6877. char tempdata[65]={0};
  6878. json_object *FirmwareStatusNotification = json_object_new_object();
  6879. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6880. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6881. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6882. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6883. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6884. random_uuid(guid);
  6885. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6886. json_object_put(FirmwareStatusNotification);
  6887. LWS_Send(message);
  6888. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6889. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6890. {
  6891. result = PASS;
  6892. }
  6893. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6894. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6895. return result;
  6896. }
  6897. //==========================================
  6898. // send confirm routine
  6899. //==========================================
  6900. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6901. {
  6902. mtrace();
  6903. int result = FAIL;
  6904. char message[100]={0};
  6905. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6906. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6907. LWS_Send(message);
  6908. result = TRUE;
  6909. return result;
  6910. }
  6911. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6912. {
  6913. mtrace();
  6914. int result = FAIL;
  6915. char message[100]={0};
  6916. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6917. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6918. LWS_Send(message);
  6919. result = TRUE;
  6920. return result;
  6921. }
  6922. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6923. {
  6924. mtrace();
  6925. int result = FAIL;
  6926. char message[100]={0};
  6927. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6928. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6929. LWS_Send(message);
  6930. result = TRUE;
  6931. return result;
  6932. }
  6933. int sendClearCacheConfirmation(char *uuid,char *payload)
  6934. {
  6935. mtrace();
  6936. int result = FAIL;
  6937. char message[500]={0};
  6938. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6939. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6940. LWS_Send(message);
  6941. return result;
  6942. }
  6943. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6944. {
  6945. mtrace();
  6946. int result = FAIL;
  6947. char message[500]={0};
  6948. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6949. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6950. LWS_Send(message);
  6951. return result;
  6952. }
  6953. int sendDataTransferConfirmation(char *uuid,char *payload)
  6954. {
  6955. mtrace();
  6956. char statusStr[20]={0};
  6957. char dataStr[10]={0};
  6958. char sstr[20]={0};
  6959. int c = 0;
  6960. char *loc;
  6961. int result = FAIL;
  6962. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6963. /**********************status**************************/
  6964. loc = strstr(payload, "status");
  6965. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6966. c = 0;
  6967. while (loc[3+strlen("status")+c] != '\"')
  6968. {
  6969. sstr[c] = loc[3+strlen("status")+c];
  6970. c++;
  6971. }
  6972. sstr[c] = '\0';
  6973. strcpy(statusStr, sstr);
  6974. /**********************data**************************/
  6975. loc = strstr(payload, "data");
  6976. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6977. c = 0;
  6978. while (loc[3+strlen("data")+c] != '\"')
  6979. {
  6980. sstr[c] = loc[3+strlen("data")+c];
  6981. c++;
  6982. }
  6983. sstr[c] = '\0';
  6984. strcpy(dataStr, sstr);
  6985. return result;
  6986. }
  6987. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6988. {
  6989. mtrace();
  6990. int result = FAIL;
  6991. char message[1000]={0};
  6992. int CompositeScheduleIndex = 0;
  6993. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6994. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6995. if(nPeriod == 0)
  6996. {
  6997. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6998. {
  6999. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7000. ,MESSAGE_TYPE_CALLRESULT
  7001. ,uuid
  7002. ,payload
  7003. ,connectorIdInt);
  7004. }
  7005. else
  7006. {
  7007. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7008. ,MESSAGE_TYPE_CALLRESULT
  7009. ,uuid
  7010. ,payload
  7011. ,connectorIdInt
  7012. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7013. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7014. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7015. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7016. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7017. }
  7018. }
  7019. else
  7020. {
  7021. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7022. ,MESSAGE_TYPE_CALLRESULT
  7023. ,uuid
  7024. ,payload
  7025. ,connectorIdInt
  7026. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7027. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7028. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7029. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7030. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7031. {
  7032. if (idx_sample == 0)
  7033. {
  7034. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7035. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7036. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7037. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7038. }
  7039. else
  7040. {
  7041. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7042. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7043. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7044. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7045. }
  7046. }
  7047. sprintf(message + strlen(message), "]}}]");
  7048. }
  7049. LWS_Send(message);
  7050. result = TRUE;
  7051. return result;
  7052. }
  7053. int sendGetConfigurationConfirmation(char *uuid)
  7054. {
  7055. mtrace();
  7056. int result = FAIL;
  7057. int MaxKeySupported = 0;
  7058. int sentConfigurationNumber= 0;
  7059. int sentunConfigurationNumber= 0;
  7060. char message[1024*10]={0};
  7061. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7062. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7063. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7064. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7065. ,MESSAGE_TYPE_CALLRESULT
  7066. ,uuid );
  7067. //configuration key
  7068. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7069. {
  7070. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7071. {
  7072. if (sentConfigurationNumber == 0)
  7073. {
  7074. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7075. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7076. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7077. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7078. }
  7079. else
  7080. {
  7081. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7082. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7083. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7084. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7085. }
  7086. sentConfigurationNumber = sentConfigurationNumber + 1;
  7087. }
  7088. }
  7089. sprintf(message + strlen(message), "]");
  7090. if(UnknownKeynum != 0)
  7091. {
  7092. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7093. //unkown key
  7094. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7095. {
  7096. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7097. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7098. if(sentunConfigurationNumber == 0)
  7099. {
  7100. sprintf(message + strlen(message), "\"%s\""
  7101. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7102. }
  7103. else
  7104. {
  7105. sprintf(message + strlen(message), ",\"%s\""
  7106. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7107. }
  7108. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7109. }
  7110. sprintf(message + strlen(message), "]");
  7111. }
  7112. sprintf(message + strlen(message), "}]");
  7113. LWS_Send(message);
  7114. return result;
  7115. }
  7116. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7117. {
  7118. mtrace();
  7119. int result = FAIL;
  7120. char message[400]={0};
  7121. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7122. if(strcmp(payload,"")==0)
  7123. {
  7124. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7125. }
  7126. else
  7127. {
  7128. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7129. }
  7130. LWS_Send(message);
  7131. result = TRUE;
  7132. return result;
  7133. }
  7134. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7135. {
  7136. mtrace();
  7137. int result = FAIL;
  7138. char message[80]={0};
  7139. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7140. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7141. LWS_Send(message);
  7142. result = TRUE;
  7143. return result;
  7144. }
  7145. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7146. {
  7147. mtrace();
  7148. int result = FAIL;
  7149. char message[80]={0};
  7150. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7151. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7152. LWS_Send(message);
  7153. result = TRUE;
  7154. return result;
  7155. }
  7156. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7157. {
  7158. mtrace();
  7159. int result = FAIL;
  7160. char message[80]={0};
  7161. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7162. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7163. LWS_Send(message);
  7164. result = TRUE;
  7165. return result;
  7166. }
  7167. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7168. {
  7169. mtrace();
  7170. int result = FAIL;
  7171. char message[80]={0};
  7172. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7173. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7174. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7175. LWS_Send(message);
  7176. result = TRUE;
  7177. return result;
  7178. }
  7179. int sendResetConfirmation(char *uuid,char *payload)
  7180. {
  7181. mtrace();
  7182. int result = FAIL;
  7183. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7184. char message[80]={0};
  7185. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7186. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7187. LWS_Send(message);
  7188. result = TRUE;
  7189. return result;
  7190. }
  7191. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7192. {
  7193. mtrace();
  7194. int result = FAIL;
  7195. char message[500]={0};
  7196. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7197. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7198. LWS_Send(message);
  7199. result = TRUE;
  7200. return result;
  7201. }
  7202. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7203. {
  7204. mtrace();
  7205. int result = FAIL;
  7206. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7207. char message[80]={0};
  7208. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7209. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7210. LWS_Send(message);
  7211. result = TRUE;
  7212. return result;
  7213. }
  7214. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7215. {
  7216. mtrace();
  7217. int result = FAIL;
  7218. char message[80]={0};
  7219. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7220. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7221. LWS_Send(message);
  7222. result = TRUE;
  7223. return result;
  7224. }
  7225. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7226. {
  7227. mtrace();
  7228. int result = FAIL;
  7229. char message[80]={0};
  7230. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7231. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7232. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7233. LWS_Send(message);
  7234. result = TRUE;
  7235. return result;
  7236. }
  7237. int sendUpdateFirmwareConfirmation(char *uuid)
  7238. {
  7239. mtrace();
  7240. int result = FAIL;
  7241. char message[60]={0};
  7242. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7243. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7244. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7245. LWS_Send(message);
  7246. result = TRUE;
  7247. return result;
  7248. }
  7249. int sendCertificateSignedConfirmation(char *uuid)
  7250. {
  7251. mtrace();
  7252. int result = PASS;
  7253. char message[4096]={0};
  7254. json_object *CertificateSigned = json_object_new_object();
  7255. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7256. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7257. sprintf(message,"[%d,\"%s\",%s]"
  7258. ,MESSAGE_TYPE_CALLRESULT
  7259. ,uuid
  7260. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7261. json_object_put(CertificateSigned);
  7262. LWS_Send(message);
  7263. return result;
  7264. }
  7265. int sendDeleteCertificateConfirmation(char *uuid)
  7266. {
  7267. mtrace();
  7268. int result = PASS;
  7269. char message[4096]={0};
  7270. json_object *DeleteCertificate = json_object_new_object();
  7271. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7272. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7273. sprintf(message,"[%d,\"%s\",%s]"
  7274. ,MESSAGE_TYPE_CALLRESULT
  7275. ,uuid
  7276. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7277. json_object_put(DeleteCertificate);
  7278. LWS_Send(message);
  7279. return result;
  7280. }
  7281. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7282. {
  7283. mtrace();
  7284. int result = PASS;
  7285. char message[4096]={0};
  7286. json_object *ExtendedTriggerMessage = json_object_new_object();
  7287. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7288. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7289. sprintf(message,"[%d,\"%s\",%s]"
  7290. ,MESSAGE_TYPE_CALLRESULT
  7291. ,uuid
  7292. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7293. json_object_put(ExtendedTriggerMessage);
  7294. LWS_Send(message);
  7295. return result;
  7296. }
  7297. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7298. {
  7299. mtrace();
  7300. int result = PASS;
  7301. char message[4096]={0};
  7302. json_object *GetInstalledCertificateIds = json_object_new_object();
  7303. json_object *certificateHashDataDatas = json_object_new_array();
  7304. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7305. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7306. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7307. {
  7308. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7309. {
  7310. json_object *certificateHashData = json_object_new_object();
  7311. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7312. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7313. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7314. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7315. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7316. }
  7317. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7318. }
  7319. else
  7320. {
  7321. json_object_put(certificateHashDataDatas);
  7322. }
  7323. sprintf(message,"[%d,\"%s\",%s]"
  7324. ,MESSAGE_TYPE_CALLRESULT
  7325. ,uuid
  7326. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7327. json_object_put(GetInstalledCertificateIds);
  7328. LWS_Send(message);
  7329. return result;
  7330. }
  7331. int sendGetLogConfirmation(char *uuid)
  7332. {
  7333. mtrace();
  7334. int result = PASS;
  7335. char message[4096]={0};
  7336. json_object *GetLog = json_object_new_object();
  7337. DEBUG_INFO("sendGetLogConfirmation...\n");
  7338. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7339. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7340. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7341. sprintf(message,"[%d,\"%s\",%s]"
  7342. ,MESSAGE_TYPE_CALLRESULT
  7343. ,uuid
  7344. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7345. json_object_put(GetLog);
  7346. LWS_Send(message);
  7347. return result;
  7348. }
  7349. int sendInstallCertificateConfirmation(char *uuid)
  7350. {
  7351. mtrace();
  7352. int result = PASS;
  7353. char message[4096]={0};
  7354. json_object *InstallCertificate = json_object_new_object();
  7355. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7356. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7357. sprintf(message,"[%d,\"%s\",%s]"
  7358. ,MESSAGE_TYPE_CALLRESULT
  7359. ,uuid
  7360. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7361. json_object_put(InstallCertificate);
  7362. LWS_Send(message);
  7363. return result;
  7364. }
  7365. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7366. {
  7367. mtrace();
  7368. int result = PASS;
  7369. char message[4096]={0};
  7370. json_object *SignedUpdateFirmware = json_object_new_object();
  7371. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7372. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7373. sprintf(message,"[%d,\"%s\",%s]"
  7374. ,MESSAGE_TYPE_CALLRESULT
  7375. ,uuid
  7376. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7377. json_object_put(SignedUpdateFirmware);
  7378. LWS_Send(message);
  7379. return result;
  7380. }
  7381. int sendUnknownConfirmation(char *uuid)
  7382. {
  7383. mtrace();
  7384. int result = PASS;
  7385. char message[256]={0};
  7386. DEBUG_INFO("sendUnknownConfirmation...\n");
  7387. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7388. LWS_Send(message);
  7389. return result;
  7390. }
  7391. //==========================================
  7392. // Handle server request routine Start
  7393. //==========================================
  7394. int handleCancelReservationRequest(char *uuid, char *payload)
  7395. {
  7396. mtrace();
  7397. int result = FAIL;
  7398. int gunNO = 0;
  7399. int reservationIdInt = -1;
  7400. char comfirmstr[20];
  7401. DEBUG_INFO("handleCancelReservationRequest...\n");
  7402. json_object *CancelReservation;
  7403. CancelReservation = json_tokener_parse(payload);
  7404. if(!is_error(CancelReservation))
  7405. {
  7406. // Required data
  7407. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7408. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7409. }
  7410. json_object_put(CancelReservation);
  7411. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7412. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7413. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7414. if(reservationIdInt != -1)
  7415. {
  7416. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7417. //check Transaction active
  7418. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7420. {
  7421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7422. {
  7423. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7424. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7425. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7426. {
  7427. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7428. }
  7429. else
  7430. {
  7431. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7432. }
  7433. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7434. goto end;
  7435. }
  7436. }
  7437. for (int index = 0; index < CCS_QUANTITY; index++)
  7438. {
  7439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7440. {
  7441. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7442. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7443. if(gunType[2] == GUN_TYPE_CCS)
  7444. {
  7445. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7446. }
  7447. else
  7448. {
  7449. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7450. }
  7451. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7452. goto end;
  7453. }
  7454. }
  7455. for (int index = 0; index < GB_QUANTITY; index++)
  7456. {
  7457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7458. {
  7459. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7460. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7461. if(gunType[2] == GUN_TYPE_GBT)
  7462. {
  7463. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7464. }
  7465. else
  7466. {
  7467. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7468. }
  7469. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7470. goto end;
  7471. }
  7472. }
  7473. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7474. {
  7475. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7476. {
  7477. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7478. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7479. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7480. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7481. goto end;
  7482. }
  7483. }
  7484. for (int index = 0; index < AC_QUANTITY; index++)
  7485. {
  7486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7487. {
  7488. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7489. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7491. {
  7492. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7493. }
  7494. else
  7495. {
  7496. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7497. }
  7498. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7499. goto end;
  7500. }
  7501. }
  7502. }
  7503. //The reservationId does NOT match the reservationId
  7504. sendCancelReservationConfirmation(uuid, comfirmstr);
  7505. end:
  7506. // Fill in ocpp packet uuid
  7507. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7508. return result;
  7509. }
  7510. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7511. {
  7512. mtrace();
  7513. int result = FAIL;
  7514. int gunIndex = -1;
  7515. char typeStr[16]={0};
  7516. char comfirmstr[20];
  7517. int specificId = FALSE;
  7518. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7519. json_object *ChangeAvailability;
  7520. ChangeAvailability = json_tokener_parse(payload);
  7521. if(!is_error(ChangeAvailability))
  7522. {
  7523. // Required data
  7524. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7525. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7526. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7527. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7528. }
  7529. json_object_put(ChangeAvailability);
  7530. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7531. {
  7532. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7533. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7534. }
  7535. else if(gunIndex == 0)
  7536. {
  7537. for(int i=0; i < gunTotalNumber; i++)
  7538. {
  7539. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7540. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7541. }
  7542. }
  7543. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7545. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7546. {
  7547. specificId = TRUE;
  7548. }
  7549. if(specificId == FALSE)
  7550. goto end;
  7551. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7552. {
  7553. //----------------------gunIndex is 0 ------------------------------------------------//
  7554. if(gunIndex == 0)
  7555. {
  7556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7557. {
  7558. for(int i=0; i < gunTotalNumber; i++)
  7559. {
  7560. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7561. {
  7562. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7563. {
  7564. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7565. {
  7566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7567. goto end;
  7568. }
  7569. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7570. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7571. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7572. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7573. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7574. {
  7575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7576. goto end;
  7577. }
  7578. }
  7579. }//END FOR CHAdeMO_QUANTITY
  7580. for (int index = 0; index < CCS_QUANTITY; index++)
  7581. {
  7582. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7583. {
  7584. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7585. {
  7586. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7587. goto end;
  7588. }
  7589. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7590. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7591. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7592. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7593. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7594. {
  7595. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7596. goto end;
  7597. }
  7598. }
  7599. }//END FOR CCS_QUANTITY
  7600. for (int index = 0; index < GB_QUANTITY; index++)
  7601. {
  7602. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7603. {
  7604. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7605. {
  7606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7607. goto end;
  7608. }
  7609. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7610. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7611. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7612. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7613. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7614. {
  7615. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7616. goto end;
  7617. }
  7618. }
  7619. }// END FOR GB_QUANTITY
  7620. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7621. {
  7622. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7623. {
  7624. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7625. {
  7626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7627. goto end;
  7628. }
  7629. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7631. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7632. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7633. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7634. {
  7635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7636. goto end;
  7637. }
  7638. }
  7639. }// END FOR GENERAL_GUN_QUANTITY
  7640. for (int index = 0; index < AC_QUANTITY; index++)
  7641. {
  7642. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7643. {
  7644. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7645. {
  7646. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7647. goto end;
  7648. }
  7649. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7652. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7653. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7654. {
  7655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7656. goto end;
  7657. }
  7658. }
  7659. }//END FOR AC_QUANTITY
  7660. }// END FOR gunTotalNumber
  7661. }
  7662. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7663. {
  7664. for(int i=0; i < gunTotalNumber; i++)
  7665. {
  7666. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7667. {
  7668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7669. goto end;
  7670. }
  7671. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7673. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7674. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7676. {
  7677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7678. goto end;
  7679. }
  7680. }
  7681. }
  7682. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7683. goto end;
  7684. }
  7685. //----------------------gunIndex is not 0 ------------------------------------------------//
  7686. //check Transaction active
  7687. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7688. {
  7689. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7690. {
  7691. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7692. {
  7693. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7694. goto end;
  7695. }
  7696. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7697. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7698. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7699. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7700. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7701. {
  7702. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7703. goto end;
  7704. }
  7705. else
  7706. {
  7707. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7709. goto end;
  7710. }
  7711. }
  7712. }//END FOR CHAdeMO_QUANTITY
  7713. for (int index = 0; index < CCS_QUANTITY; index++)
  7714. {
  7715. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7716. {
  7717. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7718. {
  7719. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7720. goto end;
  7721. }
  7722. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7723. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7724. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7725. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7726. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7727. {
  7728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7729. goto end;
  7730. }
  7731. else
  7732. {
  7733. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7734. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7735. goto end;
  7736. }
  7737. }
  7738. }//END FOR CCS_QUANTITY
  7739. for (int index = 0; index < GB_QUANTITY; index++)
  7740. {
  7741. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7742. {
  7743. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7744. {
  7745. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7746. goto end;
  7747. }
  7748. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7749. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7750. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7751. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7752. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7753. {
  7754. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7755. goto end;
  7756. }
  7757. else
  7758. {
  7759. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7760. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7761. goto end;
  7762. }
  7763. }
  7764. }// END FOR GB_QUANTITY
  7765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7766. {
  7767. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7768. {
  7769. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7770. {
  7771. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7772. goto end;
  7773. }
  7774. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7775. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7776. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7777. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7779. {
  7780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7781. goto end;
  7782. }
  7783. else
  7784. {
  7785. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7786. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7787. goto end;
  7788. }
  7789. }
  7790. }// END FOR GENERAL_GUN_QUANTITY
  7791. for (int index = 0; index < AC_QUANTITY; index++)
  7792. {
  7793. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7794. {
  7795. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7796. {
  7797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7798. goto end;
  7799. }
  7800. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7801. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7802. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7803. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7804. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7805. {
  7806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7807. goto end;
  7808. }
  7809. else
  7810. {
  7811. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7812. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7813. goto end;
  7814. }
  7815. }
  7816. }//END FOR AC_QUANTITY
  7817. }//END FOR AvailabilityTypeStr[Inoperative]
  7818. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7819. {
  7820. //----------------------gunIndex is 0 ------------------------------------------------//
  7821. if(gunIndex == 0)
  7822. {
  7823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7824. {
  7825. for(int i=0; i < gunTotalNumber; i++)
  7826. {
  7827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7828. {
  7829. 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
  7830. {
  7831. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7832. goto end;
  7833. }
  7834. }//END FOR CHAdeMO_QUANTITY
  7835. for (int index = 0; index < CCS_QUANTITY; index++)
  7836. {
  7837. 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
  7838. {
  7839. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7840. goto end;
  7841. }
  7842. }//END FOR CCS_QUANTITY
  7843. for (int index = 0; index < GB_QUANTITY; index++)
  7844. {
  7845. 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
  7846. {
  7847. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7848. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7849. goto end;
  7850. }
  7851. }// END FOR GB_QUANTITY
  7852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7853. {
  7854. 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
  7855. {
  7856. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7857. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7858. goto end;
  7859. }
  7860. }// END FOR GENERAL_GUN_QUANTITY
  7861. for (int index = 0; index < AC_QUANTITY; index++)
  7862. {
  7863. 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
  7864. {
  7865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7866. goto end;
  7867. }
  7868. }//END FOR CHAdeMO_QUANTITY
  7869. }// END FOR gunTotalNumber
  7870. }
  7871. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7872. {
  7873. for(int i=0; i < gunTotalNumber; i++)
  7874. {
  7875. for (int index = 0; index < AC_QUANTITY; index++)
  7876. {
  7877. 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
  7878. {
  7879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7880. goto end;
  7881. }
  7882. }//END FOR CHAdeMO_QUANTITY
  7883. } // END FOR gunTotalNumber
  7884. }
  7885. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7886. goto end;
  7887. }
  7888. //----------------------gunIndex is not 0 ------------------------------------------------//
  7889. //check Transaction active
  7890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7891. {
  7892. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7893. {
  7894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7895. goto end;
  7896. }
  7897. }//END FOR CHAdeMO_QUANTITY
  7898. for (int index = 0; index < CCS_QUANTITY; index++)
  7899. {
  7900. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7901. {
  7902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7903. goto end;
  7904. }
  7905. }//END FOR CCS_QUANTITY
  7906. for (int index = 0; index < GB_QUANTITY; index++)
  7907. {
  7908. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7909. {
  7910. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7911. goto end;
  7912. }
  7913. }// END FOR GB_QUANTITY
  7914. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7915. {
  7916. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7917. {
  7918. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7919. goto end;
  7920. }
  7921. }// END FOR GENERAL_GUN_QUANTITY
  7922. for (int index = 0; index < AC_QUANTITY; index++)
  7923. {
  7924. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7925. {
  7926. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7927. goto end;
  7928. }
  7929. }//END FOR AC_QUANTITY
  7930. }//END FOR AvailabilityTypeStr[Operative]
  7931. end:
  7932. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7933. {
  7934. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7935. }
  7936. else
  7937. {
  7938. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7939. }
  7940. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7941. {
  7942. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7943. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7944. }
  7945. else if(gunIndex == 0)
  7946. {
  7947. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7948. {
  7949. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7950. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7951. }
  7952. }
  7953. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7954. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7955. return result;
  7956. }
  7957. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7958. {
  7959. mtrace();
  7960. int valueInvalid = NO;
  7961. int result = FAIL;
  7962. char keystr[40]={0};
  7963. char valuestr[501]={0}; //value should be limited in 500 bytes
  7964. char comfirmstr[20]={0};
  7965. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7966. json_object *ChangeConfiguration;
  7967. ChangeConfiguration = json_tokener_parse(payload);
  7968. if(!is_error(ChangeConfiguration))
  7969. {
  7970. // Required data
  7971. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7972. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7973. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  7974. {
  7975. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7976. }
  7977. else
  7978. {
  7979. valueInvalid = YES;
  7980. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  7981. }
  7982. }
  7983. json_object_put(ChangeConfiguration);
  7984. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  7985. {
  7986. DEBUG_ERROR("Payload is null or not accepted.\n");
  7987. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7988. }
  7989. else
  7990. {
  7991. int status = setKeyValue(keystr, valuestr);
  7992. switch(status)
  7993. {
  7994. case ConfigurationStatus_Accepted:
  7995. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7996. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7997. StoreConfigurationTable();
  7998. break;
  7999. case RebootRequired:
  8000. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8001. StoreConfigurationTable();
  8002. break;
  8003. case NotSupported:
  8004. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8005. break;
  8006. case ConfigurationStatus_Rejected:
  8007. default:
  8008. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8009. break;
  8010. }
  8011. }
  8012. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8013. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8014. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8015. {
  8016. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8017. SetOcppConnStatus(FALSE);
  8018. }
  8019. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8020. {
  8021. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8022. }
  8023. return result;
  8024. }
  8025. int handleClearCacheRequest(char *uuid, char *payload)
  8026. {
  8027. mtrace();
  8028. int result = FAIL;
  8029. char comfirmstr[20];
  8030. char rmFileCmd[100]={0};
  8031. struct stat stats;
  8032. DEBUG_INFO("handleClearCacheRequest...\n");
  8033. stat("/Storage/OCPP_PH", &stats);
  8034. // Check for directory existence
  8035. if (S_ISDIR(stats.st_mode) == 1)
  8036. {}
  8037. else
  8038. {
  8039. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8040. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8041. system(rmFileCmd);
  8042. }
  8043. if(OCPP_cleanLocalCache())
  8044. {
  8045. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8046. }
  8047. else
  8048. {
  8049. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8050. }
  8051. sendClearCacheConfirmation(uuid, comfirmstr);
  8052. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8053. return result;
  8054. }
  8055. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8056. {
  8057. mtrace();
  8058. int result = FAIL;
  8059. int resultRename;
  8060. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8061. char chargingProfilePurposeStr[26]={0};
  8062. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8063. char tempchargingProfilePurposeStr[26]={0};
  8064. char str[100]={0};
  8065. char fname[200]={0};
  8066. char comfirmstr[20]={0};
  8067. char word[1600]={0};
  8068. int clearflag = FALSE;
  8069. int chargingProfileIdIsNULL = FALSE;
  8070. int connectorIsNULL = FALSE;
  8071. int chargingProfilePurposeIsNULL = FALSE;
  8072. int stackLevelIsNULL = FALSE;
  8073. //int GotoEnd = FALSE;
  8074. FILE *fptr1, *fptr2;
  8075. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8076. int n_chargingProfile=0;
  8077. int isEmptyFile = FALSE;
  8078. char sLineWord[1600]={0};
  8079. char chargingProfiles[10][100]={0};
  8080. int ChargeProfileCount = 0;
  8081. int ch;
  8082. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8083. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8084. json_object *ClearChargingProfile;
  8085. ClearChargingProfile = json_tokener_parse(payload);
  8086. if(!is_error(ClearChargingProfile))
  8087. {
  8088. // Optional data
  8089. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8090. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8091. else
  8092. chargingProfileIdIsNULL = TRUE;
  8093. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8094. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8095. else
  8096. connectorIsNULL = TRUE;
  8097. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8098. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8099. else
  8100. chargingProfilePurposeIsNULL = TRUE;
  8101. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8102. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8103. else
  8104. stackLevelIsNULL = TRUE;
  8105. }
  8106. json_object_put(ClearChargingProfile);
  8107. if(connectorIsNULL == FALSE)
  8108. {
  8109. switch(connectorIdInt)
  8110. {
  8111. case 0:
  8112. if(chargingProfilePurposeIsNULL == TRUE)
  8113. {
  8114. int l = 0;
  8115. strcpy(fname, ChargePointMaxProfile_JSON);
  8116. if((access(fname,F_OK))!=-1)
  8117. {
  8118. strcpy(chargingProfiles[l], fname);
  8119. l = l + 1;
  8120. }
  8121. strcpy(fname, TxDefaultProfile_0_JSON);
  8122. if((access(fname,F_OK))!=-1)
  8123. {
  8124. strcpy(chargingProfiles[l], fname);
  8125. l = l + 1;
  8126. }
  8127. ChargeProfileCount = l;
  8128. }
  8129. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8130. {
  8131. strcpy(fname, ChargePointMaxProfile_JSON);
  8132. if((access(fname,F_OK))!=-1)
  8133. {
  8134. strcpy(chargingProfiles[0], fname);
  8135. ChargeProfileCount = 1;
  8136. }
  8137. }
  8138. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8139. {
  8140. strcpy(fname, TxDefaultProfile_0_JSON);
  8141. if((access(fname,F_OK))!=-1)
  8142. {
  8143. strcpy(chargingProfiles[0], fname);
  8144. ChargeProfileCount = 1;
  8145. }
  8146. }
  8147. break;
  8148. default:
  8149. if(chargingProfilePurposeIsNULL == TRUE)
  8150. {
  8151. int m = 0;
  8152. memset(fname, 0, ARRAY_SIZE(fname));
  8153. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8154. if((access(fname,F_OK))!=-1)
  8155. {
  8156. strcpy(chargingProfiles[m], fname);
  8157. m = m + 1;
  8158. }
  8159. memset(fname, 0, ARRAY_SIZE(fname));
  8160. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8161. if((access(fname,F_OK))!=-1)
  8162. {
  8163. strcpy(chargingProfiles[m], fname);
  8164. m = m + 1;
  8165. }
  8166. ChargeProfileCount = m;
  8167. }
  8168. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8169. {
  8170. //strcpy(fname, TxDefaultProfile_1_JSON);
  8171. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8172. if((access(fname,F_OK))!=-1)
  8173. {
  8174. strcpy(chargingProfiles[0], fname);
  8175. ChargeProfileCount = 1;
  8176. }
  8177. }
  8178. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8179. {
  8180. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8181. if((access(fname,F_OK))!=-1)
  8182. {
  8183. strcpy(chargingProfiles[0], fname);
  8184. ChargeProfileCount = 1;
  8185. }
  8186. //strcpy(fname, TxProfile_1_JSON);
  8187. }
  8188. //strcpy(fname, ChargePointMaxProfile_JSON );
  8189. break;
  8190. }
  8191. }
  8192. else // Check all Charging Profiles
  8193. {
  8194. int i = 0;
  8195. char fnametemp[200]={0};
  8196. ChargeProfileCount = 0;
  8197. //Check ChargePointMaxProfile.json exit
  8198. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8199. {
  8200. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8201. i = i + 1;
  8202. }
  8203. //Check TxDefaultProfile_0.json exit
  8204. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8205. {
  8206. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8207. i = i + 1;
  8208. }
  8209. //Check TxDefaultProfile_%d.json
  8210. for(int j=1; j <= gunTotalNumber; j++)
  8211. {
  8212. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8213. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8214. if((access(fnametemp,F_OK))!=-1)
  8215. {
  8216. strcpy(chargingProfiles[i], fnametemp);
  8217. i = i + 1;
  8218. }
  8219. }
  8220. //Check TxProfile_%d.json
  8221. for(int j=1; j <= gunTotalNumber; j++)
  8222. {
  8223. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8224. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8225. if((access(fnametemp,F_OK))!=-1)
  8226. {
  8227. strcpy(chargingProfiles[i], fnametemp);
  8228. i = i + 1;
  8229. }
  8230. }
  8231. ChargeProfileCount = i;
  8232. }// End connectorIsNULL is TRUE
  8233. if(ChargeProfileCount == 0)
  8234. {
  8235. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8236. goto end;
  8237. }
  8238. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8239. {
  8240. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8241. goto end;
  8242. }
  8243. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8244. {
  8245. memset(str, 0, ARRAY_SIZE(str));
  8246. // clear temp file
  8247. sprintf(str,"rm -f %s",temp);
  8248. system(str);
  8249. for(int k=0; k < ChargeProfileCount; k++)
  8250. {
  8251. memset(str, 0, ARRAY_SIZE(str));
  8252. //clear file in C
  8253. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8254. system(str);
  8255. }
  8256. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8257. goto end;
  8258. }
  8259. else if(connectorIsNULL == TRUE)
  8260. {
  8261. for(int k=0; k < ChargeProfileCount; k++)
  8262. {
  8263. fptr1 = fopen(chargingProfiles[k], "r");
  8264. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8265. //Check Charging Profile Count
  8266. while(fscanf(fptr1, "%s", word) != EOF)
  8267. {
  8268. //DEBUG_INFO("word=%s\n",word);
  8269. if(strstr(word, "chargingProfileId")!= NULL)
  8270. {
  8271. //DEBUG_INFO("test chargingProfileId \n");
  8272. n_chargingProfile = n_chargingProfile + 1;
  8273. //DEBUG_INFO("chargingProfileId Found\n");
  8274. }
  8275. }
  8276. rewind(fptr1);
  8277. //search Charging Profile Element
  8278. //int i= 0;
  8279. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8280. {
  8281. json_object *tmpProfilee;
  8282. tmpProfilee = json_tokener_parse(sLineWord);
  8283. if(!is_error(tmpProfilee))
  8284. {
  8285. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8286. {
  8287. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8288. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8289. }
  8290. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8291. {
  8292. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8293. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8294. }
  8295. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8296. {
  8297. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8298. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8299. }
  8300. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8301. {
  8302. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8303. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8304. }
  8305. }
  8306. json_object_put(tmpProfilee);
  8307. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8308. {
  8309. //------- not write to fptr2-------//
  8310. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8311. //clearflag = TRUE;
  8312. }
  8313. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8314. {
  8315. //------- not write to fptr2-------//
  8316. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8317. }
  8318. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8319. {
  8320. //------- not write to fptr2-------//
  8321. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8322. }
  8323. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8324. {
  8325. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8326. }
  8327. else
  8328. {
  8329. fprintf(fptr2, sLineWord);//writing data into file
  8330. }
  8331. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8332. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8333. if(clearflag == TRUE)
  8334. {
  8335. fclose(fptr1);
  8336. fclose(fptr2);
  8337. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8338. system(str);
  8339. // clear temp file
  8340. sprintf(str,"rm -f %s",temp);
  8341. system(str);
  8342. }
  8343. else
  8344. {
  8345. fclose(fptr1);
  8346. fclose(fptr2);
  8347. memset(str, 0, ARRAY_SIZE(str));
  8348. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8349. system(str);
  8350. resultRename = rename(temp, chargingProfiles[k]);
  8351. if(resultRename == 0)
  8352. {
  8353. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8354. }
  8355. else
  8356. {
  8357. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8358. }
  8359. if(comfirmstr[0]== 0)
  8360. {
  8361. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8362. }
  8363. //Check chargingProfile is empty file
  8364. /*------ Read the file ----------------*/
  8365. fptr1=fopen(chargingProfiles[k],"r");
  8366. ch=fgetc(fptr1);
  8367. rewind(fptr1);
  8368. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8369. if(ch!=EOF)
  8370. {
  8371. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8372. {
  8373. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8374. if(sLineWord[0]=='\0')
  8375. {
  8376. isEmptyFile = TRUE;
  8377. break;
  8378. }
  8379. else
  8380. {
  8381. isEmptyFile = FALSE;
  8382. break;
  8383. }
  8384. }
  8385. }
  8386. else
  8387. isEmptyFile = TRUE;
  8388. fclose(fptr1);
  8389. if(isEmptyFile == TRUE)
  8390. {
  8391. memset(str, 0, ARRAY_SIZE(str));
  8392. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8393. system(str);
  8394. }
  8395. }
  8396. }// End of while(int k=0; k < ChargePointCount; k++)
  8397. }
  8398. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8399. {
  8400. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8401. for(int k=0; k < ChargeProfileCount; k++)
  8402. {
  8403. fptr1 = fopen(chargingProfiles[k], "r");
  8404. fptr2 = fopen(temp, "w+");
  8405. //Check Charging Profile Count
  8406. while(fscanf(fptr1, "%s", word) != EOF)
  8407. {
  8408. //DEBUG_INFO("word=%s\n",word);
  8409. if(strstr(word, "chargingProfileId")!= NULL)
  8410. {
  8411. n_chargingProfile = n_chargingProfile + 1;
  8412. }
  8413. }
  8414. rewind(fptr1);
  8415. //search Charging Profile Element
  8416. //int i= 0;
  8417. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8418. {
  8419. json_object *tmpProfilee;
  8420. tmpProfilee = json_tokener_parse(sLineWord);
  8421. if(!is_error(tmpProfilee))
  8422. {
  8423. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8424. {
  8425. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8426. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8427. }
  8428. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8429. {
  8430. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8431. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8432. }
  8433. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8434. {
  8435. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8436. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8437. }
  8438. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8439. {
  8440. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8441. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8442. }
  8443. }
  8444. json_object_put(tmpProfilee);
  8445. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8446. {
  8447. //------- not write to fptr2-------//
  8448. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8449. //clearflag = TRUE;
  8450. }
  8451. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8452. {
  8453. //------- not write to fptr2-------//
  8454. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8455. }
  8456. else if(stackLevelIsNULL == TRUE)
  8457. {
  8458. //Clear Whole File
  8459. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8460. clearflag = TRUE;
  8461. break;
  8462. }
  8463. else
  8464. {
  8465. fprintf(fptr2, sLineWord);//writing data into file
  8466. }
  8467. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8468. }
  8469. if(clearflag == TRUE)
  8470. {
  8471. fclose(fptr1);
  8472. fclose(fptr2);
  8473. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8474. system(str);
  8475. // clear temp file
  8476. sprintf(str,"rm -f %s",temp);
  8477. system(str);
  8478. }
  8479. else
  8480. {
  8481. fclose(fptr1);
  8482. fclose(fptr2);
  8483. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8484. system(str);
  8485. resultRename = rename(temp, chargingProfiles[k]);
  8486. if(resultRename == 0)
  8487. {
  8488. DEBUG_INFO("File ChargingProfile renamed successfully");
  8489. }
  8490. else
  8491. {
  8492. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8493. }
  8494. if(comfirmstr[0]== 0)
  8495. {
  8496. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8497. }
  8498. //Check chargingProfile is empty file
  8499. /*------ Read the file ----------------*/
  8500. fptr1=fopen(chargingProfiles[k],"r");
  8501. ch=fgetc(fptr1);
  8502. rewind(fptr1);
  8503. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8504. if(ch!=EOF)
  8505. {
  8506. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8507. {
  8508. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8509. if(sLineWord[0]=='\0')
  8510. {
  8511. isEmptyFile = TRUE;
  8512. break;
  8513. }
  8514. else
  8515. {
  8516. isEmptyFile = FALSE;
  8517. break;
  8518. }
  8519. }
  8520. }
  8521. else
  8522. isEmptyFile = TRUE;
  8523. fclose(fptr1);
  8524. if(isEmptyFile == TRUE)
  8525. {
  8526. memset(str, 0, ARRAY_SIZE(str));
  8527. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8528. system(str);
  8529. }
  8530. /*------- End of reading ---------------*/
  8531. }
  8532. } // while(int k=0; k < ChargeProfileCount; k++)
  8533. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8534. end:
  8535. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8536. {
  8537. if(connectorIdInt == 0)
  8538. {
  8539. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8540. {
  8541. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8542. }
  8543. }
  8544. else
  8545. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8546. }
  8547. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8548. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8549. return result;
  8550. }
  8551. void createFirmwareVersionByDataTransfer(void)
  8552. {
  8553. json_object *FirmwareDataTransfer = json_object_new_object();
  8554. // AC & DC model
  8555. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8556. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8557. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8558. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8559. // DC model
  8560. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8561. {
  8562. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8563. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8564. (gunType[3] != GUN_TYPE_UNKNOWN))
  8565. {
  8566. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8567. }
  8568. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8569. {
  8570. // DS DM DW
  8571. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8572. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8573. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8574. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8575. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8576. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8577. }
  8578. else
  8579. {
  8580. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8581. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8582. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8583. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8584. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8585. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8586. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8587. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8588. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8589. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8590. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8591. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8592. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8593. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8594. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8595. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8596. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8597. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8598. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8599. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8600. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8601. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8602. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8603. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8604. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8605. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8606. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8607. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8608. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8609. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8610. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8611. }
  8612. }
  8613. // 4G model
  8614. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8615. {
  8616. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8617. }
  8618. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8619. json_object_put(FirmwareDataTransfer);
  8620. }
  8621. int handleDataTransferRequest(char *uuid, char *payload)
  8622. {
  8623. mtrace();
  8624. json_object *response = json_object_new_object();
  8625. int result = FAIL;
  8626. char tempvendorId[255]={0};
  8627. char tempmessageId[50]={0};
  8628. char tempdata[512]={0};
  8629. char message[2048]={0};
  8630. DEBUG_INFO("handleDataTransferRequest...\n");
  8631. if((uuid != NULL) && (payload != NULL))
  8632. {
  8633. json_object *DataTransfer;
  8634. DataTransfer = json_tokener_parse(payload);
  8635. if(!is_error(DataTransfer))
  8636. {
  8637. // Required data
  8638. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8639. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8640. // Optional data
  8641. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8642. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8643. if(json_object_object_get(DataTransfer, "data") != NULL)
  8644. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8645. result = PASS;
  8646. }
  8647. json_object_put(DataTransfer);
  8648. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8649. {
  8650. // Send all moudle firmware version on EVSE
  8651. createFirmwareVersionByDataTransfer();
  8652. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8653. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8654. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8655. json_object_put(response);
  8656. }
  8657. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8658. {
  8659. system("/usr/bin/run_tmate_restart.sh &");
  8660. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8661. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8662. json_object_put(response);
  8663. }
  8664. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8665. {
  8666. json_object *data;
  8667. data = json_tokener_parse(tempdata);
  8668. if(!is_error(data))
  8669. {
  8670. 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))
  8671. {
  8672. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8673. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8674. if(json_object_object_get(data, "SOC") != NULL)
  8675. {
  8676. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8677. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8678. }
  8679. if(json_object_object_get(data, "Energy") != NULL)
  8680. {
  8681. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8682. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8683. }
  8684. if(json_object_object_get(data, "Duration") != NULL)
  8685. {
  8686. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8687. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8688. }
  8689. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8690. }
  8691. else
  8692. {
  8693. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8694. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8695. }
  8696. }
  8697. else
  8698. {
  8699. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8700. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8701. }
  8702. json_object_put(data);
  8703. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8704. json_object_put(response);
  8705. }
  8706. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8707. {
  8708. json_object *data;
  8709. data = json_tokener_parse(tempdata);
  8710. if(!is_error(data))
  8711. {
  8712. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8713. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8714. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8715. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8716. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8717. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8718. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8719. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8720. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8721. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8722. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8723. }
  8724. else
  8725. {
  8726. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8727. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8728. }
  8729. json_object_put(data);
  8730. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8731. json_object_put(response);
  8732. }
  8733. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8734. {
  8735. json_object *data;
  8736. data = json_tokener_parse(tempdata);
  8737. if(!is_error(data))
  8738. {
  8739. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8740. if(json_object_object_get(data, "idToken") != NULL)
  8741. {
  8742. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8743. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8744. }
  8745. if(json_object_object_get(data, "price") != NULL)
  8746. {
  8747. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8748. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8749. }
  8750. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8751. }
  8752. else
  8753. {
  8754. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8755. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8756. }
  8757. json_object_put(data);
  8758. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8759. json_object_put(response);
  8760. }
  8761. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8762. {
  8763. json_object *data;
  8764. data = json_tokener_parse(tempdata);
  8765. if(!is_error(data))
  8766. {
  8767. if(json_object_object_get(data, "txId") != NULL)
  8768. {
  8769. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8770. for(int idx = 0;idx<gunTotalNumber;idx++)
  8771. {
  8772. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8773. {
  8774. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8775. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8776. if(json_object_object_get(data, "description") != NULL)
  8777. {
  8778. // California pricing V1.0
  8779. DEBUG_INFO("California pricing V1.0\n");
  8780. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8781. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8782. }
  8783. else
  8784. {
  8785. // California pricing V1.1
  8786. DEBUG_INFO("California pricing V1.1\n");
  8787. if(json_object_object_get(data, "timestamp") != NULL)
  8788. {
  8789. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8790. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8791. }
  8792. if(json_object_object_get(data, "meterValue") != NULL)
  8793. {
  8794. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8795. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8796. }
  8797. if(json_object_object_get(data, "cost") != NULL)
  8798. {
  8799. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8800. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8801. }
  8802. if(json_object_object_get(data, "state") != NULL)
  8803. {
  8804. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8805. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8806. }
  8807. if(json_object_object_get(data, "chargingPrice") != NULL)
  8808. {
  8809. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8810. {
  8811. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8812. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8813. }
  8814. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8815. {
  8816. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8817. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8818. }
  8819. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8820. {
  8821. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8822. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8823. }
  8824. }
  8825. if(json_object_object_get(data, "idlePrice") != NULL)
  8826. {
  8827. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8828. {
  8829. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8830. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8831. }
  8832. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8833. {
  8834. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8835. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8836. }
  8837. }
  8838. if(json_object_object_get(data, "nextPeriod") != NULL)
  8839. {
  8840. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8841. {
  8842. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8843. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8844. }
  8845. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8846. {
  8847. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8848. {
  8849. 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")));
  8850. 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"));
  8851. }
  8852. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8853. {
  8854. 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")));
  8855. 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"));
  8856. }
  8857. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8858. {
  8859. 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")));
  8860. 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"));
  8861. }
  8862. }
  8863. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8864. {
  8865. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8866. {
  8867. 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")));
  8868. 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"));
  8869. }
  8870. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8871. {
  8872. 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")));
  8873. 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"));
  8874. }
  8875. }
  8876. }
  8877. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8878. {
  8879. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8880. {
  8881. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8882. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8883. }
  8884. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8885. {
  8886. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8887. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8888. }
  8889. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8890. {
  8891. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8892. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8893. }
  8894. }
  8895. }
  8896. }
  8897. }
  8898. }
  8899. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8900. }
  8901. else
  8902. {
  8903. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8904. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8905. }
  8906. json_object_put(data);
  8907. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8908. json_object_put(response);
  8909. }
  8910. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8911. {
  8912. json_object *data;
  8913. data = json_tokener_parse(tempdata);
  8914. if(!is_error(data))
  8915. {
  8916. if(json_object_object_get(data, "txId") != NULL)
  8917. {
  8918. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8919. for(int idx = 0;idx<gunTotalNumber;idx++)
  8920. {
  8921. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8922. {
  8923. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8924. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8925. if(json_object_object_get(data, "description") != NULL)
  8926. {
  8927. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8928. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8929. }
  8930. }
  8931. }
  8932. }
  8933. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8934. }
  8935. else
  8936. {
  8937. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8938. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8939. }
  8940. json_object_put(data);
  8941. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8942. json_object_put(response);
  8943. }
  8944. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8945. {
  8946. json_object *data;
  8947. data = json_tokener_parse(tempdata);
  8948. if(!is_error(data))
  8949. {
  8950. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8951. if(json_object_object_get(data, "Content_Type") != NULL)
  8952. {
  8953. 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))
  8954. {
  8955. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8956. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8957. {
  8958. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8959. }
  8960. }
  8961. else
  8962. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8963. }
  8964. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8965. }
  8966. else
  8967. {
  8968. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8969. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8970. }
  8971. json_object_put(data);
  8972. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8973. json_object_put(response);
  8974. }
  8975. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8976. {
  8977. json_object *data;
  8978. data = json_tokener_parse(tempdata);
  8979. if(!is_error(data))
  8980. {
  8981. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8982. if(json_object_object_get(data, "Page_Index") != NULL)
  8983. {
  8984. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8985. }
  8986. if(json_object_object_get(data, "Duration") != NULL)
  8987. {
  8988. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8989. }
  8990. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8991. }
  8992. else
  8993. {
  8994. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8995. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8996. }
  8997. json_object_put(data);
  8998. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8999. json_object_put(response);
  9000. }
  9001. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9002. {
  9003. json_object *data;
  9004. data = json_tokener_parse(tempdata);
  9005. if(!is_error(data))
  9006. {
  9007. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9008. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9009. {
  9010. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9011. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9012. else
  9013. {
  9014. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9015. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9016. }
  9017. }
  9018. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9019. {
  9020. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9021. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9022. else
  9023. {
  9024. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9025. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9026. }
  9027. }
  9028. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9029. {
  9030. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9031. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9032. else
  9033. {
  9034. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9035. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9036. }
  9037. }
  9038. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9039. {
  9040. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9041. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9042. else
  9043. {
  9044. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9045. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9046. }
  9047. }
  9048. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9049. {
  9050. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9051. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9052. else
  9053. {
  9054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9055. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9056. }
  9057. }
  9058. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9059. {
  9060. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9061. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9062. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9063. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9064. else
  9065. {
  9066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9067. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9068. }
  9069. }
  9070. if(json_object_object_get(data, "isAuthentication") != NULL)
  9071. {
  9072. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9073. {
  9074. case 0:
  9075. case 1:
  9076. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9077. break;
  9078. default:
  9079. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9080. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9081. break;
  9082. }
  9083. }
  9084. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9085. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9086. }
  9087. else
  9088. {
  9089. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9090. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9091. }
  9092. json_object_put(data);
  9093. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9094. json_object_put(response);
  9095. }
  9096. else if(strstr(tempmessageId, "refund_status") != NULL)
  9097. {
  9098. json_object *data;
  9099. data = json_tokener_parse(tempdata);
  9100. if(!is_error(data))
  9101. {
  9102. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9103. if(json_object_object_get(data, "status") != NULL)
  9104. {
  9105. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9106. 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"))
  9107. {
  9108. sprintf((char*)ShmOCPP16DataPH->YesCustomData.RefundStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9109. }
  9110. else
  9111. {
  9112. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9113. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9114. }
  9115. }
  9116. else
  9117. {
  9118. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9119. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9120. }
  9121. if(json_object_object_get(data, "chargeDate") != NULL)
  9122. {
  9123. sprintf((char *)ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeDate, "%s", json_object_get_string(json_object_object_get(data,"chargeDate")));
  9124. }
  9125. else
  9126. {
  9127. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9128. json_object_object_add(response, "data", json_object_new_string("chargeDate data can not get."));
  9129. }
  9130. if(json_object_object_get(data, "holdAmt") != NULL)
  9131. {
  9132. if(json_object_get_int(json_object_object_get(data, "holdAmt")) >= 0)
  9133. ShmOCPP16DataPH->YesCustomData.RefundStatus.holdAmt = json_object_get_int(json_object_object_get(data, "holdAmt"));
  9134. else
  9135. {
  9136. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9137. json_object_object_add(response, "data", json_object_new_string("holdAmt data is invalid."));
  9138. }
  9139. }
  9140. else
  9141. {
  9142. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9143. json_object_object_add(response, "data", json_object_new_string("holdAmt data can not get."));
  9144. }
  9145. if(json_object_object_get(data, "chargeAmt") != NULL)
  9146. {
  9147. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9148. ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9149. else
  9150. {
  9151. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9152. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9153. }
  9154. }
  9155. else
  9156. {
  9157. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9158. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9159. }
  9160. if(json_object_object_get(data, "refundAmt") != NULL)
  9161. {
  9162. if(json_object_get_int(json_object_object_get(data, "refundAmt")) >= 0)
  9163. ShmOCPP16DataPH->YesCustomData.RefundStatus.refundAmt = json_object_get_int(json_object_object_get(data, "refundAmt"));
  9164. else
  9165. {
  9166. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9167. json_object_object_add(response, "data", json_object_new_string("refundAmt data is invalid."));
  9168. }
  9169. }
  9170. else
  9171. {
  9172. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9173. json_object_object_add(response, "data", json_object_new_string("refundAmt data can not get."));
  9174. }
  9175. if(json_object_object_get(data, "page") != NULL)
  9176. {
  9177. if(json_object_get_int(json_object_object_get(data, "page")) >= 0 && json_object_get_int(json_object_object_get(data, "page")) <= 3)
  9178. ShmOCPP16DataPH->YesCustomData.RefundStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9179. else
  9180. {
  9181. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9182. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9183. }
  9184. }
  9185. else
  9186. {
  9187. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9188. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9189. }
  9190. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9191. {
  9192. ShmOCPP16DataPH->YesCustomData.RefundStatusReq = 1;
  9193. DEBUG_INFO("<<< RefundStatus:{status:%s, chargeDate:%s, holdAmt:%d, chargeAmt:%d, refundAmt:%d, page:%d}\n",
  9194. ShmOCPP16DataPH->YesCustomData.RefundStatus.status,
  9195. ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeDate,
  9196. ShmOCPP16DataPH->YesCustomData.RefundStatus.holdAmt,
  9197. ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeAmt,
  9198. ShmOCPP16DataPH->YesCustomData.RefundStatus.refundAmt,
  9199. ShmOCPP16DataPH->YesCustomData.RefundStatus.page);
  9200. }
  9201. }
  9202. else
  9203. {
  9204. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9205. json_object_object_add(response, "data", json_object_new_string("refund_status content got something wrong."));
  9206. }
  9207. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9208. json_object_put(response);
  9209. }
  9210. else if(strstr(tempmessageId, "deduct_status") != NULL)
  9211. {
  9212. json_object *data;
  9213. data = json_tokener_parse(tempdata);
  9214. if(!is_error(data))
  9215. {
  9216. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9217. if(json_object_object_get(data, "status") != NULL)
  9218. {
  9219. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9220. 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))
  9221. {
  9222. sprintf((char*)ShmOCPP16DataPH->YesCustomData.DeductStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9223. }
  9224. else
  9225. {
  9226. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9227. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9228. }
  9229. }
  9230. else
  9231. {
  9232. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9233. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9234. }
  9235. if(json_object_object_get(data, "autoLoadAmt") != NULL)
  9236. {
  9237. if(json_object_get_int(json_object_object_get(data, "autoLoadAmt")) >= 0)
  9238. ShmOCPP16DataPH->YesCustomData.DeductStatus.autoLoadAmt = json_object_get_int(json_object_object_get(data, "autoLoadAmt"));
  9239. else
  9240. {
  9241. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9242. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt is invalid."));
  9243. }
  9244. }
  9245. else
  9246. {
  9247. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9248. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt data can not get."));
  9249. }
  9250. if(json_object_object_get(data, "beforeAmt") != NULL)
  9251. {
  9252. if(json_object_get_int(json_object_object_get(data, "beforeAmt")) >= 0)
  9253. ShmOCPP16DataPH->YesCustomData.DeductStatus.beforeAmt = json_object_get_int(json_object_object_get(data, "beforeAmt"));
  9254. else
  9255. {
  9256. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9257. json_object_object_add(response, "data", json_object_new_string("beforeAmt data is invalid."));
  9258. }
  9259. }
  9260. else
  9261. {
  9262. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9263. json_object_object_add(response, "data", json_object_new_string("beforeAmt data can not get."));
  9264. }
  9265. if(json_object_object_get(data, "chargeAmt") != NULL)
  9266. {
  9267. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9268. ShmOCPP16DataPH->YesCustomData.DeductStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9269. else
  9270. {
  9271. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9272. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9273. }
  9274. }
  9275. else
  9276. {
  9277. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9278. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9279. }
  9280. if(json_object_object_get(data, "afterAmt") != NULL)
  9281. {
  9282. if(json_object_get_int(json_object_object_get(data, "afterAmt")) >= 0)
  9283. ShmOCPP16DataPH->YesCustomData.DeductStatus.afterAmt = json_object_get_int(json_object_object_get(data, "afterAmt"));
  9284. else
  9285. {
  9286. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9287. json_object_object_add(response, "data", json_object_new_string("afterAmt data is invalid."));
  9288. }
  9289. }
  9290. else
  9291. {
  9292. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9293. json_object_object_add(response, "data", json_object_new_string("afterAmt data can not get."));
  9294. }
  9295. if(json_object_object_get(data, "page") != NULL)
  9296. {
  9297. if(json_object_get_int(json_object_object_get(data, "page")) >= 0)
  9298. ShmOCPP16DataPH->YesCustomData.DeductStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9299. else
  9300. {
  9301. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9302. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9303. }
  9304. }
  9305. else
  9306. {
  9307. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9308. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9309. }
  9310. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9311. {
  9312. ShmOCPP16DataPH->YesCustomData.DeductStatusReq = 1;
  9313. DEBUG_INFO("<<< deduct_status:{status:%s, autoLoadAmt:%d, beforeAmt:%d, chargeAmt:%d, afterAmt:%d, page:%d}\n",
  9314. ShmOCPP16DataPH->YesCustomData.DeductStatus.status,
  9315. ShmOCPP16DataPH->YesCustomData.DeductStatus.autoLoadAmt,
  9316. ShmOCPP16DataPH->YesCustomData.DeductStatus.beforeAmt,
  9317. ShmOCPP16DataPH->YesCustomData.DeductStatus.chargeAmt,
  9318. ShmOCPP16DataPH->YesCustomData.DeductStatus.afterAmt,
  9319. ShmOCPP16DataPH->YesCustomData.DeductStatus.page);
  9320. }
  9321. }
  9322. else
  9323. {
  9324. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9325. json_object_object_add(response, "data", json_object_new_string("deduct_status content got something wrong."));
  9326. }
  9327. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9328. json_object_put(response);
  9329. }
  9330. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9331. {
  9332. json_object *data;
  9333. data = json_tokener_parse(tempdata);
  9334. if(!is_error(data))
  9335. {
  9336. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9337. if(json_object_object_get(data, "stationName") != NULL)
  9338. {
  9339. sprintf((char *)ShmOCPP16DataPH->YesCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9340. }
  9341. else
  9342. {
  9343. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9344. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9345. }
  9346. /*if(json_object_object_get(data, "station_id") != NULL)
  9347. {
  9348. sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_id, "%s", json_object_get_string(json_object_object_get(data,"station_id")));
  9349. }
  9350. else
  9351. {
  9352. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9353. json_object_object_add(response, "data", json_object_new_string("station_id data can not get."));
  9354. }
  9355. if(json_object_object_get(data, "charge_id") != NULL)
  9356. {
  9357. for(int idx=0;idx<json_object_array_length(json_object_object_get(data, "charge_id"));idx++)
  9358. {
  9359. 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)));
  9360. }
  9361. }
  9362. else
  9363. {
  9364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9365. json_object_object_add(response, "data", json_object_new_string("charge_id data can not get."));
  9366. }*/
  9367. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9368. {
  9369. ShmOCPP16DataPH->YesCustomData.ChargerInfoReq = 1;
  9370. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9371. ShmOCPP16DataPH->YesCustomData.ChargerInfo.station_name);
  9372. }
  9373. }
  9374. else
  9375. {
  9376. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9377. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9378. }
  9379. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9380. json_object_put(response);
  9381. }
  9382. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9383. {
  9384. json_object *data;
  9385. data = json_tokener_parse(tempdata);
  9386. if(!is_error(data))
  9387. {
  9388. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9389. if(json_object_object_get(data, "weatherId") != NULL)
  9390. {
  9391. ShmOCPP16DataPH->YesCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9392. }
  9393. else
  9394. {
  9395. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9396. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9397. }
  9398. if(json_object_object_get(data, "Temperature") != NULL)
  9399. {
  9400. ShmOCPP16DataPH->YesCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9401. }
  9402. else
  9403. {
  9404. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9405. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9406. }
  9407. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9408. {
  9409. ShmOCPP16DataPH->YesCustomData.WeatherInfoReq = 1;
  9410. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9411. ShmOCPP16DataPH->YesCustomData.WeatherInfo.weatherId,
  9412. ShmOCPP16DataPH->YesCustomData.WeatherInfo.temperature);
  9413. }
  9414. }
  9415. else
  9416. {
  9417. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9418. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9419. }
  9420. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9421. json_object_put(response);
  9422. }
  9423. else if(strstr(tempmessageId, "set_qrcode") != NULL)
  9424. {
  9425. json_object *data;
  9426. data = json_tokener_parse(tempdata);
  9427. if(!is_error(data))
  9428. {
  9429. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9430. if(json_object_object_get(data, "connectorId") != NULL)
  9431. {
  9432. if((json_object_get_int(json_object_object_get(data, "connectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "connectorId")) <= gunTotalNumber))
  9433. {
  9434. int idx = json_object_get_int(json_object_object_get(data, "connectorId"))-1;
  9435. if(json_object_object_get(data, "qrcode") != NULL)
  9436. {
  9437. sprintf((char *)ShmOCPP16DataPH->YesCustomData.QrCode[idx], "%s", json_object_get_string(json_object_object_get(data,"qrcode")));
  9438. ShmOCPP16DataPH->YesCustomData.SetQrCodeReq = 1;
  9439. DEBUG_INFO("<<< set_qrcode:{connectorId:%d, qrcode:%s}\n",
  9440. idx,
  9441. ShmOCPP16DataPH->YesCustomData.QrCode[idx]
  9442. );
  9443. }
  9444. else
  9445. {
  9446. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9447. json_object_object_add(response, "data", json_object_new_string("qrcode data can not get."));
  9448. }
  9449. }
  9450. else
  9451. {
  9452. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9453. json_object_object_add(response, "data", json_object_new_string("connectorId data is invalid."));
  9454. }
  9455. }
  9456. else
  9457. {
  9458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9459. json_object_object_add(response, "data", json_object_new_string("connectorId data can not get."));
  9460. }
  9461. }
  9462. else
  9463. {
  9464. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9465. json_object_object_add(response, "data", json_object_new_string("set_qrcode content got something wrong."));
  9466. }
  9467. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9468. json_object_put(response);
  9469. }
  9470. else
  9471. {
  9472. // Can not find valid message id
  9473. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9474. }
  9475. }
  9476. else
  9477. {
  9478. // Payload is null
  9479. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9480. }
  9481. LWS_Send(message);
  9482. return result;
  9483. }
  9484. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9485. {
  9486. mtrace();
  9487. int result = FAIL;
  9488. int connectorIdInt, durationInt;
  9489. char chargingRateUnitStr[4]={0};
  9490. char comfirmstr[20];
  9491. int confirmPeriods = 0;
  9492. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9493. json_object *GetCompositeSchedule;
  9494. GetCompositeSchedule = json_tokener_parse(payload);
  9495. if(!is_error(GetCompositeSchedule))
  9496. {
  9497. // Required data
  9498. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9499. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9500. else
  9501. connectorIdInt = -1;
  9502. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9503. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9504. else
  9505. durationInt = 86400;
  9506. // Optional data
  9507. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9508. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9509. }
  9510. json_object_put(GetCompositeSchedule);
  9511. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9512. if((connectorIdInt == 0) ||
  9513. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9514. {
  9515. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9516. struct StructChargingProfile tmpProfile[1];
  9517. if(strstr(chargingRateUnitStr, "W") != NULL)
  9518. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9519. else
  9520. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9521. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9522. {
  9523. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9524. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9525. }
  9526. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9527. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9528. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9529. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9530. {
  9531. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9532. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9533. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9534. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9535. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9536. {
  9537. confirmPeriods = idx;
  9538. break;
  9539. }
  9540. }
  9541. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9542. {
  9543. confirmPeriods += 1;
  9544. }
  9545. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9546. }
  9547. else
  9548. {
  9549. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9550. }
  9551. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9552. return result;
  9553. }
  9554. int handleGetConfigurationRequest(char *uuid, char *payload)
  9555. {
  9556. mtrace();
  9557. int result = FAIL;
  9558. int MaxKeySupported = 0;
  9559. int n_keys = 0;
  9560. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9561. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9562. json_object *GetConfiguration;
  9563. GetConfiguration = json_tokener_parse(payload);
  9564. if(!is_error(GetConfiguration))
  9565. {
  9566. // Optional data
  9567. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9568. {
  9569. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9570. {
  9571. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9572. n_keys = idx + 1;
  9573. }
  9574. }
  9575. }
  9576. json_object_put(GetConfiguration);
  9577. UnknownKeynum = 0;
  9578. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9579. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9580. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9581. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9582. if(n_keys != 0)
  9583. {
  9584. for(int i=0;i<n_keys;i++)
  9585. {
  9586. getKeyValue(requestKey[i]);
  9587. }
  9588. }
  9589. else
  9590. {
  9591. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9592. getKeyValue("");
  9593. }
  9594. processUnkownKey();
  9595. sendGetConfigurationConfirmation(uuid);
  9596. return result;
  9597. }
  9598. static char fnamePlusPath[100]={0};
  9599. static char fnamePWithNoPath[60]={0};
  9600. void checkUploadLog(void)
  9601. {
  9602. FILE *fp;
  9603. /* Open the command for reading. */
  9604. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9605. if (fp == NULL) {
  9606. DEBUG_WARN("Failed to run command\n" );
  9607. exit(1);
  9608. }
  9609. int ftppathlen = 0;
  9610. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9611. int i = 0;
  9612. /* Read the output a line at a time - output it. */
  9613. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9614. if(i==0)
  9615. {
  9616. ftppathlen = strlen(fnamePlusPath);
  9617. DEBUG_INFO("%s\n", fnamePlusPath);
  9618. fnamePlusPath[ftppathlen]='\0';
  9619. break;
  9620. }
  9621. i= i+1;
  9622. }
  9623. /* close */
  9624. pclose(fp);
  9625. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9626. {
  9627. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9628. {
  9629. fnamePlusPath[k]='\0';
  9630. }
  9631. }
  9632. i=1;
  9633. //char fname[60]={0};
  9634. while(i < ftppathlen)
  9635. {
  9636. int len=ftppathlen-i;
  9637. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9638. {
  9639. DEBUG_INFO("compare '/' all right\n");
  9640. break;
  9641. }
  9642. i=i+1;
  9643. }
  9644. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9645. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9646. fnamePWithNoPath[i+1] = '\0';
  9647. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9648. {
  9649. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9650. {
  9651. fnamePWithNoPath[j]='\0';
  9652. }
  9653. }
  9654. FILE* fp1 = fopen(fnamePlusPath, "r");
  9655. if (fp1)
  9656. {
  9657. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9658. // file exists
  9659. fclose(fp1);
  9660. }
  9661. else
  9662. {
  9663. // file doesn't exist
  9664. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9665. }
  9666. }
  9667. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9668. {
  9669. mtrace();
  9670. int result = FAIL;
  9671. time_t CurrentTime;
  9672. struct tm *tm;
  9673. pthread_t th_Status;
  9674. CurrentTime = time(NULL);
  9675. tm = localtime(&CurrentTime);
  9676. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9677. 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);
  9678. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9679. if(!interLock.isGetDiagnosticGoing)
  9680. {
  9681. interLock.isGetDiagnosticGoing = 1;
  9682. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9683. sleep(1);
  9684. }
  9685. else
  9686. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9687. return result;
  9688. }
  9689. void* GetDiagnosticsProcess(void* data)
  9690. {
  9691. pthread_detach(pthread_self());
  9692. mtrace();
  9693. int retriesInt=0, retryIntervalInt=0;
  9694. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9695. 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};
  9696. int port=0;
  9697. int isSuccess = FALSE;
  9698. char ftpbuf[200]={0};
  9699. char cmdBuf[2048];
  9700. struct tm *tmNow;
  9701. time_t CurrentTime;
  9702. struct tm tmStart;
  9703. struct tm tmStop;
  9704. CurrentTime = time(NULL);
  9705. tmNow=localtime(&CurrentTime);
  9706. uint16_t targetYear, targetMonth;
  9707. json_object *GetDiagnostics;
  9708. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9709. GetDiagnostics = json_tokener_parse(data);
  9710. if(!is_error(GetDiagnostics))
  9711. {
  9712. // Required data
  9713. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9714. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9715. // Optional data
  9716. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9717. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9718. else
  9719. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9720. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9721. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9722. else
  9723. retryIntervalInt = 30;
  9724. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9725. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9726. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9727. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9728. }
  9729. json_object_put(GetDiagnostics);
  9730. // Pack log to compress file
  9731. 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) &&
  9732. (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))
  9733. {
  9734. // Pack system log
  9735. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9736. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9737. targetYear = tmStart.tm_year;
  9738. targetMonth = tmStart.tm_mon;
  9739. do
  9740. {
  9741. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9742. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9743. if(targetMonth+1>=13)
  9744. {
  9745. targetYear += 1;
  9746. targetMonth = 1;
  9747. }
  9748. else
  9749. {
  9750. targetMonth += 1;
  9751. }
  9752. }while((targetYear < (tmNow->tm_year+1900)) ||
  9753. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9754. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9755. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9756. system(cmdBuf);
  9757. // Pack charging & event log
  9758. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9759. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9760. targetYear = tmStart.tm_year;
  9761. targetMonth = tmStart.tm_mon;
  9762. do
  9763. {
  9764. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9765. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9766. if(targetMonth+1>=13)
  9767. {
  9768. targetYear += 1;
  9769. targetMonth = 1;
  9770. }
  9771. else
  9772. {
  9773. targetMonth += 1;
  9774. }
  9775. }while((targetYear < (tmNow->tm_year+1900)) ||
  9776. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9777. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9778. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9779. system(cmdBuf);
  9780. // Combine log file
  9781. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9782. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9783. }
  9784. else
  9785. {
  9786. system("exec /root/logPackTools 'log' 6");
  9787. }
  9788. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9789. system(cmdBuf);
  9790. checkUploadLog();
  9791. //****************location*******************/
  9792. if(strcmp(locationstr,"")==0)
  9793. {
  9794. DEBUG_INFO("location is <Empty>!\n");
  9795. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9796. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9797. goto end;
  9798. }
  9799. memset(protocol, 0, ARRAY_SIZE(protocol));
  9800. memset(user, 0, ARRAY_SIZE(user) );
  9801. memset(password, 0, ARRAY_SIZE(password));
  9802. memset(host, 0, ARRAY_SIZE(host));
  9803. memset(path, 0, ARRAY_SIZE(path));
  9804. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9805. memset(host1, 0, ARRAY_SIZE(host1));
  9806. memset(path1, 0, ARRAY_SIZE(path1));
  9807. /*location: ftp://user:password@host:port/path*/
  9808. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9809. if((access(fnamePlusPath,F_OK))!=-1)
  9810. {
  9811. DEBUG_INFO("fnamePlusPath exist.\n");
  9812. }
  9813. else
  9814. {
  9815. DEBUG_INFO("fnamePlusPath not exist!\n");
  9816. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9817. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9818. goto end;
  9819. }
  9820. if(strchr(locationstr,'@')==NULL)
  9821. {
  9822. sscanf(locationstr,
  9823. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9824. protocol, host, &port, path);
  9825. strcpy(user,"anonymous");
  9826. strcpy(password,"");
  9827. }
  9828. else
  9829. {
  9830. //DEBUG_INFO("pch=%s\n", pch);
  9831. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9832. protocol, user, password, host, &port, path);
  9833. }
  9834. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9835. {
  9836. DEBUG_INFO("protocol is not ftp/http ! \n");
  9837. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9838. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9839. goto end;
  9840. }
  9841. if(strncmp(locationstr,"http", 4) == 0)
  9842. {
  9843. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9844. sprintf(ftppath,"/%s", path);
  9845. do
  9846. {
  9847. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9848. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9849. sleep(3);
  9850. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9851. if(!isSuccess)
  9852. {
  9853. DEBUG_INFO("Diagnostics fail.\n");
  9854. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9855. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9856. sleep(retryIntervalInt);
  9857. }
  9858. else
  9859. {
  9860. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9861. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9862. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9863. }
  9864. retriesInt--;
  9865. }while((isSuccess == 0)&&(retriesInt >= 0));
  9866. }
  9867. else
  9868. {
  9869. sscanf(host,"%[^/]%s",host1, path1);
  9870. if(strlen(path) > 0)
  9871. sprintf(ftppath,"/%s", path);
  9872. else
  9873. sprintf(ftppath,"/%s", path1);
  9874. int ftppathlen=strlen(ftppath);
  9875. int i=1;
  9876. char filenametemp[50];
  9877. while(i < ftppathlen)
  9878. {
  9879. int len=ftppathlen-i;
  9880. if(ftppath[len]== 47) // '/' ascll code: 47
  9881. {
  9882. DEBUG_INFO("find '/' all right\n");
  9883. break;
  9884. }
  9885. i=i+1;
  9886. }
  9887. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9888. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9889. filenametemp[i+1] = 0;
  9890. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9891. if(port == 0)
  9892. port = 21;
  9893. do
  9894. {
  9895. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9896. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9897. sleep(3);
  9898. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9899. if(!isSuccess)
  9900. {
  9901. DEBUG_INFO("Diagnostics fail.\n");
  9902. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9903. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9904. sleep(retryIntervalInt);
  9905. }
  9906. else
  9907. {
  9908. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9909. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9910. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9911. }
  9912. retriesInt--;
  9913. }while((!isSuccess)&&(retriesInt >= 0));
  9914. }
  9915. end:
  9916. system("rm -f /mnt/*");
  9917. sleep(5);
  9918. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9919. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9920. interLock.isGetDiagnosticGoing = 0;
  9921. pthread_exit(NULL);
  9922. }
  9923. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9924. {
  9925. mtrace();
  9926. int result = FAIL;
  9927. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9928. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9929. {
  9930. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9931. locallistVersion = -1;
  9932. }
  9933. else
  9934. {
  9935. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9936. OCPP_getListVerion();
  9937. }
  9938. //from db.OCPP_getListVerion
  9939. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9940. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9941. sendGetLocalListVersionConfirmation(uuid,"");
  9942. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9943. return result;
  9944. }
  9945. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9946. {
  9947. mtrace();
  9948. int result = FAIL;
  9949. int connectorIdInt=-1;
  9950. int tempIndex = 0;
  9951. int connectorIdIsNULL, chargingProfileIsNULL;
  9952. char comfirmstr[20]={0};
  9953. char cmdBuf[512];
  9954. json_object *RemoteStartTransaction;
  9955. FILE *fp;
  9956. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9957. if(server_pending == TRUE)
  9958. {
  9959. return 0;
  9960. }
  9961. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9962. RemoteStartTransaction = json_tokener_parse(payload);
  9963. if(!is_error(RemoteStartTransaction))
  9964. {
  9965. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9966. {
  9967. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9968. }
  9969. else
  9970. {
  9971. connectorIdIsNULL = TRUE;
  9972. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9973. {
  9974. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9975. {
  9976. connectorIdIsNULL = FALSE;
  9977. connectorIdInt = (gun_index+1);
  9978. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9979. break;
  9980. }
  9981. }
  9982. }
  9983. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9984. {
  9985. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9986. // Required data
  9987. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9988. // Optional data
  9989. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9990. {
  9991. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9992. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9993. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9994. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9995. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9996. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9997. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9998. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9999. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10000. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10001. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10002. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10003. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10004. {
  10005. 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")));
  10006. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10007. 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"));
  10008. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10009. 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"));
  10010. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10011. 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")));
  10012. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10013. {
  10014. 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++)
  10015. {
  10016. 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"));
  10017. 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"));
  10018. 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)
  10019. 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"));
  10020. }
  10021. }
  10022. }
  10023. }
  10024. else
  10025. {
  10026. chargingProfileIsNULL = TRUE;
  10027. }
  10028. }
  10029. }
  10030. else
  10031. {
  10032. connectorIdIsNULL = TRUE;
  10033. }
  10034. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10035. {
  10036. DEBUG_WARN("Connector id is NULL\n.");
  10037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10038. goto end;
  10039. }
  10040. /*
  10041. enum _SYSTEM_STATUS
  10042. {
  10043. S_BOOTING = 0,
  10044. S_IDLE, = 1
  10045. S_AUTHORIZING, = 2
  10046. S_REASSIGN_CHECK, = 3
  10047. S_REASSIGN, = 4
  10048. S_PRECHARGE, = 5
  10049. S_PREPARING_FOR_EV, = 6
  10050. S_PREPARING_FOR_EVSE, = 7
  10051. S_CHARGING, = 8
  10052. S_TERMINATING, = 9
  10053. S_COMPLETE, = 10
  10054. S_ALARM, = 11
  10055. S_FAULT = 12
  10056. }
  10057. */
  10058. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10059. {
  10060. //check Transaction active
  10061. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10062. {
  10063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10064. {
  10065. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10066. }
  10067. else
  10068. {
  10069. tempIndex = connectorIdInt -1;
  10070. }
  10071. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10072. {
  10073. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10074. {
  10075. 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))
  10076. {
  10077. //Reserved
  10078. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10079. }
  10080. 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))
  10081. {
  10082. //Reserved
  10083. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10084. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10085. goto end;
  10086. }
  10087. else
  10088. {
  10089. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10090. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10091. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10092. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10093. {
  10094. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10095. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10096. goto end;
  10097. }
  10098. }//END FOR ELSE
  10099. }
  10100. }// END FOR CHAdeMO_QUANTITY
  10101. }
  10102. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10103. {
  10104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10105. {
  10106. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10107. }
  10108. else
  10109. {
  10110. tempIndex = connectorIdInt -1;
  10111. }
  10112. for (int index = 0; index < CCS_QUANTITY; index++)
  10113. {
  10114. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10115. {
  10116. 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))
  10117. {
  10118. //Reserved
  10119. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10120. }
  10121. 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))
  10122. {
  10123. //Reserved
  10124. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10125. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10126. goto end;
  10127. }
  10128. else
  10129. {
  10130. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10131. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10132. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10133. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10134. {
  10135. DEBUG_WARN("CCS connector not allow start\n.");
  10136. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10137. goto end;
  10138. }
  10139. }// END FOR ELSE
  10140. }
  10141. }// END FOR CCS_QUANTITY
  10142. }
  10143. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10144. {
  10145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10146. {
  10147. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10148. }
  10149. else
  10150. {
  10151. tempIndex = connectorIdInt -1;
  10152. }
  10153. for (int index = 0; index < GB_QUANTITY; index++)
  10154. {
  10155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10156. {
  10157. 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))
  10158. {
  10159. //Reserved
  10160. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10161. }
  10162. 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))
  10163. {
  10164. //Reserved
  10165. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10166. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10167. goto end;
  10168. }
  10169. else
  10170. {
  10171. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10172. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10173. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10174. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10175. {
  10176. DEBUG_WARN("GB connector not allow start\n.");
  10177. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10178. goto end;
  10179. }
  10180. }// END FOR ELSE
  10181. }
  10182. } // END FOR GB_QUANTITY
  10183. }
  10184. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10185. {
  10186. tempIndex = connectorIdInt -1;
  10187. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10188. {
  10189. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10190. {
  10191. 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))
  10192. {
  10193. //Reserved
  10194. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10195. }
  10196. 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))
  10197. {
  10198. //Reserved
  10199. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10200. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10201. goto end;
  10202. }
  10203. else
  10204. {
  10205. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10206. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10207. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10208. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10209. {
  10210. DEBUG_WARN("GB connector not allow start\n.");
  10211. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10212. goto end;
  10213. }
  10214. }// END FOR ELSE
  10215. }
  10216. } // END FOR GB_QUANTITY
  10217. }
  10218. else
  10219. {
  10220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10221. {
  10222. tempIndex = 2;
  10223. }
  10224. else
  10225. {
  10226. tempIndex = connectorIdInt -1;
  10227. }
  10228. for (int index = 0; index < AC_QUANTITY; index++)
  10229. {
  10230. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10231. {
  10232. 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))
  10233. {
  10234. //Reserved
  10235. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10236. }
  10237. 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))
  10238. {
  10239. //Reserved
  10240. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10241. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10242. goto end;
  10243. }
  10244. else
  10245. {
  10246. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10247. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10248. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10249. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10250. {
  10251. DEBUG_WARN("AC connector not allow start\n.");
  10252. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10253. goto end;
  10254. }
  10255. }//END FOR ELSE
  10256. }
  10257. }// END FOR AC_QUANTITY
  10258. }
  10259. if(chargingProfileIsNULL == FALSE)
  10260. {
  10261. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10262. {
  10263. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10265. //memset idTag
  10266. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10267. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10268. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10270. // Save profile to file
  10271. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10272. system(cmdBuf);
  10273. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10274. fp = fopen(cmdBuf, "w");
  10275. 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));
  10276. fclose(fp);
  10277. }
  10278. else
  10279. {
  10280. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10282. }
  10283. }
  10284. else
  10285. {
  10286. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10288. //memset idTag
  10289. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10290. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10291. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10292. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10293. }
  10294. }
  10295. else
  10296. {
  10297. DEBUG_WARN("Connector id over\n.");
  10298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10299. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10300. }
  10301. end:
  10302. json_object_put(RemoteStartTransaction);
  10303. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10304. {
  10305. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10306. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10307. }
  10308. //OCPP send RemoteStartConfirmation by first.
  10309. sendRemoteStartConfirmation(uuid, comfirmstr);
  10310. return result;
  10311. }
  10312. int handleRemoteStartRequest(char *uuid, char *payload)
  10313. {
  10314. mtrace();
  10315. int result = PASS;
  10316. int connectorIdInt=-1;
  10317. int tempIndex = 0;
  10318. char comfirmstr[20]={0};
  10319. char cmdBuf[512];
  10320. json_object *RemoteStartTransaction;
  10321. FILE *fp;
  10322. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10323. if(server_pending == TRUE)
  10324. {
  10325. result = FAIL;
  10326. }
  10327. RemoteStartTransaction = json_tokener_parse(payload);
  10328. if(!is_error(RemoteStartTransaction))
  10329. {
  10330. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10331. {
  10332. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10333. }
  10334. else
  10335. {
  10336. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10337. {
  10338. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10339. {
  10340. connectorIdInt = (gun_index+1);
  10341. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10342. break;
  10343. }
  10344. }
  10345. }
  10346. if(connectorIdInt == 0)
  10347. {
  10348. DEBUG_WARN("Connector id shall not equal 0.\n");
  10349. result = FAIL;
  10350. }
  10351. else if(connectorIdInt == -1)
  10352. {
  10353. DEBUG_INFO("Connector id does not specific.\n");
  10354. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10355. {
  10356. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10357. // Required data
  10358. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10359. // Optional data
  10360. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10361. {
  10362. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10363. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10364. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10365. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10366. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10367. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10368. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10369. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10370. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10371. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10372. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10373. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10374. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10375. {
  10376. 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")));
  10377. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10378. 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"));
  10379. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10380. 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"));
  10381. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10382. 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")));
  10383. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10384. {
  10385. 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++)
  10386. {
  10387. 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"));
  10388. 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"));
  10389. 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)
  10390. 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"));
  10391. }
  10392. }
  10393. }
  10394. }
  10395. else
  10396. {
  10397. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10398. }
  10399. }
  10400. }
  10401. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10402. {
  10403. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10404. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10405. // Required data
  10406. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10407. // Optional data
  10408. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10409. {
  10410. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10411. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10412. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10413. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10414. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10415. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10416. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10417. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10418. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10419. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10420. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10421. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10422. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10423. {
  10424. 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")));
  10425. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10426. 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"));
  10427. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10428. 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"));
  10429. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10430. 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")));
  10431. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10432. {
  10433. 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++)
  10434. {
  10435. 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"));
  10436. 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"));
  10437. 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)
  10438. 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"));
  10439. }
  10440. }
  10441. }
  10442. }
  10443. else
  10444. {
  10445. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10446. }
  10447. }
  10448. else
  10449. {
  10450. DEBUG_WARN("Connector id is over maximun value.\n");
  10451. result = FAIL;
  10452. }
  10453. }
  10454. if(result == PASS)
  10455. {
  10456. if(connectorIdInt > 0)
  10457. {
  10458. //check Transaction active
  10459. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10460. {
  10461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10462. {
  10463. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10464. }
  10465. else
  10466. {
  10467. tempIndex = connectorIdInt -1;
  10468. }
  10469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10470. {
  10471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10472. {
  10473. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10474. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10475. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10476. {
  10477. //Reserved
  10478. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10479. }
  10480. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10481. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10482. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10483. {
  10484. //Reserved
  10485. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10486. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10487. goto end;
  10488. }
  10489. else
  10490. {
  10491. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10492. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10493. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10494. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10495. {
  10496. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10498. goto end;
  10499. }
  10500. }//END FOR ELSE
  10501. }
  10502. }// END FOR CHAdeMO_QUANTITY
  10503. }
  10504. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10505. {
  10506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10507. {
  10508. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10509. }
  10510. else
  10511. {
  10512. tempIndex = connectorIdInt -1;
  10513. }
  10514. for (int index = 0; index < CCS_QUANTITY; index++)
  10515. {
  10516. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10517. {
  10518. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10519. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10520. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10521. {
  10522. //Reserved
  10523. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10524. }
  10525. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10526. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10527. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10528. {
  10529. //Reserved
  10530. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10532. goto end;
  10533. }
  10534. else
  10535. {
  10536. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10537. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10538. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10539. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10540. {
  10541. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10543. goto end;
  10544. }
  10545. }// END FOR ELSE
  10546. }
  10547. }// END FOR CCS_QUANTITY
  10548. }
  10549. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10550. {
  10551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10552. {
  10553. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10554. }
  10555. else
  10556. {
  10557. tempIndex = connectorIdInt -1;
  10558. }
  10559. for (int index = 0; index < GB_QUANTITY; index++)
  10560. {
  10561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10562. {
  10563. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10564. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10565. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10566. {
  10567. //Reserved
  10568. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10569. }
  10570. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10571. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10572. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10573. {
  10574. //Reserved
  10575. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10576. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10577. goto end;
  10578. }
  10579. else
  10580. {
  10581. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10582. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10583. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10584. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10585. {
  10586. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10587. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10588. goto end;
  10589. }
  10590. }// END FOR ELSE
  10591. }
  10592. } // END FOR GB_QUANTITY
  10593. }
  10594. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10595. {
  10596. tempIndex = connectorIdInt -1;
  10597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10598. {
  10599. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10600. {
  10601. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10602. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10603. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10604. {
  10605. //Reserved
  10606. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10607. }
  10608. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10610. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10611. {
  10612. //Reserved
  10613. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10614. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10615. goto end;
  10616. }
  10617. else
  10618. {
  10619. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10620. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10621. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10622. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10623. {
  10624. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10626. goto end;
  10627. }
  10628. }// END FOR ELSE
  10629. }
  10630. } // END FOR GB_QUANTITY
  10631. }
  10632. else
  10633. {
  10634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10635. {
  10636. tempIndex = 2;
  10637. }
  10638. else
  10639. {
  10640. tempIndex = connectorIdInt -1;
  10641. }
  10642. for (int index = 0; index < AC_QUANTITY; index++)
  10643. {
  10644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10645. {
  10646. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10647. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10648. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10649. {
  10650. //Reserved
  10651. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10652. }
  10653. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10654. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10655. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10656. {
  10657. //Reserved
  10658. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10659. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10660. goto end;
  10661. }
  10662. else
  10663. {
  10664. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10665. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10666. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10667. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10668. {
  10669. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10670. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10671. goto end;
  10672. }
  10673. }//END FOR ELSE
  10674. }
  10675. }// END FOR AC_QUANTITY
  10676. }
  10677. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10678. {
  10679. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10680. {
  10681. // Save profile to file
  10682. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10683. system(cmdBuf);
  10684. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10685. fp = fopen(cmdBuf, "w");
  10686. 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));
  10687. fclose(fp);
  10688. }
  10689. else
  10690. {
  10691. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10692. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10693. goto end;
  10694. }
  10695. }
  10696. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10697. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10698. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10699. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10700. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10702. }
  10703. else
  10704. {
  10705. uint8_t isHasIdleConnector = FALSE;
  10706. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10707. {
  10708. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10709. {
  10710. isHasIdleConnector = TRUE;
  10711. break;
  10712. }
  10713. }
  10714. if(isHasIdleConnector == TRUE)
  10715. {
  10716. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10717. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10718. {
  10719. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10720. {
  10721. // Save profile to file
  10722. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10723. system(cmdBuf);
  10724. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10725. fp = fopen(cmdBuf, "w");
  10726. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10727. fclose(fp);
  10728. refreshStartTimer(&clientTime.RemoteStartWait);
  10729. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10731. }
  10732. else
  10733. {
  10734. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10735. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10736. }
  10737. }
  10738. else
  10739. {
  10740. refreshStartTimer(&clientTime.RemoteStartWait);
  10741. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10742. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10743. }
  10744. }
  10745. else
  10746. {
  10747. DEBUG_INFO("There is not any connector is idle.\n");
  10748. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10749. }
  10750. }
  10751. }
  10752. else
  10753. {
  10754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10755. }
  10756. end:
  10757. json_object_put(RemoteStartTransaction);
  10758. sendRemoteStartConfirmation(uuid, comfirmstr);
  10759. return result;
  10760. }
  10761. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10762. {
  10763. mtrace();
  10764. int result = FAIL;
  10765. int match = FALSE;
  10766. int GunNO = 0;
  10767. int tempIndex = 0;
  10768. int transactionIdInt=0;
  10769. int transactionIdIsNULL= TRUE;
  10770. char comfirmstr[20];
  10771. json_object *RemoteStopTransaction;
  10772. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10773. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10774. if(server_pending == TRUE)
  10775. {
  10776. return 0;
  10777. }
  10778. RemoteStopTransaction = json_tokener_parse(payload);
  10779. if(!is_error(RemoteStopTransaction))
  10780. {
  10781. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10782. {
  10783. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10784. transactionIdIsNULL = FALSE;
  10785. }
  10786. }
  10787. json_object_put(RemoteStopTransaction);
  10788. if(transactionIdIsNULL == FALSE)
  10789. {
  10790. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10791. {
  10792. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10793. {
  10794. //check Transaction active
  10795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10796. {
  10797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10798. {
  10799. tempIndex = ((gun_index==2) ? 1: 0);
  10800. }
  10801. else
  10802. {
  10803. tempIndex = gun_index;
  10804. }
  10805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10806. {
  10807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10808. {
  10809. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10810. {
  10811. match = TRUE;
  10812. GunNO = gun_index;
  10813. }
  10814. }
  10815. }// END FOR CHAdeMO_QUANTITY
  10816. }
  10817. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10818. {
  10819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10820. {
  10821. tempIndex = ((gun_index==2) ? 1: 0);
  10822. }
  10823. else
  10824. {
  10825. tempIndex = gun_index;
  10826. }
  10827. for (int index = 0; index < CCS_QUANTITY; index++)
  10828. {
  10829. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10830. {
  10831. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10832. {
  10833. match = TRUE;
  10834. GunNO = gun_index;
  10835. }
  10836. }
  10837. }// END FOR CCS_QUANTITY
  10838. }
  10839. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10840. {
  10841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10842. {
  10843. tempIndex = ((gun_index==2) ? 1: 0);
  10844. }
  10845. else
  10846. {
  10847. tempIndex = gun_index;
  10848. }
  10849. for (int index = 0; index < GB_QUANTITY; index++)
  10850. {
  10851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10852. {
  10853. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10854. {
  10855. match = TRUE;
  10856. GunNO = gun_index;
  10857. }
  10858. }
  10859. }// END FOR GB_QUANTITY
  10860. }
  10861. else if(gunType[gun_index] == GUN_TYPE_DO)
  10862. {
  10863. tempIndex = gun_index;
  10864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10865. {
  10866. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10867. {
  10868. 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
  10869. {
  10870. match = TRUE;
  10871. GunNO = gun_index;
  10872. }
  10873. }
  10874. }// END FOR GB_QUANTITY
  10875. }
  10876. else
  10877. {
  10878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10879. {
  10880. tempIndex = 2;
  10881. }
  10882. else
  10883. {
  10884. tempIndex = gun_index;
  10885. }
  10886. for (int index = 0; index < AC_QUANTITY; index++)
  10887. {
  10888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10889. {
  10890. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10891. {
  10892. match = TRUE;
  10893. GunNO = gun_index;
  10894. }
  10895. }
  10896. }// END FOR CHAdeMO_QUANTITY
  10897. } // END FOR AC ELSE
  10898. }// CHECK IF ResponseTransactionId == transactionIdInt
  10899. }//END FOR
  10900. if( match == TRUE)
  10901. {
  10902. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10903. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10904. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10905. }
  10906. else
  10907. {
  10908. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10909. }
  10910. }
  10911. else
  10912. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10913. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10914. return result;
  10915. }
  10916. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10917. {
  10918. mtrace();
  10919. int result = FAIL;
  10920. int connectorIdInt=0, reservationIdInt=0;
  10921. int tempIndex = 0;
  10922. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10923. char comfirmstr[20]={0};
  10924. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10925. int c = 0;
  10926. char *loc;
  10927. //char *ptr;
  10928. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10929. strcpy(sstrtemp, stringtrimspace(payload));
  10930. //***(1)connectorId ****/
  10931. c=0;
  10932. loc = strstr(sstrtemp, "connectorId");
  10933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10934. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10935. {
  10936. sstr[c] = loc[strlen("connectorId")+2+c];
  10937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10938. c++;
  10939. }
  10940. sstr[c] = '\0';
  10941. connectorIdInt = atoi(sstr);
  10942. //***(2)expiryDate ****/
  10943. loc = strstr(sstrtemp, "expiryDate");
  10944. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10945. c = 0;
  10946. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10947. {
  10948. sstr[c] = loc[3+strlen("expiryDate")+c];
  10949. c++;
  10950. }
  10951. sstr[c] = '\0';
  10952. strcpy(expiryDatestr, sstr);
  10953. //***(3)idTag ****/
  10954. loc = strstr(sstrtemp, "idTag");
  10955. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10956. c = 0;
  10957. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10958. {
  10959. sstr[c] = loc[3+strlen("idTag")+c];
  10960. c++;
  10961. }
  10962. sstr[c] = '\0';
  10963. strcpy(idTagstr, sstr);
  10964. //***(4)parentIdTag ****/
  10965. loc = strstr(sstrtemp, "parentIdTag");
  10966. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10967. c = 0;
  10968. if(loc == NULL)
  10969. {
  10970. strcpy(parentIdTagstr, "");
  10971. }
  10972. else
  10973. {
  10974. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10975. {
  10976. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10977. c++;
  10978. }
  10979. sstr[c] = '\0';
  10980. strcpy(parentIdTagstr, sstr);
  10981. }
  10982. //***(5)reservationId ****/
  10983. c=0;
  10984. loc = strstr(sstrtemp, "reservationId");
  10985. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10986. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10987. {
  10988. sstr[c] = loc[strlen("reservationId")+2+c];
  10989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10990. c++;
  10991. }
  10992. sstr[c] = '\0';
  10993. reservationIdInt = atoi(sstr);
  10994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10995. /*
  10996. enum SYSTEM_STATUS
  10997. {
  10998. SYS_MODE_BOOTING = 0,
  10999. SYS_MODE_IDLE = 1,
  11000. SYS_MODE_AUTHORIZING = 2,
  11001. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11002. SYS_MODE_REASSIGN = 4,
  11003. SYS_MODE_PREPARING = 5,
  11004. SYS_MODE_PREPARE_FOR_EV = 6,
  11005. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11006. SYS_MODE_CHARGING = 8,
  11007. SYS_MODE_TERMINATING = 9,
  11008. SYS_MODE_COMPLETE = 10,
  11009. SYS_MODE_ALARM = 11,
  11010. SYS_MODE_FAULT = 12,
  11011. SYS_MODE_RESERVATION = 13,
  11012. SYS_MODE_BOOKING = 14,
  11013. SYS_MODE_MAINTAIN = 15,
  11014. SYS_MODE_DEBUG = 16,
  11015. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11016. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11017. SYS_MODE_UPDATE = 19
  11018. };
  11019. */
  11020. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11021. {
  11022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11023. goto end;
  11024. }
  11025. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11026. {
  11027. //check Transaction active
  11028. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11029. {
  11030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11031. {
  11032. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11033. }
  11034. else
  11035. {
  11036. tempIndex = connectorIdInt -1;
  11037. }
  11038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11039. {
  11040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11041. {
  11042. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11043. {
  11044. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11045. {
  11046. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11047. {
  11048. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11050. }
  11051. 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'))
  11052. {
  11053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11054. }
  11055. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11056. {
  11057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11058. }
  11059. else
  11060. {
  11061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11062. }
  11063. }
  11064. 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
  11065. {
  11066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11067. }
  11068. }
  11069. else
  11070. {
  11071. //replace reservation
  11072. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11074. }
  11075. }
  11076. } // END FOR CHAdeMO_QUANTITY
  11077. }
  11078. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11079. {
  11080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11081. {
  11082. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11083. }
  11084. else
  11085. {
  11086. tempIndex = connectorIdInt -1;
  11087. }
  11088. for (int index = 0; index < CCS_QUANTITY; index++)
  11089. {
  11090. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11091. {
  11092. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11093. {
  11094. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11095. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11096. {
  11097. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11098. {
  11099. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11101. }
  11102. 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'))
  11103. {
  11104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11105. }
  11106. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11107. {
  11108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11109. }
  11110. else
  11111. {
  11112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11113. }
  11114. }
  11115. 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
  11116. {
  11117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11118. }
  11119. }
  11120. else
  11121. {
  11122. //replace reservation
  11123. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11125. }
  11126. }
  11127. } // END FOR CCS_QUANTITY
  11128. }
  11129. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11130. {
  11131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11132. {
  11133. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11134. }
  11135. else
  11136. {
  11137. tempIndex = connectorIdInt -1;
  11138. }
  11139. for (int index = 0; index < GB_QUANTITY; index++)
  11140. {
  11141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11142. {
  11143. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11144. {
  11145. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11146. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11147. {
  11148. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11149. {
  11150. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11152. }
  11153. 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'))
  11154. {
  11155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11156. }
  11157. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11158. {
  11159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11160. }
  11161. else
  11162. {
  11163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11164. }
  11165. }
  11166. 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
  11167. {
  11168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11169. }
  11170. }
  11171. else
  11172. {
  11173. //replace reservation
  11174. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11176. }
  11177. }
  11178. }// END FOR GB_QUANTITY
  11179. }
  11180. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11181. {
  11182. tempIndex = connectorIdInt -1;
  11183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11184. {
  11185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11186. {
  11187. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11188. {
  11189. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11190. 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
  11191. {
  11192. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11193. {
  11194. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11196. }
  11197. 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'))
  11198. {
  11199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11200. }
  11201. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11202. {
  11203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11204. }
  11205. else
  11206. {
  11207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11208. }
  11209. }
  11210. 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
  11211. {
  11212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11213. }
  11214. }
  11215. else
  11216. {
  11217. //replace reservation
  11218. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11220. }
  11221. }
  11222. }// END FOR GB_QUANTITY
  11223. }
  11224. else
  11225. {
  11226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11227. {
  11228. tempIndex = 2;
  11229. }
  11230. else
  11231. {
  11232. tempIndex = (connectorIdInt -1);
  11233. }
  11234. for (int index = 0; index < AC_QUANTITY; index++)
  11235. {
  11236. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11237. {
  11238. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11239. {
  11240. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11241. {
  11242. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11243. {
  11244. 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))
  11245. {
  11246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11247. }
  11248. else
  11249. {
  11250. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11252. }
  11253. }
  11254. 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'))
  11255. {
  11256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11257. }
  11258. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11259. {
  11260. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11261. }
  11262. else
  11263. {
  11264. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11265. }
  11266. }
  11267. 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
  11268. {
  11269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11270. }
  11271. }
  11272. else
  11273. {
  11274. //replace reservation
  11275. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11277. }
  11278. }
  11279. } // END FOR AC_QUANTITY
  11280. }
  11281. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11282. }
  11283. else if(connectorIdInt == 0)
  11284. {
  11285. //check Transaction active
  11286. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11287. {
  11288. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11289. {
  11290. 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'))
  11291. {
  11292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11293. goto end;
  11294. }
  11295. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11296. {
  11297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11298. goto end;
  11299. }
  11300. 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
  11301. {
  11302. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11303. goto end;
  11304. }
  11305. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11306. {
  11307. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11308. goto end;
  11309. }
  11310. }
  11311. }// END FOR CHAdeMO_QUANTITY
  11312. for (int index = 0; index < CCS_QUANTITY; index++)
  11313. {
  11314. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11315. {
  11316. 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'))
  11317. {
  11318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11319. goto end;
  11320. }
  11321. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11322. {
  11323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11324. goto end;
  11325. }
  11326. 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
  11327. {
  11328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11329. goto end;
  11330. }
  11331. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11332. {
  11333. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11334. goto end;
  11335. }
  11336. }
  11337. } // END FOR CCS_QUANTITY
  11338. for (int index = 0; index < GB_QUANTITY; index++)
  11339. {
  11340. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11341. {
  11342. 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'))
  11343. {
  11344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11345. goto end;
  11346. }
  11347. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11348. {
  11349. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11350. goto end;
  11351. }
  11352. 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
  11353. {
  11354. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11355. goto end;
  11356. }
  11357. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11358. {
  11359. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11360. goto end;
  11361. }
  11362. }
  11363. } // END FOR GB_QUANTITY
  11364. for (int index = 0; index < AC_QUANTITY; index++)
  11365. {
  11366. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11367. {
  11368. 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'))
  11369. {
  11370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11371. goto end;
  11372. }
  11373. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11374. {
  11375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11376. goto end;
  11377. }
  11378. 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
  11379. {
  11380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11381. goto end;
  11382. }
  11383. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11384. {
  11385. 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))
  11386. {
  11387. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11388. goto end;
  11389. }
  11390. }
  11391. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11392. {
  11393. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11394. goto end;
  11395. }
  11396. }
  11397. }// END FOR AC_QUANTITY
  11398. //The connectorId is 0
  11399. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11400. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11401. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11402. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11403. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11404. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11405. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11406. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11407. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11408. result = TRUE;
  11409. return result;
  11410. }
  11411. else
  11412. {
  11413. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11414. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11415. }
  11416. if(strcmp(comfirmstr,"Accepted") == 0)
  11417. {
  11418. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11419. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11420. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11421. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11422. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11423. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11424. result = TRUE;
  11425. return result;
  11426. }
  11427. end:
  11428. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11429. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11430. return result;
  11431. }
  11432. int handleResetRequest(char *uuid, char *payload)
  11433. {
  11434. mtrace();
  11435. int result = FAIL;
  11436. char sstr[10]={0},sstrtemp[30]={ 0 };
  11437. char typestr[10]={0};
  11438. char comfirmstr[20]={0};
  11439. int c = 0;
  11440. char *loc;
  11441. DEBUG_INFO("handleResetRequest...\n");
  11442. strcpy(sstrtemp, stringtrimspace(payload));
  11443. loc = strstr(sstrtemp, "type");
  11444. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11445. c = 0;
  11446. while (loc[3+strlen("type")+c] != '\"')
  11447. {
  11448. sstr[c] = loc[3+strlen("type")+c];
  11449. c++;
  11450. }
  11451. sstr[c] = '\0';
  11452. strcpy(typestr,sstr);
  11453. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11454. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11455. {
  11456. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11457. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11458. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11459. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11460. }
  11461. else
  11462. {
  11463. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11464. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11465. result = PASS;
  11466. }
  11467. sendResetConfirmation(uuid, comfirmstr);
  11468. return result;
  11469. }
  11470. int handleSendLocalListRequest(char *uuid, char *payload)
  11471. {
  11472. mtrace();
  11473. int result = FAIL;
  11474. char comfirmstr[20];
  11475. int checkState_Faulted = FALSE;
  11476. json_object *SendLocalList;
  11477. DEBUG_INFO("handleSendLocalListRequest...\n");
  11478. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11479. {
  11480. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11481. goto end;
  11482. }
  11483. //check Charge Point state
  11484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11485. {
  11486. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11487. {
  11488. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11489. }
  11490. }
  11491. for (int index = 0; index < CCS_QUANTITY; index++)
  11492. {
  11493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11494. {
  11495. checkState_Faulted = TRUE; //OCPP Status
  11496. }
  11497. }
  11498. for (int index = 0; index < GB_QUANTITY; index++)
  11499. {
  11500. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11501. {
  11502. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11503. }
  11504. }
  11505. //check Charge Point state
  11506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11507. {
  11508. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11509. {
  11510. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11511. }
  11512. }
  11513. //check Charge Point state
  11514. for (int index = 0; index < AC_QUANTITY; index++)
  11515. {
  11516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11517. {
  11518. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11519. }
  11520. }
  11521. if(checkState_Faulted == TRUE)
  11522. {
  11523. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11524. goto end;
  11525. }
  11526. // Parsing payload
  11527. SendLocalList = json_tokener_parse(payload);
  11528. if(!is_error(SendLocalList))
  11529. {
  11530. // Required data
  11531. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11532. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11533. // Optional data
  11534. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11535. {
  11536. //Check UpdateType
  11537. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11538. {
  11539. //Local list full update
  11540. DEBUG_INFO("Local list full update.\n");
  11541. OCPP_getListVerion();
  11542. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11543. {
  11544. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11545. goto end;
  11546. }
  11547. OCPP_cleanLocalList();
  11548. }
  11549. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11550. {
  11551. //Local list different update
  11552. DEBUG_INFO("Local list different update.\n");
  11553. OCPP_getListVerion();
  11554. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11555. {
  11556. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11557. goto end;
  11558. }
  11559. }
  11560. else
  11561. {
  11562. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11563. goto end;
  11564. }
  11565. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11566. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11567. {
  11568. 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")));
  11569. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11570. {
  11571. 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")));
  11572. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11573. 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")));
  11574. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11575. 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")));
  11576. }
  11577. // Add to db
  11578. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11579. {
  11580. //Local list full update
  11581. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11582. idx,
  11583. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11584. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11585. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11586. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11587. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11588. // update list
  11589. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11590. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11591. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11592. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11593. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11594. }
  11595. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11596. {
  11597. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11598. idx,
  11599. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11600. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11601. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11602. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11603. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11604. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11605. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11606. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11607. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11608. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11609. }
  11610. }
  11611. }
  11612. else
  11613. {
  11614. //Check UpdateType
  11615. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11616. {
  11617. //Local list full update
  11618. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11619. OCPP_cleanLocalList();
  11620. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11621. goto end;
  11622. }
  11623. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11624. {
  11625. //Local list different update
  11626. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11627. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11628. goto end;
  11629. }
  11630. }
  11631. result = PASS;
  11632. }
  11633. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11634. end:
  11635. json_object_put(SendLocalList);
  11636. sendSendLocalListConfirmation(uuid, comfirmstr);
  11637. return result;
  11638. }
  11639. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11640. {
  11641. mtrace();
  11642. int result = FAIL;
  11643. struct StructSetChargingProfile SetProfileReq = {0};
  11644. int tempchargingProfileIdInt;
  11645. int chargingSchedulePeriodCount = 0;
  11646. char comfirmstr[20]={0};
  11647. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11648. char rmFileCmd[128]={0};
  11649. int profileQuantity = 0;
  11650. json_object *SetChargingProfile;
  11651. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11652. SetChargingProfile = json_tokener_parse(payload);
  11653. if(!is_error(SetChargingProfile))
  11654. {
  11655. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11656. {
  11657. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11658. }
  11659. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11660. {
  11661. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11662. {
  11663. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11664. }
  11665. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11666. {
  11667. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11668. }
  11669. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11670. {
  11671. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11672. }
  11673. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11674. {
  11675. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11676. }
  11677. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11678. {
  11679. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11680. }
  11681. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11682. {
  11683. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11684. }
  11685. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11686. {
  11687. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11688. }
  11689. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11690. {
  11691. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11692. }
  11693. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11694. {
  11695. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11696. {
  11697. 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")));
  11698. }
  11699. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11700. {
  11701. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11702. }
  11703. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11704. {
  11705. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11706. }
  11707. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11708. {
  11709. 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")));
  11710. }
  11711. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11712. {
  11713. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11714. if(chargingSchedulePeriodCount <= 10)
  11715. {
  11716. 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++)
  11717. {
  11718. 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)
  11719. {
  11720. 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"));
  11721. }
  11722. 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)
  11723. {
  11724. 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"));
  11725. }
  11726. 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)
  11727. {
  11728. 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"));
  11729. }
  11730. }
  11731. }
  11732. }
  11733. }
  11734. }
  11735. }
  11736. // Profile periods quantity check
  11737. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11738. {
  11739. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11740. goto end;
  11741. }
  11742. // Check invalid limit
  11743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11744. {
  11745. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11746. {
  11747. 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)))) ||
  11748. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11749. {
  11750. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11751. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11752. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11753. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11754. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11755. goto end;
  11756. }
  11757. }
  11758. }
  11759. else
  11760. {
  11761. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11762. {
  11763. 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))
  11764. {
  11765. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11766. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11767. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11768. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11769. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11770. goto end;
  11771. }
  11772. }
  11773. }
  11774. // Profile purpose info check
  11775. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11776. {
  11777. FILE *fp;
  11778. char dataLine[4096]={0};
  11779. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11780. if(SetProfileReq.ConnectorId != 0)
  11781. {
  11782. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11783. goto end;
  11784. }
  11785. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11786. if (!fp)
  11787. {
  11788. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11789. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11790. }
  11791. else
  11792. {
  11793. while(fscanf(fp, "%s", dataLine) != EOF)
  11794. {
  11795. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11796. {
  11797. profileQuantity += 1;
  11798. }
  11799. }
  11800. }
  11801. fclose(fp);
  11802. }
  11803. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11804. {
  11805. FILE *fp;
  11806. char dataLine[4096]={0};
  11807. char filename[128]={0};
  11808. int tmpProfileQuantity;
  11809. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11810. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11811. {
  11812. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11813. goto end;
  11814. }
  11815. if(SetProfileReq.ConnectorId == 0)
  11816. {
  11817. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11818. {
  11819. tmpProfileQuantity = 0;
  11820. memset(filename, 0, ARRAY_SIZE(filename));
  11821. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11822. fp = fopen(filename, "r");
  11823. if (!fp)
  11824. {
  11825. DEBUG_INFO("%s does not create.\n", filename);
  11826. fp = fopen(filename, "w+");
  11827. }
  11828. else
  11829. {
  11830. while(fscanf(fp, "%s", dataLine) != EOF)
  11831. {
  11832. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11833. {
  11834. tmpProfileQuantity += 1;
  11835. }
  11836. }
  11837. }
  11838. fclose(fp);
  11839. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11840. }
  11841. }
  11842. else
  11843. {
  11844. memset(filename, 0, ARRAY_SIZE(filename));
  11845. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11846. fp = fopen(filename, "r");
  11847. if (!fp)
  11848. {
  11849. DEBUG_INFO("%s does not create.\n", filename);
  11850. fp = fopen(filename, "w+");
  11851. }
  11852. else
  11853. {
  11854. while(fscanf(fp, "%s", dataLine) != EOF)
  11855. {
  11856. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11857. {
  11858. profileQuantity += 1;
  11859. }
  11860. }
  11861. }
  11862. fclose(fp);
  11863. }
  11864. }
  11865. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11866. {
  11867. int isMatchTransactiodId= FALSE;
  11868. FILE *fp;
  11869. char dataLine[4096]={0};
  11870. char filename[128]={0};
  11871. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11872. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11873. if(SetProfileReq.ConnectorId == 0)
  11874. {
  11875. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11876. goto end;
  11877. }
  11878. int tempIndex = 0;
  11879. //check Transaction active
  11880. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11881. {
  11882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11883. {
  11884. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11885. }
  11886. else
  11887. {
  11888. tempIndex = SetProfileReq.ConnectorId -1;
  11889. }
  11890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11891. {
  11892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11893. {
  11894. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11895. {
  11896. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11897. {
  11898. isMatchTransactiodId = TRUE;
  11899. break;
  11900. }
  11901. }
  11902. }
  11903. }
  11904. }
  11905. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11906. {
  11907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11908. {
  11909. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11910. }
  11911. else
  11912. {
  11913. tempIndex = SetProfileReq.ConnectorId -1;
  11914. }
  11915. for (int index = 0; index < CCS_QUANTITY; index++)
  11916. {
  11917. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11918. {
  11919. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11920. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11921. {
  11922. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11923. {
  11924. isMatchTransactiodId = TRUE;
  11925. break;
  11926. }
  11927. }
  11928. }
  11929. }
  11930. }
  11931. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11932. {
  11933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11934. {
  11935. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11936. }
  11937. else
  11938. {
  11939. tempIndex = SetProfileReq.ConnectorId -1;
  11940. }
  11941. for (int index = 0; index < GB_QUANTITY; index++)
  11942. {
  11943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11944. {
  11945. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11946. {
  11947. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11948. {
  11949. isMatchTransactiodId = TRUE;
  11950. break;
  11951. }
  11952. }
  11953. }
  11954. }
  11955. }
  11956. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11957. {
  11958. tempIndex = SetProfileReq.ConnectorId -1;
  11959. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11960. {
  11961. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11962. {
  11963. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11964. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11965. {
  11966. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11967. {
  11968. isMatchTransactiodId = TRUE;
  11969. break;
  11970. }
  11971. }
  11972. }
  11973. }
  11974. }
  11975. else
  11976. {
  11977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11978. {
  11979. tempIndex = 2;
  11980. }
  11981. else
  11982. {
  11983. tempIndex = (SetProfileReq.ConnectorId -1);
  11984. }
  11985. for (int index = 0; index < AC_QUANTITY; index++)
  11986. {
  11987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11988. {
  11989. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11990. {
  11991. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11992. {
  11993. isMatchTransactiodId = TRUE;
  11994. break;
  11995. }
  11996. }
  11997. }
  11998. }
  11999. }
  12000. //check Transaction active
  12001. if(isMatchTransactiodId == FALSE)
  12002. {
  12003. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12004. goto end;
  12005. }
  12006. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12007. {
  12008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12009. goto end;
  12010. }
  12011. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12012. fp = fopen(filename, "r");
  12013. if (!fp)
  12014. {
  12015. DEBUG_INFO("%s does not create.\n", filename);
  12016. fp = fopen(filename, "w+");
  12017. }
  12018. else
  12019. {
  12020. //Check Charging Profile Count
  12021. while(fscanf(fp, "%s", dataLine) != EOF)
  12022. {
  12023. //DEBUG_INFO("word=%s\n",word);
  12024. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12025. {
  12026. profileQuantity += 1;
  12027. }
  12028. }
  12029. }
  12030. fclose(fp);
  12031. }
  12032. // Check ChargeProfileMaxStackLevel
  12033. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12034. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12035. {
  12036. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12037. goto end;
  12038. }
  12039. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12040. {
  12041. FILE *fp;
  12042. char dataLine[4096]={0};
  12043. char fnametemp[128]={0};
  12044. int tmpProfileQuantity;
  12045. //Check ChargePointMaxProfile.json exit
  12046. profileQuantity = 0;
  12047. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12048. {
  12049. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12050. //Check Charging Profile Count
  12051. tmpProfileQuantity = 0;
  12052. while(fscanf(fp, "%s", dataLine) != EOF)
  12053. {
  12054. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12055. {
  12056. profileQuantity += 1;
  12057. tmpProfileQuantity += 1;
  12058. }
  12059. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12060. }
  12061. fclose(fp);
  12062. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12063. }
  12064. //Check TxDefaultProfile_%d.json
  12065. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12066. {
  12067. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12068. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12069. if((access(fnametemp,F_OK))!=-1)
  12070. {
  12071. fp = fopen(fnametemp, "r");
  12072. //Check Charging Profile Count
  12073. tmpProfileQuantity = 0;
  12074. while(fscanf(fp, "%s", dataLine) != EOF)
  12075. {
  12076. //DEBUG_INFO("word=%s\n",word);
  12077. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12078. {
  12079. profileQuantity += 1;
  12080. tmpProfileQuantity += 1;
  12081. }
  12082. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12083. }
  12084. fclose(fp);
  12085. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12086. }
  12087. }
  12088. //Check TxProfile_%d.json
  12089. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12090. {
  12091. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12092. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12093. if((access(fnametemp,F_OK))!=-1)
  12094. {
  12095. fp = fopen(fnametemp, "r");
  12096. //Check Charging Profile Count
  12097. tmpProfileQuantity = 0;
  12098. while(fscanf(fp, "%s", dataLine) != EOF)
  12099. {
  12100. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12101. {
  12102. profileQuantity += 1;
  12103. tmpProfileQuantity += 1;
  12104. }
  12105. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12106. }
  12107. fclose(fp);
  12108. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12109. }
  12110. }
  12111. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12112. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12113. {
  12114. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12115. goto end;
  12116. }
  12117. }
  12118. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12119. //**********************************Write to File********************************************************/
  12120. {
  12121. FILE *infile;
  12122. FILE *outfile;
  12123. char dataLine[4096]={0};
  12124. char filename[128]={0};
  12125. int chkChar=0;
  12126. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12127. {
  12128. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12129. {
  12130. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12131. }
  12132. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12133. {
  12134. if(SetProfileReq.ConnectorId==0)
  12135. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12136. else
  12137. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12138. }
  12139. else
  12140. {
  12141. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12142. }
  12143. infile = fopen (filename, "r");
  12144. outfile = fopen (tempfile, "w");
  12145. chkChar = fgetc(infile);
  12146. rewind(infile);
  12147. if(chkChar == EOF)
  12148. {
  12149. // Profile is empty
  12150. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12151. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12152. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12153. fclose(infile);
  12154. fclose(outfile);
  12155. sprintf(rmFileCmd,"rm -f %s",filename);
  12156. system(rmFileCmd);
  12157. rename(tempfile, filename);
  12158. }
  12159. else
  12160. {
  12161. // Profile is not empty
  12162. int ChargingProfileAdded = FALSE;
  12163. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12164. {
  12165. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12166. json_object *tmpChargingProfile;
  12167. tmpChargingProfile = json_tokener_parse(dataLine);
  12168. if(!is_error(SetChargingProfile))
  12169. {
  12170. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12171. {
  12172. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12173. {
  12174. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12175. }
  12176. }
  12177. }
  12178. json_object_put(tmpChargingProfile);
  12179. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12180. {
  12181. if(ChargingProfileAdded == FALSE)
  12182. {
  12183. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12184. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12185. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12186. ChargingProfileAdded = TRUE;
  12187. }
  12188. }
  12189. else
  12190. {
  12191. fprintf(outfile,"%s\n",dataLine);
  12192. if(ChargingProfileAdded == FALSE)
  12193. {
  12194. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12195. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12196. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12197. ChargingProfileAdded = TRUE;
  12198. }
  12199. }
  12200. } // end of while loop
  12201. fclose(infile);
  12202. fclose(outfile);
  12203. sprintf(rmFileCmd,"rm -f %s",filename);
  12204. system(rmFileCmd);
  12205. rename(tempfile, filename);
  12206. }
  12207. }
  12208. sleep(1);
  12209. result = TRUE;
  12210. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12211. }
  12212. end:
  12213. json_object_put(SetChargingProfile);
  12214. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12215. {
  12216. if(SetProfileReq.ConnectorId == 0)
  12217. {
  12218. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12219. {
  12220. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12221. }
  12222. }
  12223. else
  12224. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12225. }
  12226. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12227. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12228. return result;
  12229. }
  12230. int handleTriggerMessageRequest(char *uuid, char *payload)
  12231. {
  12232. mtrace();
  12233. int result = FAIL;
  12234. int connectorIdIsNULL = FALSE;
  12235. int connectorIdInt =0;
  12236. char sstr[40]={0},sstrtemp[100]={ 0 };
  12237. char requestedMessagestr[40]={0};
  12238. char comfirmstr[20]={0};
  12239. int c = 0;
  12240. char *loc;
  12241. DEBUG_INFO("handleTriggerMessageRequest\n");
  12242. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12243. strcpy(sstrtemp, stringtrimspace(payload));
  12244. c = 0;
  12245. loc = strstr(sstrtemp, "requestedMessage");
  12246. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12247. {
  12248. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12249. c++;
  12250. }
  12251. sstr[c] = '\0';
  12252. strcpy(requestedMessagestr, sstr);
  12253. c = 0;
  12254. loc = strstr(sstrtemp, "connectorId");
  12255. if(loc == NULL)
  12256. {
  12257. connectorIdIsNULL = TRUE;
  12258. }
  12259. else
  12260. {
  12261. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12262. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12263. {
  12264. sstr[c] = loc[strlen("connectorId")+2+c];
  12265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12266. c++;
  12267. }
  12268. sstr[c] = '\0';
  12269. connectorIdInt = atoi(sstr);
  12270. }
  12271. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12272. {
  12273. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12274. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12275. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12276. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12277. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12278. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12279. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12280. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12281. {
  12282. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12283. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12284. return TRUE;
  12285. }
  12286. else
  12287. {
  12288. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12289. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12290. }
  12291. }
  12292. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12293. {
  12294. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12295. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12296. return TRUE;
  12297. }
  12298. //==========================
  12299. // Trigger message
  12300. //==========================
  12301. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12302. {
  12303. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12304. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12305. {
  12306. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12307. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12308. }
  12309. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12310. }
  12311. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12312. {
  12313. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12314. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12315. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12316. }
  12317. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12318. {
  12319. //sendBootNotificationRequest();
  12320. server_sign = FALSE;
  12321. }
  12322. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12323. {
  12324. refreshStartTimer(&clientTime.Heartbeat);
  12325. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12326. }
  12327. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12328. {
  12329. if(connectorIdIsNULL == FALSE)
  12330. {
  12331. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12332. {
  12333. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12334. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12335. }
  12336. }
  12337. else
  12338. {
  12339. for(int idx=0;idx< gunTotalNumber;idx++)
  12340. {
  12341. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12342. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12343. }
  12344. }
  12345. }
  12346. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12347. {
  12348. if(connectorIdIsNULL == FALSE)
  12349. {
  12350. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12351. {
  12352. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12353. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12354. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12355. }
  12356. }
  12357. else
  12358. {
  12359. for(int idx=0;idx< gunTotalNumber;idx++)
  12360. {
  12361. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12362. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12363. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12364. }
  12365. }
  12366. }
  12367. return result;
  12368. }
  12369. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12370. {
  12371. mtrace();
  12372. int result = FAIL;
  12373. int connectorIdInt =0;
  12374. char comfirmstr[20]={0};
  12375. int tempIndex = 0;
  12376. json_object *UnlockConnector;
  12377. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12378. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12379. UnlockConnector = json_tokener_parse(payload);
  12380. if(!is_error(UnlockConnector))
  12381. {
  12382. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12383. {
  12384. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12385. }
  12386. }
  12387. json_object_put(UnlockConnector);
  12388. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12389. if(gunTotalNumber == 0)
  12390. {
  12391. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12392. goto end;
  12393. }
  12394. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12395. {
  12396. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12397. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12398. goto end;
  12399. }
  12400. else
  12401. {
  12402. //check Transaction active
  12403. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12404. {
  12405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12406. {
  12407. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12408. }
  12409. else
  12410. {
  12411. tempIndex = connectorIdInt -1;
  12412. }
  12413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12414. {
  12415. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12416. {
  12417. //stop Transaction
  12418. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12419. }
  12420. }
  12421. }
  12422. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12423. {
  12424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12425. {
  12426. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12427. }
  12428. else
  12429. {
  12430. tempIndex = connectorIdInt -1;
  12431. }
  12432. for (int index = 0; index < CCS_QUANTITY; index++)
  12433. {
  12434. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12435. {
  12436. //stop Transaction
  12437. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12438. }
  12439. }
  12440. }
  12441. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12442. {
  12443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12444. {
  12445. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12446. }
  12447. else
  12448. {
  12449. tempIndex = connectorIdInt -1;
  12450. }
  12451. for (int index = 0; index < GB_QUANTITY; index++)
  12452. {
  12453. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12454. {
  12455. //stop Transaction
  12456. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12457. }
  12458. }
  12459. }
  12460. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12461. {
  12462. tempIndex = connectorIdInt -1;
  12463. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12464. {
  12465. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12466. {
  12467. //stop Transaction
  12468. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12469. }
  12470. }
  12471. }
  12472. else
  12473. {
  12474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12475. {
  12476. tempIndex = 2;
  12477. }
  12478. else
  12479. {
  12480. tempIndex = connectorIdInt-1;
  12481. }
  12482. for (int index = 0; index < AC_QUANTITY; index++)
  12483. {
  12484. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12485. {
  12486. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12487. }
  12488. }
  12489. }
  12490. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12491. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12492. result = TRUE;
  12493. return result;
  12494. }
  12495. end:
  12496. //json_object_put(obj); --- remove temporally
  12497. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12498. return result;
  12499. }
  12500. static char UpdateFirmwarepayloadData[300]={0};
  12501. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12502. {
  12503. mtrace();
  12504. int result = FAIL;
  12505. pthread_t t;
  12506. sendUpdateFirmwareConfirmation(uuid);
  12507. memset(UpdateFirmwarepayloadData, 0, 300);
  12508. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12509. if(!interLock.isUpdateFirmwareGoing)
  12510. {
  12511. interLock.isUpdateFirmwareGoing = 1;
  12512. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12513. sleep(1);
  12514. }
  12515. else
  12516. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12517. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12518. return result;
  12519. }
  12520. void *UpdateFirmwareProcess(void *data)
  12521. {
  12522. pthread_detach(pthread_self());
  12523. mtrace();
  12524. int retriesInt =0, retryIntervalInt=0;
  12525. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12526. int port=0;
  12527. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12528. int isSuccess = 0;
  12529. char ftpbuf[512];
  12530. char temp[100];
  12531. char * pch;
  12532. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12533. json_object *UpdateFirmware;
  12534. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12535. if(!is_error(UpdateFirmware))
  12536. {
  12537. // Required data
  12538. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12539. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12540. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12541. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12542. // Optional data
  12543. if(json_object_object_get(UpdateFirmware, "retries"))
  12544. {
  12545. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12546. }
  12547. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12548. {
  12549. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12550. }
  12551. }
  12552. json_object_put(UpdateFirmware);
  12553. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12554. memset(path, 0, ARRAY_SIZE(path));
  12555. // Wait retrieveData
  12556. if(strlen(retrieveDatestr) > 10)
  12557. {
  12558. do
  12559. {
  12560. sleep(1);
  12561. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12562. }
  12563. // Ready to download
  12564. system("rm -f /mnt/*");
  12565. if(strncmp(locationstr,"http", 4) == 0)
  12566. {
  12567. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12568. sprintf(ftppath,"/%s", path);
  12569. DEBUG_INFO("locationstr: %s\n", locationstr);
  12570. DEBUG_INFO("protocol: %s\n",protocol);
  12571. DEBUG_INFO("host: %s\n",host);
  12572. DEBUG_INFO("path: %s\n",path);
  12573. DEBUG_INFO("ftppath: %s\n",ftppath);
  12574. int ftppathlen=strlen(ftppath);
  12575. int i=1;
  12576. char filenametemp[50];
  12577. while(i < ftppathlen)
  12578. {
  12579. int len=ftppathlen-i;
  12580. if(ftppath[len]== 47) // '/' ascll code: 47
  12581. {
  12582. DEBUG_INFO("compare '/' all right\n");
  12583. break;
  12584. }
  12585. i=i+1;
  12586. }
  12587. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12588. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12589. filenametemp[i+1] = 0;
  12590. do
  12591. {
  12592. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12593. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12594. sleep(1);
  12595. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12596. if(!isSuccess)
  12597. {
  12598. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12599. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12600. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12601. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12602. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12603. }
  12604. else
  12605. {
  12606. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12607. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12608. }
  12609. retriesInt--;
  12610. }while((isSuccess == 0)&&(retriesInt >= 0));
  12611. }
  12612. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12613. {
  12614. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12615. memset(temp, 0, ARRAY_SIZE(temp));
  12616. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12617. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12618. int ftppathlen=strlen(ftpbuf);
  12619. int i=1;
  12620. char filenametemp[50];
  12621. while(i < ftppathlen)
  12622. {
  12623. int len=ftppathlen-i;
  12624. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12625. {
  12626. DEBUG_INFO(" compare '/' all right\n");
  12627. break;
  12628. }
  12629. i=i+1;
  12630. }
  12631. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12632. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12633. filenametemp[i+1] = 0;
  12634. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12635. pch=strchr(temp,'@');
  12636. if(pch==NULL)
  12637. {
  12638. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12639. protocol, host, &port, path);
  12640. strcpy(user,"anonymous");
  12641. strcpy(password,"");
  12642. }
  12643. else
  12644. {
  12645. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12646. protocol, user, password, host, &port, path);
  12647. }
  12648. sscanf(host,"%[^/]%s",host1, path1);
  12649. sprintf(ftppath,"%s", path1);
  12650. //DEBUG_INFO("protocol =%s\n",protocol);
  12651. //DEBUG_INFO("user =%s\n",user);
  12652. //DEBUG_INFO("password =%s\n",password);
  12653. //DEBUG_INFO("host1 =%s\n",host1);
  12654. //DEBUG_INFO("port =%d\n",port);
  12655. //DEBUG_INFO("path1 =%s\n",path1);
  12656. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12657. //ftpFile(host, user, password, port, ftppath, fname);
  12658. //download firmware pthred
  12659. if(port == 0)
  12660. {
  12661. port = 21;
  12662. }
  12663. do
  12664. {
  12665. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12666. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12667. sleep(1);
  12668. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12669. if(!isSuccess)
  12670. {
  12671. //BulldogUtil.sleepMs(interval*1000);
  12672. DEBUG_INFO("Update firmware request and download file fail.\n");
  12673. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12674. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12675. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12676. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12677. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12678. }
  12679. else
  12680. {
  12681. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12682. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12683. }
  12684. retriesInt--;
  12685. }while((!isSuccess)&&(retriesInt >= 0));
  12686. }
  12687. else
  12688. {
  12689. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12690. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12691. sleep(1);
  12692. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12693. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12694. }
  12695. // OCPPPH only, must announce CSU upgrade firmware
  12696. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12697. interLock.isUpdateFirmwareGoing = 0;
  12698. pthread_exit(NULL);
  12699. }
  12700. int handleCertificateSignedRequest(char *uuid, char *payload)
  12701. {
  12702. mtrace();
  12703. int result = PASS;
  12704. json_object *CertificateSigned;
  12705. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12706. CertificateSigned = json_tokener_parse(payload);
  12707. if(!is_error(CertificateSigned))
  12708. {
  12709. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12710. }
  12711. json_object_put(CertificateSigned);
  12712. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12713. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12714. fclose(fp);
  12715. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12716. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12717. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12718. sendCertificateSignedConfirmation(uuid);
  12719. return result;
  12720. }
  12721. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12722. {
  12723. mtrace();
  12724. int result = PASS;
  12725. json_object *DeleteCertificate;
  12726. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12727. DeleteCertificate = json_tokener_parse(payload);
  12728. if(!is_error(DeleteCertificate))
  12729. {
  12730. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12731. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12732. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12733. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12734. }
  12735. json_object_put(DeleteCertificate);
  12736. /*
  12737. * TODO: Delete certificateSigned process
  12738. */
  12739. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12740. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12741. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12742. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12743. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12744. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12745. sendDeleteCertificateConfirmation(uuid);
  12746. return result;
  12747. }
  12748. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12749. {
  12750. mtrace();
  12751. int result = PASS;
  12752. json_object *ExtendedTriggerMessage;
  12753. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12754. ExtendedTriggerMessage = json_tokener_parse(payload);
  12755. if(!is_error(ExtendedTriggerMessage))
  12756. {
  12757. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12758. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12759. {
  12760. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12761. }
  12762. else
  12763. {
  12764. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12765. }
  12766. }
  12767. json_object_put(ExtendedTriggerMessage);
  12768. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12769. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12770. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12771. {
  12772. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12773. }
  12774. else
  12775. {
  12776. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12777. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12778. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12779. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12780. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12781. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12782. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12783. {
  12784. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12785. }
  12786. else
  12787. {
  12788. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12789. }
  12790. }
  12791. sendExtendedTriggerMessageConfirmation(uuid);
  12792. //==========================
  12793. // Trigger message
  12794. //==========================
  12795. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12796. {
  12797. //sendBootNotificationRequest();
  12798. server_sign = FALSE;
  12799. }
  12800. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12801. {
  12802. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12803. }
  12804. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12805. {
  12806. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12807. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12808. {
  12809. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12810. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12811. }
  12812. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12813. }
  12814. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12815. {
  12816. refreshStartTimer(&clientTime.Heartbeat);
  12817. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12818. }
  12819. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12820. {
  12821. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12822. {
  12823. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12824. }
  12825. else
  12826. {
  12827. for(int idx=0;idx< gunTotalNumber;idx++)
  12828. {
  12829. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12830. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12831. }
  12832. }
  12833. }
  12834. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12835. {
  12836. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12837. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12838. {
  12839. 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\" &");
  12840. }
  12841. }
  12842. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12843. {
  12844. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12845. {
  12846. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12847. }
  12848. else
  12849. {
  12850. for(int idx=0;idx< gunTotalNumber;idx++)
  12851. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12852. }
  12853. }
  12854. return result;
  12855. }
  12856. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12857. {
  12858. mtrace();
  12859. int result = PASS;
  12860. json_object *GetInstalledCertificateIds;
  12861. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12862. GetInstalledCertificateIds = json_tokener_parse(payload);
  12863. if(!is_error(GetInstalledCertificateIds))
  12864. {
  12865. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12866. }
  12867. json_object_put(GetInstalledCertificateIds);
  12868. /*
  12869. * TODO: Return installed certificate process
  12870. */
  12871. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12872. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12873. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12874. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12875. sendGetInstalledCertificateIdsConfirmation(uuid);
  12876. return result;
  12877. }
  12878. int handleGetLogRequest(char *uuid, char *payload)
  12879. {
  12880. mtrace();
  12881. int result = PASS;
  12882. json_object *GetLog;
  12883. DEBUG_INFO("handleGetLogRequest...\n");
  12884. GetLog = json_tokener_parse(payload);
  12885. if(!is_error(GetLog))
  12886. {
  12887. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12888. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12889. if(json_object_object_get(GetLog, "retries") != NULL)
  12890. {
  12891. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12892. }
  12893. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12894. {
  12895. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12896. }
  12897. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12898. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12899. {
  12900. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12901. }
  12902. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12903. {
  12904. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12905. }
  12906. }
  12907. json_object_put(GetLog);
  12908. /*
  12909. * TODO: Upload log process
  12910. */
  12911. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12912. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12913. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12914. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12915. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12916. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12917. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12918. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12919. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12920. sendGetLogConfirmation(uuid);
  12921. return result;
  12922. }
  12923. int handleInstallCertificateRequest(char *uuid, char *payload)
  12924. {
  12925. mtrace();
  12926. int result = PASS;
  12927. json_object *InstallCertificate;
  12928. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12929. InstallCertificate = json_tokener_parse(payload);
  12930. if(!is_error(InstallCertificate))
  12931. {
  12932. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12933. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12934. /*
  12935. * TODO: Install certificate process
  12936. */
  12937. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12938. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12939. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12940. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12941. sendInstallCertificateConfirmation(uuid);
  12942. }
  12943. json_object_put(InstallCertificate);
  12944. return result;
  12945. }
  12946. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12947. {
  12948. mtrace();
  12949. int result = PASS;
  12950. json_object *SignedUpdateFirmware;
  12951. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12952. SignedUpdateFirmware = json_tokener_parse(payload);
  12953. if(!is_error(SignedUpdateFirmware))
  12954. {
  12955. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12956. {
  12957. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12958. }
  12959. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12960. {
  12961. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12962. }
  12963. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12964. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12965. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12966. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12967. {
  12968. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12969. }
  12970. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12971. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12972. }
  12973. json_object_put(SignedUpdateFirmware);
  12974. /*
  12975. * TODO: Upgrade firmware process
  12976. */
  12977. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12978. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12979. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12980. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12981. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12982. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12983. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12984. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12985. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12986. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12987. sendInstallCertificateConfirmation(uuid);
  12988. return result;
  12989. }
  12990. int handleUnknownRequest(char *uuid, char *payload)
  12991. {
  12992. mtrace();
  12993. int result = PASS;
  12994. DEBUG_INFO("handleUnknownRequest...\n");
  12995. sendUnknownConfirmation(uuid);
  12996. result = PASS;
  12997. return result;
  12998. }
  12999. //==========================================
  13000. // Handle server response routine
  13001. //==========================================
  13002. void handleAuthorizeResponse(char *payload, int gun_index)
  13003. {
  13004. mtrace();
  13005. char expiryDatestr[30]={0};
  13006. char parentIdTagstr[20]={0};
  13007. char statusstr[20]={0};
  13008. int expiryDateISNULL=FALSE;
  13009. int parentIdTagISNULL=FALSE;
  13010. DEBUG_INFO("handleAuthorizeResponse...\n");
  13011. json_object *Authorize;
  13012. Authorize = json_tokener_parse(payload);
  13013. if(!is_error(Authorize))
  13014. {
  13015. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13016. {
  13017. // Required data
  13018. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13019. // Optional data
  13020. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13021. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13022. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13023. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13024. }
  13025. }
  13026. json_object_put(Authorize);
  13027. if(expiryDateISNULL == FALSE)
  13028. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13029. if(parentIdTagISNULL == FALSE)
  13030. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13031. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13032. //Update idTag information to authorization cache if supproted
  13033. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13034. {
  13035. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13036. }
  13037. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13038. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13039. authorizeRetryTimes = 0;
  13040. }
  13041. void handleBootNotificationResponse(char *payload, int gun_index)
  13042. {
  13043. mtrace();
  13044. char statusStr[12]={0};
  13045. char currentTimeStr[30]={0};
  13046. int intervalInt = 0;
  13047. DEBUG_INFO("handleBootNotificationResponse...\n");
  13048. json_object *BootNotification;
  13049. BootNotification = json_tokener_parse(payload);
  13050. if(!is_error(BootNotification))
  13051. {
  13052. // Required data
  13053. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13054. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13055. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13056. }
  13057. json_object_put(BootNotification);
  13058. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13059. BootNotificationInterval = intervalInt;
  13060. HeartBeatWaitTime = intervalInt;
  13061. //write back to ShmOCPP16DataPH->BootNotification
  13062. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13063. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13064. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13065. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13066. {
  13067. if((intervalInt == 0) || (intervalInt >= 10))
  13068. {
  13069. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13070. HeartBeatWaitTime = intervalInt;
  13071. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13072. }
  13073. server_sign = TRUE;
  13074. server_pending =FALSE;
  13075. }
  13076. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13077. {
  13078. server_pending = TRUE;
  13079. }
  13080. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13081. srand(time(NULL));
  13082. refreshStartTimer(&clientTime.Heartbeat);
  13083. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13084. SetOcppConnStatus(TRUE);
  13085. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13086. }
  13087. void handleDataTransferResponse(char *payload, int gun_index)
  13088. {
  13089. json_object *DataTransfer = json_tokener_parse(payload);
  13090. char status[32];
  13091. if(!is_error(DataTransfer))
  13092. {
  13093. // Required data
  13094. sprintf(status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13095. DEBUG_INFO("Status: %s.\n", status);
  13096. // Optional data
  13097. if(json_object_object_get(DataTransfer, "data") != NULL)
  13098. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13099. // YES call_reader message confirm
  13100. if(ShmOCPP16DataPH->YesCustomData.CallReaderReq == 1)
  13101. {
  13102. sprintf((char *)ShmOCPP16DataPH->YesCustomData.CallReaderStatus, "%s",status);
  13103. ShmOCPP16DataPH->YesCustomData.CallReaderConf = 1;
  13104. ShmOCPP16DataPH->YesCustomData.CallReaderReq = 0;
  13105. DEBUG_INFO("Report CallReader status to CSU: %s\n",ShmOCPP16DataPH->YesCustomData.CallReaderStatus);
  13106. }
  13107. }
  13108. }
  13109. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13110. {
  13111. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13112. //struct json_object *obj;
  13113. // obj = json_tokener_parse(payload);
  13114. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13115. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13116. //No fields are defined.
  13117. }
  13118. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13119. {
  13120. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13121. //struct json_object *obj;
  13122. // obj = json_tokener_parse(payload);
  13123. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13124. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13125. //No fields are defined.
  13126. }
  13127. void handleHeartbeatResponse(char *payload, int gun_index)
  13128. {
  13129. mtrace();
  13130. DEBUG_INFO("handleHeartbeatResponse...\n");
  13131. json_object *Heartbeat;
  13132. Heartbeat = json_tokener_parse(payload);
  13133. if(!is_error(Heartbeat))
  13134. {
  13135. // Required data
  13136. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13137. }
  13138. json_object_put(Heartbeat);
  13139. if(FirstHeartBeat == 0)
  13140. {
  13141. FirstHeartBeat = 1;
  13142. DEBUG_INFO("FirstHeartBeat \n");
  13143. }
  13144. HeartBeatWithNOResponse = 0;
  13145. refreshStartTimer(&clientTime.Heartbeat);
  13146. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13147. }
  13148. void handleMeterValuesResponse(char *payload, int gun_index)
  13149. {
  13150. mtrace();
  13151. DEBUG_INFO("handleMeterValuesResponse...\n");
  13152. isQueueSendable = 1;
  13153. }
  13154. void handleStartTransactionResponse(char *payload, int gun_index)
  13155. {
  13156. mtrace();
  13157. //int transactionIdInt = 0;
  13158. FILE *outfile;
  13159. char data[100]={0};
  13160. DEBUG_INFO("handleStartTransactionResponse...\n");
  13161. json_object *StartTransaction;
  13162. StartTransaction = json_tokener_parse(payload);
  13163. if(!is_error(StartTransaction))
  13164. {
  13165. // Required data
  13166. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13167. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13168. // Optional data
  13169. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13170. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13171. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13172. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13173. }
  13174. json_object_put(StartTransaction);
  13175. isQueueSendable = 1;
  13176. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13177. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13178. //-----------Start : write to the Queue TransactionId file -----------------//
  13179. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13180. {}
  13181. else
  13182. {
  13183. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13184. if(log == NULL)
  13185. {
  13186. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13187. return ;
  13188. }
  13189. else
  13190. {
  13191. fclose(log);
  13192. }
  13193. }
  13194. // open file for writing
  13195. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13196. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13197. {
  13198. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13199. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13200. fputs(data, outfile);
  13201. fclose (outfile);
  13202. }
  13203. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13204. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13205. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13206. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13207. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13208. }
  13209. void handleStatusNotificationResponse(char *payload, int gun_index)
  13210. {
  13211. mtrace();
  13212. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13213. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13214. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13215. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13216. }
  13217. void handleStopTransactionnResponse(char *payload, int gun_index)
  13218. {
  13219. mtrace();
  13220. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13221. json_object *StopTransaction;
  13222. StopTransaction = json_tokener_parse(payload);
  13223. if(!is_error(StopTransaction))
  13224. {
  13225. // Optional data
  13226. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13227. {
  13228. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13229. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13230. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13231. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13232. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13233. }
  13234. }
  13235. json_object_put(StopTransaction);
  13236. isQueueSendable = 1;
  13237. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13238. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13239. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13240. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13241. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13242. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13243. }
  13244. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13245. {
  13246. mtrace();
  13247. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13248. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13249. }
  13250. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13251. {
  13252. mtrace();
  13253. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13254. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13255. }
  13256. void handleSignCertificateResponse(char *payload, int gun_index)
  13257. {
  13258. mtrace();
  13259. DEBUG_INFO("handleSignCertificateResponse...\n");
  13260. json_object *SignCertificate;
  13261. SignCertificate = json_tokener_parse(payload);
  13262. if(!is_error(SignCertificate))
  13263. {
  13264. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13265. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13266. }
  13267. json_object_put(SignCertificate);
  13268. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13269. }
  13270. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13271. {
  13272. mtrace();
  13273. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13274. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13275. }
  13276. //==========================================
  13277. // Handle Error routine
  13278. //==========================================
  13279. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13280. {
  13281. mtrace();
  13282. #ifdef SystemLogMessage
  13283. DEBUG_INFO("errorCode: %s\n", errorCode);
  13284. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13285. DEBUG_INFO("errorDetails: %s\n", payload);
  13286. #endif
  13287. }
  13288. //===============================================
  13289. // Common routine
  13290. //===============================================
  13291. int initialConfigurationTable(void)
  13292. {
  13293. //clock_t start_t, end_t, total_t;
  13294. FILE *fp;
  13295. FILE *outfile;
  13296. char str[512]={0};
  13297. char sstr[256]={0};
  13298. int c = 0;
  13299. char *loc;
  13300. int confVersion = 12;
  13301. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13302. //start_t = clock();
  13303. //printf("Starting of the program, start_t = %ld\n", start_t);
  13304. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13305. // Check configuration file size is correct
  13306. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13307. {
  13308. struct stat st;
  13309. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13310. if(st.st_size < 3100)
  13311. {
  13312. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13313. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13314. }
  13315. }
  13316. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13317. {
  13318. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13319. if(outfile == NULL)
  13320. {
  13321. DEBUG_INFO("Error opening file\n");
  13322. return FALSE;
  13323. }
  13324. /*Core Profile*/
  13325. //AllowOfflineTxForUnknownId
  13326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13330. //AuthorizationCacheEnabled
  13331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13335. //AuthorizeRemoteTxRequests
  13336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13340. //BlinkRepeat
  13341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13345. //ClockAlignedDataInterval
  13346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13350. //ConnectionTimeOut
  13351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13355. //GetConfigurationMaxKeys
  13356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13358. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13360. // HeartbeatInterval
  13361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13365. // LightIntensity
  13366. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13370. // LocalAuthorizeOffline
  13371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13375. // LocalPreAuthorize
  13376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13380. // MaxEnergyOnInvalidId
  13381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13385. // MeterValuesAlignedData
  13386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13388. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13389. 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" );
  13390. else
  13391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13393. // MeterValuesAlignedDataMaxLength
  13394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13398. else
  13399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13401. // MeterValuesSampledData
  13402. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13405. 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" );
  13406. else
  13407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13409. // MeterValuesSampledDataMaxLength
  13410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13414. else
  13415. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13417. // MeterValueSampleInterval
  13418. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13420. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13422. // MinimumStatusDuration
  13423. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13426. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13428. // NumberOfConnectors
  13429. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13432. {
  13433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13434. }
  13435. else
  13436. {
  13437. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13438. }
  13439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13440. // ResetRetries
  13441. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13445. // ConnectorPhaseRotation
  13446. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13450. // ConnectorPhaseRotationMaxLength
  13451. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13453. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13455. // StopTransactionOnEVSideDisconnect
  13456. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13460. // StopTransactionOnInvalidId
  13461. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13465. // StopTxnAlignedData
  13466. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13468. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13470. // StopTxnAlignedDataMaxLength
  13471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13475. // StopTxnSampledData
  13476. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13479. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13480. else
  13481. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13483. // StopTxnSampledDataMaxLength
  13484. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13485. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13487. {
  13488. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13489. }
  13490. else
  13491. {
  13492. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13493. }
  13494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13495. // SupportedFeatureProfiles
  13496. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13497. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13500. // SupportedFeatureProfilesMaxLength
  13501. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13505. // TransactionMessageAttempts
  13506. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13507. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13509. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13511. // TransactionMessageRetryInterval
  13512. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13513. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13515. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13517. // UnlockConnectorOnEVSideDisconnect
  13518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13522. // WebSocketPingInterval
  13523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13524. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13525. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13527. // QueueOffLineMeterValues
  13528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13530. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13532. // AuthorizationKey
  13533. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13535. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13537. // SecurityProfile
  13538. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13539. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13542. // DefaultPrice
  13543. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13544. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13545. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13547. // CustomDisplayCostAndPrice
  13548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13552. // CustomIdleFeeAfterStop
  13553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13555. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13557. // SystemUptimeSec
  13558. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13560. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13562. // FreeVend
  13563. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13567. // OcppServer
  13568. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13570. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13572. // MaintainServer
  13573. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13575. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13577. // StatusNotificationPeriodically
  13578. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13579. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13582. // StatusNotificationInterval
  13583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13587. // Configuration Version
  13588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13592. //* Local Auth List Management Profile*/
  13593. #if 0
  13594. //For OCTT Test Case
  13595. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13598. #endif
  13599. #if 1
  13600. //LocalAuthListEnabled
  13601. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13605. #endif
  13606. //LocalAuthListMaxLength
  13607. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13611. //SendLocalListMaxLength
  13612. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13616. //ReserveConnectorZeroSupported
  13617. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13621. //* Smart Charging Profile */
  13622. //ChargeProfileMaxStackLevel
  13623. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13624. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13627. // ChargingScheduleAllowedChargingRateUnit
  13628. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13632. // ChargingScheduleMaxPeriods
  13633. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13637. // ConnectorSwitch3to1PhaseSupported
  13638. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13642. // MaxChargingProfilesInstalled
  13643. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13645. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13647. fclose(outfile);
  13648. }
  13649. else
  13650. {
  13651. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13652. char keystr[60]={0};
  13653. char readonlystr[10]={0};
  13654. char valuestr[256]={0};
  13655. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13656. if(fp == NULL) {
  13657. DEBUG_INFO("Error opening file");
  13658. return FALSE;
  13659. }
  13660. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13661. {
  13662. //DEBUG_INFO("Get Configuration \n");
  13663. if(strlen(str) > 0)
  13664. {
  13665. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13666. //*************************key*********************************/
  13667. if(strstr(str, "key") != NULL)
  13668. {
  13669. loc = strstr(str, "key");
  13670. c = 0;
  13671. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13672. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13673. {
  13674. sstr[c] = loc[strlen("key")+3+c];
  13675. c++;
  13676. }
  13677. sstr[c] = '\0';
  13678. strcpy(keystr,sstr);
  13679. }
  13680. //*************************readonly*********************************/
  13681. if(strstr(str, "readonly") != NULL)
  13682. {
  13683. loc = strstr(str, "readonly");
  13684. c = 0;
  13685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13686. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13687. {
  13688. sstr[c] = loc[strlen("readonly")+2+c];
  13689. c++;
  13690. }
  13691. sstr[c] = '\0';
  13692. strcpy(readonlystr,sstr);
  13693. }
  13694. //*************************value*********************************/
  13695. if(strstr(str, "value") != NULL)
  13696. {
  13697. loc = strstr(str, "value");
  13698. c = 0;
  13699. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13700. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13701. {
  13702. sstr[c] = loc[strlen("value")+3+c];
  13703. c++;
  13704. }
  13705. sstr[c] = '\0';
  13706. strcpy(valuestr,sstr);
  13707. }
  13708. // DEBUG_INFO("keystr=%s\n",keystr);
  13709. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13710. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13711. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13712. {
  13713. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13716. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13717. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13718. }
  13719. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13720. {
  13721. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13724. }
  13725. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13726. {
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13729. }
  13730. if(strcmp(keystr, "BlinkRepeat") == 0)
  13731. {
  13732. //Charger.BlinkRepeat = Integer.parseInt(value);
  13733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13735. }
  13736. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13737. {
  13738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13740. }
  13741. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13742. {
  13743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13745. }
  13746. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13747. {
  13748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13750. }
  13751. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13752. {
  13753. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13755. HeartBeatWaitTime = atoi(valuestr);
  13756. }
  13757. if(strcmp(keystr, "LightIntensity") == 0)
  13758. {
  13759. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13760. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13761. }
  13762. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13763. {
  13764. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13766. }
  13767. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13768. {
  13769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13770. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13771. }
  13772. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13773. {
  13774. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13775. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13776. }
  13777. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13778. {
  13779. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13780. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13781. }
  13782. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13783. {
  13784. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13786. }
  13787. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13788. {
  13789. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13790. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13791. }
  13792. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13793. {
  13794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13795. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13796. }
  13797. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13798. {
  13799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13800. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13801. }
  13802. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13803. {
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13806. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13807. }
  13808. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13809. {
  13810. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13811. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13812. }
  13813. if(strcmp(keystr, "ResetRetries") == 0)
  13814. {
  13815. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13816. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13817. }
  13818. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13819. {
  13820. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13821. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13822. }
  13823. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13824. {
  13825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13826. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13827. }
  13828. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13829. {
  13830. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13832. }
  13833. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13834. {
  13835. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13836. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13837. }
  13838. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13839. {
  13840. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13841. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13842. }
  13843. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13844. {
  13845. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13846. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13847. }
  13848. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13849. {
  13850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13851. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13852. }
  13853. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13854. {
  13855. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13857. }
  13858. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13859. {
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13862. }
  13863. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13864. {
  13865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13866. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13867. }
  13868. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13869. {
  13870. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13871. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13872. TransactionMessageAttemptsValue = atoi(valuestr);
  13873. }
  13874. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13875. {
  13876. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13877. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13878. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13879. }
  13880. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13881. {
  13882. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13883. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13884. }
  13885. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13886. {
  13887. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13888. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13889. }
  13890. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13891. {
  13892. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13894. }
  13895. if(strcmp(keystr, "AuthorizationKey") == 0)
  13896. {
  13897. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13898. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13900. }
  13901. if(strcmp(keystr, "SecurityProfile") == 0)
  13902. {
  13903. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13904. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13905. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13906. }
  13907. if(strcmp(keystr, "DefaultPrice") == 0)
  13908. {
  13909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13910. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13911. }
  13912. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13913. {
  13914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13915. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13916. }
  13917. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13918. {
  13919. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13920. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13921. }
  13922. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13923. {
  13924. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13925. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13926. }
  13927. if(strcmp(keystr, "FreeVend") == 0)
  13928. {
  13929. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13930. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13931. }
  13932. if(strcmp(keystr, "OcppServer") == 0)
  13933. {
  13934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13935. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13936. }
  13937. if(strcmp(keystr, "MaintainServer") == 0)
  13938. {
  13939. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13940. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13941. }
  13942. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13943. {
  13944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13945. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13946. }
  13947. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13948. {
  13949. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13950. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13951. }
  13952. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13953. {
  13954. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13955. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13956. }
  13957. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13958. {
  13959. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13960. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13961. }
  13962. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13963. {
  13964. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13965. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13966. }
  13967. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13968. {
  13969. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13970. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13971. }
  13972. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13973. {
  13974. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13975. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13976. }
  13977. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13978. {
  13979. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13980. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13981. }
  13982. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13983. {
  13984. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13985. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13986. }
  13987. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13988. {
  13989. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13990. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13991. }
  13992. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13993. {
  13994. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13996. }
  13997. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13998. {
  13999. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14000. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14001. }
  14002. }
  14003. }
  14004. fclose(fp);
  14005. }
  14006. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14007. {
  14008. return PASS;
  14009. }
  14010. else
  14011. {
  14012. return FAIL;
  14013. }
  14014. }
  14015. void StoreConfigurationTable(void)
  14016. {
  14017. FILE *outfile;
  14018. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14019. if(outfile == NULL)
  14020. {
  14021. DEBUG_INFO("Error opening file");
  14022. return ;
  14023. }
  14024. /*Core Profile*/
  14025. //AllowOfflineTxForUnknownId
  14026. /*
  14027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14028. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14031. */
  14032. //DEBUG_INFO("data=%s\n",data);
  14033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14034. //AuthorizationCacheEnabled
  14035. /*
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14039. */
  14040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14041. //AuthorizeRemoteTxRequests
  14042. /*
  14043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14046. */
  14047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14048. //BlinkRepeat
  14049. /*
  14050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14053. */
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14055. //ClockAlignedDataInterval
  14056. /*
  14057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14060. */
  14061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14062. //ConnectionTimeOut
  14063. /*
  14064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14067. */
  14068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14069. //GetConfigurationMaxKeys
  14070. /*
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14074. */
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14076. // HeartbeatInterval
  14077. /*
  14078. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14081. */
  14082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14083. // LightIntensity
  14084. /*
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14088. */
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14090. // LocalAuthorizeOffline
  14091. /*
  14092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14095. */
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14097. // LocalPreAuthorize
  14098. /*
  14099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14102. */
  14103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14104. // MaxEnergyOnInvalidId
  14105. /*
  14106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14109. */
  14110. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14112. // MeterValuesAlignedData
  14113. /*
  14114. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14117. */
  14118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14119. // MeterValuesAlignedDataMaxLength
  14120. /*
  14121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14124. */
  14125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14126. // MeterValuesSampledData
  14127. /*
  14128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14131. */
  14132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14133. // MeterValuesSampledDataMaxLength
  14134. /*
  14135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14138. */
  14139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14140. // MeterValueSampleInterval
  14141. /*
  14142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14145. */
  14146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14147. // MinimumStatusDuration
  14148. /*
  14149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14152. */
  14153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14154. // NumberOfConnectors
  14155. /*
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14159. {
  14160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14161. }
  14162. else
  14163. {
  14164. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14165. }
  14166. */
  14167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14168. // ResetRetries
  14169. /*
  14170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14173. */
  14174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14175. // ConnectorPhaseRotation
  14176. /*
  14177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14180. */
  14181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14182. // ConnectorPhaseRotationMaxLength
  14183. /*
  14184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14187. */
  14188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14189. // StopTransactionOnEVSideDisconnect
  14190. /*
  14191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14194. */
  14195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14196. // StopTransactionOnInvalidId
  14197. /*
  14198. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14201. */
  14202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14203. // StopTxnAlignedData
  14204. /*
  14205. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14208. */
  14209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14210. // StopTxnAlignedDataMaxLength
  14211. /*
  14212. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14215. */
  14216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14217. // StopTxnSampledData
  14218. /*
  14219. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14222. */
  14223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14224. // StopTxnSampledDataMaxLength
  14225. /*
  14226. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14229. */
  14230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14231. // SupportedFeatureProfiles
  14232. /*
  14233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14236. */
  14237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14238. // SupportedFeatureProfilesMaxLength
  14239. /*
  14240. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14243. */
  14244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14245. // TransactionMessageAttempts
  14246. /*
  14247. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14250. */
  14251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14252. // TransactionMessageRetryInterval
  14253. /*
  14254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14257. */
  14258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14259. // UnlockConnectorOnEVSideDisconnect
  14260. /*
  14261. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14264. */
  14265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14266. // WebSocketPingInterval
  14267. /*
  14268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14271. */
  14272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14273. // QueueOffLineMeterValues
  14274. /*
  14275. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14278. */
  14279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14280. // AuthorizationKey
  14281. /*
  14282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14285. */
  14286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14287. // SecurityProfile
  14288. /*
  14289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14292. */
  14293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14294. // DefaultPrice
  14295. /*
  14296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14299. */
  14300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14301. // CustomDisplayCostAndPrice
  14302. /*
  14303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14306. */
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14308. // CustomIdleFeeAfterStop
  14309. /*
  14310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14313. */
  14314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14315. // SystemUptimeSec
  14316. /*
  14317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14320. */
  14321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14322. // FreeVend
  14323. /*
  14324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14327. */
  14328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14329. // OcppServer
  14330. /*
  14331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14334. */
  14335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14336. // MaintainServer
  14337. /*
  14338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14341. */
  14342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14343. // StatusNotificationPeriodically
  14344. /*
  14345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14348. */
  14349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14350. // StatusNotificationInterval
  14351. /*
  14352. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14355. */
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14357. // ConfigurationVersion
  14358. /*
  14359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14362. */
  14363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14364. //* Local Auth List Management Profile*/
  14365. //LocalAuthListEnabled
  14366. /*
  14367. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14370. */
  14371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14372. //LocalAuthListMaxLength
  14373. /*
  14374. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14377. */
  14378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14379. //SendLocalListMaxLength
  14380. /*
  14381. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14384. */
  14385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14386. //ReserveConnectorZeroSupported
  14387. /*
  14388. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14391. */
  14392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14393. //* Smart Charging Profile */
  14394. //ChargeProfileMaxStackLevel
  14395. /*
  14396. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14399. */
  14400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14401. // ChargingScheduleAllowedChargingRateUnit
  14402. /*
  14403. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14406. */
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14408. // ChargingScheduleMaxPeriods
  14409. /*
  14410. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14413. */
  14414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14415. // ConnectorSwitch3to1PhaseSupported
  14416. /*
  14417. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14420. */
  14421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14422. // MaxChargingProfilesInstalled
  14423. /*
  14424. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14427. */
  14428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14429. fclose(outfile);
  14430. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14431. }
  14432. void getKeyValue(char *keyReq)
  14433. {
  14434. int isEmpty = FALSE;
  14435. int isKnowKey = FALSE;
  14436. DEBUG_INFO("keyReq = %s\n", keyReq);
  14437. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14438. isEmpty = TRUE;
  14439. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14440. {
  14441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14443. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14444. {
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14446. }
  14447. else
  14448. {
  14449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14450. }
  14451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14452. isKnowKey = TRUE;
  14453. }
  14454. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14455. {
  14456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14458. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14459. {
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14461. }
  14462. else
  14463. {
  14464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14465. }
  14466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14467. isKnowKey = TRUE;
  14468. }
  14469. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14470. {
  14471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14473. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14474. {
  14475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14476. }
  14477. else
  14478. {
  14479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14480. }
  14481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14482. isKnowKey = TRUE;
  14483. }
  14484. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14485. {
  14486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14488. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14489. {
  14490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14491. }
  14492. else
  14493. {
  14494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14495. }
  14496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14497. isKnowKey = TRUE;
  14498. }
  14499. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14500. {
  14501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14503. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14504. {
  14505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14506. }
  14507. else
  14508. {
  14509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14510. }
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14512. isKnowKey = TRUE;
  14513. }
  14514. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14515. {
  14516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14518. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14519. {
  14520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14521. }
  14522. else
  14523. {
  14524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14525. }
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14527. isKnowKey = TRUE;
  14528. }
  14529. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14530. {
  14531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14533. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14534. {
  14535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14536. }
  14537. else
  14538. {
  14539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14540. }
  14541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14542. isKnowKey = TRUE;
  14543. }
  14544. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14545. {
  14546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14548. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14549. {
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14551. }
  14552. else
  14553. {
  14554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14555. }
  14556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14557. isKnowKey = TRUE;
  14558. }
  14559. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14560. {
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14563. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14564. {
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14566. }
  14567. else
  14568. {
  14569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14570. }
  14571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14572. isKnowKey = TRUE;
  14573. }
  14574. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14575. {
  14576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14578. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14579. {
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14581. }
  14582. else
  14583. {
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14585. }
  14586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14587. isKnowKey = TRUE;
  14588. }
  14589. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14590. {
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14593. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14594. {
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14596. }
  14597. else
  14598. {
  14599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14600. }
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14602. isKnowKey = TRUE;
  14603. }
  14604. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14605. {
  14606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14608. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14609. {
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14611. }
  14612. else
  14613. {
  14614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14615. }
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14617. isKnowKey = TRUE;
  14618. }
  14619. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14620. {
  14621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14623. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14624. {
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14626. }
  14627. else
  14628. {
  14629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14630. }
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14632. isKnowKey = TRUE;
  14633. }
  14634. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14635. {
  14636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14638. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14639. {
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14641. }
  14642. else
  14643. {
  14644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14645. }
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14647. isKnowKey = TRUE;
  14648. }
  14649. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14650. {
  14651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14653. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14654. {
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14656. }
  14657. else
  14658. {
  14659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14660. }
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14662. isKnowKey = TRUE;
  14663. }
  14664. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14665. {
  14666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14668. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14669. {
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14671. }
  14672. else
  14673. {
  14674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14675. }
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14677. isKnowKey = TRUE;
  14678. }
  14679. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14680. {
  14681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14683. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14684. {
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14686. }
  14687. else
  14688. {
  14689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14690. }
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14692. isKnowKey = TRUE;
  14693. }
  14694. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14695. {
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14698. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14701. }
  14702. else
  14703. {
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14705. }
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14707. isKnowKey = TRUE;
  14708. }
  14709. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14710. {
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14713. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14714. {
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14716. }
  14717. else
  14718. {
  14719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14720. }
  14721. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14723. isKnowKey = TRUE;
  14724. }
  14725. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14726. {
  14727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14729. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14730. {
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14732. }
  14733. else
  14734. {
  14735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14736. }
  14737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14738. isKnowKey = TRUE;
  14739. }
  14740. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14741. {
  14742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14744. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14745. {
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14747. }
  14748. else
  14749. {
  14750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14751. }
  14752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14753. isKnowKey = TRUE;
  14754. }
  14755. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14756. {
  14757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14759. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14760. {
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14762. }
  14763. else
  14764. {
  14765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14766. }
  14767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14768. isKnowKey = TRUE;
  14769. }
  14770. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14771. {
  14772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14774. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14775. {
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14777. }
  14778. else
  14779. {
  14780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14781. }
  14782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14783. isKnowKey = TRUE;
  14784. }
  14785. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14786. {
  14787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14789. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14790. {
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14792. }
  14793. else
  14794. {
  14795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14796. }
  14797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14798. isKnowKey = TRUE;
  14799. }
  14800. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14801. {
  14802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14804. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14805. {
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14807. }
  14808. else
  14809. {
  14810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14811. }
  14812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14813. isKnowKey = TRUE;
  14814. }
  14815. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14816. {
  14817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14819. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14820. {
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14822. }
  14823. else
  14824. {
  14825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14826. }
  14827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14828. isKnowKey = TRUE;
  14829. }
  14830. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14831. {
  14832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14834. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14835. {
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14837. }
  14838. else
  14839. {
  14840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14841. }
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14843. isKnowKey = TRUE;
  14844. }
  14845. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14846. {
  14847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14849. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14850. {
  14851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14852. }
  14853. else
  14854. {
  14855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14856. }
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14858. isKnowKey = TRUE;
  14859. }
  14860. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14861. {
  14862. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14864. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14865. {
  14866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14867. }
  14868. else
  14869. {
  14870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14871. }
  14872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14873. isKnowKey = TRUE;
  14874. }
  14875. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14876. {
  14877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14879. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14880. {
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14882. }
  14883. else
  14884. {
  14885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14886. }
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14888. isKnowKey = TRUE;
  14889. }
  14890. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14891. {
  14892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14894. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14895. {
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14897. }
  14898. else
  14899. {
  14900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14901. }
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14903. isKnowKey = TRUE;
  14904. }
  14905. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14906. {
  14907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14909. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14910. {
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14912. }
  14913. else
  14914. {
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14916. }
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14918. isKnowKey = TRUE;
  14919. }
  14920. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14921. {
  14922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14924. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14925. {
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14927. }
  14928. else
  14929. {
  14930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14931. }
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14933. isKnowKey = TRUE;
  14934. }
  14935. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14936. {
  14937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14939. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14940. {
  14941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14942. }
  14943. else
  14944. {
  14945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14946. }
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14948. isKnowKey = TRUE;
  14949. }
  14950. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14951. {
  14952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14954. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14955. {
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14957. }
  14958. else
  14959. {
  14960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14961. }
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14963. isKnowKey = TRUE;
  14964. }
  14965. /*
  14966. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14967. {
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14970. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14971. {
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14973. }
  14974. else
  14975. {
  14976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14977. }
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14979. isKnowKey = TRUE;
  14980. }*/
  14981. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14982. {
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14985. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14988. }
  14989. else
  14990. {
  14991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14992. }
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14994. isKnowKey = TRUE;
  14995. }
  14996. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14997. {
  14998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15000. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15001. {
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15003. }
  15004. else
  15005. {
  15006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15007. }
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15009. isKnowKey = TRUE;
  15010. }
  15011. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15012. {
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15015. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15016. {
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15018. }
  15019. else
  15020. {
  15021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15022. }
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15024. isKnowKey = TRUE;
  15025. }
  15026. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15027. {
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15030. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15031. {
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15033. }
  15034. else
  15035. {
  15036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15037. }
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15039. isKnowKey = TRUE;
  15040. }
  15041. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15042. {
  15043. struct sysinfo s_info;
  15044. int error = sysinfo(&s_info);
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15047. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15048. {
  15049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15050. }
  15051. else
  15052. {
  15053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15054. }
  15055. if(error != 0)
  15056. {
  15057. DEBUG_WARN("System uptime get error: %d\n", error);
  15058. }
  15059. else
  15060. {
  15061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15062. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15063. }
  15064. isKnowKey = TRUE;
  15065. }
  15066. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15067. {
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15070. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15071. {
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15073. }
  15074. else
  15075. {
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15077. }
  15078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15079. isKnowKey = TRUE;
  15080. }
  15081. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15085. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15086. {
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15088. }
  15089. else
  15090. {
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15092. }
  15093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15094. isKnowKey = TRUE;
  15095. }
  15096. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15097. {
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15100. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15101. {
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15103. }
  15104. else
  15105. {
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15107. }
  15108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15109. isKnowKey = TRUE;
  15110. }
  15111. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15112. {
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "StatusNotificationPeriodically");
  15115. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15116. {
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15118. }
  15119. else
  15120. {
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15122. }
  15123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15124. isKnowKey = TRUE;
  15125. }
  15126. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15127. {
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15130. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15131. {
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15133. }
  15134. else
  15135. {
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15137. }
  15138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15139. isKnowKey = TRUE;
  15140. }
  15141. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15142. {
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15146. {
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15148. }
  15149. else
  15150. {
  15151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15152. }
  15153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15154. isKnowKey = TRUE;
  15155. }
  15156. #if 1
  15157. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15158. {
  15159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15161. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15162. {
  15163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15164. }
  15165. else
  15166. {
  15167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15168. }
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15170. isKnowKey = TRUE;
  15171. }
  15172. #endif
  15173. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15174. {
  15175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15177. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15178. {
  15179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15180. }
  15181. else
  15182. {
  15183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15184. }
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15186. isKnowKey = TRUE;
  15187. }
  15188. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15189. {
  15190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15192. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15193. {
  15194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15195. }
  15196. else
  15197. {
  15198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15199. }
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15201. isKnowKey = TRUE;
  15202. }
  15203. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15204. {
  15205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15207. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15208. {
  15209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15210. }
  15211. else
  15212. {
  15213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15214. }
  15215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15216. isKnowKey = TRUE;
  15217. }
  15218. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15219. {
  15220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15222. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15223. {
  15224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15225. }
  15226. else
  15227. {
  15228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15229. }
  15230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15231. isKnowKey = TRUE;
  15232. }
  15233. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15234. {
  15235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15237. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15238. {
  15239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15240. }
  15241. else
  15242. {
  15243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15244. }
  15245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15246. isKnowKey = TRUE;
  15247. }
  15248. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15249. {
  15250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15252. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15253. {
  15254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15255. }
  15256. else
  15257. {
  15258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15259. }
  15260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15261. isKnowKey = TRUE;
  15262. }
  15263. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15264. {
  15265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15267. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15268. {
  15269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15270. }
  15271. else
  15272. {
  15273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15274. }
  15275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15276. isKnowKey = TRUE;
  15277. }
  15278. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15279. {
  15280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15282. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15283. {
  15284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15285. }
  15286. else
  15287. {
  15288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15289. }
  15290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15291. isKnowKey = TRUE;
  15292. }
  15293. //=========================================================
  15294. if(!isEmpty && !isKnowKey)
  15295. {
  15296. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15297. strcpy(unknownkey[UnknownKeynum], keyReq);
  15298. UnknownKeynum = UnknownKeynum + 1;
  15299. }
  15300. }
  15301. void processUnkownKey(void)
  15302. {
  15303. DEBUG_INFO("processUnkownKey...\n");
  15304. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15305. for(int index=0; index < UnknownKeynum; index++)
  15306. {
  15307. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15308. {
  15309. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15310. }
  15311. }
  15312. }
  15313. int setKeyValue(char *key, char *value)
  15314. {
  15315. int isSuccess = NotSupported;
  15316. int check_ascii=0;
  15317. char str[501]={0};
  15318. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15319. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15320. {
  15321. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15322. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15323. {
  15324. strcpy(str, (const char*)value);
  15325. for(int i = 0; str[i]; i++){
  15326. str[i] = tolower(str[i]);
  15327. }
  15328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15329. isSuccess = ConfigurationStatus_Accepted;
  15330. }
  15331. else
  15332. {
  15333. isSuccess = ConfigurationStatus_Rejected;
  15334. }
  15335. }
  15336. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15337. {
  15338. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15339. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15340. {
  15341. strcpy(str, (const char*)value);
  15342. for(int i = 0; str[i]; i++){
  15343. str[i] = tolower(str[i]);
  15344. }
  15345. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15346. isSuccess = ConfigurationStatus_Accepted;
  15347. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15348. }
  15349. else
  15350. {
  15351. isSuccess = ConfigurationStatus_Rejected;
  15352. }
  15353. }
  15354. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15355. {
  15356. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15357. {
  15358. strcpy(str, (const char*)value);
  15359. for(int i = 0; str[i]; i++)
  15360. {
  15361. str[i] = tolower(str[i]);
  15362. }
  15363. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15364. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15365. isSuccess = ConfigurationStatus_Accepted;
  15366. }
  15367. else
  15368. {
  15369. isSuccess = ConfigurationStatus_Rejected;
  15370. }
  15371. }
  15372. if(strcmp(key, "BlinkRepeat") == 0)
  15373. {
  15374. //Charger.BlinkRepeat = Integer.parseInt(value);
  15375. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15376. {
  15377. check_ascii = value[0];
  15378. if( (check_ascii < 48) || (check_ascii > 57) )
  15379. {
  15380. isSuccess = ConfigurationStatus_Rejected;
  15381. }
  15382. else
  15383. {
  15384. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15385. isSuccess = ConfigurationStatus_Accepted;
  15386. }
  15387. }
  15388. else
  15389. {
  15390. isSuccess = ConfigurationStatus_Rejected;
  15391. }
  15392. }
  15393. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15394. {
  15395. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15396. {
  15397. check_ascii = value[0];
  15398. if( (check_ascii < 48) || (check_ascii > 57) )
  15399. {
  15400. isSuccess = ConfigurationStatus_Rejected;
  15401. }
  15402. else
  15403. {
  15404. if((atoi(value) == 0) || (atoi(value) >= 5))
  15405. {
  15406. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15408. isSuccess = ConfigurationStatus_Accepted;
  15409. }
  15410. else
  15411. isSuccess = ConfigurationStatus_Rejected;
  15412. }
  15413. }
  15414. else
  15415. {
  15416. isSuccess = ConfigurationStatus_Rejected;
  15417. }
  15418. }
  15419. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15420. {
  15421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15422. {
  15423. check_ascii = value[0];
  15424. if( (check_ascii < 48) || (check_ascii > 57) )
  15425. {
  15426. isSuccess = ConfigurationStatus_Rejected;
  15427. }
  15428. else
  15429. {
  15430. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15432. isSuccess = ConfigurationStatus_Accepted;
  15433. }
  15434. }
  15435. else
  15436. {
  15437. isSuccess = ConfigurationStatus_Rejected;
  15438. }
  15439. }
  15440. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15441. {
  15442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15443. {
  15444. check_ascii = value[0];
  15445. if( (check_ascii < 48) || (check_ascii > 57) )
  15446. {
  15447. isSuccess = ConfigurationStatus_Rejected;
  15448. }
  15449. else
  15450. {
  15451. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15452. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15453. isSuccess = ConfigurationStatus_Accepted;
  15454. }
  15455. }
  15456. else
  15457. {
  15458. isSuccess = ConfigurationStatus_Rejected;
  15459. }
  15460. }
  15461. if(strcmp(key, "HeartbeatInterval") == 0)
  15462. {
  15463. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15464. {
  15465. check_ascii = value[0];
  15466. if( (check_ascii < 48) || (check_ascii > 57) )
  15467. {
  15468. isSuccess = ConfigurationStatus_Rejected;
  15469. }
  15470. else
  15471. {
  15472. if((atoi(value) == 0) || (atoi(value) >= 10))
  15473. {
  15474. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15475. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15476. HeartBeatWaitTime = atoi(value);
  15477. isSuccess = ConfigurationStatus_Accepted;
  15478. }
  15479. else
  15480. {
  15481. isSuccess = ConfigurationStatus_Rejected;
  15482. }
  15483. }
  15484. }
  15485. else
  15486. {
  15487. isSuccess = ConfigurationStatus_Rejected;
  15488. }
  15489. }
  15490. if(strcmp(key, "LightIntensity") == 0)
  15491. {
  15492. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15493. {
  15494. check_ascii = value[0];
  15495. if( (check_ascii < 48) || (check_ascii > 57) )
  15496. {
  15497. isSuccess = ConfigurationStatus_Rejected;
  15498. }
  15499. else
  15500. {
  15501. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15502. isSuccess = ConfigurationStatus_Accepted;
  15503. }
  15504. }
  15505. else
  15506. {
  15507. isSuccess = ConfigurationStatus_Rejected;
  15508. }
  15509. }
  15510. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15511. {
  15512. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15513. {
  15514. strcpy(str, (const char*)value);
  15515. for(int i = 0; str[i]; i++)
  15516. {
  15517. str[i] = tolower(str[i]);
  15518. }
  15519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15520. isSuccess = ConfigurationStatus_Accepted;
  15521. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15522. }
  15523. else
  15524. {
  15525. isSuccess = ConfigurationStatus_Rejected;
  15526. }
  15527. }
  15528. if(strcmp(key, "LocalPreAuthorize") == 0)
  15529. {
  15530. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15531. {
  15532. strcpy(str, (const char*)value);
  15533. for(int i = 0; str[i]; i++)
  15534. {
  15535. str[i] = tolower(str[i]);
  15536. }
  15537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15538. isSuccess = ConfigurationStatus_Accepted;
  15539. }
  15540. else
  15541. {
  15542. isSuccess = ConfigurationStatus_Rejected;
  15543. }
  15544. }
  15545. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15546. {
  15547. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15548. {
  15549. check_ascii = value[0];
  15550. if( (check_ascii < 48) || (check_ascii > 57) )
  15551. {
  15552. isSuccess = ConfigurationStatus_Rejected;
  15553. }
  15554. else
  15555. {
  15556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15557. isSuccess = ConfigurationStatus_Accepted;
  15558. }
  15559. }
  15560. else
  15561. {
  15562. isSuccess = ConfigurationStatus_Rejected;
  15563. }
  15564. }
  15565. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15566. {
  15567. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15568. {
  15569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15570. isSuccess = ConfigurationStatus_Accepted;
  15571. }
  15572. else
  15573. {
  15574. isSuccess = ConfigurationStatus_Rejected;
  15575. }
  15576. }
  15577. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15578. {
  15579. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15580. {
  15581. check_ascii = value[0];
  15582. if( (check_ascii < 48) || (check_ascii > 57) )
  15583. {
  15584. isSuccess = ConfigurationStatus_Rejected;
  15585. }
  15586. else
  15587. {
  15588. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15589. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15590. isSuccess = ConfigurationStatus_Accepted;
  15591. }
  15592. }
  15593. else
  15594. {
  15595. isSuccess = ConfigurationStatus_Rejected;
  15596. }
  15597. }
  15598. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15599. {
  15600. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15601. {
  15602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15603. isSuccess = ConfigurationStatus_Accepted;
  15604. }
  15605. else
  15606. {
  15607. isSuccess = ConfigurationStatus_Rejected;
  15608. }
  15609. }
  15610. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15611. {
  15612. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15613. {
  15614. check_ascii = value[0];
  15615. if( (check_ascii < 48) || (check_ascii > 57) )
  15616. {
  15617. isSuccess = ConfigurationStatus_Rejected;
  15618. }
  15619. else
  15620. {
  15621. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15622. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15623. isSuccess = ConfigurationStatus_Accepted;
  15624. }
  15625. }
  15626. else
  15627. {
  15628. isSuccess = ConfigurationStatus_Rejected;
  15629. }
  15630. }
  15631. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15632. {
  15633. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15634. {
  15635. check_ascii = value[0];
  15636. if( (check_ascii < 48) || (check_ascii > 57) )
  15637. {
  15638. isSuccess = ConfigurationStatus_Rejected;
  15639. }
  15640. else
  15641. {
  15642. if((atoi(value) == 0) || (atoi(value) >= 3))
  15643. {
  15644. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15646. isSuccess = ConfigurationStatus_Accepted;
  15647. }
  15648. else
  15649. {
  15650. isSuccess = ConfigurationStatus_Rejected;
  15651. }
  15652. }
  15653. }
  15654. else
  15655. {
  15656. isSuccess = ConfigurationStatus_Rejected;
  15657. }
  15658. }
  15659. if(strcmp(key, "MinimumStatusDuration") == 0)
  15660. {
  15661. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15662. {
  15663. check_ascii = value[0];
  15664. if( (check_ascii < 48) || (check_ascii > 57) )
  15665. {
  15666. isSuccess = ConfigurationStatus_Rejected;
  15667. }
  15668. else
  15669. {
  15670. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15671. {
  15672. isSuccess = ConfigurationStatus_Rejected;
  15673. }
  15674. else
  15675. {
  15676. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15677. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15678. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15679. isSuccess = ConfigurationStatus_Accepted;
  15680. }
  15681. }
  15682. }
  15683. else
  15684. {
  15685. isSuccess = ConfigurationStatus_Rejected;
  15686. }
  15687. }
  15688. if(strcmp(key, "NumberOfConnectors") == 0)
  15689. {
  15690. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15691. {
  15692. check_ascii = value[0];
  15693. if( (check_ascii < 48) || (check_ascii > 57) )
  15694. {
  15695. isSuccess = ConfigurationStatus_Rejected;
  15696. }
  15697. else
  15698. {
  15699. //Charger.ResetRetries = Integer.parseInt(value);
  15700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15701. isSuccess = ConfigurationStatus_Accepted;
  15702. }
  15703. }
  15704. else
  15705. {
  15706. isSuccess = ConfigurationStatus_Rejected;
  15707. }
  15708. }
  15709. if(strcmp(key, "ResetRetries") == 0)
  15710. {
  15711. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15712. {
  15713. check_ascii = value[0];
  15714. if( (check_ascii < 48) || (check_ascii > 57) )
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. else
  15719. {
  15720. //Charger.ResetRetries = Integer.parseInt(value);
  15721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15722. isSuccess = ConfigurationStatus_Accepted;
  15723. }
  15724. }
  15725. else
  15726. {
  15727. isSuccess = ConfigurationStatus_Rejected;
  15728. }
  15729. }
  15730. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15731. {
  15732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15733. {
  15734. strcpy(str, (const char*)value);
  15735. for(int i = 0; str[i]; i++)
  15736. {
  15737. str[i] = tolower(str[i]);
  15738. }
  15739. if(strcmp(str, "notapplicable")== 0)
  15740. {
  15741. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15742. isSuccess = ConfigurationStatus_Accepted;
  15743. }
  15744. else if(strcmp(str, "unknown")== 0)
  15745. {
  15746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15747. isSuccess = ConfigurationStatus_Accepted;
  15748. }
  15749. else if(strcmp(str, "rst")== 0)
  15750. {
  15751. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15752. isSuccess = ConfigurationStatus_Accepted;
  15753. }
  15754. else if(strcmp(str, "rts")== 0)
  15755. {
  15756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15757. isSuccess = ConfigurationStatus_Accepted;
  15758. }
  15759. else if(strcmp(str, "srt")== 0)
  15760. {
  15761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15762. isSuccess = ConfigurationStatus_Accepted;
  15763. }
  15764. else if(strcmp(str, "str")== 0)
  15765. {
  15766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15767. isSuccess = ConfigurationStatus_Accepted;
  15768. }
  15769. else if(strcmp(str, "trs")== 0)
  15770. {
  15771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15772. isSuccess = ConfigurationStatus_Accepted;
  15773. }
  15774. else if(strcmp(str, "tsr")== 0)
  15775. {
  15776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15777. isSuccess = ConfigurationStatus_Accepted;
  15778. }
  15779. else
  15780. {
  15781. isSuccess = ConfigurationStatus_Rejected;
  15782. }
  15783. }
  15784. else
  15785. {
  15786. isSuccess = ConfigurationStatus_Rejected;
  15787. }
  15788. }
  15789. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15790. {
  15791. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15792. {
  15793. check_ascii = value[0];
  15794. if( (check_ascii < 48) || (check_ascii > 57) )
  15795. {
  15796. isSuccess = ConfigurationStatus_Rejected;
  15797. }
  15798. else
  15799. {
  15800. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15801. isSuccess = ConfigurationStatus_Accepted;
  15802. }
  15803. }
  15804. else
  15805. {
  15806. isSuccess = ConfigurationStatus_Rejected;
  15807. }
  15808. }
  15809. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15810. {
  15811. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15812. {
  15813. strcpy(str, (const char*)value);
  15814. for(int i = 0; str[i]; i++)
  15815. {
  15816. str[i] = tolower(str[i]);
  15817. }
  15818. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15820. isSuccess = ConfigurationStatus_Accepted;
  15821. }
  15822. else
  15823. {
  15824. isSuccess = ConfigurationStatus_Rejected;
  15825. }
  15826. }
  15827. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15828. {
  15829. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15830. {
  15831. strcpy(str, (const char*)value);
  15832. for(int i = 0; str[i]; i++)
  15833. {
  15834. str[i] = tolower(str[i]);
  15835. }
  15836. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15837. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15838. isSuccess = ConfigurationStatus_Accepted;
  15839. }
  15840. else
  15841. {
  15842. isSuccess = ConfigurationStatus_Rejected;
  15843. }
  15844. }
  15845. if(strcmp(key, "StopTxnAlignedData") == 0)
  15846. {
  15847. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15848. {
  15849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15850. isSuccess = ConfigurationStatus_Accepted;
  15851. }
  15852. else
  15853. {
  15854. isSuccess = ConfigurationStatus_Rejected;
  15855. }
  15856. }
  15857. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15858. {
  15859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15860. {
  15861. check_ascii = value[0];
  15862. if( (check_ascii < 48) || (check_ascii > 57) )
  15863. {
  15864. isSuccess = ConfigurationStatus_Rejected;
  15865. }
  15866. else
  15867. {
  15868. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15869. isSuccess = ConfigurationStatus_Accepted;
  15870. }
  15871. }
  15872. else
  15873. {
  15874. isSuccess = ConfigurationStatus_Rejected;
  15875. }
  15876. }
  15877. if(strcmp(key, "StopTxnSampledData") == 0)
  15878. {
  15879. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15880. {
  15881. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15882. isSuccess = ConfigurationStatus_Accepted;
  15883. }
  15884. else
  15885. {
  15886. isSuccess = ConfigurationStatus_Rejected;
  15887. }
  15888. }
  15889. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15890. {
  15891. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15892. {
  15893. check_ascii = value[0];
  15894. if( (check_ascii < 48) || (check_ascii > 57) )
  15895. {
  15896. isSuccess = ConfigurationStatus_Rejected;
  15897. }
  15898. else
  15899. {
  15900. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15901. isSuccess = ConfigurationStatus_Accepted;
  15902. }
  15903. }
  15904. else
  15905. {
  15906. isSuccess = ConfigurationStatus_Rejected;
  15907. }
  15908. }
  15909. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15910. {
  15911. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15912. {
  15913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15914. isSuccess = ConfigurationStatus_Accepted;
  15915. }
  15916. else
  15917. {
  15918. isSuccess = ConfigurationStatus_Rejected;
  15919. }
  15920. }
  15921. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15922. {
  15923. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15924. {
  15925. check_ascii = value[0];
  15926. if( (check_ascii < 48) || (check_ascii > 57) )
  15927. {
  15928. isSuccess = ConfigurationStatus_Rejected;
  15929. }
  15930. else
  15931. {
  15932. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15933. isSuccess = ConfigurationStatus_Accepted;
  15934. }
  15935. }
  15936. else
  15937. {
  15938. isSuccess = ConfigurationStatus_Rejected;
  15939. }
  15940. }
  15941. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15942. {
  15943. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15944. {
  15945. check_ascii = value[0];
  15946. if( (check_ascii < 48) || (check_ascii > 57) )
  15947. {
  15948. isSuccess = ConfigurationStatus_Rejected;
  15949. }
  15950. else
  15951. {
  15952. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15953. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15954. TransactionMessageAttemptsValue = atoi(value);
  15955. isSuccess = ConfigurationStatus_Accepted;
  15956. }
  15957. }
  15958. else
  15959. {
  15960. isSuccess = ConfigurationStatus_Rejected;
  15961. }
  15962. }
  15963. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15964. {
  15965. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15966. {
  15967. check_ascii = value[0];
  15968. if( (check_ascii < 48) || (check_ascii > 57) )
  15969. {
  15970. isSuccess = ConfigurationStatus_Rejected;
  15971. }
  15972. else
  15973. {
  15974. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15975. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15976. TransactionMessageRetryIntervalValue = atoi(value);
  15977. isSuccess = ConfigurationStatus_Accepted;
  15978. }
  15979. }
  15980. else
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. }
  15985. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15986. {
  15987. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15988. {
  15989. strcpy(str, (const char*)value);
  15990. for(int i = 0; str[i]; i++)
  15991. {
  15992. str[i] = tolower(str[i]);
  15993. }
  15994. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15996. isSuccess = ConfigurationStatus_Accepted;
  15997. }
  15998. else
  15999. {
  16000. isSuccess = ConfigurationStatus_Rejected;
  16001. }
  16002. }
  16003. if(strcmp(key, "WebSocketPingInterval") == 0)
  16004. {
  16005. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16006. {
  16007. check_ascii = value[0];
  16008. if( (check_ascii < 48) || (check_ascii > 57) )
  16009. {
  16010. isSuccess = ConfigurationStatus_Rejected;
  16011. }
  16012. else
  16013. {
  16014. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16015. isSuccess = ConfigurationStatus_Accepted;
  16016. if((atoi(value) == 0) || (atoi(value) >= 10))
  16017. {
  16018. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16019. isSuccess = ConfigurationStatus_Accepted;
  16020. }
  16021. else
  16022. isSuccess = ConfigurationStatus_Rejected;
  16023. }
  16024. }
  16025. else
  16026. {
  16027. isSuccess = ConfigurationStatus_Rejected;
  16028. }
  16029. }
  16030. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16031. {
  16032. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16033. {
  16034. strcpy(str, (const char*)value);
  16035. for(int i = 0; str[i]; i++)
  16036. {
  16037. str[i] = tolower(str[i]);
  16038. }
  16039. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16040. isSuccess = ConfigurationStatus_Accepted;
  16041. }
  16042. else
  16043. {
  16044. isSuccess = ConfigurationStatus_Rejected;
  16045. }
  16046. }
  16047. if(strcmp(key, "AuthorizationKey") == 0)
  16048. {
  16049. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16050. {
  16051. strcpy(str, (const char*)value);
  16052. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16053. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16054. isSuccess = ConfigurationStatus_Accepted;
  16055. }
  16056. else
  16057. {
  16058. isSuccess = ConfigurationStatus_Rejected;
  16059. }
  16060. }
  16061. if(strcmp(key, "SecurityProfile") == 0)
  16062. {
  16063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16064. {
  16065. check_ascii = value[0];
  16066. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16067. {
  16068. isSuccess = ConfigurationStatus_Rejected;
  16069. }
  16070. else if(check_ascii == 0x33)
  16071. {
  16072. isSuccess = NotSupported;
  16073. }
  16074. else
  16075. {
  16076. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16077. {
  16078. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16079. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16080. isSuccess = ConfigurationStatus_Accepted;
  16081. }
  16082. else
  16083. isSuccess = ConfigurationStatus_Rejected;
  16084. }
  16085. }
  16086. else
  16087. {
  16088. isSuccess = ConfigurationStatus_Rejected;
  16089. }
  16090. }
  16091. if(strcmp(key, "DefaultPrice") == 0)
  16092. {
  16093. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16094. {
  16095. strcpy(str, (const char*)value);
  16096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16097. isSuccess = ConfigurationStatus_Accepted;
  16098. }
  16099. else
  16100. {
  16101. isSuccess = ConfigurationStatus_Rejected;
  16102. }
  16103. }
  16104. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16105. {
  16106. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16107. {
  16108. strcpy(str, (const char*)value);
  16109. for(int i = 0; str[i]; i++)
  16110. {
  16111. str[i] = tolower(str[i]);
  16112. }
  16113. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16114. isSuccess = ConfigurationStatus_Accepted;
  16115. }
  16116. else
  16117. {
  16118. isSuccess = ConfigurationStatus_Rejected;
  16119. }
  16120. }
  16121. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16122. {
  16123. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16124. {
  16125. strcpy(str, (const char*)value);
  16126. for(int i = 0; str[i]; i++)
  16127. {
  16128. str[i] = tolower(str[i]);
  16129. }
  16130. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16131. isSuccess = ConfigurationStatus_Accepted;
  16132. }
  16133. else
  16134. {
  16135. isSuccess = ConfigurationStatus_Rejected;
  16136. }
  16137. }
  16138. if(strcmp(key, "SystemUptimeSec") == 0)
  16139. {
  16140. isSuccess = NotSupported;
  16141. }
  16142. if(strcmp(key, "FreeVend") == 0)
  16143. {
  16144. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16145. {
  16146. strcpy(str, (const char*)value);
  16147. for(int i = 0; str[i]; i++)
  16148. {
  16149. str[i] = tolower(str[i]);
  16150. }
  16151. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16153. isSuccess = ConfigurationStatus_Accepted;
  16154. }
  16155. else
  16156. {
  16157. isSuccess = ConfigurationStatus_Rejected;
  16158. }
  16159. }
  16160. if(strcmp(key, "OcppServer") == 0)
  16161. {
  16162. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16163. {
  16164. strcpy(str, (const char*)value);
  16165. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16166. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16167. isSuccess = ConfigurationStatus_Accepted;
  16168. }
  16169. else
  16170. {
  16171. isSuccess = ConfigurationStatus_Rejected;
  16172. }
  16173. }
  16174. if(strcmp(key, "MaintainServer") == 0)
  16175. {
  16176. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16177. {
  16178. strcpy(str, (const char*)value);
  16179. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16180. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16181. isSuccess = ConfigurationStatus_Accepted;
  16182. }
  16183. else
  16184. {
  16185. isSuccess = ConfigurationStatus_Rejected;
  16186. }
  16187. }
  16188. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16189. {
  16190. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16191. {
  16192. strcpy(str, (const char*)value);
  16193. for(int i = 0; str[i]; i++)
  16194. {
  16195. str[i] = tolower(str[i]);
  16196. }
  16197. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16198. isSuccess = ConfigurationStatus_Accepted;
  16199. }
  16200. else
  16201. {
  16202. isSuccess = ConfigurationStatus_Rejected;
  16203. }
  16204. }
  16205. if(strcmp(key, "StatusNotificationInterval") == 0)
  16206. {
  16207. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16208. {
  16209. check_ascii = value[0];
  16210. if( (check_ascii < 48) || (check_ascii > 57) )
  16211. {
  16212. isSuccess = ConfigurationStatus_Rejected;
  16213. }
  16214. else
  16215. {
  16216. if((atoi(value) == 0) || (atoi(value) >= 10))
  16217. {
  16218. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16219. isSuccess = ConfigurationStatus_Accepted;
  16220. }
  16221. else
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. }
  16225. else
  16226. {
  16227. isSuccess = ConfigurationStatus_Rejected;
  16228. }
  16229. }
  16230. #if 0
  16231. //For OCPP Test Case
  16232. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16233. {
  16234. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16235. {
  16236. strcpy(str, (const char*)value);
  16237. for(int i = 0; str[i]; i++)
  16238. {
  16239. str[i] = tolower(str[i]);
  16240. }
  16241. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16242. isSuccess = ConfigurationStatus_Accepted;
  16243. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16244. }
  16245. else
  16246. {
  16247. isSuccess = ConfigurationStatus_Rejected;
  16248. }
  16249. }
  16250. #endif
  16251. #if 1
  16252. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16253. {
  16254. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16255. {
  16256. strcpy(str, (const char*)value);
  16257. for(int i = 0; str[i]; i++)
  16258. {
  16259. str[i] = tolower(str[i]);
  16260. }
  16261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16262. isSuccess = ConfigurationStatus_Accepted;
  16263. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16264. }
  16265. else
  16266. {
  16267. isSuccess = ConfigurationStatus_Rejected;
  16268. }
  16269. }
  16270. #endif
  16271. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16272. {
  16273. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16274. {
  16275. check_ascii = value[0];
  16276. if( (check_ascii < 48) || (check_ascii > 57) )
  16277. {
  16278. isSuccess = ConfigurationStatus_Rejected;
  16279. }
  16280. else
  16281. {
  16282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16283. isSuccess = ConfigurationStatus_Accepted;
  16284. }
  16285. }
  16286. else
  16287. {
  16288. isSuccess = ConfigurationStatus_Rejected;
  16289. }
  16290. }
  16291. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16292. {
  16293. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16294. {
  16295. check_ascii = value[0];
  16296. if( (check_ascii < 48) || (check_ascii > 57) )
  16297. {
  16298. isSuccess = ConfigurationStatus_Rejected;
  16299. }
  16300. else
  16301. {
  16302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16303. isSuccess = ConfigurationStatus_Accepted;
  16304. }
  16305. }
  16306. else
  16307. {
  16308. isSuccess = ConfigurationStatus_Rejected;
  16309. }
  16310. }
  16311. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16312. {
  16313. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16314. {
  16315. strcpy(str, (const char*)value);
  16316. for(int i = 0; str[i]; i++)
  16317. {
  16318. str[i] = tolower(str[i]);
  16319. }
  16320. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16321. isSuccess = ConfigurationStatus_Accepted;
  16322. }
  16323. else
  16324. {
  16325. isSuccess = ConfigurationStatus_Rejected;
  16326. }
  16327. }
  16328. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16329. {
  16330. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16331. {
  16332. check_ascii = value[0];
  16333. if( (check_ascii < 48) || (check_ascii > 57) )
  16334. {
  16335. isSuccess = ConfigurationStatus_Rejected;
  16336. }
  16337. else
  16338. {
  16339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16340. isSuccess = ConfigurationStatus_Accepted;
  16341. }
  16342. }
  16343. else
  16344. {
  16345. isSuccess = ConfigurationStatus_Rejected;
  16346. }
  16347. }
  16348. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16349. {
  16350. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16351. {
  16352. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16353. isSuccess = ConfigurationStatus_Accepted;
  16354. }
  16355. else
  16356. {
  16357. isSuccess = ConfigurationStatus_Rejected;
  16358. }
  16359. }
  16360. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16361. {
  16362. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16363. {
  16364. check_ascii = value[0];
  16365. if( (check_ascii < 48) || (check_ascii > 57) )
  16366. {
  16367. isSuccess = ConfigurationStatus_Rejected;
  16368. }
  16369. else
  16370. {
  16371. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16372. isSuccess = ConfigurationStatus_Accepted;
  16373. }
  16374. }
  16375. else
  16376. {
  16377. isSuccess = ConfigurationStatus_Rejected;
  16378. }
  16379. }
  16380. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16381. {
  16382. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16383. {
  16384. strcpy(str, (const char*)value);
  16385. for(int i = 0; str[i]; i++)
  16386. {
  16387. str[i] = tolower(str[i]);
  16388. }
  16389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16390. isSuccess = ConfigurationStatus_Accepted;
  16391. }
  16392. else
  16393. {
  16394. isSuccess = ConfigurationStatus_Rejected;
  16395. }
  16396. }
  16397. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16398. {
  16399. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16400. {
  16401. check_ascii = value[0];
  16402. if( (check_ascii < 48) || (check_ascii > 57) )
  16403. {
  16404. isSuccess = ConfigurationStatus_Rejected;
  16405. }
  16406. else
  16407. {
  16408. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16409. isSuccess = ConfigurationStatus_Accepted;
  16410. }
  16411. }
  16412. else
  16413. {
  16414. isSuccess = ConfigurationStatus_Rejected;
  16415. }
  16416. }
  16417. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16418. return isSuccess;
  16419. }
  16420. int TransactionMessageAttemptsGet(void)
  16421. {
  16422. return TransactionMessageAttemptsValue;
  16423. }
  16424. int FirstHeartBeatResponse(void)
  16425. {
  16426. return FirstHeartBeat;
  16427. }
  16428. int TransactionMessageRetryIntervalGet(void)
  16429. {
  16430. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16431. }
  16432. int ReadHttpStatus(int sock)
  16433. {
  16434. //char c;
  16435. char buff[1024]="",*ptr=buff+1;
  16436. int bytes_received, status;
  16437. DEBUG_INFO("Begin Response ..\n");
  16438. while((bytes_received = recv(sock, ptr, 1, 0))){
  16439. if(bytes_received==-1){
  16440. perror("ReadHttpStatus");
  16441. exit(1);
  16442. }
  16443. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16444. ptr++;
  16445. }
  16446. *ptr=0;
  16447. ptr=buff+1;
  16448. sscanf(ptr,"%*s %d ", &status);
  16449. DEBUG_INFO("%s\n",ptr);
  16450. DEBUG_INFO("status=%d\n",status);
  16451. DEBUG_INFO("End Response ..\n");
  16452. return (bytes_received>0)?status:0;
  16453. }
  16454. //the only filed that it parsed is 'Content-Length'
  16455. int ParseHeader(int sock)
  16456. {
  16457. //char c;
  16458. char buff[1024]="",*ptr=buff+4;
  16459. int bytes_received;
  16460. DEBUG_INFO("Begin HEADER ..\n");
  16461. while((bytes_received = recv(sock, ptr, 1, 0))){
  16462. if(bytes_received==-1){
  16463. perror("Parse Header");
  16464. exit(1);
  16465. }
  16466. if(
  16467. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16468. (ptr[-1]=='\r') && (*ptr=='\n' )
  16469. ) break;
  16470. ptr++;
  16471. }
  16472. *ptr=0;
  16473. ptr=buff+4;
  16474. //printf("%s",ptr);
  16475. if(bytes_received){
  16476. ptr=strstr(ptr,"Content-Length:");
  16477. if(ptr){
  16478. sscanf(ptr,"%*s %d",&bytes_received);
  16479. }else
  16480. bytes_received=-1; //unknown size
  16481. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16482. }
  16483. DEBUG_INFO("End HEADER ..\n");
  16484. return bytes_received ;
  16485. }
  16486. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16487. {
  16488. int result = TRUE;
  16489. char rmFileCmd[100]={0};
  16490. char FilePath[100]={0};
  16491. char ftpbuf[200];
  16492. int systemresult;
  16493. sprintf(FilePath,"/mnt/%s",filename);
  16494. system("ping 8.8.8.8 &");
  16495. if((access(FilePath,F_OK))!=-1)
  16496. {
  16497. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16498. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16499. system(rmFileCmd);
  16500. }
  16501. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16502. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16503. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16504. systemresult = system(ftpbuf);
  16505. if(systemresult != 0)
  16506. {
  16507. DEBUG_INFO("http DownLoad error!\n");
  16508. result = FALSE;
  16509. }
  16510. system("pkill ping");
  16511. return result;
  16512. }
  16513. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16514. {
  16515. int result = TRUE;
  16516. char rmFileCmd[100]={0};
  16517. char FilePath[100]={0};
  16518. char ftpbuf[200];
  16519. int systemresult;
  16520. sprintf(FilePath,"/mnt/%s",filename);
  16521. system("ping 8.8.8.8 &");
  16522. if((access(FilePath,F_OK))!=-1)
  16523. {
  16524. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16525. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16526. system(rmFileCmd);
  16527. }
  16528. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16529. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16530. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16531. systemresult = system(ftpbuf);
  16532. if(systemresult != 0)
  16533. {
  16534. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16535. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16536. systemresult = system(ftpbuf);
  16537. if(systemresult != 0)
  16538. {
  16539. DEBUG_WARN("wget error!\n");
  16540. result = FALSE;
  16541. }
  16542. }
  16543. system("pkill ping");
  16544. return result;
  16545. }
  16546. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16547. {
  16548. char rmFileCmd[100]={0};
  16549. char FilePath[100]={0};
  16550. char buf[512];
  16551. int systemresult = 0;
  16552. //DEBUG_INFO("filename=%s\n",filename);
  16553. //DEBUG_INFO("url=%s\n",url);
  16554. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16555. if((access(FilePath,F_OK))!=-1)
  16556. {
  16557. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16558. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16559. system(rmFileCmd);
  16560. }
  16561. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16562. if(fp == NULL)
  16563. {
  16564. DEBUG_INFO("log is NULL\n");
  16565. return FALSE;
  16566. }
  16567. else
  16568. {
  16569. fprintf(fp, "%s\n", url);
  16570. fprintf(fp, "%s\n", filename);
  16571. fclose(fp);
  16572. }
  16573. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16574. if(phpFP == NULL)
  16575. {
  16576. DEBUG_INFO("PHP upload fail.\n");
  16577. return FALSE;
  16578. }
  16579. else
  16580. {
  16581. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16582. {
  16583. if(strstr(buf, "result") != NULL)
  16584. {
  16585. sscanf(buf, "result: %d", &systemresult);
  16586. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16587. }
  16588. }
  16589. pclose(phpFP);
  16590. }
  16591. if(systemresult != 1)
  16592. {
  16593. DEBUG_INFO("HTTP upload error!\n");
  16594. return FALSE;
  16595. }
  16596. return TRUE;
  16597. }
  16598. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16599. {
  16600. int result = FALSE;
  16601. char ftpbuf[200];
  16602. int systemresult;
  16603. /*
  16604. // Domaind name transfer to IP address
  16605. struct hostent* server;
  16606. char *IPbuffer;
  16607. server = gethostbyname(location);
  16608. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16609. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16610. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16611. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16612. systemresult = system(ftpbuf);
  16613. if(systemresult != 0)
  16614. {
  16615. DEBUG_INFO("ftpput error!\n");
  16616. }
  16617. else
  16618. {
  16619. result = TRUE;
  16620. DEBUG_INFO("ftpput OK!\n");
  16621. }
  16622. return result;
  16623. }
  16624. int GetOcppServerURL()
  16625. {
  16626. int result = FALSE;
  16627. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16628. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16629. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16630. struct yuarel url;
  16631. char urlStr[512];
  16632. // OCPPPH only
  16633. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16634. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16635. {
  16636. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16637. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16638. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16639. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16640. if(yuarel_parse(&url, urlStr) != -1)
  16641. {
  16642. sprintf(OcppProtocol, "%s", url.scheme);
  16643. sprintf(OcppHost, "%s", url.host);
  16644. if(url.path == NULL)
  16645. OcppTempPath[0] = '\0';
  16646. else
  16647. sprintf(OcppTempPath, "%s", url.path);
  16648. if(url.port == 0)
  16649. {
  16650. if(strcmp(OcppProtocol, "wss") == 0)
  16651. OcppPort = 443;
  16652. else
  16653. OcppPort = 80;
  16654. }
  16655. else
  16656. OcppPort = url.port;
  16657. result = TRUE;
  16658. }
  16659. }
  16660. else
  16661. {
  16662. strcpy(OcppHost,"");
  16663. }
  16664. return result;
  16665. }
  16666. int GetOcppPath()
  16667. {
  16668. int result = FALSE;
  16669. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16670. {
  16671. if(OcppTempPath == NULL)
  16672. {
  16673. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16674. }
  16675. else
  16676. {
  16677. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16678. }
  16679. result = TRUE;
  16680. goto End;
  16681. }
  16682. else
  16683. {
  16684. strcpy(OcppPath,"");
  16685. }
  16686. End:
  16687. return result;
  16688. }
  16689. int GetOcppPort()
  16690. {
  16691. return OcppPort;
  16692. }
  16693. int GetOcppConnStatus(void)
  16694. {
  16695. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16696. }
  16697. void SetOcppConnStatus(uint8_t status)
  16698. {
  16699. ShmOCPP16DataPH->OcppConnStatus = status;
  16700. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16701. }
  16702. int GetHeartBeatWithNOResponse(void)
  16703. {
  16704. return HeartBeatWithNOResponse;
  16705. }
  16706. void SetHeartBeatWithNOResponse(void)
  16707. {
  16708. HeartBeatWithNOResponse = 0;
  16709. }
  16710. void GetStartTransactionIdTag(int gun_index)
  16711. {
  16712. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16713. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16714. }
  16715. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16716. {
  16717. char ch;
  16718. FILE *fptr1;
  16719. int temptransactionId;
  16720. char str[100]={0};
  16721. temptransactionId = 0;
  16722. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16723. {
  16724. DEBUG_INFO("IdTag is empty.\n");
  16725. return temptransactionId;
  16726. }
  16727. /*------ Read the file ----------------*/
  16728. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16729. if (!fptr1)
  16730. {
  16731. DEBUG_INFO("QueueTransactionId file open error.\n");
  16732. //printf(" File not found or unable to open the input file!!\n");
  16733. return temptransactionId;
  16734. }
  16735. ch=fgetc(fptr1);
  16736. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16737. rewind(fptr1);
  16738. if(ch!=EOF)
  16739. {
  16740. // printf("%c",ch);
  16741. while (fgets(str, 100, fptr1) != NULL)
  16742. {
  16743. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16744. if(str[0]=='\0')
  16745. {
  16746. break;
  16747. }
  16748. char *revbuf[8] = {0}; // Variable store string split
  16749. int num = 0;// Quantity after string split
  16750. DEBUG_INFO("Transaction queue data= %s\n", str);
  16751. splitstring(str,",",revbuf,&num); // String split
  16752. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16753. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16754. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16755. DEBUG_INFO("------------------------------\n");
  16756. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16757. {
  16758. if(isStopTransaction)
  16759. {
  16760. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16761. {
  16762. temptransactionId = atoi(revbuf[2]);
  16763. //break;
  16764. }
  16765. }
  16766. else
  16767. {
  16768. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16769. {
  16770. temptransactionId = atoi(revbuf[2]);
  16771. //break;
  16772. }
  16773. }
  16774. }
  16775. }
  16776. }
  16777. else
  16778. DEBUG_INFO("EOF\n");
  16779. fclose(fptr1);
  16780. /*------- End of reading ---------------*/
  16781. return temptransactionId;
  16782. }
  16783. void SetTransactionIdZero(int transactionId)
  16784. {
  16785. char ch;
  16786. FILE *fptr1, *fptr2;
  16787. int temptransactionId = 0;
  16788. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16789. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16790. if (!fptr1)
  16791. {
  16792. //printf(" File not found or unable to open the input file!!\n");
  16793. return ;
  16794. }
  16795. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16796. if (!fptr2)
  16797. {
  16798. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16799. fclose(fptr1);
  16800. return ;
  16801. }
  16802. ch=fgetc(fptr1);
  16803. rewind(fptr1);
  16804. if(ch!=EOF)
  16805. {
  16806. // copy all contents to the temporary file except the specific line
  16807. while (fgets(str, 100, fptr1) != NULL)
  16808. {
  16809. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16810. if(str[0]=='\0')
  16811. {
  16812. break;
  16813. }
  16814. char *revbuf[8] = {0};
  16815. int num = 0;
  16816. strcpy(strtemp, str);
  16817. splitstring(str,",",revbuf,&num);
  16818. if(revbuf[2][0] != '\0')
  16819. {
  16820. temptransactionId = atoi(revbuf[2]);
  16821. if(transactionId != temptransactionId)
  16822. {
  16823. fprintf(fptr2, "%s\n", strtemp);
  16824. }
  16825. }
  16826. }
  16827. }
  16828. fclose(fptr1);
  16829. fclose(fptr2);
  16830. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16831. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16832. /*------ Read the file ----------------*/
  16833. }
  16834. int InternetDisconnect(void)
  16835. {
  16836. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16837. }
  16838. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16839. void storeTempStopTransaction(int gun_index)
  16840. {
  16841. char guid[37]={0};
  16842. int tempIndex = 0;
  16843. char TempStopTransaction[256];
  16844. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16845. DEBUG_INFO("storeTempStopTransaction...\n");
  16846. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16847. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16848. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16849. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16850. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16851. {
  16852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16853. {
  16854. tempIndex = ((gun_index==2) ? 1: 0);
  16855. }
  16856. else
  16857. {
  16858. tempIndex = gun_index;
  16859. }
  16860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16861. {
  16862. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16863. {
  16864. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16865. }
  16866. }// END OF CHAdeMO_QUANTITY
  16867. }
  16868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16869. {
  16870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16871. {
  16872. tempIndex = ((gun_index==2) ? 1: 0);
  16873. }
  16874. else
  16875. {
  16876. tempIndex = gun_index;
  16877. }
  16878. for (int index = 0; index < CCS_QUANTITY; index++)
  16879. {
  16880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16881. {
  16882. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16883. }
  16884. }// END OF CCS_QUANTITY
  16885. }
  16886. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16887. {
  16888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16889. {
  16890. tempIndex = ((gun_index==2) ? 1: 0);
  16891. }
  16892. else
  16893. {
  16894. tempIndex = gun_index;
  16895. }
  16896. for (int index = 0; index < GB_QUANTITY; index++)
  16897. {
  16898. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16899. {
  16900. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16901. }
  16902. }// END OF GB_QUANTITY
  16903. }
  16904. else if(gunType[gun_index] == GUN_TYPE_DO)
  16905. {
  16906. tempIndex = gun_index;
  16907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16908. {
  16909. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16910. {
  16911. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16912. }
  16913. }
  16914. }
  16915. else
  16916. {
  16917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16918. {
  16919. tempIndex = 2;
  16920. }
  16921. else
  16922. {
  16923. tempIndex = gun_index;
  16924. }
  16925. for (int index = 0; index < AC_QUANTITY; index++)
  16926. {
  16927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16928. {
  16929. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16930. }
  16931. }// END OF AC_QUANTITY
  16932. }
  16933. //Stop Transaction Time
  16934. struct timeval tmnow;
  16935. struct tm *tm;
  16936. char buf[28];//, usec_buf[6];
  16937. gettimeofday(&tmnow, NULL);
  16938. time_t t;
  16939. t = time(NULL);
  16940. /*UTC time and date*/
  16941. tm = gmtime(&t);
  16942. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16944. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16946. random_uuid(guid);
  16947. /***********************************transactionData******************************************************/
  16948. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16949. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16950. //=================================
  16951. //1. Transaction_Begin
  16952. //=================================
  16953. //============================== Energy.Active.Import.Interval ===========================================
  16954. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16955. {
  16956. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16959. 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*/]);
  16960. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16961. 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))
  16962. {
  16963. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16964. }
  16965. else
  16966. {
  16967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16968. }
  16969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16971. }
  16972. //=================================
  16973. //2. Transaction_End
  16974. //=================================
  16975. //2.1====================================== Current.Import L1 ==============================================
  16976. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16977. {
  16978. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16979. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16980. {
  16981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16982. {
  16983. tempIndex = ((gun_index==2) ? 1: 0);
  16984. }
  16985. else
  16986. {
  16987. tempIndex = gun_index;
  16988. }
  16989. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16990. {
  16991. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16992. {
  16993. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16994. }
  16995. }// End of for CHAdeMO_QUANTITY
  16996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16997. }
  16998. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16999. {
  17000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17001. {
  17002. tempIndex = ((gun_index==2) ? 1: 0);
  17003. }
  17004. else
  17005. {
  17006. tempIndex = gun_index;
  17007. }
  17008. for (int index = 0; index < CCS_QUANTITY; index++)
  17009. {
  17010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17011. {
  17012. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17013. }
  17014. }// End of for CCS_QUANTITY
  17015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17016. }
  17017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17018. {
  17019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17020. {
  17021. tempIndex = ((gun_index==2) ? 1: 0);
  17022. }
  17023. else
  17024. {
  17025. tempIndex = gun_index;
  17026. }
  17027. for (int index = 0; index < GB_QUANTITY; index++)
  17028. {
  17029. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17030. {
  17031. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17032. }
  17033. }// End of for GB_QUANTITY
  17034. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17035. }
  17036. else if(gunType[gun_index] == GUN_TYPE_DO)
  17037. {
  17038. tempIndex = gun_index;
  17039. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17040. {
  17041. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17042. {
  17043. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17044. }
  17045. }
  17046. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17047. }
  17048. else
  17049. {
  17050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17051. {
  17052. tempIndex = 2;
  17053. }
  17054. else
  17055. {
  17056. tempIndex = gun_index;
  17057. }
  17058. for (int index = 0; index < AC_QUANTITY; index++)
  17059. {
  17060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17061. {
  17062. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17063. }
  17064. }// End of for AC_QUANTITY
  17065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17066. }
  17067. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17069. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17070. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17073. }
  17074. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17075. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17076. {
  17077. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17078. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17079. {
  17080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17081. {
  17082. tempIndex = ((gun_index==2) ? 1: 0);
  17083. }
  17084. else
  17085. {
  17086. tempIndex = gun_index;
  17087. }
  17088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17089. {
  17090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17091. {
  17092. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17093. }
  17094. }// END OF CHAdeMO_QUANTITY
  17095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17096. }
  17097. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17098. {
  17099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17100. {
  17101. tempIndex = ((gun_index==2) ? 1: 0);
  17102. }
  17103. else
  17104. {
  17105. tempIndex = gun_index;
  17106. }
  17107. for (int index = 0; index < CCS_QUANTITY; index++)
  17108. {
  17109. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17110. {
  17111. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17112. }
  17113. }// END OF CCS_QUANTITY
  17114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17115. }
  17116. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17117. {
  17118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17119. {
  17120. tempIndex = ((gun_index==2) ? 1: 0);
  17121. }
  17122. else
  17123. {
  17124. tempIndex = gun_index;
  17125. }
  17126. for (int index = 0; index < GB_QUANTITY; index++)
  17127. {
  17128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17129. {
  17130. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17131. }
  17132. }// END OF GB_QUANTITY
  17133. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17134. }
  17135. else if(gunType[gun_index] == GUN_TYPE_DO)
  17136. {
  17137. tempIndex = gun_index;
  17138. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17139. {
  17140. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17141. {
  17142. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17143. }
  17144. }
  17145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17146. }
  17147. else
  17148. {
  17149. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17150. {
  17151. tempIndex = 2;
  17152. }
  17153. else
  17154. {
  17155. tempIndex = gun_index;
  17156. }
  17157. for (int index = 0; index < AC_QUANTITY; index++)
  17158. {
  17159. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17160. {
  17161. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17162. }
  17163. }// END OF AC_QUANTITY
  17164. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17165. }
  17166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17169. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17172. }
  17173. //2.3====================================== Power.Active.Import =========================================
  17174. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17175. {
  17176. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17177. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17178. {
  17179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17180. {
  17181. tempIndex = ((gun_index==2) ? 1: 0);
  17182. }
  17183. else
  17184. {
  17185. tempIndex = gun_index;
  17186. }
  17187. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17188. {
  17189. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17190. {
  17191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17192. }
  17193. } // End for CHAdeMO_QUANTITY
  17194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17195. }
  17196. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17197. {
  17198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17199. {
  17200. tempIndex = ((gun_index==2) ? 1: 0);
  17201. }
  17202. else
  17203. {
  17204. tempIndex = gun_index;
  17205. }
  17206. for (int index = 0; index < CCS_QUANTITY; index++)
  17207. {
  17208. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17209. {
  17210. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17211. }
  17212. } // END for CCS_QUANTITY
  17213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17214. }
  17215. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17216. {
  17217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17218. {
  17219. tempIndex = ((gun_index==2) ? 1: 0);
  17220. }
  17221. else
  17222. {
  17223. tempIndex = gun_index;
  17224. }
  17225. for (int index = 0; index < GB_QUANTITY; index++)
  17226. {
  17227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17228. {
  17229. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17230. }
  17231. }// END for GB_QUANTITY
  17232. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17233. }
  17234. else if(gunType[gun_index] == GUN_TYPE_DO)
  17235. {
  17236. tempIndex = gun_index;
  17237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17238. {
  17239. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17240. {
  17241. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17242. }
  17243. }
  17244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17245. }
  17246. else
  17247. {
  17248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17249. {
  17250. tempIndex = 2;
  17251. }
  17252. else
  17253. {
  17254. tempIndex = gun_index;
  17255. }
  17256. for (int index = 0; index < AC_QUANTITY; index++)
  17257. {
  17258. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17259. {
  17260. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17261. }
  17262. } // END for AC_QUANTITY
  17263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17264. }
  17265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17268. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17271. }
  17272. //2.4====================================== Voltage L1 ====================================================
  17273. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17274. {
  17275. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17276. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17277. {
  17278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17279. {
  17280. tempIndex = ((gun_index==2) ? 1: 0);
  17281. }
  17282. else
  17283. {
  17284. tempIndex = gun_index;
  17285. }
  17286. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17287. {
  17288. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17289. {
  17290. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17291. }
  17292. } // END OF FOR CHAdeMO_QUANTITY
  17293. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17294. }
  17295. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17296. {
  17297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17298. {
  17299. tempIndex = ((gun_index==2) ? 1: 0);
  17300. }
  17301. else
  17302. {
  17303. tempIndex = gun_index;
  17304. }
  17305. for (int index = 0; index < CCS_QUANTITY; index++)
  17306. {
  17307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17308. {
  17309. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17310. }
  17311. } // END OF FOR CCS_QUANTITY
  17312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17313. }
  17314. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17315. {
  17316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17317. {
  17318. tempIndex = ((gun_index==2) ? 1: 0);
  17319. }
  17320. else
  17321. {
  17322. tempIndex = gun_index;
  17323. }
  17324. for (int index = 0; index < GB_QUANTITY; index++)
  17325. {
  17326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17327. {
  17328. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17329. }
  17330. } // END OF FOR GB_QUANTITY
  17331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17332. }
  17333. else if(gunType[gun_index] == GUN_TYPE_DO)
  17334. {
  17335. tempIndex = gun_index;
  17336. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17337. {
  17338. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17339. {
  17340. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17341. }
  17342. }
  17343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17344. }
  17345. else
  17346. {
  17347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17348. {
  17349. tempIndex = 2;
  17350. }
  17351. else
  17352. {
  17353. tempIndex = gun_index;
  17354. }
  17355. for (int index = 0; index < AC_QUANTITY; index++)
  17356. {
  17357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17358. {
  17359. 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
  17360. }
  17361. } // END OF FOR AC_QUANTITY
  17362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17363. }
  17364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17367. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17368. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17370. }
  17371. //2.5============================================== End SoC =========================================================
  17372. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17373. {
  17374. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17375. 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))
  17376. {
  17377. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17378. {
  17379. tempIndex = ((gun_index==2) ? 1: 0);
  17380. }
  17381. else
  17382. {
  17383. tempIndex = gun_index;
  17384. }
  17385. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17386. {
  17387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17388. {
  17389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17390. {
  17391. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17392. }
  17393. }
  17394. }
  17395. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17396. {
  17397. for (int index = 0; index < CCS_QUANTITY; index++)
  17398. {
  17399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17400. {
  17401. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17402. }
  17403. }
  17404. }
  17405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17406. {
  17407. for (int index = 0; index < GB_QUANTITY; index++)
  17408. {
  17409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17410. {
  17411. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17412. }
  17413. }
  17414. }
  17415. else if(gunType[gun_index] == GUN_TYPE_DO)
  17416. {
  17417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17418. {
  17419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17420. {
  17421. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17422. }
  17423. }
  17424. }
  17425. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17426. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17427. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17430. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17431. } // END FOR DC CASE
  17432. }
  17433. //2.6====================================== Current.Import L2 ==============================================
  17434. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17435. {
  17436. // AC 3 phase L2 current
  17437. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17438. {
  17439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17440. {
  17441. tempIndex = 2;
  17442. }
  17443. else
  17444. {
  17445. tempIndex = gun_index;
  17446. }
  17447. for (int index = 0; index < AC_QUANTITY; index++)
  17448. {
  17449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17450. {
  17451. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17452. }
  17453. }// End of for AC_QUANTITY
  17454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17455. }
  17456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17461. }
  17462. //2.7====================================== Current.Import L3 ==============================================
  17463. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17464. {
  17465. // AC 3 phase L3 current
  17466. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17467. {
  17468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17469. {
  17470. tempIndex = 2;
  17471. }
  17472. else
  17473. {
  17474. tempIndex = gun_index;
  17475. }
  17476. for (int index = 0; index < AC_QUANTITY; index++)
  17477. {
  17478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17479. {
  17480. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17481. }
  17482. }// End of for AC_QUANTITY
  17483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17484. }
  17485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17490. }
  17491. //2.9====================================== Voltage L2 ====================================================
  17492. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17493. {
  17494. // AC 3 phase L2 volatge
  17495. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17496. {
  17497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17498. {
  17499. tempIndex = 2;
  17500. }
  17501. else
  17502. {
  17503. tempIndex = gun_index;
  17504. }
  17505. for (int index = 0; index < AC_QUANTITY; index++)
  17506. {
  17507. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17508. {
  17509. 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
  17510. }
  17511. } // END OF FOR AC_QUANTITY
  17512. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17513. }
  17514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17515. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17516. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17517. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17518. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17519. }
  17520. //2.10====================================== Voltage L3 ====================================================
  17521. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17522. {
  17523. // AC 3 phase L3 volatge
  17524. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17525. {
  17526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17527. {
  17528. tempIndex = 2;
  17529. }
  17530. else
  17531. {
  17532. tempIndex = gun_index;
  17533. }
  17534. for (int index = 0; index < AC_QUANTITY; index++)
  17535. {
  17536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17537. {
  17538. 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
  17539. }
  17540. } // END OF FOR AC_QUANTITY
  17541. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17542. }
  17543. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17548. }
  17549. //====================== Start SoC ================================
  17550. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17551. {
  17552. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17553. 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))
  17554. {
  17555. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17556. {
  17557. tempIndex = ((gun_index==2) ? 1: 0);
  17558. }
  17559. else
  17560. {
  17561. tempIndex = gun_index;
  17562. }
  17563. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17564. {
  17565. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17566. {
  17567. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17568. {
  17569. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17570. }
  17571. }
  17572. }
  17573. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17574. {
  17575. for (int index = 0; index < CCS_QUANTITY; index++)
  17576. {
  17577. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17578. {
  17579. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17580. }
  17581. }
  17582. }
  17583. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17584. {
  17585. for (int index = 0; index < GB_QUANTITY; index++)
  17586. {
  17587. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17588. {
  17589. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17590. }
  17591. }
  17592. }
  17593. else if(gunType[gun_index] == GUN_TYPE_DO)
  17594. {
  17595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17596. {
  17597. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17598. {
  17599. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17600. }
  17601. }
  17602. }
  17603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17609. } // END FOR DC CASE
  17610. }
  17611. //======================================== Message create ==============================================
  17612. json_object *StopTransaction = json_object_new_object();
  17613. json_object *transactionDatas = json_object_new_array();
  17614. json_object *sampledValues = json_object_new_array();
  17615. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17616. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17617. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17618. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17619. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17620. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17621. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17622. {
  17623. json_object *transactionData = json_object_new_object();
  17624. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17625. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17626. {
  17627. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17628. {
  17629. json_object *sampledValue = json_object_new_object();
  17630. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17631. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17632. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17633. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17634. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17635. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17636. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17637. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17638. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17639. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17640. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17641. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17642. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17643. json_object_array_add(sampledValues, sampledValue);
  17644. }
  17645. }
  17646. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17647. json_object_array_add(transactionDatas, transactionData);
  17648. }
  17649. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17650. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17651. ,MESSAGE_TYPE_CALL
  17652. ,guid
  17653. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17654. json_object_put(StopTransaction);
  17655. // Check File "TempStopTransaction" Exist
  17656. if((access(TempStopTransaction,F_OK))!=-1)
  17657. {
  17658. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17659. fclose(fopen(TempStopTransaction, "w"));
  17660. }
  17661. else
  17662. {
  17663. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17664. FILE *log = fopen(TempStopTransaction, "w+");
  17665. if(log == NULL)
  17666. {
  17667. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17668. return ;
  17669. }
  17670. else
  17671. {
  17672. fclose(log);
  17673. }
  17674. }
  17675. //Add TempStopTransaction | Update TempStopTransaction
  17676. // open file for writing
  17677. FILE *outfile;
  17678. outfile = fopen (TempStopTransaction, "a");
  17679. //DEBUG_INFO("data = %s\n", queuedata);
  17680. fputs(queuedata, outfile);
  17681. fputs("\n", outfile);
  17682. fclose (outfile);
  17683. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17684. }
  17685. void checkTempStopTransaction(int gun_index)
  17686. {
  17687. FILE *fptr1;
  17688. char ch;
  17689. char str[QUEUE_MESSAGE_LENGTH]={0};
  17690. char guid[37]={0};
  17691. char tempdata[65]={0};
  17692. char connectorStr[2]={0};
  17693. char TempStopTransaction[256];
  17694. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17695. fptr1 = fopen(TempStopTransaction, "r");
  17696. //TempStopTransaction格式: 槍號,StopTransaction封包
  17697. if (!fptr1)
  17698. {
  17699. //printf(" File not found or unable to open the input file!!\n");
  17700. return ;
  17701. }
  17702. ch=fgetc(fptr1);
  17703. //printf(" Now the content of the file %s is : \n",fname);
  17704. rewind(fptr1);
  17705. if(ch!=EOF)
  17706. {
  17707. // copy all contents to the temporary file except the specific line
  17708. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17709. {
  17710. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17711. if(str[0]=='\0')
  17712. {
  17713. break;
  17714. }
  17715. //TempStopTransaction格式: 槍號,StopTransaction封包
  17716. strncpy(connectorStr, str, 1);
  17717. if(atoi(connectorStr) != (gun_index+1))
  17718. {
  17719. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17720. fclose(fptr1);
  17721. return ;
  17722. }
  17723. //random_uuid(guid);
  17724. strncpy(guid, str+6, 36); //copy guid
  17725. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17726. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17727. {
  17728. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17729. }
  17730. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17731. OCPP_insert_transaction_msg(NO, str);
  17732. memset(str,0,ARRAY_SIZE(str));
  17733. }
  17734. }
  17735. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17736. fclose(fptr1);
  17737. remove(TempStopTransaction); // remove the original file
  17738. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17739. }
  17740. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17741. {
  17742. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17743. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17744. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17745. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17746. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17747. }
  17748. int GetWebSocketPingInterval(void)
  17749. {
  17750. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17751. }
  17752. int GetServerSign(void)
  17753. {
  17754. return server_sign;
  17755. }
  17756. uint8_t GetOcppSecurityProfile()
  17757. {
  17758. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17759. }
  17760. void GetOcppChargerBoxId(uint8_t *data)
  17761. {
  17762. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17763. }
  17764. void GetOcppSecurityPassword(uint8_t *data)
  17765. {
  17766. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17767. }
  17768. void SetOcppVersion(uint8_t *version)
  17769. {
  17770. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17771. DEBUG_INFO("ocpp version: %s\n", version);
  17772. if(strstr((char*)version, "ocpp1.6") != NULL)
  17773. {
  17774. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17775. }
  17776. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17777. {
  17778. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17779. system("pkill OcppBackend");
  17780. }
  17781. }
  17782. void SetServerSign(int value)
  17783. {
  17784. server_sign = value;
  17785. }
  17786. int GetBootNotificationInterval(void)
  17787. {
  17788. return BootNotificationInterval;
  17789. }
  17790. int GetInternetConn(void)
  17791. {
  17792. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17793. }
  17794. int GetBackendConnectionTimeout(void)
  17795. {
  17796. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17797. }
  17798. int isConnectorInitMode(int gun_index)
  17799. {
  17800. int tempIndex = 0;
  17801. int result = TRUE;
  17802. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17803. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17804. {
  17805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17806. {
  17807. tempIndex = ((gun_index==2) ? 1: 0);
  17808. }
  17809. else
  17810. {
  17811. tempIndex = gun_index;
  17812. }
  17813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17814. {
  17815. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17816. {
  17817. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17818. } //end of the same index
  17819. }//end of for CHAdeMO_QUANTITY
  17820. }
  17821. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17822. {
  17823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17824. {
  17825. tempIndex = ((gun_index==2) ? 1: 0);
  17826. }
  17827. else
  17828. {
  17829. tempIndex = gun_index;
  17830. }
  17831. for (int index = 0; index < CCS_QUANTITY; index++)
  17832. {
  17833. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17834. {
  17835. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17836. } //end of the same index
  17837. } // end of for CCS_QUANTITY
  17838. }
  17839. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17840. {
  17841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17842. {
  17843. tempIndex = ((gun_index==2) ? 1: 0);
  17844. }
  17845. else
  17846. {
  17847. tempIndex = gun_index;
  17848. }
  17849. for (int index = 0; index < GB_QUANTITY; index++)
  17850. {
  17851. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17852. {
  17853. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17854. } //end of the same index
  17855. } // end of for GB_QUANTITY
  17856. }
  17857. else if(gunType[gun_index] == GUN_TYPE_DO)
  17858. {
  17859. tempIndex = gun_index;
  17860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17861. {
  17862. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17863. {
  17864. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17865. } //end of the same index
  17866. }
  17867. }
  17868. else
  17869. {
  17870. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17871. {
  17872. tempIndex = 2;
  17873. }
  17874. else
  17875. {
  17876. tempIndex = gun_index;
  17877. }
  17878. for (int index = 0; index < AC_QUANTITY; index++)
  17879. {
  17880. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17881. {
  17882. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17883. }//end of the same index
  17884. }//end of for AC_QUANTITY
  17885. }
  17886. return result;
  17887. }
  17888. void refreshProcDogTimer()
  17889. {
  17890. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17891. }
  17892. void InitialSystemValue(void)
  17893. {
  17894. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17895. locallistVersion=0;
  17896. BootNotificationInterval = 0;
  17897. authorizeRetryTimes = 0;
  17898. GunStatusInterval = 10;
  17899. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17900. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17901. //Hear Beat
  17902. HeartBeatWithNOResponse = 0;
  17903. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17904. FirstHeartBeat = 0;
  17905. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17906. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17907. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17908. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17909. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17910. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17911. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17912. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17913. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17914. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17915. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17916. //Status && ConnectorPlugIn Setting
  17917. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17918. {
  17919. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17920. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17921. }
  17922. for (int index = 0; index < CCS_QUANTITY; index++)
  17923. {
  17924. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17925. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17926. }
  17927. for (int index = 0; index < GB_QUANTITY; index++)
  17928. {
  17929. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17930. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17931. }
  17932. for (int index = 0; index < AC_QUANTITY; index++)
  17933. {
  17934. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17935. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17936. }
  17937. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17938. {
  17939. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17940. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17941. }
  17942. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17943. {
  17944. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17945. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17946. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17947. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17948. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17949. }
  17950. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17951. refreshStartTimer(&clientTime.Heartbeat);
  17952. sleep(1);
  17953. }
  17954. void LWS_Send(char *str)
  17955. {
  17956. //=====================================================
  17957. // Check InternetConn 0: disconnected, 1: connected
  17958. //====================================================
  17959. if(GetOcppConnStatus() == 0)
  17960. {
  17961. DEBUG_INFO("offline now !!!\n");
  17962. return;
  17963. }
  17964. // Only disable isWebsocketSendable operation initiated by charger
  17965. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17966. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17967. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17968. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17969. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17970. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17971. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17972. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17973. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17974. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17975. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17976. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17977. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17978. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17979. {
  17980. isWebsocketSendable = 0;
  17981. }
  17982. pthread_mutex_lock(&lock_send);
  17983. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17984. sprintf((char *)SendBuffer, "%s", str);
  17985. SendBufLen = strlen(str);
  17986. pthread_mutex_unlock(&lock_send);
  17987. lws_callback_on_writable(wsi_client);
  17988. //lws_service(context, 0);
  17989. //sleep(1);
  17990. }
  17991. void LWS_SendNow(char *str)
  17992. {
  17993. //=====================================================
  17994. // Check InternetConn 0: disconnected, 1: connected
  17995. //====================================================
  17996. if(GetOcppConnStatus() == 0)
  17997. {
  17998. DEBUG_INFO("offline now !!!\n");
  17999. return;
  18000. }
  18001. // Only disable isWebsocketSendable operation initiated by charger
  18002. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18003. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18004. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18005. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18006. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18007. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18008. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18009. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18010. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18011. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18012. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18013. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18014. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18015. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18016. {
  18017. isWebsocketSendable = 0;
  18018. }
  18019. pthread_mutex_lock(&lock_send);
  18020. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18021. sprintf((char *)SendBuffer, "%s", str);
  18022. SendBufLen = strlen(str);
  18023. pthread_mutex_unlock(&lock_send);
  18024. lws_callback_on_writable(wsi_client);
  18025. lws_service(context, 0);
  18026. //sleep(1);
  18027. }