MessageHandler.c 907 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":%s}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. //==========================================
  735. // Check time passed since today
  736. //==========================================
  737. long long DiffTimebWithNow(struct timeb ST)
  738. {
  739. //return milli-second
  740. struct timeb ET;
  741. long long StartTime,StopTime;
  742. ftime(&ET);
  743. StartTime=(long long)ST.time;
  744. StopTime=(long long)ET.time;
  745. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  746. }
  747. int getTimePassSinceToday(uint8_t gun_index)
  748. {
  749. int result = -1;
  750. static time_t lastTime[4];
  751. time_t t;
  752. struct tm *tmStartToday;
  753. struct timeb tbStartToday;
  754. t=time(NULL);
  755. if(difftime(t, lastTime[gun_index])>0)
  756. {
  757. tmStartToday=localtime(&t);
  758. tmStartToday->tm_hour = 0;
  759. tmStartToday->tm_min = 0;
  760. tmStartToday->tm_sec = 0;
  761. tbStartToday.time = mktime(tmStartToday);
  762. tbStartToday.millitm = 0;
  763. result = DiffTimebWithNow(tbStartToday)/1000;
  764. lastTime[gun_index] = t;
  765. }
  766. return result;
  767. }
  768. void getNowDatetime(uint8_t *data)
  769. {
  770. time_t t = time(NULL);
  771. struct tm tm = *localtime(&t);
  772. 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);
  773. }
  774. int syncDateTimeRTC(uint8_t *data)
  775. {
  776. struct ParsingResult
  777. {
  778. int result;
  779. int scanedElement;
  780. int year;
  781. int month;
  782. int mday;
  783. int hour;
  784. int min;
  785. int sec;
  786. int tz_hour;
  787. int tz_min;
  788. float minSec;
  789. }result;
  790. struct tm tmOrg;
  791. struct tm *tmTarget;
  792. struct timeb tbTarget;
  793. char buf[128];
  794. memset(&result, 0x00, sizeof(struct ParsingResult));
  795. result.result = PASS;
  796. if(strstr((char*)data, ".") != NULL)
  797. {
  798. // Original data with mini second
  799. if(strstr((char*)data, "Z") != NULL)
  800. {
  801. // Original data with Z
  802. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  803. &result.year,
  804. &result.month,
  805. &result.mday,
  806. &result.hour,
  807. &result.min,
  808. &result.sec,
  809. &result.minSec);
  810. }
  811. else
  812. {
  813. // Original data without Z
  814. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  815. &result.year,
  816. &result.month,
  817. &result.mday,
  818. &result.hour,
  819. &result.min,
  820. &result.sec,
  821. &result.minSec,
  822. &result.tz_hour,
  823. &result.tz_min);
  824. }
  825. }
  826. else
  827. {
  828. // Original data without mini second
  829. if(strstr((char*)data, "Z") != NULL)
  830. {
  831. // Original data with Z
  832. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  833. &result.year,
  834. &result.month,
  835. &result.mday,
  836. &result.hour,
  837. &result.min,
  838. &result.sec);
  839. }
  840. else
  841. {
  842. // Original data without Z
  843. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  844. &result.year,
  845. &result.month,
  846. &result.mday,
  847. &result.hour,
  848. &result.min,
  849. &result.sec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. tmOrg.tm_year = result.year - 1900;
  855. tmOrg.tm_mon = result.month - 1;
  856. tmOrg.tm_mday = result.mday;
  857. tmOrg.tm_hour = result.hour;
  858. tmOrg.tm_min = result.min;
  859. tmOrg.tm_sec = result.sec;
  860. tmOrg.tm_gmtoff = 0;
  861. tbTarget.time = mktime(&tmOrg);
  862. tbTarget.timezone = 0;
  863. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  864. tmTarget = gmtime(&tbTarget.time);
  865. 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);
  866. //DEBUG_INFO(" org date time: %s\n", data);
  867. //DEBUG_INFO("parse date time: %s\n", buf);
  868. system(buf);
  869. system("/sbin/hwclock -w --systohc");
  870. if(result.scanedElement < 6)
  871. result.result = FAIL;
  872. return result.result;
  873. }
  874. //==========================================
  875. // GetCompositeSchedule logic related function
  876. //==========================================
  877. int DiffTimebSec(struct timeb ST, struct timeb ET)
  878. {
  879. //return milli-second
  880. unsigned int StartTime,StopTime;
  881. StartTime=(unsigned int)ST.time;
  882. StopTime=(unsigned int)ET.time;
  883. return (StopTime-StartTime);
  884. }
  885. int DiffTimebWithNowSec(struct timeb ST)
  886. {
  887. //return milli-second
  888. struct timeb ET;
  889. unsigned int StartTime,StopTime;
  890. ftime(&ET);
  891. StartTime=(unsigned int)ST.time;
  892. StopTime=(unsigned int)ET.time;
  893. return (StopTime-StartTime);
  894. }
  895. int getStartStop(uint8_t *start, uint8_t *stop)
  896. {
  897. int result = -1;
  898. struct tm tmStart;
  899. struct timeb tbStart;
  900. struct tm tmStop;
  901. struct timeb tbStop;
  902. 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) &&
  903. (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))
  904. {
  905. //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);
  906. //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);
  907. tmStart.tm_year -= 1900;
  908. tmStart.tm_mon -= 1;
  909. tbStart.time = mktime(&tmStart);
  910. tbStart.millitm = 0;
  911. tmStop.tm_year -= 1900;
  912. tmStop.tm_mon -= 1;
  913. tbStop.time = mktime(&tmStop);
  914. tbStop.millitm = 0;
  915. result = DiffTimebSec(tbStart, tbStop);
  916. //DEBUG_INFO("getStartStop(): %d\n", result);
  917. }
  918. else
  919. {
  920. DEBUG_WARN("Start or stop date parsing error.\r\n");
  921. }
  922. return result;
  923. }
  924. int isOvertNow(uint8_t *start)
  925. {
  926. int result = NO;
  927. struct ParsingResult
  928. {
  929. int result;
  930. int scanedElement;
  931. int year;
  932. int month;
  933. int mday;
  934. int hour;
  935. int min;
  936. int sec;
  937. int tz_hour;
  938. int tz_min;
  939. float minSec;
  940. }parsingResult;
  941. struct tm tmStart;
  942. struct timeb tbStart;
  943. if(strstr((char*)start, ".") != NULL)
  944. {
  945. // Original data with mini second
  946. if(strstr((char*)start, "Z") != NULL)
  947. {
  948. // Original data with Z
  949. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  950. &parsingResult.year,
  951. &parsingResult.month,
  952. &parsingResult.mday,
  953. &parsingResult.hour,
  954. &parsingResult.min,
  955. &parsingResult.sec,
  956. &parsingResult.minSec);
  957. }
  958. else
  959. {
  960. // Original data without Z
  961. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  962. &parsingResult.year,
  963. &parsingResult.month,
  964. &parsingResult.mday,
  965. &parsingResult.hour,
  966. &parsingResult.min,
  967. &parsingResult.sec,
  968. &parsingResult.minSec,
  969. &parsingResult.tz_hour,
  970. &parsingResult.tz_min);
  971. }
  972. }
  973. else
  974. {
  975. // Original data without mini second
  976. if(strstr((char*)start, "Z") != NULL)
  977. {
  978. // Original data with Z
  979. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  980. &parsingResult.year,
  981. &parsingResult.month,
  982. &parsingResult.mday,
  983. &parsingResult.hour,
  984. &parsingResult.min,
  985. &parsingResult.sec);
  986. }
  987. else
  988. {
  989. // Original data without Z
  990. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  991. &parsingResult.year,
  992. &parsingResult.month,
  993. &parsingResult.mday,
  994. &parsingResult.hour,
  995. &parsingResult.min,
  996. &parsingResult.sec,
  997. &parsingResult.tz_hour,
  998. &parsingResult.tz_min);
  999. }
  1000. }
  1001. if(parsingResult.scanedElement >= 6)
  1002. {
  1003. tmStart.tm_year = parsingResult.year - 1900;
  1004. tmStart.tm_mon = parsingResult.month - 1;
  1005. tmStart.tm_mday = parsingResult.mday;
  1006. tmStart.tm_hour = parsingResult.hour;
  1007. tmStart.tm_min = parsingResult.min;
  1008. tmStart.tm_sec = parsingResult.sec;
  1009. tmStart.tm_gmtoff = 0;
  1010. tbStart.time = mktime(&tmStart);
  1011. tbStart.timezone = 0;
  1012. tbStart.millitm = 0;
  1013. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1014. if(DiffTimebWithNowSec(tbStart) <= 0)
  1015. result = NO;
  1016. else
  1017. result = YES;
  1018. }
  1019. else
  1020. {
  1021. DEBUG_WARN("Start date parsing error.\n");
  1022. }
  1023. return result;
  1024. }
  1025. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1026. {
  1027. int result = -1;
  1028. struct tm tmStart;
  1029. struct timeb tbStart;
  1030. struct tm tmStop;
  1031. struct timeb tbStop;
  1032. 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) &&
  1033. (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))
  1034. {
  1035. tmStart.tm_year -= 1900;
  1036. tmStart.tm_mon -= 1;
  1037. tbStart.time = mktime(&tmStart);
  1038. tbStart.millitm = 0;
  1039. tmStop.tm_year -= 1900;
  1040. tmStop.tm_mon -= 1;
  1041. tbStop.time = mktime(&tmStop);
  1042. tbStop.millitm = 0;
  1043. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1044. }
  1045. return result;
  1046. }
  1047. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1048. {
  1049. FILE *fp;
  1050. char profileFileName[128];
  1051. char *line = NULL;
  1052. size_t len = 0;
  1053. time_t CurrentTime;
  1054. struct tm *tmComposite;
  1055. struct StructChargingProfile maxProfile;
  1056. uint8_t limitMax=0;
  1057. int compositePeriodIdx = 0;
  1058. CurrentTime = time(NULL);
  1059. tmComposite=localtime(&CurrentTime);
  1060. 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);
  1061. if(isUnitA)
  1062. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1063. else
  1064. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1065. compositeProfile->ChargingSchedule.Duration = durationReq;
  1066. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1067. {
  1068. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1069. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1070. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1071. }
  1072. compositeProfile->ChargingProfileId = 0;
  1073. compositeProfile->StackLevel = 99 ;
  1074. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1075. maxProfile.ChargingProfileId = -1;
  1076. maxProfile.ChargingSchedule.Duration = -1;
  1077. system("rm -f /tmp/*.json");
  1078. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1079. // Search max profile
  1080. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1081. if((access(profileFileName, F_OK))!=-1)
  1082. {
  1083. fp = fopen(profileFileName, "r");
  1084. while(getline(&line, &len, fp) != -1)
  1085. {
  1086. json_object *obj = NULL;
  1087. obj = json_tokener_parse(line);
  1088. if(is_error(obj))
  1089. {
  1090. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1091. }
  1092. else
  1093. {
  1094. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1095. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1096. )
  1097. {
  1098. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1099. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1100. )
  1101. {
  1102. struct tm tmFrom, tmTo;
  1103. struct timeb tbFrom, tbTo;
  1104. 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) &&
  1105. (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))
  1106. {
  1107. tmFrom.tm_year -= 1900;
  1108. tmFrom.tm_mon -= 1;
  1109. tbFrom.time = mktime(&tmFrom);
  1110. tmTo.tm_year -= 1900;
  1111. tmTo.tm_mon -= 1;
  1112. tbTo.time = mktime(&tmTo);
  1113. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1114. {
  1115. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1116. {
  1117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1118. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1119. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1120. }
  1121. maxProfile.ChargingProfileId = -1;
  1122. maxProfile.StackLevel = -1;
  1123. if(maxProfile.ChargingProfileId == -1)
  1124. DEBUG_INFO("MaxProfile found.\n");
  1125. else
  1126. DEBUG_INFO("MaxProfile updated.\n");
  1127. // Required item
  1128. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1129. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1130. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1131. if(isUnitA)
  1132. {
  1133. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1134. 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++)
  1135. {
  1136. 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"));
  1137. 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?
  1138. 3:
  1139. 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")));
  1140. 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")));
  1141. }
  1142. }
  1143. else
  1144. {
  1145. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1146. 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++)
  1147. {
  1148. 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"));
  1149. 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?
  1150. 3:
  1151. 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")));
  1152. 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));
  1153. }
  1154. }
  1155. // Optional item
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1157. {
  1158. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1159. }
  1160. else
  1161. {
  1162. sprintf((char*)maxProfile.ValidFrom, " ");
  1163. }
  1164. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1165. {
  1166. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1167. }
  1168. else
  1169. {
  1170. sprintf((char*)maxProfile.ValidTo, " ");
  1171. }
  1172. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1173. {
  1174. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1175. }
  1176. else
  1177. {
  1178. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1179. }
  1180. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1181. {
  1182. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.TransactionId = -1;
  1187. }
  1188. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1189. {
  1190. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1191. }
  1192. else
  1193. {
  1194. maxProfile.ChargingSchedule.Duration = 86400;
  1195. }
  1196. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1197. {
  1198. 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")));
  1199. }
  1200. else
  1201. {
  1202. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1203. }
  1204. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1205. {
  1206. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1207. }
  1208. else
  1209. {
  1210. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1211. }
  1212. }
  1213. }
  1214. }
  1215. else
  1216. {
  1217. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1218. {
  1219. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1220. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1221. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1222. }
  1223. maxProfile.ChargingProfileId = -1;
  1224. maxProfile.StackLevel = -1;
  1225. if(maxProfile.ChargingProfileId == -1)
  1226. DEBUG_INFO("MaxProfile found.\n");
  1227. else
  1228. DEBUG_INFO("MaxProfile updated.\n");
  1229. // Required item
  1230. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1231. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1232. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1233. if(isUnitA)
  1234. {
  1235. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1236. 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++)
  1237. {
  1238. 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"));
  1239. 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?
  1240. 3:
  1241. 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")));
  1242. 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")));
  1243. }
  1244. }
  1245. else
  1246. {
  1247. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1248. 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++)
  1249. {
  1250. 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"));
  1251. 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?
  1252. 3:
  1253. 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")));
  1254. 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));
  1255. }
  1256. }
  1257. // Optional item
  1258. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1259. {
  1260. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1261. }
  1262. else
  1263. {
  1264. sprintf((char*)maxProfile.ValidFrom, " ");
  1265. }
  1266. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1267. {
  1268. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1269. }
  1270. else
  1271. {
  1272. sprintf((char*)maxProfile.ValidTo, " ");
  1273. }
  1274. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1275. {
  1276. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1277. }
  1278. else
  1279. {
  1280. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1281. }
  1282. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1283. {
  1284. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1285. }
  1286. else
  1287. {
  1288. maxProfile.TransactionId = -1;
  1289. }
  1290. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1291. {
  1292. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1293. }
  1294. else
  1295. {
  1296. maxProfile.ChargingSchedule.Duration = 86400;
  1297. }
  1298. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1299. {
  1300. 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")));
  1301. }
  1302. else
  1303. {
  1304. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1305. }
  1306. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1307. {
  1308. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1309. }
  1310. else
  1311. {
  1312. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. json_object_put(obj);
  1318. }
  1319. fclose(fp);
  1320. /*
  1321. if(maxProfile.ChargingProfileId !=-1)
  1322. {
  1323. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1324. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1325. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1326. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1327. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1328. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1329. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1330. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1331. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1332. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1333. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1334. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1335. {
  1336. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1337. {
  1338. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1339. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1340. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1341. }
  1342. }
  1343. }
  1344. else
  1345. DEBUG_INFO("MaxProfile not found.\n");
  1346. DEBUG_INFO("------------------------------------\n");*/
  1347. }
  1348. if(maxProfile.ChargingProfileId != -1)
  1349. {
  1350. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1351. {
  1352. if(maxProfile.ChargingSchedule.Duration != -1)
  1353. {
  1354. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1355. 0:
  1356. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1357. }
  1358. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1359. {
  1360. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1361. {
  1362. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1363. 0:
  1364. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1365. if(idxPeriod > 0)
  1366. {
  1367. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1368. {
  1369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1376. {
  1377. if(maxProfile.ChargingSchedule.Duration != -1)
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1380. }
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1384. {
  1385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1386. if(idxPeriod > 0)
  1387. {
  1388. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1389. {
  1390. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. else
  1397. {
  1398. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1399. {
  1400. if(maxProfile.ChargingSchedule.Duration != -1)
  1401. {
  1402. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1403. 0:
  1404. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1405. }
  1406. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1407. {
  1408. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1409. {
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1411. 0:
  1412. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1413. if(idxPeriod > 0)
  1414. {
  1415. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1416. {
  1417. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. }
  1423. else
  1424. {
  1425. if(maxProfile.ChargingSchedule.Duration != -1)
  1426. {
  1427. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1428. 0:
  1429. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1430. }
  1431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1432. {
  1433. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1434. {
  1435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1436. 0:
  1437. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1438. if(idxPeriod > 0)
  1439. {
  1440. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1441. {
  1442. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. /*
  1450. DEBUG_INFO("MaxProfile after align.\n");
  1451. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1452. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1453. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1454. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1455. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1456. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1457. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1458. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1459. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1460. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1461. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1463. {
  1464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1465. {
  1466. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1467. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1468. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1469. }
  1470. }
  1471. DEBUG_INFO("------------------------------------\n");*/
  1472. }
  1473. // Find each profile period quantity
  1474. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1475. {
  1476. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1477. limitMax = idx+1;
  1478. }
  1479. if(maxProfile.ChargingProfileId != -1)
  1480. {
  1481. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1482. {
  1483. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1484. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1485. (maxProfile.ChargingSchedule.Duration > 0))
  1486. {
  1487. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1488. {
  1489. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1490. compositePeriodIdx++;
  1491. }
  1492. else
  1493. {
  1494. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1495. }
  1496. }
  1497. }
  1498. }
  1499. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1500. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1501. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1502. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1503. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1504. {
  1505. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1506. {
  1507. compositeProfile->ChargingProfileId = 1;
  1508. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1509. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1510. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1511. }
  1512. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1514. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1516. }
  1517. if(line)
  1518. free(line);
  1519. }
  1520. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1521. {
  1522. FILE *fp;
  1523. char profileFileName[128];
  1524. char *line = NULL;
  1525. size_t len = 0;
  1526. time_t CurrentTime;
  1527. struct tm *tmComposite;
  1528. struct StructChargingProfile maxProfile;
  1529. struct StructChargingProfile defaultTxProfile;
  1530. struct StructChargingProfile txProfile;
  1531. struct StructChargingSchedulePeriod tmpPeriod;
  1532. uint8_t limitMax=0;
  1533. uint8_t limitDef=0;
  1534. uint8_t limitTx=0;
  1535. int compositePeriodIdx = 0;
  1536. CurrentTime = time(NULL);
  1537. tmComposite=localtime(&CurrentTime);
  1538. 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);
  1539. if(isUnitA)
  1540. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1541. else
  1542. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1543. compositeProfile->ChargingSchedule.Duration = durationReq;
  1544. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1545. {
  1546. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1547. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1548. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1549. }
  1550. compositeProfile->ChargingProfileId = 0;
  1551. compositeProfile->StackLevel = 99 ;
  1552. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1553. maxProfile.ChargingProfileId = -1;
  1554. defaultTxProfile.ChargingProfileId = -1;
  1555. txProfile.ChargingProfileId = -1;
  1556. maxProfile.ChargingSchedule.Duration = -1;
  1557. defaultTxProfile.ChargingSchedule.Duration = -1;
  1558. txProfile.ChargingSchedule.Duration = -1;
  1559. system("rm -f /tmp/*.json");
  1560. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1561. /*
  1562. * Search valid charging profile
  1563. */
  1564. //DEBUG_INFO("====================================\n");
  1565. // Search tx profile
  1566. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1567. if((access(profileFileName, F_OK))!=-1)
  1568. {
  1569. fp = fopen(profileFileName, "r");
  1570. while(getline(&line, &len, fp) != -1)
  1571. {
  1572. json_object *obj = NULL;
  1573. obj = json_tokener_parse(line);
  1574. if(is_error(obj))
  1575. {
  1576. DEBUG_ERROR("Parse txProfile from file error.\n");
  1577. }
  1578. else
  1579. {
  1580. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1581. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1582. )
  1583. {
  1584. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1585. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1586. )
  1587. {
  1588. struct tm tmFrom, tmTo;
  1589. struct timeb tbFrom, tbTo;
  1590. 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) &&
  1591. (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))
  1592. {
  1593. tmFrom.tm_year -= 1900;
  1594. tmFrom.tm_mon -= 1;
  1595. tbFrom.time = mktime(&tmFrom);
  1596. tmTo.tm_year -= 1900;
  1597. tmTo.tm_mon -= 1;
  1598. tbTo.time = mktime(&tmTo);
  1599. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1600. {
  1601. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1602. {
  1603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1604. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1605. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1606. }
  1607. txProfile.ChargingProfileId = -1;
  1608. txProfile.StackLevel = -1;
  1609. if(txProfile.ChargingProfileId == -1)
  1610. DEBUG_INFO("TxProfile found.\n");
  1611. else
  1612. DEBUG_INFO("TxProfile updated.\n");
  1613. // Required item
  1614. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1615. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1616. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1617. if(isUnitA)
  1618. {
  1619. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1620. 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++)
  1621. {
  1622. 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"));
  1623. 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?
  1624. 3:
  1625. 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")));
  1626. 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")));
  1627. }
  1628. }
  1629. else
  1630. {
  1631. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1632. 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++)
  1633. {
  1634. 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"));
  1635. 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?
  1636. 3:
  1637. 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")));
  1638. 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));
  1639. }
  1640. }
  1641. // Optional item
  1642. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1643. {
  1644. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1645. }
  1646. else
  1647. {
  1648. sprintf((char*)txProfile.ValidFrom, " ");
  1649. }
  1650. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1651. {
  1652. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1653. }
  1654. else
  1655. {
  1656. sprintf((char*)txProfile.ValidTo, " ");
  1657. }
  1658. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1659. {
  1660. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1661. }
  1662. else
  1663. {
  1664. sprintf((char*)txProfile.RecurrencyKind, " ");
  1665. }
  1666. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1667. {
  1668. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1669. }
  1670. else
  1671. {
  1672. txProfile.TransactionId = -1;
  1673. }
  1674. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1675. {
  1676. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1677. }
  1678. else
  1679. {
  1680. txProfile.ChargingSchedule.Duration = 86400;
  1681. }
  1682. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1683. {
  1684. 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")));
  1685. }
  1686. else
  1687. {
  1688. 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));
  1689. }
  1690. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1691. {
  1692. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1693. }
  1694. else
  1695. {
  1696. txProfile.ChargingSchedule.MinChargingRate = -1;
  1697. }
  1698. }
  1699. }
  1700. }
  1701. else
  1702. {
  1703. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1704. {
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1706. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1707. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1708. }
  1709. txProfile.ChargingProfileId = -1;
  1710. txProfile.StackLevel = -1;
  1711. if(txProfile.ChargingProfileId == -1)
  1712. DEBUG_INFO("TxProfile found.\n");
  1713. else
  1714. DEBUG_INFO("TxProfile updated.\n");
  1715. // Required item
  1716. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1717. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1718. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1719. if(isUnitA)
  1720. {
  1721. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1722. 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++)
  1723. {
  1724. 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"));
  1725. 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?
  1726. 3:
  1727. 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")));
  1728. 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")));
  1729. }
  1730. }
  1731. else
  1732. {
  1733. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1734. 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++)
  1735. {
  1736. 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"));
  1737. 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?
  1738. 3:
  1739. 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")));
  1740. 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));
  1741. }
  1742. }
  1743. // Optional item
  1744. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1745. {
  1746. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1747. }
  1748. else
  1749. {
  1750. sprintf((char*)txProfile.ValidFrom, " ");
  1751. }
  1752. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1753. {
  1754. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1755. }
  1756. else
  1757. {
  1758. sprintf((char*)txProfile.ValidTo, " ");
  1759. }
  1760. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1761. {
  1762. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1763. }
  1764. else
  1765. {
  1766. sprintf((char*)txProfile.RecurrencyKind, " ");
  1767. }
  1768. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1769. {
  1770. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1771. }
  1772. else
  1773. {
  1774. txProfile.TransactionId = -1;
  1775. }
  1776. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1777. {
  1778. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1779. }
  1780. else
  1781. {
  1782. txProfile.ChargingSchedule.Duration = 86400;
  1783. }
  1784. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1785. {
  1786. 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")));
  1787. }
  1788. else
  1789. {
  1790. 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));
  1791. }
  1792. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1793. {
  1794. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1795. }
  1796. else
  1797. {
  1798. txProfile.ChargingSchedule.MinChargingRate = -1;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. json_object_put(obj);
  1804. }
  1805. fclose(fp);
  1806. /*
  1807. if(txProfile.ChargingProfileId != -1)
  1808. {
  1809. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1810. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1811. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1812. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1813. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1814. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1815. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1816. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1817. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1818. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1819. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1820. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1821. {
  1822. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1823. {
  1824. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1825. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1826. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1827. }
  1828. }
  1829. }
  1830. else
  1831. DEBUG_INFO("TxProfile not found.\n");*/
  1832. }
  1833. // Search default tx profile
  1834. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1835. if((access(profileFileName, F_OK))==-1)
  1836. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1837. if((access(profileFileName, F_OK))!=-1)
  1838. {
  1839. fp = fopen(profileFileName, "r");
  1840. while(getline(&line, &len, fp) != -1)
  1841. {
  1842. json_object *obj = NULL;
  1843. obj = json_tokener_parse(line);
  1844. if(is_error(obj))
  1845. {
  1846. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1847. }
  1848. else
  1849. {
  1850. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1851. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1852. )
  1853. {
  1854. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1855. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1856. )
  1857. {
  1858. struct tm tmFrom, tmTo;
  1859. struct timeb tbFrom, tbTo;
  1860. 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) &&
  1861. (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))
  1862. {
  1863. tmFrom.tm_year -= 1900;
  1864. tmFrom.tm_mon -= 1;
  1865. tbFrom.time = mktime(&tmFrom);
  1866. tmTo.tm_year -= 1900;
  1867. tmTo.tm_mon -= 1;
  1868. tbTo.time = mktime(&tmTo);
  1869. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1870. {
  1871. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1874. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1876. }
  1877. defaultTxProfile.ChargingProfileId = -1;
  1878. defaultTxProfile.StackLevel = -1;
  1879. if(defaultTxProfile.ChargingProfileId == -1)
  1880. DEBUG_INFO("TxDefaultProfile found.\n");
  1881. else
  1882. DEBUG_INFO("TxDefaultProfile updated.\n");
  1883. // Required item
  1884. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1885. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1886. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1887. if(isUnitA)
  1888. {
  1889. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1890. 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++)
  1891. {
  1892. 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"));
  1893. 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?
  1894. 3:
  1895. 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")));
  1896. 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")));
  1897. }
  1898. }
  1899. else
  1900. {
  1901. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1902. 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++)
  1903. {
  1904. 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"));
  1905. 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?
  1906. 3:
  1907. 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")));
  1908. 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));
  1909. }
  1910. }
  1911. // Optional item
  1912. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1913. {
  1914. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1915. }
  1916. else
  1917. {
  1918. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1919. }
  1920. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1921. {
  1922. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1923. }
  1924. else
  1925. {
  1926. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1927. }
  1928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1929. {
  1930. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1931. }
  1932. else
  1933. {
  1934. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1935. }
  1936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1937. {
  1938. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1939. }
  1940. else
  1941. {
  1942. defaultTxProfile.TransactionId = -1;
  1943. }
  1944. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1945. {
  1946. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1947. }
  1948. else
  1949. {
  1950. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1951. }
  1952. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1953. {
  1954. 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")));
  1955. }
  1956. else
  1957. {
  1958. 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));
  1959. }
  1960. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1961. {
  1962. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1963. }
  1964. else
  1965. {
  1966. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1967. }
  1968. }
  1969. }
  1970. }
  1971. else
  1972. {
  1973. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1974. {
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1977. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1978. }
  1979. defaultTxProfile.ChargingProfileId = -1;
  1980. defaultTxProfile.StackLevel = -1;
  1981. if(defaultTxProfile.ChargingProfileId == -1)
  1982. DEBUG_INFO("TxDefaultProfile found.\n");
  1983. else
  1984. DEBUG_INFO("TxDefaultProfile updated.\n");
  1985. // Required item
  1986. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1987. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1988. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1989. if(isUnitA)
  1990. {
  1991. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1992. 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++)
  1993. {
  1994. 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"));
  1995. 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?
  1996. 3:
  1997. 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")));
  1998. 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")));
  1999. }
  2000. }
  2001. else
  2002. {
  2003. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2004. 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++)
  2005. {
  2006. 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"));
  2007. 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?
  2008. 3:
  2009. 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")));
  2010. 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));
  2011. }
  2012. }
  2013. // Optional item
  2014. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2015. {
  2016. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2017. }
  2018. else
  2019. {
  2020. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2021. }
  2022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2023. {
  2024. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2025. }
  2026. else
  2027. {
  2028. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2029. }
  2030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2031. {
  2032. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2033. }
  2034. else
  2035. {
  2036. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2037. }
  2038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2039. {
  2040. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2041. }
  2042. else
  2043. {
  2044. defaultTxProfile.TransactionId = -1;
  2045. }
  2046. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2047. {
  2048. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2049. }
  2050. else
  2051. {
  2052. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2053. }
  2054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2055. {
  2056. 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")));
  2057. }
  2058. else
  2059. {
  2060. 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));
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2063. {
  2064. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2065. }
  2066. else
  2067. {
  2068. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2069. }
  2070. }
  2071. }
  2072. }
  2073. json_object_put(obj);
  2074. }
  2075. fclose(fp);
  2076. /*
  2077. if(defaultTxProfile.ChargingProfileId != -1)
  2078. {
  2079. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2080. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2081. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2082. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2083. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2084. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2085. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2086. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2087. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2088. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2089. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2090. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2091. {
  2092. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2093. {
  2094. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2095. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2096. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2097. }
  2098. }
  2099. }
  2100. else
  2101. DEBUG_INFO("TxDefaultProfile not found.\n");
  2102. DEBUG_INFO("------------------------------------\n");*/
  2103. }
  2104. // Search max profile
  2105. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2106. if((access(profileFileName, F_OK))!=-1)
  2107. {
  2108. fp = fopen(profileFileName, "r");
  2109. while(getline(&line, &len, fp) != -1)
  2110. {
  2111. json_object *obj = NULL;
  2112. obj = json_tokener_parse(line);
  2113. if(is_error(obj))
  2114. {
  2115. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2116. }
  2117. else
  2118. {
  2119. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2120. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2121. )
  2122. {
  2123. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2124. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2125. )
  2126. {
  2127. struct tm tmFrom, tmTo;
  2128. struct timeb tbFrom, tbTo;
  2129. 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) &&
  2130. (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))
  2131. {
  2132. tmFrom.tm_year -= 1900;
  2133. tmFrom.tm_mon -= 1;
  2134. tbFrom.time = mktime(&tmFrom);
  2135. tmTo.tm_year -= 1900;
  2136. tmTo.tm_mon -= 1;
  2137. tbTo.time = mktime(&tmTo);
  2138. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2139. {
  2140. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2141. {
  2142. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2143. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2144. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2145. }
  2146. maxProfile.ChargingProfileId = -1;
  2147. maxProfile.StackLevel = -1;
  2148. if(maxProfile.ChargingProfileId == -1)
  2149. DEBUG_INFO("MaxProfile found.\n");
  2150. else
  2151. DEBUG_INFO("MaxProfile updated.\n");
  2152. // Required item
  2153. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2154. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2155. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2156. if(isUnitA)
  2157. {
  2158. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2159. 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++)
  2160. {
  2161. 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"));
  2162. 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?
  2163. 3:
  2164. 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")));
  2165. 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")));
  2166. }
  2167. }
  2168. else
  2169. {
  2170. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2171. 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++)
  2172. {
  2173. 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"));
  2174. 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?
  2175. 3:
  2176. 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")));
  2177. 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));
  2178. }
  2179. }
  2180. // Optional item
  2181. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2182. {
  2183. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2184. }
  2185. else
  2186. {
  2187. sprintf((char*)maxProfile.ValidFrom, " ");
  2188. }
  2189. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2190. {
  2191. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2192. }
  2193. else
  2194. {
  2195. sprintf((char*)maxProfile.ValidTo, " ");
  2196. }
  2197. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2198. {
  2199. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2200. }
  2201. else
  2202. {
  2203. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2204. }
  2205. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2206. {
  2207. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2208. }
  2209. else
  2210. {
  2211. maxProfile.TransactionId = -1;
  2212. }
  2213. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2214. {
  2215. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2216. }
  2217. else
  2218. {
  2219. maxProfile.ChargingSchedule.Duration = 86400;
  2220. }
  2221. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2222. {
  2223. 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")));
  2224. }
  2225. else
  2226. {
  2227. 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));
  2228. }
  2229. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2230. {
  2231. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2232. }
  2233. else
  2234. {
  2235. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2236. }
  2237. }
  2238. }
  2239. }
  2240. else
  2241. {
  2242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2243. {
  2244. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2245. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2246. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2247. }
  2248. maxProfile.ChargingProfileId = -1;
  2249. maxProfile.StackLevel = -1;
  2250. if(maxProfile.ChargingProfileId == -1)
  2251. DEBUG_INFO("MaxProfile found.\n");
  2252. else
  2253. DEBUG_INFO("MaxProfile updated.\n");
  2254. // Required item
  2255. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2256. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2257. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2258. if(isUnitA)
  2259. {
  2260. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2261. 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++)
  2262. {
  2263. 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"));
  2264. 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?
  2265. 3:
  2266. 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")));
  2267. 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")));
  2268. }
  2269. }
  2270. else
  2271. {
  2272. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2273. 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++)
  2274. {
  2275. 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"));
  2276. 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?
  2277. 3:
  2278. 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")));
  2279. 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));
  2280. }
  2281. }
  2282. // Optional item
  2283. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2284. {
  2285. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2286. }
  2287. else
  2288. {
  2289. sprintf((char*)maxProfile.ValidFrom, " ");
  2290. }
  2291. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2292. {
  2293. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2294. }
  2295. else
  2296. {
  2297. sprintf((char*)maxProfile.ValidTo, " ");
  2298. }
  2299. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2300. {
  2301. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2302. }
  2303. else
  2304. {
  2305. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2306. }
  2307. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2308. {
  2309. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2310. }
  2311. else
  2312. {
  2313. maxProfile.TransactionId = -1;
  2314. }
  2315. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2316. {
  2317. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2318. }
  2319. else
  2320. {
  2321. maxProfile.ChargingSchedule.Duration = 86400;
  2322. }
  2323. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2324. {
  2325. 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")));
  2326. }
  2327. else
  2328. {
  2329. 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));
  2330. }
  2331. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2332. {
  2333. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2334. }
  2335. else
  2336. {
  2337. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2338. }
  2339. }
  2340. }
  2341. }
  2342. json_object_put(obj);
  2343. }
  2344. fclose(fp);
  2345. /*
  2346. if(maxProfile.ChargingProfileId !=-1)
  2347. {
  2348. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2349. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2350. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2351. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2352. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2353. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2354. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2355. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2356. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2357. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2358. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2359. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2360. {
  2361. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2362. {
  2363. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2364. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2365. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2366. }
  2367. }
  2368. }
  2369. else
  2370. DEBUG_INFO("MaxProfile not found.\n");
  2371. DEBUG_INFO("------------------------------------\n");*/
  2372. }
  2373. /*
  2374. * Align found profile start schedule & periods
  2375. */
  2376. //DEBUG_INFO("====================================\n");
  2377. /*
  2378. // For local test usage, force modify found profile start schedule info
  2379. 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);
  2380. 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);
  2381. 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);
  2382. */
  2383. if(txProfile.ChargingProfileId != -1)
  2384. {
  2385. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2386. {
  2387. if(txProfile.ChargingSchedule.Duration != -1)
  2388. {
  2389. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2390. 0:
  2391. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2392. }
  2393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2394. {
  2395. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2396. {
  2397. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2398. 0:
  2399. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2400. if(idxPeriod > 0)
  2401. {
  2402. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2403. {
  2404. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2411. {
  2412. if(txProfile.ChargingSchedule.Duration != -1)
  2413. {
  2414. 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?
  2415. 0:
  2416. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2417. }
  2418. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2419. {
  2420. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2421. {
  2422. 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?
  2423. 0:
  2424. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2425. if(idxPeriod > 0)
  2426. {
  2427. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2428. {
  2429. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. else
  2436. {
  2437. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2438. {
  2439. if(txProfile.ChargingSchedule.Duration != -1)
  2440. {
  2441. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2442. 0:
  2443. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2444. }
  2445. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2446. {
  2447. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2448. {
  2449. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2450. 0:
  2451. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2452. if(idxPeriod > 0)
  2453. {
  2454. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2455. {
  2456. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2457. }
  2458. }
  2459. }
  2460. }
  2461. }
  2462. else
  2463. {
  2464. if(txProfile.ChargingSchedule.Duration != -1)
  2465. {
  2466. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2467. 0:
  2468. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2469. }
  2470. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2471. {
  2472. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2473. {
  2474. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2475. 0:
  2476. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2477. if(idxPeriod > 0)
  2478. {
  2479. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2480. {
  2481. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2482. }
  2483. }
  2484. }
  2485. }
  2486. }
  2487. }
  2488. /*
  2489. DEBUG_INFO("txProfile after align.\n");
  2490. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2491. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2492. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2493. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2494. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2495. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2496. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2497. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2498. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2499. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2500. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2502. {
  2503. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2504. {
  2505. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2506. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2507. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2508. }
  2509. }*/
  2510. }
  2511. if(defaultTxProfile.ChargingProfileId != -1)
  2512. {
  2513. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2514. {
  2515. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2516. {
  2517. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2518. 0:
  2519. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  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-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2526. 0:
  2527. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  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 if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2543. {
  2544. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2545. {
  2546. 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?
  2547. 0:
  2548. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  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 = !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?
  2555. 0:
  2556. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  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. else
  2572. {
  2573. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2574. {
  2575. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2576. {
  2577. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2578. 0:
  2579. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2580. }
  2581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2582. {
  2583. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2584. {
  2585. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2586. 0:
  2587. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2588. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2589. {
  2590. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2591. }
  2592. if(idxPeriod > 0)
  2593. {
  2594. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2595. {
  2596. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2597. }
  2598. }
  2599. }
  2600. }
  2601. }
  2602. else
  2603. {
  2604. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2605. {
  2606. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2607. 0:
  2608. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2609. }
  2610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2611. {
  2612. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2613. {
  2614. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2615. 0:
  2616. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2617. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2618. {
  2619. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2620. }
  2621. if(idxPeriod > 0)
  2622. {
  2623. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2624. {
  2625. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2626. }
  2627. }
  2628. }
  2629. }
  2630. }
  2631. }
  2632. /*
  2633. DEBUG_INFO("defaultTxProfile after align.\n");
  2634. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2635. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2636. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2637. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2638. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2639. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2640. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2641. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2642. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2643. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2644. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2645. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2646. {
  2647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2648. {
  2649. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2650. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2651. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2652. }
  2653. }
  2654. DEBUG_INFO("------------------------------------\n");*/
  2655. }
  2656. if(maxProfile.ChargingProfileId != -1)
  2657. {
  2658. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2659. {
  2660. if(maxProfile.ChargingSchedule.Duration != -1)
  2661. {
  2662. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2663. 0:
  2664. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2665. }
  2666. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2667. {
  2668. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2669. {
  2670. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2671. 0:
  2672. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2673. if(idxPeriod > 0)
  2674. {
  2675. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2676. {
  2677. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2684. {
  2685. if(maxProfile.ChargingSchedule.Duration != -1)
  2686. {
  2687. 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?
  2688. 0:
  2689. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2690. }
  2691. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2692. {
  2693. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2694. {
  2695. 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?
  2696. 0:
  2697. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2698. if(idxPeriod > 0)
  2699. {
  2700. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2701. {
  2702. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2703. }
  2704. }
  2705. }
  2706. }
  2707. }
  2708. else
  2709. {
  2710. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2711. {
  2712. if(maxProfile.ChargingSchedule.Duration != -1)
  2713. {
  2714. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2715. 0:
  2716. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2717. }
  2718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2719. {
  2720. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2721. {
  2722. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2723. 0:
  2724. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2725. if(idxPeriod > 0)
  2726. {
  2727. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2728. {
  2729. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2730. }
  2731. }
  2732. }
  2733. }
  2734. }
  2735. else
  2736. {
  2737. if(maxProfile.ChargingSchedule.Duration != -1)
  2738. {
  2739. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2740. 0:
  2741. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2742. }
  2743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2744. {
  2745. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2746. {
  2747. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2748. 0:
  2749. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2750. if(idxPeriod > 0)
  2751. {
  2752. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2753. {
  2754. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. }
  2761. /*
  2762. DEBUG_INFO("MaxProfile after align.\n");
  2763. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2764. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2765. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2766. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2767. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2768. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2769. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2770. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2771. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2772. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2773. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2775. {
  2776. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2777. {
  2778. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2779. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2780. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2781. }
  2782. }
  2783. DEBUG_INFO("------------------------------------\n");*/
  2784. }
  2785. /*
  2786. * Merge to conposite schedule
  2787. */
  2788. //DEBUG_INFO("====================================\n");
  2789. // Find each profile period quantity
  2790. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2791. {
  2792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2793. limitMax = idx+1;
  2794. }
  2795. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2796. {
  2797. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2798. limitDef = idx+1;
  2799. }
  2800. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2801. {
  2802. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2803. limitTx = idx+1;
  2804. }
  2805. // TxProfile found, composite schedule based on it
  2806. if(txProfile.ChargingProfileId != -1)
  2807. {
  2808. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2809. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2810. {
  2811. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2812. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2813. (txProfile.ChargingSchedule.Duration > 0))
  2814. {
  2815. if(maxProfile.ChargingProfileId != -1)
  2816. {
  2817. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2818. {
  2819. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2820. {
  2821. if((maxProfile.ChargingSchedule.Duration > 0))
  2822. {
  2823. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2824. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2825. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2826. }
  2827. else
  2828. {
  2829. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2830. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2831. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2832. }
  2833. }
  2834. if(idxMaxPeriod == (limitMax-1))
  2835. {
  2836. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2837. {
  2838. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2839. {
  2840. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2841. compositePeriodIdx++;
  2842. }
  2843. else
  2844. {
  2845. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. else
  2852. {
  2853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2854. {
  2855. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2856. compositePeriodIdx++;
  2857. }
  2858. else
  2859. {
  2860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2861. }
  2862. }
  2863. }
  2864. if(idxTxPeriod == (limitTx-1))
  2865. {
  2866. if(defaultTxProfile.ChargingProfileId != -1)
  2867. {
  2868. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2869. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2870. {
  2871. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2872. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2873. (defaultTxProfile.ChargingSchedule.Duration>0))
  2874. {
  2875. if(maxProfile.ChargingProfileId != -1)
  2876. {
  2877. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2878. {
  2879. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2880. {
  2881. if((maxProfile.ChargingSchedule.Duration > 0))
  2882. {
  2883. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2884. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2885. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2886. }
  2887. else
  2888. {
  2889. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2890. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2891. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2892. }
  2893. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2894. {
  2895. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2896. {
  2897. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2898. compositePeriodIdx++;
  2899. }
  2900. else
  2901. {
  2902. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2903. }
  2904. }
  2905. // Delete duplicate period
  2906. if(compositePeriodIdx > 1)
  2907. {
  2908. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2909. {
  2910. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2911. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2912. compositePeriodIdx -= 1;
  2913. }
  2914. }
  2915. }
  2916. else
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2919. {
  2920. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2921. compositePeriodIdx++;
  2922. }
  2923. else
  2924. {
  2925. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2926. }
  2927. break;
  2928. }
  2929. }
  2930. }
  2931. else
  2932. {
  2933. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2934. {
  2935. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2936. compositePeriodIdx++;
  2937. }
  2938. else
  2939. {
  2940. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2950. else if(defaultTxProfile.ChargingProfileId != -1)
  2951. {
  2952. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2953. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2954. {
  2955. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2956. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2957. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2958. {
  2959. if(maxProfile.ChargingProfileId != -1)
  2960. {
  2961. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2962. {
  2963. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2964. {
  2965. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2966. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2967. if((maxProfile.ChargingSchedule.Duration > 0))
  2968. {
  2969. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2970. }
  2971. else
  2972. {
  2973. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2974. }
  2975. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2976. {
  2977. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2978. {
  2979. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2980. compositePeriodIdx++;
  2981. }
  2982. else
  2983. {
  2984. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2985. }
  2986. }
  2987. // Delete duplicate period
  2988. if(compositePeriodIdx > 1)
  2989. {
  2990. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2991. {
  2992. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2993. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2994. compositePeriodIdx -= 1;
  2995. }
  2996. }
  2997. }
  2998. else
  2999. {
  3000. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3001. {
  3002. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3003. compositePeriodIdx++;
  3004. }
  3005. else
  3006. {
  3007. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3008. }
  3009. break;
  3010. }
  3011. }
  3012. }
  3013. else
  3014. {
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3016. {
  3017. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3018. compositePeriodIdx++;
  3019. }
  3020. else
  3021. {
  3022. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3023. }
  3024. }
  3025. }
  3026. }
  3027. }
  3028. // Fill other period by MaxProfile
  3029. if(maxProfile.ChargingProfileId != -1)
  3030. {
  3031. if(compositePeriodIdx==0)
  3032. {
  3033. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3034. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3035. {
  3036. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3037. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3038. (maxProfile.ChargingSchedule.Duration > 0))
  3039. {
  3040. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3041. {
  3042. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3043. compositePeriodIdx++;
  3044. }
  3045. else
  3046. {
  3047. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3048. }
  3049. }
  3050. }
  3051. }
  3052. else
  3053. {
  3054. int lastCompositePeriodIdx = compositePeriodIdx;
  3055. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3056. {
  3057. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3058. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3059. (maxProfile.ChargingSchedule.Duration > 0))
  3060. {
  3061. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3062. {
  3063. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3064. {
  3065. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3066. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3067. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3068. }
  3069. else
  3070. {
  3071. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3072. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3073. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3074. }
  3075. }
  3076. if(tmpPeriod.Limit != -1)
  3077. {
  3078. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3079. {
  3080. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3081. {
  3082. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3083. compositePeriodIdx++;
  3084. }
  3085. else
  3086. {
  3087. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3088. }
  3089. }
  3090. // Delete duplicate period
  3091. if(compositePeriodIdx > 1)
  3092. {
  3093. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3094. {
  3095. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3096. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3097. compositePeriodIdx -= 1;
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. }
  3104. }
  3105. compositeProfile->ChargingSchedule.Duration = durationReq;
  3106. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3107. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3108. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3109. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3110. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3111. {
  3112. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3113. {
  3114. compositeProfile->ChargingProfileId = 1;
  3115. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3116. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3117. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3118. }
  3119. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3120. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3121. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3122. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3123. }
  3124. if(line)
  3125. free(line);
  3126. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3127. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3128. }
  3129. //==========================================
  3130. // Init all share memory
  3131. //==========================================
  3132. int InitShareMemory()
  3133. {
  3134. int result = PASS;
  3135. int MeterSMId;
  3136. //creat ShmSysConfigAndInfo
  3137. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3138. {
  3139. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3140. result = FAIL;
  3141. }
  3142. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3143. {
  3144. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3145. result = FAIL;
  3146. }
  3147. else
  3148. {}
  3149. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3150. {
  3151. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3152. result = FAIL;
  3153. }
  3154. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3155. {
  3156. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3157. result = FAIL;
  3158. }
  3159. else
  3160. {}
  3161. //creat ShmPsuData
  3162. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3163. {
  3164. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3165. result = FAIL;
  3166. }
  3167. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3168. {
  3169. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3170. result = FAIL;
  3171. }
  3172. else
  3173. {}
  3174. //link ShmOCPP16Data
  3175. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3176. {
  3177. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3178. result = FAIL;
  3179. }
  3180. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3181. {
  3182. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3183. result = FAIL;
  3184. }
  3185. else
  3186. {}
  3187. //creat ShmOCPP16DataPH
  3188. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3189. {
  3190. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3191. result = FAIL;
  3192. }
  3193. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3194. {
  3195. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3196. result = FAIL;
  3197. }
  3198. else
  3199. {}
  3200. /****************************** For Initial Settings************************************************/
  3201. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3202. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3203. // allocate Configuration memory address
  3204. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3205. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3206. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3207. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3208. //offline MeterValue Interval
  3209. TempMeterValueInterval = 0;
  3210. return result;
  3211. }
  3212. int ProcessShareMemory()
  3213. {
  3214. int result = PASS;
  3215. if(InitShareMemory() == FAIL)
  3216. {
  3217. DEBUG_ERROR("InitShareMemory NG\n");
  3218. if(ShmStatusCodeData!=NULL)
  3219. {
  3220. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3221. }
  3222. result = FAIL;
  3223. }
  3224. // Model name parsing
  3225. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3226. {
  3227. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3228. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3229. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3230. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3231. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3232. ) // 'D' means DC
  3233. {
  3234. // DO series
  3235. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3236. {
  3237. SystemInitial += 1;
  3238. gunTotalNumber += 1;
  3239. gunType[gun_index] = GUN_TYPE_DO;
  3240. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3241. {
  3242. case Gun_Type_Chademo:
  3243. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3244. break;
  3245. case Gun_Type_CCS_2:
  3246. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3247. break;
  3248. case Gun_Type_GB:
  3249. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3250. break;
  3251. case Gun_Type_AC:
  3252. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3253. break;
  3254. default:
  3255. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3256. break;
  3257. }
  3258. }
  3259. }
  3260. else
  3261. {
  3262. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3263. {
  3264. SystemInitial += 1;
  3265. gunTotalNumber += 1;
  3266. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3267. {
  3268. case Gun_Type_Chademo:
  3269. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3270. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3271. break;
  3272. case Gun_Type_CCS_2:
  3273. gunType[gun_index] = GUN_TYPE_CCS;
  3274. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3275. break;
  3276. case Gun_Type_GB:
  3277. gunType[gun_index] = GUN_TYPE_GBT;
  3278. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3279. break;
  3280. case Gun_Type_AC:
  3281. gunType[gun_index] = GUN_TYPE_AC;
  3282. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3283. break;
  3284. default:
  3285. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3286. break;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. else
  3292. {
  3293. DEBUG_ERROR("Model name parsing fail.\n");
  3294. result = FAIL;
  3295. }
  3296. if(result != PASS)sleep(5);
  3297. return result;
  3298. }
  3299. void checkRemoteStart(uint8_t connectorIdInt)
  3300. {
  3301. uint8_t tempIndex;
  3302. int result = PASS;
  3303. char cmdBuf[512];
  3304. //check Transaction active
  3305. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3306. {
  3307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3308. {
  3309. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3310. }
  3311. else
  3312. {
  3313. tempIndex = connectorIdInt -1;
  3314. }
  3315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3316. {
  3317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3318. {
  3319. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3320. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3321. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3322. {
  3323. //Reserved
  3324. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3325. }
  3326. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3327. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3328. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3329. {
  3330. //Reserved
  3331. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3332. result = FAIL;
  3333. goto end;
  3334. }
  3335. else
  3336. {
  3337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3339. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3340. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3341. {
  3342. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3343. result = FAIL;
  3344. goto end;
  3345. }
  3346. }//END FOR ELSE
  3347. }
  3348. }// END FOR CHAdeMO_QUANTITY
  3349. }
  3350. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3351. {
  3352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3353. {
  3354. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3355. }
  3356. else
  3357. {
  3358. tempIndex = connectorIdInt -1;
  3359. }
  3360. for (int index = 0; index < CCS_QUANTITY; index++)
  3361. {
  3362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3363. {
  3364. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3365. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3366. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3367. {
  3368. //Reserved
  3369. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3370. }
  3371. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3372. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3373. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3374. {
  3375. //Reserved
  3376. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3377. result = FAIL;
  3378. goto end;
  3379. }
  3380. else
  3381. {
  3382. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3383. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3384. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3385. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3386. {
  3387. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3388. result = FAIL;
  3389. goto end;
  3390. }
  3391. }// END FOR ELSE
  3392. }
  3393. }// END FOR CCS_QUANTITY
  3394. }
  3395. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3396. {
  3397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3398. {
  3399. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3400. }
  3401. else
  3402. {
  3403. tempIndex = connectorIdInt -1;
  3404. }
  3405. for (int index = 0; index < GB_QUANTITY; index++)
  3406. {
  3407. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3408. {
  3409. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3410. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3411. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3412. {
  3413. //Reserved
  3414. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3415. }
  3416. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3417. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3418. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3419. {
  3420. //Reserved
  3421. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3422. result = FAIL;
  3423. goto end;
  3424. }
  3425. else
  3426. {
  3427. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3429. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3430. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3431. {
  3432. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3433. result = FAIL;
  3434. goto end;
  3435. }
  3436. }// END FOR ELSE
  3437. }
  3438. } // END FOR GB_QUANTITY
  3439. }
  3440. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3441. {
  3442. tempIndex = connectorIdInt -1;
  3443. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3444. {
  3445. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3446. {
  3447. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3448. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3449. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3450. {
  3451. //Reserved
  3452. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3453. }
  3454. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3455. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3456. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3457. {
  3458. //Reserved
  3459. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3460. result = FAIL;
  3461. goto end;
  3462. }
  3463. else
  3464. {
  3465. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3466. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3467. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3468. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3469. {
  3470. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3471. result = FAIL;
  3472. goto end;
  3473. }
  3474. }// END FOR ELSE
  3475. }
  3476. } // END FOR GB_QUANTITY
  3477. }
  3478. else
  3479. {
  3480. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3481. {
  3482. tempIndex = 2;
  3483. }
  3484. else
  3485. {
  3486. tempIndex = connectorIdInt -1;
  3487. }
  3488. for (int index = 0; index < AC_QUANTITY; index++)
  3489. {
  3490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3491. {
  3492. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3493. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3494. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3495. {
  3496. //Reserved
  3497. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3498. }
  3499. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3500. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3501. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3502. {
  3503. //Reserved
  3504. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3505. result = FAIL;
  3506. goto end;
  3507. }
  3508. else
  3509. {
  3510. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3511. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3512. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3513. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3514. {
  3515. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3516. result = FAIL;
  3517. goto end;
  3518. }
  3519. }//END FOR ELSE
  3520. }
  3521. }// END FOR AC_QUANTITY
  3522. }
  3523. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3524. {
  3525. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3526. {
  3527. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3528. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3529. {
  3530. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3531. system(cmdBuf);
  3532. }
  3533. }
  3534. else
  3535. {
  3536. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3537. result = FAIL;
  3538. }
  3539. }
  3540. end:
  3541. if(result == PASS)
  3542. {
  3543. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3544. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3545. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3546. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3548. }
  3549. }
  3550. void CheckSystemValue(void)
  3551. {
  3552. char filenmae[100]={0};
  3553. char str[100]={0};
  3554. int tempIndex = 0;
  3555. //===============================
  3556. // send Heartbeat
  3557. //===============================
  3558. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3559. {
  3560. //parameter for test
  3561. sendHeartbeatRequest(0);
  3562. //==============================================
  3563. // Reset Waiting Time
  3564. //==============================================
  3565. HeartBeatWithNOResponse += 2;
  3566. }
  3567. //===============================
  3568. // Credit deduct report
  3569. //===============================
  3570. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3571. {
  3572. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3573. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3574. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3575. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3576. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3577. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3578. }
  3579. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3580. {
  3581. OCPP_query_deduct_info();
  3582. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3583. }
  3584. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3585. {
  3586. // ClockAlign MeterValue
  3587. 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))
  3588. {
  3589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3590. {
  3591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3592. {
  3593. tempIndex = ((gun_index==2) ? 1: 0);
  3594. }
  3595. else
  3596. {
  3597. tempIndex = gun_index;
  3598. }
  3599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3600. {
  3601. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3603. {
  3604. reqClockAlignMeter[gun_index] = 1;
  3605. }
  3606. }// End for CHAdeMO
  3607. }
  3608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3609. {
  3610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3611. {
  3612. tempIndex = ((gun_index==2) ? 1: 0);
  3613. }
  3614. else
  3615. {
  3616. tempIndex = gun_index;
  3617. }
  3618. for (int index = 0; index < CCS_QUANTITY; index++)
  3619. {
  3620. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3621. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3622. {
  3623. reqClockAlignMeter[gun_index] = 1;
  3624. }
  3625. } // End for CCS
  3626. }
  3627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3628. {
  3629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3630. {
  3631. tempIndex = ((gun_index==2) ? 1: 0);
  3632. }
  3633. else
  3634. {
  3635. tempIndex = gun_index;
  3636. }
  3637. for (int index = 0; index < GB_QUANTITY; index++)
  3638. {
  3639. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3641. {
  3642. reqClockAlignMeter[gun_index] = 1;
  3643. }
  3644. }// End for GB
  3645. }
  3646. else if(gunType[gun_index] == GUN_TYPE_DO)
  3647. {
  3648. tempIndex = gun_index;
  3649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3650. {
  3651. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3652. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3653. {
  3654. reqClockAlignMeter[gun_index] = 1;
  3655. }
  3656. }
  3657. }
  3658. else
  3659. {
  3660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3661. {
  3662. tempIndex = 2;
  3663. }
  3664. else
  3665. {
  3666. tempIndex = gun_index;
  3667. }
  3668. for (int index = 0; index < AC_QUANTITY; index++)
  3669. {
  3670. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3671. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3672. {
  3673. reqClockAlignMeter[gun_index] = 1;
  3674. }
  3675. }//End for AC
  3676. }
  3677. }
  3678. }
  3679. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3680. {
  3681. //==========================================
  3682. // Check remote start without connector id
  3683. //==========================================
  3684. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3685. {
  3686. int connectorIdInt = -1;
  3687. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3688. {
  3689. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3690. {
  3691. connectorIdInt = (gun_index+1);
  3692. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3693. checkRemoteStart(connectorIdInt);
  3694. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3695. break;
  3696. }
  3697. }
  3698. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3699. {
  3700. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3701. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3702. }
  3703. }
  3704. //==========================================
  3705. // csu trigger DataTransferReq
  3706. //==========================================
  3707. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3708. {
  3709. sendDataTransferRequest(gun_index);
  3710. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3711. }
  3712. //===============================
  3713. // CSU Trigger Authorize Request
  3714. //===============================
  3715. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3716. {
  3717. sendAuthorizeRequest(0);
  3718. authorizeRetryTimes = authorizeRetryTimes + 1;
  3719. if(authorizeRetryTimes < 3)
  3720. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3721. }
  3722. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3723. {
  3724. authorizeRetryTimes = 0;
  3725. SetOcppConnStatus(FALSE);
  3726. server_sign = FALSE;
  3727. }
  3728. 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))
  3729. {
  3730. sendAuthorizeRequest(0);
  3731. }
  3732. //==============================================
  3733. // Charger start transaction
  3734. //==============================================
  3735. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3736. {
  3737. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3738. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3739. sendStartTransactionRequest(gun_index);
  3740. refreshStartTimer(&clientTime.StartTransaction);
  3741. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3742. //storeTempStopTransaction(gun_index);
  3743. }
  3744. //==============================================
  3745. // Charger stop transaction
  3746. //==============================================
  3747. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3748. {
  3749. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3750. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3751. sendStopTransactionRequest(gun_index);
  3752. refreshStartTimer(&clientTime.StopTransaction);
  3753. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3754. }
  3755. //==============================================
  3756. // Charger status report
  3757. //==============================================
  3758. //--- Check Mode Change ---//
  3759. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3760. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3761. {
  3762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3763. {
  3764. tempIndex = ((gun_index==2) ? 1: 0);
  3765. }
  3766. else
  3767. {
  3768. tempIndex = gun_index;
  3769. }
  3770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3771. {
  3772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3773. {
  3774. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3775. {
  3776. // Sent unplug message for California pricing logic
  3777. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3778. {
  3779. uint8_t ts[20];
  3780. getNowDatetime(ts);
  3781. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3782. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3783. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3784. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3785. }
  3786. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3787. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3788. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3789. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3790. {
  3791. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3792. if((access(filenmae,F_OK))!=-1)
  3793. {
  3794. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3795. sprintf(str,"rm -f %s",filenmae);
  3796. system(str);
  3797. }
  3798. }
  3799. }
  3800. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3801. #if 1 // for TempStopTransaction
  3802. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3803. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3804. {
  3805. checkTempStopTransaction(gun_index);
  3806. }
  3807. #endif
  3808. }
  3809. }
  3810. }
  3811. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3812. {
  3813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3814. {
  3815. tempIndex = ((gun_index==2) ? 1: 0);
  3816. }
  3817. else
  3818. {
  3819. tempIndex = gun_index;
  3820. }
  3821. for (int index = 0; index < CCS_QUANTITY; index++)
  3822. {
  3823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3824. {
  3825. 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]*/ )
  3826. {
  3827. // Sent unplug message for California pricing logic
  3828. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3829. {
  3830. uint8_t ts[20];
  3831. getNowDatetime(ts);
  3832. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3833. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3834. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3835. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3836. }
  3837. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3838. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3839. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3840. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3841. {
  3842. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3843. if((access(filenmae,F_OK))!=-1)
  3844. {
  3845. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3846. sprintf(str,"rm -f %s",filenmae);
  3847. system(str);
  3848. }
  3849. }
  3850. }
  3851. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3852. #if 1 // for TempStopTransaction
  3853. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3854. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3855. {
  3856. checkTempStopTransaction(gun_index);
  3857. }
  3858. #endif
  3859. }
  3860. }
  3861. }
  3862. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3863. {
  3864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3865. {
  3866. tempIndex = ((gun_index==2) ? 1: 0);
  3867. }
  3868. else
  3869. {
  3870. tempIndex = gun_index;
  3871. }
  3872. for (int index = 0; index < GB_QUANTITY; index++)
  3873. {
  3874. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3875. {
  3876. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3877. {
  3878. // Sent unplug message for California pricing logic
  3879. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3880. {
  3881. uint8_t ts[20];
  3882. getNowDatetime(ts);
  3883. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3884. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3885. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3886. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3887. }
  3888. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3889. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3891. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3892. {
  3893. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3894. if((access(filenmae,F_OK))!=-1)
  3895. {
  3896. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3897. sprintf(str,"rm -f %s",filenmae);
  3898. system(str);
  3899. }
  3900. }
  3901. }
  3902. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3903. #if 1 // for TempStopTransaction
  3904. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3905. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3906. {
  3907. checkTempStopTransaction(gun_index);
  3908. }
  3909. #endif
  3910. }
  3911. }
  3912. }
  3913. else if(gunType[gun_index] == GUN_TYPE_DO)
  3914. {
  3915. tempIndex = gun_index;
  3916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3917. {
  3918. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3919. {
  3920. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3921. {
  3922. // Sent unplug message for California pricing logic
  3923. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3924. {
  3925. uint8_t ts[20];
  3926. getNowDatetime(ts);
  3927. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3928. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3929. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3930. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3931. }
  3932. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3933. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3934. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3935. 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
  3936. {
  3937. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3938. if((access(filenmae,F_OK))!=-1)
  3939. {
  3940. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3941. sprintf(str,"rm -f %s",filenmae);
  3942. system(str);
  3943. }
  3944. }
  3945. }
  3946. 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);
  3947. #if 1 // for TempStopTransaction
  3948. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3949. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3950. {
  3951. checkTempStopTransaction(gun_index);
  3952. }
  3953. #endif
  3954. }
  3955. }
  3956. }
  3957. else
  3958. {
  3959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3960. {
  3961. tempIndex = 2;
  3962. }
  3963. else
  3964. {
  3965. tempIndex = gun_index;
  3966. }
  3967. for (int index = 0; index < AC_QUANTITY; index++)
  3968. {
  3969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3970. {
  3971. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3972. {
  3973. // Sent unplug message for California pricing logic
  3974. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3975. {
  3976. uint8_t ts[20];
  3977. getNowDatetime(ts);
  3978. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3979. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3980. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3981. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3982. }
  3983. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3984. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3985. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3986. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3987. {
  3988. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3989. if((access(filenmae,F_OK))!=-1)
  3990. {
  3991. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3992. sprintf(str,"rm -f %s",filenmae);
  3993. system(str);
  3994. }
  3995. }
  3996. }
  3997. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3998. #if 1 // for TempStopTransaction
  3999. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4000. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4001. {
  4002. checkTempStopTransaction(gun_index);
  4003. }
  4004. #endif
  4005. }
  4006. }// END
  4007. }
  4008. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4009. (
  4010. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4011. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4012. )
  4013. )
  4014. {
  4015. if(SystemInitial > 0)
  4016. SystemInitial -= 1;
  4017. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4018. sendStatusNotificationRequest(gun_index);
  4019. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4020. }
  4021. //==============================================
  4022. // CSU Trigger Smart Charging Profilw
  4023. //==============================================
  4024. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4025. {
  4026. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4027. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4028. }
  4029. //==============================================
  4030. // Meter report
  4031. //==============================================
  4032. // Trigger MeterValue
  4033. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4034. {
  4035. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4036. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4037. }
  4038. // Clock-aligned Meter value
  4039. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4040. {
  4041. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4042. reqClockAlignMeter[gun_index] = 0;
  4043. }
  4044. // Sample period MeterValue
  4045. 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))))
  4046. {
  4047. //check Transaction active
  4048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4049. {
  4050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4051. {
  4052. tempIndex = ((gun_index==2) ? 1: 0);
  4053. }
  4054. else
  4055. {
  4056. tempIndex = gun_index;
  4057. }
  4058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4059. {
  4060. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4061. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4062. {
  4063. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4064. {
  4065. reqSampleMeter[gun_index] = 1;
  4066. }
  4067. }
  4068. }// End for CHAdeMO
  4069. }
  4070. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4071. {
  4072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4073. {
  4074. tempIndex = ((gun_index==2) ? 1: 0);
  4075. }
  4076. else
  4077. {
  4078. tempIndex = gun_index;
  4079. }
  4080. for (int index = 0; index < CCS_QUANTITY; index++)
  4081. {
  4082. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4083. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4084. {
  4085. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4086. {
  4087. reqSampleMeter[gun_index] = 1;
  4088. }
  4089. }
  4090. } // End for CCS
  4091. }
  4092. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4093. {
  4094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4095. {
  4096. tempIndex = ((gun_index==2) ? 1: 0);
  4097. }
  4098. else
  4099. {
  4100. tempIndex = gun_index;
  4101. }
  4102. for (int index = 0; index < GB_QUANTITY; index++)
  4103. {
  4104. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4105. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4106. {
  4107. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4108. {
  4109. reqSampleMeter[gun_index] = 1;
  4110. }
  4111. }
  4112. }// End for GB
  4113. }
  4114. else if(gunType[gun_index] == GUN_TYPE_DO)
  4115. {
  4116. tempIndex = gun_index;
  4117. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4118. {
  4119. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4120. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4121. {
  4122. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4123. {
  4124. reqSampleMeter[gun_index] = 1;
  4125. }
  4126. }
  4127. }
  4128. }
  4129. else
  4130. {
  4131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4132. {
  4133. tempIndex = 2;
  4134. }
  4135. else
  4136. {
  4137. tempIndex = gun_index;
  4138. }
  4139. for (int index = 0; index < AC_QUANTITY; index++)
  4140. {
  4141. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4142. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4143. {
  4144. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4145. {
  4146. reqSampleMeter[gun_index] = 1;
  4147. }
  4148. }
  4149. }//End for AC
  4150. }
  4151. if(reqSampleMeter[gun_index] == 1)
  4152. {
  4153. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4154. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4155. //storeTempStopTransaction(gun_index);
  4156. reqSampleMeter[gun_index] = 0;
  4157. }
  4158. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4159. }
  4160. //==============================================
  4161. // Check Connector reserved
  4162. //==============================================
  4163. //===============================
  4164. // Check if Reserve is expired
  4165. //===============================
  4166. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4167. {
  4168. double diff_t;
  4169. struct tm tp;
  4170. // current time
  4171. time_t t = time(NULL);
  4172. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4173. tp.tm_isdst = -1;
  4174. time_t utc = mktime(&tp);
  4175. diff_t = difftime(utc, t);
  4176. if(diff_t <= 0)
  4177. {
  4178. DEBUG_INFO("reserve expired.\n");
  4179. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4180. }
  4181. }//END OF Check if Reserve is expired
  4182. //==========================================
  4183. // csu trigger FirmwareStatusNotificationReq
  4184. //==========================================
  4185. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4186. {
  4187. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4188. }
  4189. //==========================================
  4190. // csu trigger DiagnosticsStatusNotificationReq
  4191. //==========================================
  4192. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4193. {
  4194. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4195. }
  4196. //==========================================
  4197. // csu trigger CancelReservationConf
  4198. //==========================================
  4199. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4200. {
  4201. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4202. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4203. }
  4204. //==========================================
  4205. // csu trigger ChangeAvailabilityConf
  4206. //==========================================
  4207. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4208. {
  4209. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4210. }
  4211. //==========================================
  4212. // csu trigger UnlockConnectorConf
  4213. //==========================================
  4214. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4215. {
  4216. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4217. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4218. }
  4219. //==========================================
  4220. // csu trigger ReserveNowConf
  4221. //==========================================
  4222. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4223. {
  4224. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4225. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4226. }
  4227. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4228. {
  4229. sendSignCertificateRequest();
  4230. }
  4231. }
  4232. }
  4233. //==========================================
  4234. // send request routine
  4235. //==========================================
  4236. int sendAuthorizeRequest(int gun_index)
  4237. {
  4238. mtrace();
  4239. int result = FAIL;
  4240. char message[100]={0};
  4241. char guid[37];
  4242. char tempdata[65]={0};
  4243. DEBUG_INFO("sendAuthorizeRequest...\n");
  4244. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4245. //Local Authorize
  4246. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4247. {
  4248. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4249. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4250. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4251. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4252. result = PASS;
  4253. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4254. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4255. authorizeRetryTimes = 0;
  4256. return result;
  4257. }
  4258. 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))||
  4259. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4260. {
  4261. // Query from cache
  4262. DEBUG_INFO("Authorize from cache.\n");
  4263. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4264. // Query from list
  4265. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4266. {
  4267. DEBUG_INFO("Authorize from list.\n");
  4268. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4269. }
  4270. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4271. {
  4272. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4273. {
  4274. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4275. }
  4276. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4277. {
  4278. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4279. }
  4280. if(!GetOcppConnStatus())
  4281. {
  4282. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4283. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4284. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4285. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4286. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4287. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4288. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4289. authorizeRetryTimes = 0;
  4290. return result;
  4291. }
  4292. }
  4293. else
  4294. {
  4295. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4296. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4297. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4298. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4299. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4300. else
  4301. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4302. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4303. result = PASS;
  4304. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4305. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4306. authorizeRetryTimes = 0;
  4307. return result;
  4308. }
  4309. }
  4310. //initialize struct Authorize
  4311. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4312. //get data from shared memory
  4313. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4314. random_uuid(guid);
  4315. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4316. LWS_Send(message);
  4317. sprintf(tempdata, "Authorize,%d", gun_index);
  4318. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4319. {
  4320. result = PASS;
  4321. DEBUG_INFO("Authorize mapItem pass\n");
  4322. }
  4323. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4324. return result;
  4325. }
  4326. int sendBootNotificationRequest(void)
  4327. {
  4328. mtrace();
  4329. int result = FAIL;
  4330. char message[500]={0}, payload[700]={0};
  4331. char guid[37]={0};
  4332. char tempdata[65]={0};
  4333. // Fill BootNotification fields
  4334. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4335. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4336. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4337. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4338. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4339. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4340. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4341. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4342. ShmOCPP16DataPH->ChargeBoxId
  4343. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4344. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4345. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4346. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4347. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4348. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4349. random_uuid(guid);
  4350. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4351. LWS_Send(message);
  4352. sprintf(tempdata, "BootNotification,0");
  4353. 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*/)
  4354. {
  4355. result = PASS;
  4356. }
  4357. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4358. strcpy(queuedata,message);
  4359. return result;
  4360. }
  4361. int sendDataTransferRequest(int gun_index)
  4362. {
  4363. mtrace();
  4364. char message[1000]={0};
  4365. char guid[37]={0};
  4366. char tempdata[65]={0};
  4367. int result = FAIL;
  4368. random_uuid(guid);
  4369. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4370. MESSAGE_TYPE_CALL,
  4371. guid,
  4372. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4373. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4374. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4375. LWS_Send(message);
  4376. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4377. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4378. {
  4379. result = PASS;
  4380. DEBUG_INFO("DataTransfer mapItem pass\n");
  4381. }
  4382. return result;
  4383. }
  4384. int sendDiagnosticsStatusNotificationRequest(char *status)
  4385. {
  4386. mtrace();
  4387. int result = FAIL;
  4388. char message[110]={0};
  4389. char guid[37]={0};
  4390. char tempdata[65]={0};
  4391. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4392. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4393. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4394. random_uuid(guid);
  4395. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4396. LWS_SendNow(message);
  4397. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4398. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4399. {
  4400. result = PASS;
  4401. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4402. }
  4403. //#ifdef SystemLogMessage
  4404. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4405. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4406. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4407. //#endif
  4408. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4409. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4410. //record status
  4411. if(strcmp(status,"Idle")==0)
  4412. {
  4413. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4414. }
  4415. else if(strcmp(status,"Uploaded")==0)
  4416. {
  4417. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4418. }
  4419. else if(strcmp(status,"UploadFailed")==0)
  4420. {
  4421. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4422. }
  4423. else if(strcmp(status,"Uploading")==0)
  4424. {
  4425. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4426. }
  4427. return result;
  4428. }
  4429. int sendFirmwareStatusNotificationRequest(char *status)
  4430. {
  4431. mtrace();
  4432. int result = FAIL;
  4433. char message[110]={0};
  4434. char guid[37]={0};
  4435. char tempdata[65]={0};
  4436. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4437. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4438. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4439. random_uuid(guid);
  4440. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4441. LWS_SendNow(message);
  4442. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4443. 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*/)
  4444. {
  4445. result = PASS;
  4446. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4447. }
  4448. //#ifdef SystemLogMessage
  4449. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4450. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4451. //#endif
  4452. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4453. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4454. //record status
  4455. if(strcmp(status,"Downloaded")==0)
  4456. {
  4457. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4458. }
  4459. else if(strcmp(status,"DownloadFailed")==0)
  4460. {
  4461. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4462. }
  4463. else if(strcmp(status,"Downloading")==0)
  4464. {
  4465. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4466. }
  4467. else if(strcmp(status,"Idle")==0)
  4468. {
  4469. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4470. }
  4471. else if(strcmp(status,"InstallationFailed")==0)
  4472. {
  4473. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4474. }
  4475. else if(strcmp(status,"Installing")==0)
  4476. {
  4477. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4478. }
  4479. else if(strcmp(status,"Installed")==0)
  4480. {
  4481. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4482. }
  4483. return result;
  4484. }
  4485. int sendHeartbeatRequest(int gun_index)
  4486. {
  4487. mtrace();
  4488. int result = FAIL;
  4489. char message[80]={0};
  4490. char guid[37]={0};
  4491. char tempdata[65]={0};
  4492. random_uuid(guid);
  4493. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4494. , MESSAGE_TYPE_CALL
  4495. , guid );
  4496. LWS_Send(message);
  4497. sprintf(tempdata, "Heartbeat,%d", 0);
  4498. 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*/)
  4499. {
  4500. result = PASS;
  4501. }
  4502. return result;
  4503. }
  4504. int sendStartTransactionRequest(int gun_index)
  4505. {
  4506. mtrace();
  4507. int result = FAIL;
  4508. char message[250]={0};
  4509. char guid[37]={0};
  4510. struct timeval tmnow;
  4511. struct tm *tm;
  4512. char buf[28];//, usec_buf[6];
  4513. char tempdata[65]={0};
  4514. int tempIndex = 0;
  4515. DEBUG_INFO("sendStartTransactionRequest...\n");
  4516. gettimeofday(&tmnow, NULL);
  4517. time_t t;
  4518. t = time(NULL);
  4519. /*UTC time and date*/
  4520. tm = gmtime(&t);
  4521. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4522. #if 0 // remove temporally
  4523. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4524. strcat(buf,".");
  4525. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4526. strcat(buf,usec_buf);
  4527. #endif
  4528. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4529. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4530. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4531. // clear StartTransaction Response
  4532. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4533. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4534. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4535. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4536. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4537. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4538. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4539. {
  4540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4541. {
  4542. tempIndex = ((gun_index==2) ? 1: 0);
  4543. }
  4544. else
  4545. {
  4546. tempIndex = gun_index;
  4547. }
  4548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4549. {
  4550. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4551. {
  4552. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4553. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4554. }
  4555. }
  4556. }
  4557. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4558. {
  4559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4560. {
  4561. tempIndex = ((gun_index==2) ? 1: 0);
  4562. }
  4563. else
  4564. {
  4565. tempIndex = gun_index;
  4566. }
  4567. for (int index = 0; index < CCS_QUANTITY; index++)
  4568. {
  4569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4570. {
  4571. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4572. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4573. }
  4574. }
  4575. }
  4576. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4577. {
  4578. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4579. {
  4580. tempIndex = ((gun_index==2) ? 1: 0);
  4581. }
  4582. else
  4583. {
  4584. tempIndex = gun_index;
  4585. }
  4586. for (int index = 0; index < GB_QUANTITY; index++)
  4587. {
  4588. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4589. {
  4590. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4591. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4592. }
  4593. }
  4594. }
  4595. else if(gunType[gun_index] == GUN_TYPE_DO)
  4596. {
  4597. tempIndex = gun_index;
  4598. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4601. {
  4602. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4603. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4604. }
  4605. }
  4606. }
  4607. else
  4608. {
  4609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4610. {
  4611. tempIndex = 2;
  4612. }
  4613. else
  4614. {
  4615. tempIndex = gun_index;
  4616. }
  4617. for (int index = 0; index < AC_QUANTITY; index++)
  4618. {
  4619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4620. {
  4621. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4622. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4623. }
  4624. }
  4625. }
  4626. random_uuid(guid);
  4627. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4628. {
  4629. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4630. , gun_index +1
  4631. , MESSAGE_TYPE_CALL
  4632. , guid
  4633. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4634. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4635. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4636. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4637. }
  4638. else
  4639. {
  4640. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4641. , gun_index +1
  4642. , MESSAGE_TYPE_CALL
  4643. , guid
  4644. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4645. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4646. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4647. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4648. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4649. }
  4650. #if 1
  4651. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4652. 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*/)
  4653. {
  4654. result = PASS;
  4655. }
  4656. #endif
  4657. strcpy(queuedata, message);
  4658. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4659. OCPP_insert_transaction_msg(YES, queuedata);
  4660. return result;
  4661. }
  4662. int sendStatusNotificationRequest(int gun_index)
  4663. {
  4664. mtrace();
  4665. int result = FAIL;
  4666. char message[600]={0};
  4667. char guid[37];
  4668. int currentStatus = 0;
  4669. struct timeval tmnow;
  4670. struct tm *tm;
  4671. char buf[28];//, usec_buf[6];
  4672. char tempdata[65]={0};
  4673. int tempIndex = 0;
  4674. uint8_t isStateChanged = TRUE;
  4675. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4676. gettimeofday(&tmnow, NULL);
  4677. time_t t;
  4678. t = time(NULL);
  4679. /*UTC time and date*/
  4680. tm = gmtime(&t);
  4681. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4682. #if 0 // remove temporally
  4683. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4684. strcat(buf,".");
  4685. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4686. strcat(buf,usec_buf);
  4687. #endif
  4688. //printf("%s",buf);
  4689. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4690. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4691. // it's option
  4692. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4693. /*
  4694. enum _SYSTEM_STATUS
  4695. {
  4696. S_BOOTING = 0,
  4697. S_IDLE, = 1
  4698. S_AUTHORIZING, =2
  4699. S_REASSIGN_CHECK, =3
  4700. S_REASSIGN, =4
  4701. S_PRECHARGE, =5
  4702. S_PREPARING_FOR_EV, =6
  4703. S_PREPARING_FOR_EVSE, =7
  4704. S_CHARGING, =8
  4705. S_TERMINATING, =9
  4706. S_COMPLETE, =10
  4707. S_ALARM, =11
  4708. S_FAULT =12
  4709. }
  4710. */
  4711. //check Transaction active
  4712. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4713. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4714. {
  4715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4716. {
  4717. tempIndex = ((gun_index==2) ? 1: 0);
  4718. }
  4719. else
  4720. {
  4721. tempIndex = gun_index;
  4722. }
  4723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4724. {
  4725. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4726. {
  4727. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4728. {
  4729. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4730. {
  4731. currentStatus = Preparing; //OCPP Status: Preparing
  4732. }
  4733. else
  4734. {
  4735. currentStatus = Available; //OCPP Status: Available
  4736. }
  4737. }
  4738. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4739. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4740. ) //S_PRECHARGE
  4741. {
  4742. currentStatus = Preparing; //OCPP Status: Preparing
  4743. }
  4744. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4745. {
  4746. currentStatus = Charging; //OCPP Status: Charging
  4747. }
  4748. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4749. {
  4750. currentStatus = Finishing; //OCPP Status: Finishing
  4751. }
  4752. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4753. {
  4754. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4755. }
  4756. 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
  4757. {
  4758. currentStatus = Unavailable; //OCPP Status: Unavailable
  4759. }
  4760. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4761. {
  4762. currentStatus = Faulted; //OCPP Status: Faulted
  4763. }
  4764. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4765. {
  4766. currentStatus = Reserved; //OCPP Status: Reserved
  4767. }
  4768. } //end of the same index
  4769. }//end of for CHAdeMO_QUANTITY
  4770. }
  4771. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4772. {
  4773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4774. {
  4775. tempIndex = ((gun_index==2) ? 1: 0);
  4776. }
  4777. else
  4778. {
  4779. tempIndex = gun_index;
  4780. }
  4781. for (int index = 0; index < CCS_QUANTITY; index++)
  4782. {
  4783. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4784. {
  4785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4786. {
  4787. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4788. {
  4789. currentStatus = Preparing; //OCPP Status: Preparing
  4790. }
  4791. else
  4792. {
  4793. currentStatus = Available; //OCPP Status: Available
  4794. }
  4795. }
  4796. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4797. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4798. ) //S_PRECHARGE
  4799. {
  4800. currentStatus = Preparing; //OCPP Status: Preparing
  4801. }
  4802. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4803. {
  4804. currentStatus = Charging; //OCPP Status: Charging
  4805. }
  4806. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4807. {
  4808. currentStatus = Finishing; //OCPP Status: Finishing
  4809. }
  4810. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4811. {
  4812. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4813. }
  4814. 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
  4815. {
  4816. currentStatus = Unavailable; //OCPP Status : Unavailable
  4817. }
  4818. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4819. {
  4820. currentStatus = Faulted; //OCPP Status: Faulted
  4821. }
  4822. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4823. {
  4824. currentStatus = Reserved; //OCPP Status: Reserved
  4825. }
  4826. } //end of the same index
  4827. } // end of for CCS_QUANTITY
  4828. }
  4829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4832. {
  4833. tempIndex = ((gun_index==2) ? 1: 0);
  4834. }
  4835. else
  4836. {
  4837. tempIndex = gun_index;
  4838. }
  4839. for (int index = 0; index < GB_QUANTITY; index++)
  4840. {
  4841. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4842. {
  4843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4844. {
  4845. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4846. {
  4847. currentStatus = Preparing; //OCPP Status: Preparing
  4848. }
  4849. else
  4850. {
  4851. currentStatus = Available; //OCPP Status: Available
  4852. }
  4853. }
  4854. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4855. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4856. ) //S_PRECHARGE
  4857. {
  4858. currentStatus = Preparing; //OCPP Status: Preparing
  4859. }
  4860. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4861. {
  4862. currentStatus = Charging; //OCPP Status: Charging
  4863. }
  4864. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4865. {
  4866. currentStatus = Finishing; //OCPP Status: Finishing
  4867. }
  4868. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4869. {
  4870. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4871. }
  4872. 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
  4873. {
  4874. currentStatus = Unavailable; //OCPP Status: Unavailable
  4875. }
  4876. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4877. {
  4878. currentStatus = Faulted; //OCPP Status: Faulted
  4879. }
  4880. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4881. {
  4882. currentStatus = Reserved; //OCPP Status: Reserved
  4883. }
  4884. } //end of the same index
  4885. } // end of for GB_QUANTITY
  4886. }
  4887. else if(gunType[gun_index] == GUN_TYPE_DO)
  4888. {
  4889. tempIndex = gun_index;
  4890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4891. {
  4892. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4893. {
  4894. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4895. {
  4896. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4897. {
  4898. currentStatus = Preparing; //OCPP Status: Preparing
  4899. }
  4900. else
  4901. {
  4902. currentStatus = Available; //OCPP Status: Available
  4903. }
  4904. }
  4905. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4906. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4907. ) //S_PRECHARGE
  4908. {
  4909. currentStatus = Preparing; //OCPP Status: Preparing
  4910. }
  4911. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4912. {
  4913. currentStatus = Charging; //OCPP Status: Charging
  4914. }
  4915. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4916. {
  4917. currentStatus = Finishing; //OCPP Status: Finishing
  4918. }
  4919. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4920. {
  4921. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4922. }
  4923. 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
  4924. {
  4925. currentStatus = Unavailable; //OCPP Status: Unavailable
  4926. }
  4927. 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
  4928. {
  4929. currentStatus = Faulted; //OCPP Status: Faulted
  4930. }
  4931. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4932. {
  4933. currentStatus = Reserved; //OCPP Status: Reserved
  4934. }
  4935. } //end of the same index
  4936. }
  4937. }
  4938. else
  4939. {
  4940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4941. {
  4942. tempIndex = 2;
  4943. }
  4944. else
  4945. {
  4946. tempIndex = gun_index;
  4947. }
  4948. for (int index = 0; index < AC_QUANTITY; index++)
  4949. {
  4950. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4951. {
  4952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4953. {
  4954. 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))
  4955. {
  4956. currentStatus = Preparing; //OCPP Status: Preparing
  4957. }
  4958. else
  4959. {
  4960. currentStatus = Available; //OCPP Status: Available
  4961. }
  4962. }
  4963. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4964. {
  4965. currentStatus = Preparing; //OCPP Status: Preparing
  4966. }
  4967. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4968. {
  4969. currentStatus = Charging; //OCPP Status: Charging
  4970. }
  4971. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4972. {
  4973. currentStatus = Finishing; //OCPP Status: Finishing
  4974. }
  4975. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4976. {
  4977. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4978. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4979. else
  4980. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4981. }
  4982. 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
  4983. {
  4984. currentStatus = Unavailable; //OCPP Status: Unavailable
  4985. }
  4986. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4987. {
  4988. currentStatus = Faulted; //OCPP Status: Faulted
  4989. }
  4990. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4991. {
  4992. currentStatus = Reserved; //OCPP Status: Reserved
  4993. }
  4994. }//end of the same index
  4995. }//end of for AC_QUANTITY
  4996. }
  4997. //it's option
  4998. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4999. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5000. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5001. {
  5002. isStateChanged = FALSE;
  5003. }
  5004. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5005. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5006. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5007. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5008. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5009. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5010. random_uuid(guid);
  5011. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5012. , MESSAGE_TYPE_CALL
  5013. , guid
  5014. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5015. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5016. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5017. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5018. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5019. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5020. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5021. if((server_sign == TRUE) && isStateChanged)
  5022. {
  5023. LWS_Send(message);
  5024. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5025. 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*/)
  5026. {
  5027. //DEBUG_ERROR("statusNotification mapitem pass");
  5028. result = PASS;
  5029. }
  5030. }
  5031. else
  5032. {
  5033. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5034. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5035. result = PASS;
  5036. }
  5037. return result;
  5038. }
  5039. int sendStopTransactionRequest(int gun_index)
  5040. {
  5041. mtrace();
  5042. int result = FAIL;
  5043. //char message[1500]={0};
  5044. char guid[37]={0};
  5045. char tempdata[65]={0};
  5046. int tempIndex = 0;
  5047. char TempStopTransaction[256];
  5048. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5049. //int idx_sample=0;
  5050. DEBUG_INFO("sendStopTransactionRequest \n");
  5051. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5052. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5053. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5054. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5055. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5056. {
  5057. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5058. {
  5059. tempIndex = ((gun_index==2) ? 1: 0);
  5060. }
  5061. else
  5062. {
  5063. tempIndex = gun_index;
  5064. }
  5065. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5066. {
  5067. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5068. {
  5069. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5070. }
  5071. }// END OF CHAdeMO_QUANTITY
  5072. }
  5073. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5074. {
  5075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5076. {
  5077. tempIndex = ((gun_index==2) ? 1: 0);
  5078. }
  5079. else
  5080. {
  5081. tempIndex = gun_index;
  5082. }
  5083. for (int index = 0; index < CCS_QUANTITY; index++)
  5084. {
  5085. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5086. {
  5087. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5088. }
  5089. }// END OF CCS_QUANTITY
  5090. }
  5091. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5092. {
  5093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5094. {
  5095. tempIndex = ((gun_index==2) ? 1: 0);
  5096. }
  5097. else
  5098. {
  5099. tempIndex = gun_index;
  5100. }
  5101. for (int index = 0; index < GB_QUANTITY; index++)
  5102. {
  5103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5104. {
  5105. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5106. }
  5107. }// END OF GB_QUANTITY
  5108. }
  5109. else if(gunType[gun_index] == GUN_TYPE_DO)
  5110. {
  5111. tempIndex = gun_index;
  5112. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5113. {
  5114. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5115. {
  5116. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5117. }
  5118. }// END OF GB_QUANTITY
  5119. }
  5120. else
  5121. {
  5122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5123. {
  5124. tempIndex = 2;
  5125. }
  5126. else
  5127. {
  5128. tempIndex = gun_index;
  5129. }
  5130. for (int index = 0; index < AC_QUANTITY; index++)
  5131. {
  5132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5133. {
  5134. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5135. }
  5136. }// END OF AC_QUANTITY
  5137. }
  5138. //====================================== Stop Transaction Time =====================================================
  5139. struct timeval tmnow;
  5140. struct tm *tm;
  5141. char buf[28];//, usec_buf[6];
  5142. gettimeofday(&tmnow, NULL);
  5143. time_t t;
  5144. t = time(NULL);
  5145. /*UTC time and date*/
  5146. tm = gmtime(&t);
  5147. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5149. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5150. random_uuid(guid);
  5151. /***********************************transactionData******************************************************/
  5152. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5154. //=================================
  5155. // Transaction_Begin
  5156. //=================================
  5157. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5158. {
  5159. //============================================ Energy.Active.Import.Interval ================================
  5160. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5163. 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*/]);
  5164. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5165. 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))
  5166. {
  5167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5168. }
  5169. else
  5170. {
  5171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5172. }
  5173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5175. }
  5176. //=================================
  5177. // Transaction_End
  5178. //=================================
  5179. // ================================= Current.Import L1 ===============================================
  5180. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5181. {
  5182. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5183. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5184. {
  5185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5186. {
  5187. tempIndex = ((gun_index==2) ? 1: 0);
  5188. }
  5189. else
  5190. {
  5191. tempIndex = gun_index;
  5192. }
  5193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5196. {
  5197. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5198. }
  5199. }// End of for CHAdeMO_QUANTITY
  5200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5201. }
  5202. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5203. {
  5204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5205. {
  5206. tempIndex = ((gun_index==2) ? 1: 0);
  5207. }
  5208. else
  5209. {
  5210. tempIndex = gun_index;
  5211. }
  5212. for (int index = 0; index < CCS_QUANTITY; index++)
  5213. {
  5214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5215. {
  5216. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5217. }
  5218. }// End of for CCS_QUANTITY
  5219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5220. }
  5221. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5222. {
  5223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5224. {
  5225. tempIndex = ((gun_index==2) ? 1: 0);
  5226. }
  5227. else
  5228. {
  5229. tempIndex = gun_index;
  5230. }
  5231. for (int index = 0; index < GB_QUANTITY; index++)
  5232. {
  5233. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5234. {
  5235. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5236. }
  5237. }// End of for GB_QUANTITY
  5238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5239. }
  5240. else if(gunType[gun_index] == GUN_TYPE_DO)
  5241. {
  5242. tempIndex = gun_index;
  5243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5248. }
  5249. }
  5250. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5251. }
  5252. else
  5253. {
  5254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5255. {
  5256. tempIndex = 2;
  5257. }
  5258. else
  5259. {
  5260. tempIndex = gun_index;
  5261. }
  5262. for (int index = 0; index < AC_QUANTITY; index++)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5265. {
  5266. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5267. }
  5268. }// End of for AC_QUANTITY
  5269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5270. }
  5271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5276. }
  5277. // ================================= Energy.Active.Import.Interval ==============================================
  5278. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5279. {
  5280. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5281. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5282. {
  5283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5284. {
  5285. tempIndex = ((gun_index==2) ? 1: 0);
  5286. }
  5287. else
  5288. {
  5289. tempIndex = gun_index;
  5290. }
  5291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5292. {
  5293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5294. {
  5295. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5296. }
  5297. }// END OF CHAdeMO_QUANTITY
  5298. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5299. }
  5300. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5301. {
  5302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5303. {
  5304. tempIndex = ((gun_index==2) ? 1: 0);
  5305. }
  5306. else
  5307. {
  5308. tempIndex = gun_index;
  5309. }
  5310. for (int index = 0; index < CCS_QUANTITY; index++)
  5311. {
  5312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5313. {
  5314. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5315. }
  5316. }// END OF CCS_QUANTITY
  5317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5318. }
  5319. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5320. {
  5321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5322. {
  5323. tempIndex = ((gun_index==2) ? 1: 0);
  5324. }
  5325. else
  5326. {
  5327. tempIndex = gun_index;
  5328. }
  5329. for (int index = 0; index < GB_QUANTITY; index++)
  5330. {
  5331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5332. {
  5333. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5334. }
  5335. }// END OF GB_QUANTITY
  5336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5337. }
  5338. else if(gunType[gun_index] == GUN_TYPE_DO)
  5339. {
  5340. tempIndex = gun_index;
  5341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5342. {
  5343. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5344. {
  5345. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5346. }
  5347. }
  5348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5349. }
  5350. else
  5351. {
  5352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5353. {
  5354. tempIndex = 2;
  5355. }
  5356. else
  5357. {
  5358. tempIndex = gun_index;
  5359. }
  5360. for (int index = 0; index < AC_QUANTITY; index++)
  5361. {
  5362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5363. {
  5364. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5365. }
  5366. }// END OF AC_QUANTITY
  5367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5368. }
  5369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5370. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5372. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5373. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5374. }
  5375. //=================================== Power.Active.Import ==================================================
  5376. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5377. {
  5378. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5380. {
  5381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5382. {
  5383. tempIndex = ((gun_index==2) ? 1: 0);
  5384. }
  5385. else
  5386. {
  5387. tempIndex = gun_index;
  5388. }
  5389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5390. {
  5391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5392. {
  5393. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5394. }
  5395. } // End for CHAdeMO_QUANTITY
  5396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5397. }
  5398. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5399. {
  5400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5401. {
  5402. tempIndex = ((gun_index==2) ? 1: 0);
  5403. }
  5404. else
  5405. {
  5406. tempIndex = gun_index;
  5407. }
  5408. for (int index = 0; index < CCS_QUANTITY; index++)
  5409. {
  5410. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5411. {
  5412. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5413. }
  5414. } // END for CCS_QUANTITY
  5415. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5416. }
  5417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5418. {
  5419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5420. {
  5421. tempIndex = ((gun_index==2) ? 1: 0);
  5422. }
  5423. else
  5424. {
  5425. tempIndex = gun_index;
  5426. }
  5427. for (int index = 0; index < GB_QUANTITY; index++)
  5428. {
  5429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5430. {
  5431. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5432. }
  5433. }// END for GB_QUANTITY
  5434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5435. }
  5436. else if(gunType[gun_index] == GUN_TYPE_DO)
  5437. {
  5438. tempIndex = gun_index;
  5439. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5440. {
  5441. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5442. {
  5443. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5444. }
  5445. }
  5446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5447. }
  5448. else
  5449. {
  5450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5451. {
  5452. tempIndex = 2;
  5453. }
  5454. else
  5455. {
  5456. tempIndex = gun_index;
  5457. }
  5458. for (int index = 0; index < AC_QUANTITY; index++)
  5459. {
  5460. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5461. {
  5462. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5463. }
  5464. } // END for AC_QUANTITY
  5465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5466. }
  5467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5468. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5470. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5471. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5472. }
  5473. //============================ Voltage L1 ====================================
  5474. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5475. {
  5476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5477. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5478. {
  5479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5480. {
  5481. tempIndex = ((gun_index==2) ? 1: 0);
  5482. }
  5483. else
  5484. {
  5485. tempIndex = gun_index;
  5486. }
  5487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5488. {
  5489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5490. {
  5491. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5492. }
  5493. } // END OF FOR CHAdeMO_QUANTITY
  5494. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5495. }
  5496. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5497. {
  5498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5499. {
  5500. tempIndex = ((gun_index==2) ? 1: 0);
  5501. }
  5502. else
  5503. {
  5504. tempIndex = gun_index;
  5505. }
  5506. for (int index = 0; index < CCS_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5511. }
  5512. } // END OF FOR CCS_QUANTITY
  5513. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5514. }
  5515. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5516. {
  5517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5518. {
  5519. tempIndex = ((gun_index==2) ? 1: 0);
  5520. }
  5521. else
  5522. {
  5523. tempIndex = gun_index;
  5524. }
  5525. for (int index = 0; index < GB_QUANTITY; index++)
  5526. {
  5527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5528. {
  5529. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5530. }
  5531. } // END OF FOR GB_QUANTITY
  5532. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5533. }
  5534. else if(gunType[gun_index] == GUN_TYPE_DO)
  5535. {
  5536. tempIndex = gun_index;
  5537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5538. {
  5539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5540. {
  5541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5542. }
  5543. }
  5544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5545. }
  5546. else
  5547. {
  5548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5549. {
  5550. tempIndex = 2;
  5551. }
  5552. else
  5553. {
  5554. tempIndex = gun_index;
  5555. }
  5556. for (int index = 0; index < AC_QUANTITY; index++)
  5557. {
  5558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5559. {
  5560. 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
  5561. }
  5562. } // END OF FOR AC_QUANTITY
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5564. }
  5565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5570. }
  5571. //====================== End SoC ================================
  5572. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5573. {
  5574. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5575. 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))
  5576. {
  5577. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5578. {
  5579. tempIndex = ((gun_index==2) ? 1: 0);
  5580. }
  5581. else
  5582. {
  5583. tempIndex = gun_index;
  5584. }
  5585. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5586. {
  5587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5588. {
  5589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5590. {
  5591. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5592. }
  5593. }
  5594. }
  5595. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5596. {
  5597. for (int index = 0; index < CCS_QUANTITY; index++)
  5598. {
  5599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5600. {
  5601. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5602. }
  5603. }
  5604. }
  5605. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5606. {
  5607. for (int index = 0; index < GB_QUANTITY; index++)
  5608. {
  5609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5610. {
  5611. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5612. }
  5613. }
  5614. }
  5615. else if(gunType[gun_index] == GUN_TYPE_DO)
  5616. {
  5617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5618. {
  5619. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5620. {
  5621. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5622. }
  5623. }
  5624. }
  5625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5631. } // END FOR DC CASE
  5632. }
  5633. // ================================= Current.Import L2 ===============================================
  5634. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5635. {
  5636. // AC 3 phse L2 current
  5637. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5638. {
  5639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5640. {
  5641. tempIndex = 2;
  5642. }
  5643. else
  5644. {
  5645. tempIndex = gun_index;
  5646. }
  5647. for (int index = 0; index < AC_QUANTITY; index++)
  5648. {
  5649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5650. {
  5651. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5652. }
  5653. }// End of for AC_QUANTITY
  5654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5655. }
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5661. }
  5662. // ================================= Current.Import L3 ===============================================
  5663. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5664. {
  5665. // AC 3 phse L3 current
  5666. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5667. {
  5668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5669. {
  5670. tempIndex = 2;
  5671. }
  5672. else
  5673. {
  5674. tempIndex = gun_index;
  5675. }
  5676. for (int index = 0; index < AC_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5681. }
  5682. }// End of for AC_QUANTITY
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5684. }
  5685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5688. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5690. }
  5691. //============================ Voltage L2 ====================================
  5692. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5693. {
  5694. // AC 3 phse L2 voltage
  5695. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5696. {
  5697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5698. {
  5699. tempIndex = 2;
  5700. }
  5701. else
  5702. {
  5703. tempIndex = gun_index;
  5704. }
  5705. for (int index = 0; index < AC_QUANTITY; index++)
  5706. {
  5707. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5708. {
  5709. 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
  5710. }
  5711. } // END OF FOR AC_QUANTITY
  5712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5713. }
  5714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5719. }
  5720. //============================ Voltage L3 ====================================
  5721. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5722. {
  5723. // AC 3 phse L3 voltage
  5724. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5725. {
  5726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5727. {
  5728. tempIndex = 2;
  5729. }
  5730. else
  5731. {
  5732. tempIndex = gun_index;
  5733. }
  5734. for (int index = 0; index < AC_QUANTITY; index++)
  5735. {
  5736. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5737. {
  5738. 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
  5739. }
  5740. } // END OF FOR AC_QUANTITY
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5742. }
  5743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5748. }
  5749. //====================== Start SoC ================================
  5750. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5751. {
  5752. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5753. 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))
  5754. {
  5755. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5756. {
  5757. tempIndex = ((gun_index==2) ? 1: 0);
  5758. }
  5759. else
  5760. {
  5761. tempIndex = gun_index;
  5762. }
  5763. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5764. {
  5765. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5768. {
  5769. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5770. }
  5771. }
  5772. }
  5773. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5774. {
  5775. for (int index = 0; index < CCS_QUANTITY; index++)
  5776. {
  5777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5778. {
  5779. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5780. }
  5781. }
  5782. }
  5783. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5784. {
  5785. for (int index = 0; index < GB_QUANTITY; index++)
  5786. {
  5787. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5788. {
  5789. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5790. }
  5791. }
  5792. }
  5793. else if(gunType[gun_index] == GUN_TYPE_DO)
  5794. {
  5795. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5796. {
  5797. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5798. {
  5799. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5800. }
  5801. }
  5802. }
  5803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5809. } // END FOR DC CASE
  5810. }
  5811. //================================================ Message create ====================================================
  5812. json_object *StopTransaction = json_object_new_object();
  5813. json_object *transactionDatas = json_object_new_array();
  5814. json_object *sampledValues = json_object_new_array();
  5815. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5816. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5817. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5818. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5819. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5820. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5821. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5822. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5823. {
  5824. json_object *transactionData = json_object_new_object();
  5825. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5826. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5827. {
  5828. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5829. {
  5830. json_object *sampledValue = json_object_new_object();
  5831. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5832. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5833. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5834. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5835. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5836. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5837. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5838. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5839. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5840. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5841. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5842. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5843. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5844. json_object_array_add(sampledValues, sampledValue);
  5845. }
  5846. }
  5847. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5848. json_object_array_add(transactionDatas, transactionData);
  5849. }
  5850. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5851. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5852. ,MESSAGE_TYPE_CALL
  5853. ,guid
  5854. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5855. json_object_put(StopTransaction);
  5856. #if 1 // for TempStopTransaction
  5857. //Delete TempStopTransaction
  5858. if((access(TempStopTransaction,F_OK))!=-1)
  5859. {
  5860. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5861. }
  5862. #endif
  5863. #if 1
  5864. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5865. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5866. {
  5867. result = PASS;
  5868. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5869. }
  5870. #endif
  5871. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5872. OCPP_insert_transaction_msg(NO, queuedata);
  5873. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5874. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5875. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5876. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5877. {
  5878. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5879. }
  5880. //for test
  5881. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5882. return result;
  5883. }
  5884. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5885. {
  5886. mtrace();
  5887. int result = FAIL;
  5888. char guid[37]={0};
  5889. char tempdata[65]={0};
  5890. int tempIndex = 0;
  5891. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5892. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5893. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5894. //set value
  5895. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5896. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5897. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5898. -1);
  5899. random_uuid(guid);
  5900. //UTC Date time
  5901. struct timeval tmnow;
  5902. struct tm *tm;
  5903. char buf[28];//, usec_buf[6];
  5904. gettimeofday(&tmnow, NULL);
  5905. time_t t;
  5906. t = time(NULL);
  5907. /*UTC time and date*/
  5908. tm = gmtime(&t);
  5909. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5910. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5911. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5912. //********************************(1)Current.Import L1************************************************/
  5913. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5914. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5915. (dataType == ReadingContext_Trigger))
  5916. {
  5917. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5918. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5919. {
  5920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5921. {
  5922. tempIndex = ((gun_index==2) ? 1: 0);
  5923. }
  5924. else
  5925. {
  5926. tempIndex = gun_index;
  5927. }
  5928. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5931. {
  5932. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5933. }
  5934. }
  5935. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5936. }
  5937. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5938. {
  5939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5940. {
  5941. tempIndex = ((gun_index==2) ? 1: 0);
  5942. }
  5943. else
  5944. {
  5945. tempIndex = gun_index;
  5946. }
  5947. for (int index = 0; index < CCS_QUANTITY; index++)
  5948. {
  5949. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5950. {
  5951. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5952. }
  5953. }
  5954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5955. }
  5956. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5957. {
  5958. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5959. {
  5960. tempIndex = ((gun_index==2) ? 1: 0);
  5961. }
  5962. else
  5963. {
  5964. tempIndex = gun_index;
  5965. }
  5966. for (int index = 0; index < GB_QUANTITY; index++)
  5967. {
  5968. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5969. {
  5970. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5971. }
  5972. }
  5973. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5974. }
  5975. else if(gunType[gun_index] == GUN_TYPE_DO)
  5976. {
  5977. tempIndex = gun_index;
  5978. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5983. }
  5984. }
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5986. }
  5987. else
  5988. {
  5989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5990. {
  5991. tempIndex = 2;
  5992. }
  5993. else
  5994. {
  5995. tempIndex = gun_index;
  5996. }
  5997. for (int index = 0; index < AC_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6000. {
  6001. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6002. }
  6003. }
  6004. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6005. }
  6006. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6007. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6008. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6009. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6010. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6011. }
  6012. //********************************(2)Energy.Active.Import.Register ************************************************/
  6013. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6014. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6015. (dataType == ReadingContext_Trigger))
  6016. {
  6017. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6018. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6019. {
  6020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6021. {
  6022. tempIndex = ((gun_index==2) ? 1: 0);
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6029. {
  6030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6031. {
  6032. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6033. }
  6034. }
  6035. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6036. }
  6037. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6038. {
  6039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6040. {
  6041. tempIndex = ((gun_index==2) ? 1: 0);
  6042. }
  6043. else
  6044. {
  6045. tempIndex = gun_index;
  6046. }
  6047. for (int index = 0; index < CCS_QUANTITY; index++)
  6048. {
  6049. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6050. {
  6051. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6052. }
  6053. }
  6054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6055. }
  6056. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6057. {
  6058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6059. {
  6060. tempIndex = ((gun_index==2) ? 1: 0);
  6061. }
  6062. else
  6063. {
  6064. tempIndex = gun_index;
  6065. }
  6066. for (int index = 0; index < GB_QUANTITY; index++)
  6067. {
  6068. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6069. {
  6070. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6071. }
  6072. }
  6073. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6074. }
  6075. else if(gunType[gun_index] == GUN_TYPE_DO)
  6076. {
  6077. tempIndex = gun_index;
  6078. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6083. }
  6084. }
  6085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6086. }
  6087. else
  6088. {
  6089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6090. {
  6091. tempIndex = 2;
  6092. }
  6093. else
  6094. {
  6095. tempIndex = gun_index;
  6096. }
  6097. for (int index = 0; index < AC_QUANTITY; index++)
  6098. {
  6099. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6100. {
  6101. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6102. }
  6103. }
  6104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6105. }
  6106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6111. }
  6112. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6113. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6114. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6115. (dataType == ReadingContext_Trigger))
  6116. {
  6117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6119. {
  6120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6121. {
  6122. tempIndex = ((gun_index==2) ? 1: 0);
  6123. }
  6124. else
  6125. {
  6126. tempIndex = gun_index;
  6127. }
  6128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6131. {
  6132. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6133. }
  6134. } // END OF FOR CHAdeMO_QUANTITY
  6135. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6136. }
  6137. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6138. {
  6139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6140. {
  6141. tempIndex = ((gun_index==2) ? 1: 0);
  6142. }
  6143. else
  6144. {
  6145. tempIndex = gun_index;
  6146. }
  6147. for (int index = 0; index < CCS_QUANTITY; index++)
  6148. {
  6149. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6150. {
  6151. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6152. }
  6153. } // END OF CCS_QUANTITY
  6154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6155. }
  6156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6157. {
  6158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6159. {
  6160. tempIndex = ((gun_index==2) ? 1: 0);
  6161. }
  6162. else
  6163. {
  6164. tempIndex = gun_index;
  6165. }
  6166. for (int index = 0; index < GB_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6171. }
  6172. } // END OF GB_QUANTITY
  6173. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6174. }
  6175. else if(gunType[gun_index] == GUN_TYPE_DO)
  6176. {
  6177. tempIndex = gun_index;
  6178. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6179. {
  6180. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6181. {
  6182. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6183. }
  6184. }
  6185. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6186. }
  6187. else
  6188. {
  6189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6190. {
  6191. tempIndex = 2;
  6192. }
  6193. else
  6194. {
  6195. tempIndex = gun_index;
  6196. }
  6197. for (int index = 0; index < AC_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6200. {
  6201. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6202. }
  6203. }
  6204. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6205. }
  6206. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6207. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6208. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6209. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6210. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6211. }
  6212. //********************************(4)Power.Active.Import************************************************/
  6213. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6214. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6215. (dataType == ReadingContext_Trigger))
  6216. {
  6217. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6218. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6219. {
  6220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6221. {
  6222. tempIndex = ((gun_index==2) ? 1: 0);
  6223. }
  6224. else
  6225. {
  6226. tempIndex = gun_index;
  6227. }
  6228. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6229. {
  6230. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6231. {
  6232. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6233. }
  6234. } // END OF FOR
  6235. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6236. }
  6237. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6238. {
  6239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6240. {
  6241. tempIndex = ((gun_index==2) ? 1: 0);
  6242. }
  6243. else
  6244. {
  6245. tempIndex = gun_index;
  6246. }
  6247. for (int index = 0; index < CCS_QUANTITY; index++)
  6248. {
  6249. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6250. {
  6251. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6252. }
  6253. }
  6254. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6255. }
  6256. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6257. {
  6258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6259. {
  6260. tempIndex = ((gun_index==2) ? 1: 0);
  6261. }
  6262. else
  6263. {
  6264. tempIndex = gun_index;
  6265. }
  6266. for (int index = 0; index < GB_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6269. {
  6270. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6271. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6272. }
  6273. }
  6274. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6275. }
  6276. else if(gunType[gun_index] == GUN_TYPE_DO)
  6277. {
  6278. tempIndex = gun_index;
  6279. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6280. {
  6281. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6282. {
  6283. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6284. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6285. }
  6286. }
  6287. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6288. }
  6289. else
  6290. {
  6291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6292. {
  6293. tempIndex = 2;
  6294. }
  6295. else
  6296. {
  6297. tempIndex = gun_index;
  6298. }
  6299. for (int index = 0; index < AC_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6302. {
  6303. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6304. }
  6305. }
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6307. }
  6308. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6309. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6310. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6311. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6312. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6313. }
  6314. //***********************************************(5)VOLTAGE L1******************************************************/
  6315. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6316. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6317. (dataType == ReadingContext_Trigger))
  6318. {
  6319. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6320. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6321. {
  6322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6323. {
  6324. tempIndex = ((gun_index==2) ? 1: 0);
  6325. }
  6326. else
  6327. {
  6328. tempIndex = gun_index;
  6329. }
  6330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6331. {
  6332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6333. {
  6334. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6335. }
  6336. }
  6337. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6338. }
  6339. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6340. {
  6341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6342. {
  6343. tempIndex = ((gun_index==2) ? 1: 0);
  6344. }
  6345. else
  6346. {
  6347. tempIndex = gun_index;
  6348. }
  6349. for (int index = 0; index < CCS_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6354. }
  6355. }
  6356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6357. }
  6358. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6359. {
  6360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6361. {
  6362. tempIndex = ((gun_index==2) ? 1: 0);
  6363. }
  6364. else
  6365. {
  6366. tempIndex = gun_index;
  6367. }
  6368. for (int index = 0; index < GB_QUANTITY; index++)
  6369. {
  6370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6371. {
  6372. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6373. }
  6374. }
  6375. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6376. }
  6377. else if(gunType[gun_index] == GUN_TYPE_DO)
  6378. {
  6379. tempIndex = gun_index;
  6380. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6381. {
  6382. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6383. {
  6384. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6385. }
  6386. }
  6387. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6388. }
  6389. else
  6390. {
  6391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6392. {
  6393. tempIndex = 2;
  6394. }
  6395. else
  6396. {
  6397. tempIndex = gun_index;
  6398. }
  6399. for (int index = 0; index < AC_QUANTITY; index++)
  6400. {
  6401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6402. {
  6403. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6404. }
  6405. }
  6406. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6407. }
  6408. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6409. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6410. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6412. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6413. }
  6414. //***********************************************(6)SOC******************************************************/
  6415. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6416. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6417. (dataType == ReadingContext_Trigger))
  6418. {
  6419. 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))
  6420. {
  6421. //idx_sample=5;
  6422. //sampledValue = NULL;
  6423. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6424. {
  6425. tempIndex = ((gun_index==2) ? 1: 0);
  6426. }
  6427. else
  6428. {
  6429. tempIndex = gun_index;
  6430. }
  6431. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6432. {
  6433. //tempIndex = ((gun_index==2) ? 1: 0);
  6434. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6435. {
  6436. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6437. {
  6438. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6439. }
  6440. }
  6441. }
  6442. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6443. {
  6444. //tempIndex = ((gun_index==2) ? 1: 0);
  6445. for (int index = 0; index < CCS_QUANTITY; index++)
  6446. {
  6447. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6448. {
  6449. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6450. }
  6451. }
  6452. }
  6453. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6454. {
  6455. //tempIndex = ((gun_index==2) ? 1: 0);
  6456. for (int index = 0; index < GB_QUANTITY; index++)
  6457. {
  6458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6459. {
  6460. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6461. }
  6462. }
  6463. }
  6464. else if(gunType[gun_index] == GUN_TYPE_DO)
  6465. {
  6466. //tempIndex = ((gun_index==2) ? 1: 0);
  6467. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6468. {
  6469. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6470. {
  6471. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6472. }
  6473. }
  6474. }
  6475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6476. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6478. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6481. }
  6482. }
  6483. //********************************(7)Current.Import L2************************************************/
  6484. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6485. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6486. (dataType == ReadingContext_Trigger))
  6487. {
  6488. // Only for AC 3 phase
  6489. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6490. {
  6491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6492. {
  6493. tempIndex = 2;
  6494. }
  6495. else
  6496. {
  6497. tempIndex = gun_index;
  6498. }
  6499. for (int index = 0; index < AC_QUANTITY; index++)
  6500. {
  6501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6502. {
  6503. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6504. }
  6505. }
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6507. }
  6508. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6513. }
  6514. //********************************(8)Current.Import L3************************************************/
  6515. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6516. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6517. (dataType == ReadingContext_Trigger))
  6518. {
  6519. // Only for AC 3 phase
  6520. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6521. {
  6522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6523. {
  6524. tempIndex = 2;
  6525. }
  6526. else
  6527. {
  6528. tempIndex = gun_index;
  6529. }
  6530. for (int index = 0; index < AC_QUANTITY; index++)
  6531. {
  6532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6533. {
  6534. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6535. }
  6536. }
  6537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6538. }
  6539. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6540. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6541. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6542. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6543. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6544. }
  6545. //***********************************************(9)VOLTAGE L2******************************************************/
  6546. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6547. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6548. (dataType == ReadingContext_Trigger))
  6549. {
  6550. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6551. {
  6552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6553. {
  6554. tempIndex = 2;
  6555. }
  6556. else
  6557. {
  6558. tempIndex = gun_index;
  6559. }
  6560. for (int index = 0; index < AC_QUANTITY; index++)
  6561. {
  6562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6563. {
  6564. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6565. }
  6566. }
  6567. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6568. }
  6569. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6570. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6571. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6572. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6573. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6574. }
  6575. //***********************************************(10)VOLTAGE L3******************************************************/
  6576. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6577. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6578. (dataType == ReadingContext_Trigger))
  6579. {
  6580. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6581. {
  6582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6583. {
  6584. tempIndex = 2;
  6585. }
  6586. else
  6587. {
  6588. tempIndex = gun_index;
  6589. }
  6590. for (int index = 0; index < AC_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6593. {
  6594. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6595. }
  6596. }
  6597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6598. }
  6599. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6601. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6602. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6603. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6604. }
  6605. //***********************************************(11)Current.Offered******************************************************/
  6606. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6607. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6608. (dataType == ReadingContext_Trigger))
  6609. {
  6610. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6611. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6612. {
  6613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6614. {
  6615. tempIndex = ((gun_index==2) ? 1: 0);
  6616. }
  6617. else
  6618. {
  6619. tempIndex = gun_index;
  6620. }
  6621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6622. {
  6623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6624. {
  6625. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6626. }
  6627. } // END OF FOR CHAdeMO_QUANTITY
  6628. }
  6629. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6630. {
  6631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6632. {
  6633. tempIndex = ((gun_index==2) ? 1: 0);
  6634. }
  6635. else
  6636. {
  6637. tempIndex = gun_index;
  6638. }
  6639. for (int index = 0; index < CCS_QUANTITY; index++)
  6640. {
  6641. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6642. {
  6643. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6644. }
  6645. } // END OF CCS_QUANTITY
  6646. }
  6647. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6648. {
  6649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6650. {
  6651. tempIndex = ((gun_index==2) ? 1: 0);
  6652. }
  6653. else
  6654. {
  6655. tempIndex = gun_index;
  6656. }
  6657. for (int index = 0; index < GB_QUANTITY; index++)
  6658. {
  6659. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6660. {
  6661. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6662. }
  6663. } // END OF GB_QUANTITY
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_DO)
  6666. {
  6667. tempIndex = gun_index;
  6668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6671. {
  6672. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6673. }
  6674. }
  6675. }
  6676. else
  6677. {
  6678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6679. {
  6680. tempIndex = 2;
  6681. }
  6682. else
  6683. {
  6684. tempIndex = gun_index;
  6685. }
  6686. for (int index = 0; index < AC_QUANTITY; index++)
  6687. {
  6688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6689. {
  6690. uint16_t currentOffer;
  6691. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6692. {
  6693. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6694. }
  6695. else
  6696. {
  6697. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6698. }
  6699. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6700. }
  6701. }
  6702. }
  6703. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6704. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6705. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6706. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6707. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6708. }
  6709. //***********************************************(12)Power.Offered******************************************************/
  6710. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6711. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6712. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6713. {
  6714. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6715. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6716. {
  6717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6718. {
  6719. tempIndex = ((gun_index==2) ? 1: 0);
  6720. }
  6721. else
  6722. {
  6723. tempIndex = gun_index;
  6724. }
  6725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6726. {
  6727. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6728. {
  6729. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6730. }
  6731. } // END OF FOR CHAdeMO_QUANTITY
  6732. }
  6733. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6734. {
  6735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6736. {
  6737. tempIndex = ((gun_index==2) ? 1: 0);
  6738. }
  6739. else
  6740. {
  6741. tempIndex = gun_index;
  6742. }
  6743. for (int index = 0; index < CCS_QUANTITY; index++)
  6744. {
  6745. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6746. {
  6747. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6748. }
  6749. } // END OF CCS_QUANTITY
  6750. }
  6751. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6752. {
  6753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6754. {
  6755. tempIndex = ((gun_index==2) ? 1: 0);
  6756. }
  6757. else
  6758. {
  6759. tempIndex = gun_index;
  6760. }
  6761. for (int index = 0; index < GB_QUANTITY; index++)
  6762. {
  6763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6764. {
  6765. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6766. }
  6767. } // END OF GB_QUANTITY
  6768. }
  6769. else if(gunType[gun_index] == GUN_TYPE_DO)
  6770. {
  6771. tempIndex = gun_index;
  6772. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6773. {
  6774. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6775. {
  6776. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6777. }
  6778. }
  6779. }
  6780. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6781. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6782. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6783. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6784. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6785. }
  6786. // Message create ====================================================================================================
  6787. if(TRUE)
  6788. {
  6789. json_object *MeterValueReq = json_object_new_object();
  6790. json_object *MeterValues = json_object_new_array();
  6791. json_object *sampledValues = json_object_new_array();
  6792. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6793. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6794. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6795. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6796. {
  6797. json_object *MeterValue = json_object_new_object();
  6798. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6799. {
  6800. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6801. {
  6802. json_object *sampledValue = json_object_new_object();
  6803. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6804. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6805. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6806. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6807. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6808. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6809. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6810. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6811. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6812. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6813. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6814. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6815. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6816. json_object_array_add(sampledValues, sampledValue);
  6817. }
  6818. }
  6819. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6820. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6821. json_object_array_add(MeterValues, MeterValue);
  6822. }
  6823. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6824. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6825. ,gun_index + 1
  6826. ,MESSAGE_TYPE_CALL
  6827. ,guid
  6828. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6829. json_object_put(MeterValueReq);
  6830. }
  6831. // Put request guid to hash map
  6832. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6833. 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*/)
  6834. {
  6835. result = PASS;
  6836. //DEBUG_INFO("MeterValues mapitem pass\n");
  6837. }
  6838. if((dataType != ReadingContext_Trigger) &&
  6839. (dataType != ReadingContext_Sample_Clock) &&
  6840. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6841. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6842. else
  6843. {
  6844. if(FirstHeartBeat)
  6845. LWS_Send(queuedata +2);
  6846. }
  6847. return result;
  6848. }
  6849. int sendLogStatusNotificationRequest(char *status)
  6850. {
  6851. mtrace();
  6852. int result = PASS;
  6853. char message[4096]={0};
  6854. char guid[37]={0};
  6855. char tempdata[128]={0};
  6856. json_object *LogStatusNotification = json_object_new_object();
  6857. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6858. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6859. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6860. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6861. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6862. random_uuid(guid);
  6863. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6864. json_object_put(LogStatusNotification);
  6865. LWS_Send(message);
  6866. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6867. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6868. {
  6869. result = PASS;
  6870. }
  6871. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6872. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6873. return result;
  6874. }
  6875. int sendSecurityEventNotificationRequest()
  6876. {
  6877. mtrace();
  6878. int result = PASS;
  6879. char message[4096]={0};
  6880. char guid[37]={0};
  6881. char tempdata[128]={0};
  6882. json_object *SecurityEventNotification = json_object_new_object();
  6883. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6884. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6885. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6886. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6887. random_uuid(guid);
  6888. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6889. json_object_put(SecurityEventNotification);
  6890. LWS_Send(message);
  6891. sprintf(tempdata, "SecurityEventNotification,0");
  6892. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6893. {
  6894. result = PASS;
  6895. }
  6896. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6897. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6898. return result;
  6899. }
  6900. int sendSignCertificateRequest()
  6901. {
  6902. mtrace();
  6903. int result = PASS;
  6904. char message[4096]={0};
  6905. char guid[37]={0};
  6906. char tempdata[128]={0};
  6907. json_object *SignCertificate = json_object_new_object();
  6908. DEBUG_INFO("sendSignCertificateRequest...\n");
  6909. // Read csr file content
  6910. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6911. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6912. char *line = NULL;
  6913. size_t len = 0;
  6914. while(getline(&line, &len, fp) != -1)
  6915. {
  6916. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6917. {
  6918. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6919. }
  6920. }
  6921. fclose(fp);
  6922. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6923. random_uuid(guid);
  6924. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6925. json_object_put(SignCertificate);
  6926. LWS_Send(message);
  6927. sprintf(tempdata, "SignCertificate,0");
  6928. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6929. {
  6930. result = PASS;
  6931. }
  6932. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6933. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6934. return result;
  6935. }
  6936. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6937. {
  6938. mtrace();
  6939. int result = PASS;
  6940. char message[110]={0};
  6941. char guid[37]={0};
  6942. char tempdata[65]={0};
  6943. json_object *FirmwareStatusNotification = json_object_new_object();
  6944. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6945. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6946. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6947. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6948. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6949. random_uuid(guid);
  6950. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6951. json_object_put(FirmwareStatusNotification);
  6952. LWS_Send(message);
  6953. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6954. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6955. {
  6956. result = PASS;
  6957. }
  6958. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6959. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6960. return result;
  6961. }
  6962. //==========================================
  6963. // send confirm routine
  6964. //==========================================
  6965. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6966. {
  6967. mtrace();
  6968. int result = FAIL;
  6969. char message[100]={0};
  6970. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6972. LWS_Send(message);
  6973. result = TRUE;
  6974. return result;
  6975. }
  6976. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6977. {
  6978. mtrace();
  6979. int result = FAIL;
  6980. char message[100]={0};
  6981. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6982. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6983. LWS_Send(message);
  6984. result = TRUE;
  6985. return result;
  6986. }
  6987. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6988. {
  6989. mtrace();
  6990. int result = FAIL;
  6991. char message[100]={0};
  6992. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6993. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6994. LWS_Send(message);
  6995. result = TRUE;
  6996. return result;
  6997. }
  6998. int sendClearCacheConfirmation(char *uuid,char *payload)
  6999. {
  7000. mtrace();
  7001. int result = FAIL;
  7002. char message[500]={0};
  7003. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7004. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7005. LWS_Send(message);
  7006. return result;
  7007. }
  7008. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7009. {
  7010. mtrace();
  7011. int result = FAIL;
  7012. char message[500]={0};
  7013. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7014. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7015. LWS_Send(message);
  7016. return result;
  7017. }
  7018. int sendDataTransferConfirmation(char *uuid,char *payload)
  7019. {
  7020. mtrace();
  7021. char statusStr[20]={0};
  7022. char dataStr[10]={0};
  7023. char sstr[20]={0};
  7024. int c = 0;
  7025. char *loc;
  7026. int result = FAIL;
  7027. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7028. /**********************status**************************/
  7029. loc = strstr(payload, "status");
  7030. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7031. c = 0;
  7032. while (loc[3+strlen("status")+c] != '\"')
  7033. {
  7034. sstr[c] = loc[3+strlen("status")+c];
  7035. c++;
  7036. }
  7037. sstr[c] = '\0';
  7038. strcpy(statusStr, sstr);
  7039. /**********************data**************************/
  7040. loc = strstr(payload, "data");
  7041. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7042. c = 0;
  7043. while (loc[3+strlen("data")+c] != '\"')
  7044. {
  7045. sstr[c] = loc[3+strlen("data")+c];
  7046. c++;
  7047. }
  7048. sstr[c] = '\0';
  7049. strcpy(dataStr, sstr);
  7050. return result;
  7051. }
  7052. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7053. {
  7054. mtrace();
  7055. int result = FAIL;
  7056. char message[1000]={0};
  7057. int CompositeScheduleIndex = 0;
  7058. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7059. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7060. if(nPeriod == 0)
  7061. {
  7062. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7063. {
  7064. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7065. ,MESSAGE_TYPE_CALLRESULT
  7066. ,uuid
  7067. ,payload
  7068. ,connectorIdInt);
  7069. }
  7070. else
  7071. {
  7072. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7073. ,MESSAGE_TYPE_CALLRESULT
  7074. ,uuid
  7075. ,payload
  7076. ,connectorIdInt
  7077. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7078. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7079. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7080. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7081. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7082. }
  7083. }
  7084. else
  7085. {
  7086. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7087. ,MESSAGE_TYPE_CALLRESULT
  7088. ,uuid
  7089. ,payload
  7090. ,connectorIdInt
  7091. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7092. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7093. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7094. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7095. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7096. {
  7097. if (idx_sample == 0)
  7098. {
  7099. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7100. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7101. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7102. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7103. }
  7104. else
  7105. {
  7106. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7107. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7108. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7109. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7110. }
  7111. }
  7112. sprintf(message + strlen(message), "]}}]");
  7113. }
  7114. LWS_Send(message);
  7115. result = TRUE;
  7116. return result;
  7117. }
  7118. int sendGetConfigurationConfirmation(char *uuid)
  7119. {
  7120. mtrace();
  7121. int result = FAIL;
  7122. int MaxKeySupported = 0;
  7123. int sentConfigurationNumber= 0;
  7124. int sentunConfigurationNumber= 0;
  7125. char message[1024*10]={0};
  7126. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7127. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7128. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7129. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7130. ,MESSAGE_TYPE_CALLRESULT
  7131. ,uuid );
  7132. //configuration key
  7133. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7134. {
  7135. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7136. {
  7137. if (sentConfigurationNumber == 0)
  7138. {
  7139. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7140. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7141. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7142. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7143. }
  7144. else
  7145. {
  7146. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7147. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7148. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7149. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7150. }
  7151. sentConfigurationNumber = sentConfigurationNumber + 1;
  7152. }
  7153. }
  7154. sprintf(message + strlen(message), "]");
  7155. if(UnknownKeynum != 0)
  7156. {
  7157. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7158. //unkown key
  7159. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7160. {
  7161. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7162. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7163. if(sentunConfigurationNumber == 0)
  7164. {
  7165. sprintf(message + strlen(message), "\"%s\""
  7166. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7167. }
  7168. else
  7169. {
  7170. sprintf(message + strlen(message), ",\"%s\""
  7171. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7172. }
  7173. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7174. }
  7175. sprintf(message + strlen(message), "]");
  7176. }
  7177. sprintf(message + strlen(message), "}]");
  7178. LWS_Send(message);
  7179. return result;
  7180. }
  7181. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7182. {
  7183. mtrace();
  7184. int result = FAIL;
  7185. char message[400]={0};
  7186. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7187. if(strcmp(payload,"")==0)
  7188. {
  7189. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7190. }
  7191. else
  7192. {
  7193. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7194. }
  7195. LWS_Send(message);
  7196. result = TRUE;
  7197. return result;
  7198. }
  7199. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7200. {
  7201. mtrace();
  7202. int result = FAIL;
  7203. char message[80]={0};
  7204. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7205. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7206. LWS_Send(message);
  7207. result = TRUE;
  7208. return result;
  7209. }
  7210. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7211. {
  7212. mtrace();
  7213. int result = FAIL;
  7214. char message[80]={0};
  7215. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7216. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7217. LWS_Send(message);
  7218. result = TRUE;
  7219. return result;
  7220. }
  7221. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7222. {
  7223. mtrace();
  7224. int result = FAIL;
  7225. char message[80]={0};
  7226. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7227. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7228. LWS_Send(message);
  7229. result = TRUE;
  7230. return result;
  7231. }
  7232. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7233. {
  7234. mtrace();
  7235. int result = FAIL;
  7236. char message[80]={0};
  7237. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7238. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7239. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7240. LWS_Send(message);
  7241. result = TRUE;
  7242. return result;
  7243. }
  7244. int sendResetConfirmation(char *uuid,char *payload)
  7245. {
  7246. mtrace();
  7247. int result = FAIL;
  7248. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7249. char message[80]={0};
  7250. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7251. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7252. LWS_Send(message);
  7253. result = TRUE;
  7254. return result;
  7255. }
  7256. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7257. {
  7258. mtrace();
  7259. int result = FAIL;
  7260. char message[500]={0};
  7261. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7262. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7263. LWS_Send(message);
  7264. result = TRUE;
  7265. return result;
  7266. }
  7267. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7268. {
  7269. mtrace();
  7270. int result = FAIL;
  7271. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7272. char message[80]={0};
  7273. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7274. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7275. LWS_Send(message);
  7276. result = TRUE;
  7277. return result;
  7278. }
  7279. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7280. {
  7281. mtrace();
  7282. int result = FAIL;
  7283. char message[80]={0};
  7284. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7285. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7286. LWS_Send(message);
  7287. result = TRUE;
  7288. return result;
  7289. }
  7290. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7291. {
  7292. mtrace();
  7293. int result = FAIL;
  7294. char message[80]={0};
  7295. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7296. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7297. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7298. LWS_Send(message);
  7299. result = TRUE;
  7300. return result;
  7301. }
  7302. int sendUpdateFirmwareConfirmation(char *uuid)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. char message[60]={0};
  7307. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7308. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7309. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7310. LWS_Send(message);
  7311. result = TRUE;
  7312. return result;
  7313. }
  7314. int sendCertificateSignedConfirmation(char *uuid)
  7315. {
  7316. mtrace();
  7317. int result = PASS;
  7318. char message[4096]={0};
  7319. json_object *CertificateSigned = json_object_new_object();
  7320. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7321. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7322. sprintf(message,"[%d,\"%s\",%s]"
  7323. ,MESSAGE_TYPE_CALLRESULT
  7324. ,uuid
  7325. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7326. json_object_put(CertificateSigned);
  7327. LWS_Send(message);
  7328. return result;
  7329. }
  7330. int sendDeleteCertificateConfirmation(char *uuid)
  7331. {
  7332. mtrace();
  7333. int result = PASS;
  7334. char message[4096]={0};
  7335. json_object *DeleteCertificate = json_object_new_object();
  7336. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7337. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7338. sprintf(message,"[%d,\"%s\",%s]"
  7339. ,MESSAGE_TYPE_CALLRESULT
  7340. ,uuid
  7341. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7342. json_object_put(DeleteCertificate);
  7343. LWS_Send(message);
  7344. return result;
  7345. }
  7346. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7347. {
  7348. mtrace();
  7349. int result = PASS;
  7350. char message[4096]={0};
  7351. json_object *ExtendedTriggerMessage = json_object_new_object();
  7352. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7353. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7354. sprintf(message,"[%d,\"%s\",%s]"
  7355. ,MESSAGE_TYPE_CALLRESULT
  7356. ,uuid
  7357. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7358. json_object_put(ExtendedTriggerMessage);
  7359. LWS_Send(message);
  7360. return result;
  7361. }
  7362. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7363. {
  7364. mtrace();
  7365. int result = PASS;
  7366. char message[4096]={0};
  7367. json_object *GetInstalledCertificateIds = json_object_new_object();
  7368. json_object *certificateHashDataDatas = json_object_new_array();
  7369. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7370. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7371. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7372. {
  7373. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7374. {
  7375. json_object *certificateHashData = json_object_new_object();
  7376. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7377. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7378. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7379. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7380. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7381. }
  7382. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7383. }
  7384. else
  7385. {
  7386. json_object_put(certificateHashDataDatas);
  7387. }
  7388. sprintf(message,"[%d,\"%s\",%s]"
  7389. ,MESSAGE_TYPE_CALLRESULT
  7390. ,uuid
  7391. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7392. json_object_put(GetInstalledCertificateIds);
  7393. LWS_Send(message);
  7394. return result;
  7395. }
  7396. int sendGetLogConfirmation(char *uuid)
  7397. {
  7398. mtrace();
  7399. int result = PASS;
  7400. char message[4096]={0};
  7401. json_object *GetLog = json_object_new_object();
  7402. DEBUG_INFO("sendGetLogConfirmation...\n");
  7403. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7404. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7405. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7406. sprintf(message,"[%d,\"%s\",%s]"
  7407. ,MESSAGE_TYPE_CALLRESULT
  7408. ,uuid
  7409. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7410. json_object_put(GetLog);
  7411. LWS_Send(message);
  7412. return result;
  7413. }
  7414. int sendInstallCertificateConfirmation(char *uuid)
  7415. {
  7416. mtrace();
  7417. int result = PASS;
  7418. char message[4096]={0};
  7419. json_object *InstallCertificate = json_object_new_object();
  7420. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7421. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7422. sprintf(message,"[%d,\"%s\",%s]"
  7423. ,MESSAGE_TYPE_CALLRESULT
  7424. ,uuid
  7425. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7426. json_object_put(InstallCertificate);
  7427. LWS_Send(message);
  7428. return result;
  7429. }
  7430. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7431. {
  7432. mtrace();
  7433. int result = PASS;
  7434. char message[4096]={0};
  7435. json_object *SignedUpdateFirmware = json_object_new_object();
  7436. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7437. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7438. sprintf(message,"[%d,\"%s\",%s]"
  7439. ,MESSAGE_TYPE_CALLRESULT
  7440. ,uuid
  7441. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7442. json_object_put(SignedUpdateFirmware);
  7443. LWS_Send(message);
  7444. return result;
  7445. }
  7446. int sendUnknownConfirmation(char *uuid)
  7447. {
  7448. mtrace();
  7449. int result = PASS;
  7450. char message[256]={0};
  7451. DEBUG_INFO("sendUnknownConfirmation...\n");
  7452. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7453. LWS_Send(message);
  7454. return result;
  7455. }
  7456. //==========================================
  7457. // Handle server request routine Start
  7458. //==========================================
  7459. int handleCancelReservationRequest(char *uuid, char *payload)
  7460. {
  7461. mtrace();
  7462. int result = FAIL;
  7463. int gunNO = 0;
  7464. int reservationIdInt = -1;
  7465. char comfirmstr[20];
  7466. DEBUG_INFO("handleCancelReservationRequest...\n");
  7467. json_object *CancelReservation;
  7468. CancelReservation = json_tokener_parse(payload);
  7469. if(!is_error(CancelReservation))
  7470. {
  7471. // Required data
  7472. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7473. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7474. }
  7475. json_object_put(CancelReservation);
  7476. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7477. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7478. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7479. if(reservationIdInt != -1)
  7480. {
  7481. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7482. //check Transaction active
  7483. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7485. {
  7486. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7487. {
  7488. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7489. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7490. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7491. {
  7492. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7493. }
  7494. else
  7495. {
  7496. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7497. }
  7498. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7499. goto end;
  7500. }
  7501. }
  7502. for (int index = 0; index < CCS_QUANTITY; index++)
  7503. {
  7504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7505. {
  7506. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7507. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7508. if(gunType[2] == GUN_TYPE_CCS)
  7509. {
  7510. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7511. }
  7512. else
  7513. {
  7514. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7515. }
  7516. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7517. goto end;
  7518. }
  7519. }
  7520. for (int index = 0; index < GB_QUANTITY; index++)
  7521. {
  7522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7523. {
  7524. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7525. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7526. if(gunType[2] == GUN_TYPE_GBT)
  7527. {
  7528. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7529. }
  7530. else
  7531. {
  7532. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7533. }
  7534. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7535. goto end;
  7536. }
  7537. }
  7538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7539. {
  7540. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7541. {
  7542. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7543. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7544. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7545. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7546. goto end;
  7547. }
  7548. }
  7549. for (int index = 0; index < AC_QUANTITY; index++)
  7550. {
  7551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7552. {
  7553. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7554. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7556. {
  7557. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7558. }
  7559. else
  7560. {
  7561. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7562. }
  7563. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7564. goto end;
  7565. }
  7566. }
  7567. }
  7568. //The reservationId does NOT match the reservationId
  7569. sendCancelReservationConfirmation(uuid, comfirmstr);
  7570. end:
  7571. // Fill in ocpp packet uuid
  7572. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7573. return result;
  7574. }
  7575. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7576. {
  7577. mtrace();
  7578. int result = FAIL;
  7579. int gunIndex = -1;
  7580. char typeStr[16]={0};
  7581. char comfirmstr[20];
  7582. int specificId = FALSE;
  7583. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7584. json_object *ChangeAvailability;
  7585. ChangeAvailability = json_tokener_parse(payload);
  7586. if(!is_error(ChangeAvailability))
  7587. {
  7588. // Required data
  7589. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7590. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7591. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7592. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7593. }
  7594. json_object_put(ChangeAvailability);
  7595. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7596. {
  7597. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7598. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7599. }
  7600. else if(gunIndex == 0)
  7601. {
  7602. for(int i=0; i < gunTotalNumber; i++)
  7603. {
  7604. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7605. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7606. }
  7607. }
  7608. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7610. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7611. {
  7612. specificId = TRUE;
  7613. }
  7614. if(specificId == FALSE)
  7615. goto end;
  7616. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7617. {
  7618. //----------------------gunIndex is 0 ------------------------------------------------//
  7619. if(gunIndex == 0)
  7620. {
  7621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7622. {
  7623. for(int i=0; i < gunTotalNumber; i++)
  7624. {
  7625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7626. {
  7627. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7628. {
  7629. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7630. {
  7631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7632. goto end;
  7633. }
  7634. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7635. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7636. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7637. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7638. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7639. {
  7640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7641. goto end;
  7642. }
  7643. }
  7644. }//END FOR CHAdeMO_QUANTITY
  7645. for (int index = 0; index < CCS_QUANTITY; index++)
  7646. {
  7647. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7648. {
  7649. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7650. {
  7651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7652. goto end;
  7653. }
  7654. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7655. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7656. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7657. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7658. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7659. {
  7660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7661. goto end;
  7662. }
  7663. }
  7664. }//END FOR CCS_QUANTITY
  7665. for (int index = 0; index < GB_QUANTITY; index++)
  7666. {
  7667. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7668. {
  7669. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7670. {
  7671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7672. goto end;
  7673. }
  7674. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7676. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7677. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7678. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7679. {
  7680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7681. goto end;
  7682. }
  7683. }
  7684. }// END FOR GB_QUANTITY
  7685. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7686. {
  7687. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7688. {
  7689. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7690. {
  7691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7692. goto end;
  7693. }
  7694. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7695. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7696. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7697. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7698. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7699. {
  7700. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7701. goto end;
  7702. }
  7703. }
  7704. }// END FOR GENERAL_GUN_QUANTITY
  7705. for (int index = 0; index < AC_QUANTITY; index++)
  7706. {
  7707. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7708. {
  7709. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7710. {
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7712. goto end;
  7713. }
  7714. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7715. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7716. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7717. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7718. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7719. {
  7720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7721. goto end;
  7722. }
  7723. }
  7724. }//END FOR AC_QUANTITY
  7725. }// END FOR gunTotalNumber
  7726. }
  7727. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7728. {
  7729. for(int i=0; i < gunTotalNumber; i++)
  7730. {
  7731. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7732. {
  7733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7734. goto end;
  7735. }
  7736. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7737. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7738. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7739. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7740. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7741. {
  7742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7743. goto end;
  7744. }
  7745. }
  7746. }
  7747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7748. goto end;
  7749. }
  7750. //----------------------gunIndex is not 0 ------------------------------------------------//
  7751. //check Transaction active
  7752. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7753. {
  7754. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7755. {
  7756. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7757. {
  7758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7759. goto end;
  7760. }
  7761. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7762. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7763. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7764. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7765. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7766. {
  7767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7768. goto end;
  7769. }
  7770. else
  7771. {
  7772. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7773. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7774. goto end;
  7775. }
  7776. }
  7777. }//END FOR CHAdeMO_QUANTITY
  7778. for (int index = 0; index < CCS_QUANTITY; index++)
  7779. {
  7780. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7781. {
  7782. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7783. {
  7784. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7785. goto end;
  7786. }
  7787. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7788. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7789. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7790. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7791. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7792. {
  7793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7794. goto end;
  7795. }
  7796. else
  7797. {
  7798. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7799. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7800. goto end;
  7801. }
  7802. }
  7803. }//END FOR CCS_QUANTITY
  7804. for (int index = 0; index < GB_QUANTITY; index++)
  7805. {
  7806. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7807. {
  7808. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7809. {
  7810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7811. goto end;
  7812. }
  7813. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7814. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7815. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7816. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7817. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7818. {
  7819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7820. goto end;
  7821. }
  7822. else
  7823. {
  7824. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7826. goto end;
  7827. }
  7828. }
  7829. }// END FOR GB_QUANTITY
  7830. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7831. {
  7832. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7833. {
  7834. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7835. {
  7836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7837. goto end;
  7838. }
  7839. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7840. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7841. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7842. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7843. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7844. {
  7845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7846. goto end;
  7847. }
  7848. else
  7849. {
  7850. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7852. goto end;
  7853. }
  7854. }
  7855. }// END FOR GENERAL_GUN_QUANTITY
  7856. for (int index = 0; index < AC_QUANTITY; index++)
  7857. {
  7858. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7859. {
  7860. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7861. {
  7862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7863. goto end;
  7864. }
  7865. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7866. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7867. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7868. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7869. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7870. {
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7872. goto end;
  7873. }
  7874. else
  7875. {
  7876. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7878. goto end;
  7879. }
  7880. }
  7881. }//END FOR AC_QUANTITY
  7882. }//END FOR AvailabilityTypeStr[Inoperative]
  7883. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7884. {
  7885. //----------------------gunIndex is 0 ------------------------------------------------//
  7886. if(gunIndex == 0)
  7887. {
  7888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7889. {
  7890. for(int i=0; i < gunTotalNumber; i++)
  7891. {
  7892. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7893. {
  7894. 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
  7895. {
  7896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7897. goto end;
  7898. }
  7899. }//END FOR CHAdeMO_QUANTITY
  7900. for (int index = 0; index < CCS_QUANTITY; index++)
  7901. {
  7902. 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
  7903. {
  7904. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7905. goto end;
  7906. }
  7907. }//END FOR CCS_QUANTITY
  7908. for (int index = 0; index < GB_QUANTITY; index++)
  7909. {
  7910. 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
  7911. {
  7912. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7913. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7914. goto end;
  7915. }
  7916. }// END FOR GB_QUANTITY
  7917. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7918. {
  7919. 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
  7920. {
  7921. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7923. goto end;
  7924. }
  7925. }// END FOR GENERAL_GUN_QUANTITY
  7926. for (int index = 0; index < AC_QUANTITY; index++)
  7927. {
  7928. 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
  7929. {
  7930. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7931. goto end;
  7932. }
  7933. }//END FOR CHAdeMO_QUANTITY
  7934. }// END FOR gunTotalNumber
  7935. }
  7936. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7937. {
  7938. for(int i=0; i < gunTotalNumber; i++)
  7939. {
  7940. for (int index = 0; index < AC_QUANTITY; index++)
  7941. {
  7942. 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
  7943. {
  7944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7945. goto end;
  7946. }
  7947. }//END FOR CHAdeMO_QUANTITY
  7948. } // END FOR gunTotalNumber
  7949. }
  7950. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7951. goto end;
  7952. }
  7953. //----------------------gunIndex is not 0 ------------------------------------------------//
  7954. //check Transaction active
  7955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7956. {
  7957. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7958. {
  7959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7960. goto end;
  7961. }
  7962. }//END FOR CHAdeMO_QUANTITY
  7963. for (int index = 0; index < CCS_QUANTITY; index++)
  7964. {
  7965. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7966. {
  7967. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7968. goto end;
  7969. }
  7970. }//END FOR CCS_QUANTITY
  7971. for (int index = 0; index < GB_QUANTITY; index++)
  7972. {
  7973. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7974. {
  7975. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7976. goto end;
  7977. }
  7978. }// END FOR GB_QUANTITY
  7979. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7980. {
  7981. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7982. {
  7983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7984. goto end;
  7985. }
  7986. }// END FOR GENERAL_GUN_QUANTITY
  7987. for (int index = 0; index < AC_QUANTITY; index++)
  7988. {
  7989. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7990. {
  7991. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7992. goto end;
  7993. }
  7994. }//END FOR AC_QUANTITY
  7995. }//END FOR AvailabilityTypeStr[Operative]
  7996. end:
  7997. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7998. {
  7999. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8000. }
  8001. else
  8002. {
  8003. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8004. }
  8005. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8006. {
  8007. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8008. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8009. }
  8010. else if(gunIndex == 0)
  8011. {
  8012. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8013. {
  8014. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8015. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8016. }
  8017. }
  8018. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8019. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8020. return result;
  8021. }
  8022. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8023. {
  8024. mtrace();
  8025. int valueInvalid = NO;
  8026. int result = FAIL;
  8027. char keystr[40]={0};
  8028. char valuestr[501]={0}; //value should be limited in 500 bytes
  8029. char comfirmstr[20]={0};
  8030. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8031. json_object *ChangeConfiguration;
  8032. ChangeConfiguration = json_tokener_parse(payload);
  8033. if(!is_error(ChangeConfiguration))
  8034. {
  8035. // Required data
  8036. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8037. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8038. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8039. {
  8040. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8041. }
  8042. else
  8043. {
  8044. valueInvalid = YES;
  8045. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8046. }
  8047. }
  8048. json_object_put(ChangeConfiguration);
  8049. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8050. {
  8051. DEBUG_ERROR("Payload is null or not accepted.\n");
  8052. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8053. }
  8054. else
  8055. {
  8056. int status = setKeyValue(keystr, valuestr);
  8057. switch(status)
  8058. {
  8059. case ConfigurationStatus_Accepted:
  8060. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8061. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8062. StoreConfigurationTable();
  8063. break;
  8064. case RebootRequired:
  8065. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8066. StoreConfigurationTable();
  8067. break;
  8068. case NotSupported:
  8069. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8070. break;
  8071. case ConfigurationStatus_Rejected:
  8072. default:
  8073. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8074. break;
  8075. }
  8076. }
  8077. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8078. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8079. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8080. {
  8081. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8082. SetOcppConnStatus(FALSE);
  8083. }
  8084. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8085. {
  8086. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8087. }
  8088. return result;
  8089. }
  8090. int handleClearCacheRequest(char *uuid, char *payload)
  8091. {
  8092. mtrace();
  8093. int result = FAIL;
  8094. char comfirmstr[20];
  8095. char rmFileCmd[100]={0};
  8096. struct stat stats;
  8097. DEBUG_INFO("handleClearCacheRequest...\n");
  8098. stat("/Storage/OCPP_PH", &stats);
  8099. // Check for directory existence
  8100. if (S_ISDIR(stats.st_mode) == 1)
  8101. {}
  8102. else
  8103. {
  8104. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8105. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8106. system(rmFileCmd);
  8107. }
  8108. if(OCPP_cleanLocalCache())
  8109. {
  8110. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8111. }
  8112. else
  8113. {
  8114. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8115. }
  8116. sendClearCacheConfirmation(uuid, comfirmstr);
  8117. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8118. return result;
  8119. }
  8120. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8121. {
  8122. mtrace();
  8123. int result = FAIL;
  8124. int resultRename;
  8125. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8126. char chargingProfilePurposeStr[26]={0};
  8127. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8128. char tempchargingProfilePurposeStr[26]={0};
  8129. char str[100]={0};
  8130. char fname[200]={0};
  8131. char comfirmstr[20]={0};
  8132. char word[1600]={0};
  8133. int clearflag = FALSE;
  8134. int chargingProfileIdIsNULL = FALSE;
  8135. int connectorIsNULL = FALSE;
  8136. int chargingProfilePurposeIsNULL = FALSE;
  8137. int stackLevelIsNULL = FALSE;
  8138. //int GotoEnd = FALSE;
  8139. FILE *fptr1, *fptr2;
  8140. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8141. int n_chargingProfile=0;
  8142. int isEmptyFile = FALSE;
  8143. char sLineWord[1600]={0};
  8144. char chargingProfiles[10][100]={0};
  8145. int ChargeProfileCount = 0;
  8146. int ch;
  8147. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8148. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8149. json_object *ClearChargingProfile;
  8150. ClearChargingProfile = json_tokener_parse(payload);
  8151. if(!is_error(ClearChargingProfile))
  8152. {
  8153. // Optional data
  8154. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8155. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8156. else
  8157. chargingProfileIdIsNULL = TRUE;
  8158. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8159. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8160. else
  8161. connectorIsNULL = TRUE;
  8162. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8163. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8164. else
  8165. chargingProfilePurposeIsNULL = TRUE;
  8166. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8167. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8168. else
  8169. stackLevelIsNULL = TRUE;
  8170. }
  8171. json_object_put(ClearChargingProfile);
  8172. if(connectorIsNULL == FALSE)
  8173. {
  8174. switch(connectorIdInt)
  8175. {
  8176. case 0:
  8177. if(chargingProfilePurposeIsNULL == TRUE)
  8178. {
  8179. int l = 0;
  8180. strcpy(fname, ChargePointMaxProfile_JSON);
  8181. if((access(fname,F_OK))!=-1)
  8182. {
  8183. strcpy(chargingProfiles[l], fname);
  8184. l = l + 1;
  8185. }
  8186. strcpy(fname, TxDefaultProfile_0_JSON);
  8187. if((access(fname,F_OK))!=-1)
  8188. {
  8189. strcpy(chargingProfiles[l], fname);
  8190. l = l + 1;
  8191. }
  8192. ChargeProfileCount = l;
  8193. }
  8194. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8195. {
  8196. strcpy(fname, ChargePointMaxProfile_JSON);
  8197. if((access(fname,F_OK))!=-1)
  8198. {
  8199. strcpy(chargingProfiles[0], fname);
  8200. ChargeProfileCount = 1;
  8201. }
  8202. }
  8203. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8204. {
  8205. strcpy(fname, TxDefaultProfile_0_JSON);
  8206. if((access(fname,F_OK))!=-1)
  8207. {
  8208. strcpy(chargingProfiles[0], fname);
  8209. ChargeProfileCount = 1;
  8210. }
  8211. }
  8212. break;
  8213. default:
  8214. if(chargingProfilePurposeIsNULL == TRUE)
  8215. {
  8216. int m = 0;
  8217. memset(fname, 0, ARRAY_SIZE(fname));
  8218. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8219. if((access(fname,F_OK))!=-1)
  8220. {
  8221. strcpy(chargingProfiles[m], fname);
  8222. m = m + 1;
  8223. }
  8224. memset(fname, 0, ARRAY_SIZE(fname));
  8225. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8226. if((access(fname,F_OK))!=-1)
  8227. {
  8228. strcpy(chargingProfiles[m], fname);
  8229. m = m + 1;
  8230. }
  8231. ChargeProfileCount = m;
  8232. }
  8233. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8234. {
  8235. //strcpy(fname, TxDefaultProfile_1_JSON);
  8236. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8237. if((access(fname,F_OK))!=-1)
  8238. {
  8239. strcpy(chargingProfiles[0], fname);
  8240. ChargeProfileCount = 1;
  8241. }
  8242. }
  8243. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8244. {
  8245. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8246. if((access(fname,F_OK))!=-1)
  8247. {
  8248. strcpy(chargingProfiles[0], fname);
  8249. ChargeProfileCount = 1;
  8250. }
  8251. //strcpy(fname, TxProfile_1_JSON);
  8252. }
  8253. //strcpy(fname, ChargePointMaxProfile_JSON );
  8254. break;
  8255. }
  8256. }
  8257. else // Check all Charging Profiles
  8258. {
  8259. int i = 0;
  8260. char fnametemp[200]={0};
  8261. ChargeProfileCount = 0;
  8262. //Check ChargePointMaxProfile.json exit
  8263. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8264. {
  8265. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8266. i = i + 1;
  8267. }
  8268. //Check TxDefaultProfile_0.json exit
  8269. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8270. {
  8271. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8272. i = i + 1;
  8273. }
  8274. //Check TxDefaultProfile_%d.json
  8275. for(int j=1; j <= gunTotalNumber; j++)
  8276. {
  8277. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8278. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8279. if((access(fnametemp,F_OK))!=-1)
  8280. {
  8281. strcpy(chargingProfiles[i], fnametemp);
  8282. i = i + 1;
  8283. }
  8284. }
  8285. //Check TxProfile_%d.json
  8286. for(int j=1; j <= gunTotalNumber; j++)
  8287. {
  8288. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8289. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8290. if((access(fnametemp,F_OK))!=-1)
  8291. {
  8292. strcpy(chargingProfiles[i], fnametemp);
  8293. i = i + 1;
  8294. }
  8295. }
  8296. ChargeProfileCount = i;
  8297. }// End connectorIsNULL is TRUE
  8298. if(ChargeProfileCount == 0)
  8299. {
  8300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8301. goto end;
  8302. }
  8303. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8304. {
  8305. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8306. goto end;
  8307. }
  8308. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8309. {
  8310. memset(str, 0, ARRAY_SIZE(str));
  8311. // clear temp file
  8312. sprintf(str,"rm -f %s",temp);
  8313. system(str);
  8314. for(int k=0; k < ChargeProfileCount; k++)
  8315. {
  8316. memset(str, 0, ARRAY_SIZE(str));
  8317. //clear file in C
  8318. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8319. system(str);
  8320. }
  8321. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8322. goto end;
  8323. }
  8324. else if(connectorIsNULL == TRUE)
  8325. {
  8326. for(int k=0; k < ChargeProfileCount; k++)
  8327. {
  8328. fptr1 = fopen(chargingProfiles[k], "r");
  8329. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8330. //Check Charging Profile Count
  8331. while(fscanf(fptr1, "%s", word) != EOF)
  8332. {
  8333. //DEBUG_INFO("word=%s\n",word);
  8334. if(strstr(word, "chargingProfileId")!= NULL)
  8335. {
  8336. //DEBUG_INFO("test chargingProfileId \n");
  8337. n_chargingProfile = n_chargingProfile + 1;
  8338. //DEBUG_INFO("chargingProfileId Found\n");
  8339. }
  8340. }
  8341. rewind(fptr1);
  8342. //search Charging Profile Element
  8343. //int i= 0;
  8344. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8345. {
  8346. json_object *tmpProfilee;
  8347. tmpProfilee = json_tokener_parse(sLineWord);
  8348. if(!is_error(tmpProfilee))
  8349. {
  8350. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8351. {
  8352. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8353. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8354. }
  8355. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8356. {
  8357. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8358. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8359. }
  8360. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8361. {
  8362. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8363. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8364. }
  8365. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8366. {
  8367. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8368. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8369. }
  8370. }
  8371. json_object_put(tmpProfilee);
  8372. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8373. {
  8374. //------- not write to fptr2-------//
  8375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8376. //clearflag = TRUE;
  8377. }
  8378. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8379. {
  8380. //------- not write to fptr2-------//
  8381. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8382. }
  8383. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8384. {
  8385. //------- not write to fptr2-------//
  8386. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8387. }
  8388. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8389. {
  8390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8391. }
  8392. else
  8393. {
  8394. fprintf(fptr2, sLineWord);//writing data into file
  8395. }
  8396. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8397. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8398. if(clearflag == TRUE)
  8399. {
  8400. fclose(fptr1);
  8401. fclose(fptr2);
  8402. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8403. system(str);
  8404. // clear temp file
  8405. sprintf(str,"rm -f %s",temp);
  8406. system(str);
  8407. }
  8408. else
  8409. {
  8410. fclose(fptr1);
  8411. fclose(fptr2);
  8412. memset(str, 0, ARRAY_SIZE(str));
  8413. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8414. system(str);
  8415. resultRename = rename(temp, chargingProfiles[k]);
  8416. if(resultRename == 0)
  8417. {
  8418. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8419. }
  8420. else
  8421. {
  8422. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8423. }
  8424. if(comfirmstr[0]== 0)
  8425. {
  8426. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8427. }
  8428. //Check chargingProfile is empty file
  8429. /*------ Read the file ----------------*/
  8430. fptr1=fopen(chargingProfiles[k],"r");
  8431. ch=fgetc(fptr1);
  8432. rewind(fptr1);
  8433. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8434. if(ch!=EOF)
  8435. {
  8436. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8437. {
  8438. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8439. if(sLineWord[0]=='\0')
  8440. {
  8441. isEmptyFile = TRUE;
  8442. break;
  8443. }
  8444. else
  8445. {
  8446. isEmptyFile = FALSE;
  8447. break;
  8448. }
  8449. }
  8450. }
  8451. else
  8452. isEmptyFile = TRUE;
  8453. fclose(fptr1);
  8454. if(isEmptyFile == TRUE)
  8455. {
  8456. memset(str, 0, ARRAY_SIZE(str));
  8457. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8458. system(str);
  8459. }
  8460. }
  8461. }// End of while(int k=0; k < ChargePointCount; k++)
  8462. }
  8463. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8464. {
  8465. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8466. for(int k=0; k < ChargeProfileCount; k++)
  8467. {
  8468. fptr1 = fopen(chargingProfiles[k], "r");
  8469. fptr2 = fopen(temp, "w+");
  8470. //Check Charging Profile Count
  8471. while(fscanf(fptr1, "%s", word) != EOF)
  8472. {
  8473. //DEBUG_INFO("word=%s\n",word);
  8474. if(strstr(word, "chargingProfileId")!= NULL)
  8475. {
  8476. n_chargingProfile = n_chargingProfile + 1;
  8477. }
  8478. }
  8479. rewind(fptr1);
  8480. //search Charging Profile Element
  8481. //int i= 0;
  8482. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8483. {
  8484. json_object *tmpProfilee;
  8485. tmpProfilee = json_tokener_parse(sLineWord);
  8486. if(!is_error(tmpProfilee))
  8487. {
  8488. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8489. {
  8490. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8491. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8492. }
  8493. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8494. {
  8495. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8496. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8497. }
  8498. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8499. {
  8500. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8501. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8502. }
  8503. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8504. {
  8505. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8506. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8507. }
  8508. }
  8509. json_object_put(tmpProfilee);
  8510. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8511. {
  8512. //------- not write to fptr2-------//
  8513. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8514. //clearflag = TRUE;
  8515. }
  8516. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8517. {
  8518. //------- not write to fptr2-------//
  8519. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8520. }
  8521. else if(stackLevelIsNULL == TRUE)
  8522. {
  8523. //Clear Whole File
  8524. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8525. clearflag = TRUE;
  8526. break;
  8527. }
  8528. else
  8529. {
  8530. fprintf(fptr2, sLineWord);//writing data into file
  8531. }
  8532. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8533. }
  8534. if(clearflag == TRUE)
  8535. {
  8536. fclose(fptr1);
  8537. fclose(fptr2);
  8538. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8539. system(str);
  8540. // clear temp file
  8541. sprintf(str,"rm -f %s",temp);
  8542. system(str);
  8543. }
  8544. else
  8545. {
  8546. fclose(fptr1);
  8547. fclose(fptr2);
  8548. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8549. system(str);
  8550. resultRename = rename(temp, chargingProfiles[k]);
  8551. if(resultRename == 0)
  8552. {
  8553. DEBUG_INFO("File ChargingProfile renamed successfully");
  8554. }
  8555. else
  8556. {
  8557. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8558. }
  8559. if(comfirmstr[0]== 0)
  8560. {
  8561. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8562. }
  8563. //Check chargingProfile is empty file
  8564. /*------ Read the file ----------------*/
  8565. fptr1=fopen(chargingProfiles[k],"r");
  8566. ch=fgetc(fptr1);
  8567. rewind(fptr1);
  8568. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8569. if(ch!=EOF)
  8570. {
  8571. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8572. {
  8573. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8574. if(sLineWord[0]=='\0')
  8575. {
  8576. isEmptyFile = TRUE;
  8577. break;
  8578. }
  8579. else
  8580. {
  8581. isEmptyFile = FALSE;
  8582. break;
  8583. }
  8584. }
  8585. }
  8586. else
  8587. isEmptyFile = TRUE;
  8588. fclose(fptr1);
  8589. if(isEmptyFile == TRUE)
  8590. {
  8591. memset(str, 0, ARRAY_SIZE(str));
  8592. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8593. system(str);
  8594. }
  8595. /*------- End of reading ---------------*/
  8596. }
  8597. } // while(int k=0; k < ChargeProfileCount; k++)
  8598. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8599. end:
  8600. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8601. {
  8602. if(connectorIdInt == 0)
  8603. {
  8604. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8605. {
  8606. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8607. }
  8608. }
  8609. else
  8610. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8611. }
  8612. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8613. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8614. return result;
  8615. }
  8616. void createFirmwareVersionByDataTransfer(void)
  8617. {
  8618. json_object *FirmwareDataTransfer = json_object_new_object();
  8619. // AC & DC model
  8620. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8621. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8622. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8623. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8624. // DC model
  8625. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8626. {
  8627. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8628. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8629. (gunType[3] != GUN_TYPE_UNKNOWN))
  8630. {
  8631. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8632. }
  8633. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8634. {
  8635. // DS DM DW
  8636. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8637. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8638. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8639. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8640. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8641. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8642. }
  8643. else
  8644. {
  8645. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8646. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8647. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8648. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8649. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8650. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8651. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8652. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8653. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8654. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8655. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8656. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8657. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8658. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8659. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8660. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8661. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8663. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8665. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8667. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8669. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8670. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8671. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8672. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8673. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8674. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8675. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8676. }
  8677. }
  8678. // 4G model
  8679. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8680. {
  8681. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8682. }
  8683. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8684. json_object_put(FirmwareDataTransfer);
  8685. }
  8686. int handleDataTransferRequest(char *uuid, char *payload)
  8687. {
  8688. mtrace();
  8689. json_object *response = json_object_new_object();
  8690. int result = FAIL;
  8691. char tempvendorId[255]={0};
  8692. char tempmessageId[50]={0};
  8693. char tempdata[512]={0};
  8694. char message[2048]={0};
  8695. DEBUG_INFO("handleDataTransferRequest...\n");
  8696. if((uuid != NULL) && (payload != NULL))
  8697. {
  8698. json_object *DataTransfer;
  8699. DataTransfer = json_tokener_parse(payload);
  8700. if(!is_error(DataTransfer))
  8701. {
  8702. // Required data
  8703. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8704. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8705. // Optional data
  8706. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8707. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8708. if(json_object_object_get(DataTransfer, "data") != NULL)
  8709. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8710. result = PASS;
  8711. }
  8712. json_object_put(DataTransfer);
  8713. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8714. {
  8715. // Send all moudle firmware version on EVSE
  8716. createFirmwareVersionByDataTransfer();
  8717. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8718. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8719. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8720. json_object_put(response);
  8721. }
  8722. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8723. {
  8724. system("/usr/bin/run_tmate_restart.sh &");
  8725. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8726. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8727. json_object_put(response);
  8728. }
  8729. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8730. {
  8731. json_object *data;
  8732. data = json_tokener_parse(tempdata);
  8733. if(!is_error(data))
  8734. {
  8735. 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))
  8736. {
  8737. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8738. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8739. if(json_object_object_get(data, "SOC") != NULL)
  8740. {
  8741. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8742. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8743. }
  8744. if(json_object_object_get(data, "Energy") != NULL)
  8745. {
  8746. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8747. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8748. }
  8749. if(json_object_object_get(data, "Duration") != NULL)
  8750. {
  8751. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8752. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8753. }
  8754. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8755. }
  8756. else
  8757. {
  8758. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8759. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8760. }
  8761. }
  8762. else
  8763. {
  8764. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8765. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8766. }
  8767. json_object_put(data);
  8768. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8769. json_object_put(response);
  8770. }
  8771. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8772. {
  8773. json_object *data;
  8774. data = json_tokener_parse(tempdata);
  8775. if(!is_error(data))
  8776. {
  8777. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8778. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8779. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8780. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8781. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8782. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8783. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8784. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8785. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8786. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8787. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8788. }
  8789. else
  8790. {
  8791. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8792. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8793. }
  8794. json_object_put(data);
  8795. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8796. json_object_put(response);
  8797. }
  8798. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8799. {
  8800. json_object *data;
  8801. data = json_tokener_parse(tempdata);
  8802. if(!is_error(data))
  8803. {
  8804. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8805. if(json_object_object_get(data, "idToken") != NULL)
  8806. {
  8807. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8808. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8809. }
  8810. if(json_object_object_get(data, "price") != NULL)
  8811. {
  8812. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8813. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8814. }
  8815. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8816. }
  8817. else
  8818. {
  8819. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8820. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8821. }
  8822. json_object_put(data);
  8823. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8824. json_object_put(response);
  8825. }
  8826. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8827. {
  8828. json_object *data;
  8829. data = json_tokener_parse(tempdata);
  8830. if(!is_error(data))
  8831. {
  8832. if(json_object_object_get(data, "txId") != NULL)
  8833. {
  8834. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8835. for(int idx = 0;idx<gunTotalNumber;idx++)
  8836. {
  8837. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8838. {
  8839. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8840. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8841. if(json_object_object_get(data, "description") != NULL)
  8842. {
  8843. // California pricing V1.0
  8844. DEBUG_INFO("California pricing V1.0\n");
  8845. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8846. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8847. }
  8848. else
  8849. {
  8850. // California pricing V1.1
  8851. DEBUG_INFO("California pricing V1.1\n");
  8852. if(json_object_object_get(data, "timestamp") != NULL)
  8853. {
  8854. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8855. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8856. }
  8857. if(json_object_object_get(data, "meterValue") != NULL)
  8858. {
  8859. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8860. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8861. }
  8862. if(json_object_object_get(data, "cost") != NULL)
  8863. {
  8864. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8865. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8866. }
  8867. if(json_object_object_get(data, "state") != NULL)
  8868. {
  8869. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8870. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8871. }
  8872. if(json_object_object_get(data, "chargingPrice") != NULL)
  8873. {
  8874. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8875. {
  8876. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8877. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8878. }
  8879. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8880. {
  8881. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8882. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8883. }
  8884. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8885. {
  8886. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8887. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8888. }
  8889. }
  8890. if(json_object_object_get(data, "idlePrice") != NULL)
  8891. {
  8892. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8893. {
  8894. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8895. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8896. }
  8897. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8898. {
  8899. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8900. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8901. }
  8902. }
  8903. if(json_object_object_get(data, "nextPeriod") != NULL)
  8904. {
  8905. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8906. {
  8907. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8908. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8909. }
  8910. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8911. {
  8912. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8913. {
  8914. 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")));
  8915. 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"));
  8916. }
  8917. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8918. {
  8919. 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")));
  8920. 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"));
  8921. }
  8922. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8923. {
  8924. 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")));
  8925. 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"));
  8926. }
  8927. }
  8928. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8929. {
  8930. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8931. {
  8932. 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")));
  8933. 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"));
  8934. }
  8935. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8936. {
  8937. 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")));
  8938. 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"));
  8939. }
  8940. }
  8941. }
  8942. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8943. {
  8944. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8945. {
  8946. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8947. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8948. }
  8949. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8950. {
  8951. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8952. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8953. }
  8954. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8955. {
  8956. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8957. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8958. }
  8959. }
  8960. }
  8961. }
  8962. }
  8963. }
  8964. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  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, "FinalCost") != NULL)
  8976. {
  8977. json_object *data;
  8978. data = json_tokener_parse(tempdata);
  8979. if(!is_error(data))
  8980. {
  8981. if(json_object_object_get(data, "txId") != NULL)
  8982. {
  8983. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8984. for(int idx = 0;idx<gunTotalNumber;idx++)
  8985. {
  8986. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8987. {
  8988. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8989. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8990. if(json_object_object_get(data, "description") != NULL)
  8991. {
  8992. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8993. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8994. }
  8995. }
  8996. }
  8997. }
  8998. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8999. }
  9000. else
  9001. {
  9002. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9003. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9004. }
  9005. json_object_put(data);
  9006. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9007. json_object_put(response);
  9008. }
  9009. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9010. {
  9011. json_object *data;
  9012. data = json_tokener_parse(tempdata);
  9013. if(!is_error(data))
  9014. {
  9015. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9016. if(json_object_object_get(data, "Content_Type") != NULL)
  9017. {
  9018. 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))
  9019. {
  9020. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9021. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9022. {
  9023. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9024. }
  9025. }
  9026. else
  9027. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9028. }
  9029. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9030. }
  9031. else
  9032. {
  9033. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9034. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9035. }
  9036. json_object_put(data);
  9037. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9038. json_object_put(response);
  9039. }
  9040. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9041. {
  9042. json_object *data;
  9043. data = json_tokener_parse(tempdata);
  9044. if(!is_error(data))
  9045. {
  9046. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9047. if(json_object_object_get(data, "ConnectorId") != NULL)
  9048. {
  9049. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9050. }
  9051. if(json_object_object_get(data, "Page_Index") != NULL)
  9052. {
  9053. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9054. }
  9055. if(json_object_object_get(data, "Duration") != NULL)
  9056. {
  9057. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9058. }
  9059. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9060. }
  9061. else
  9062. {
  9063. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9064. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9065. }
  9066. json_object_put(data);
  9067. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9068. json_object_put(response);
  9069. }
  9070. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9071. {
  9072. json_object *data;
  9073. data = json_tokener_parse(tempdata);
  9074. if(!is_error(data))
  9075. {
  9076. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9077. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9078. {
  9079. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9080. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9081. else
  9082. {
  9083. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9084. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9085. }
  9086. }
  9087. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9088. {
  9089. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9090. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9091. else
  9092. {
  9093. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9094. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9095. }
  9096. }
  9097. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9098. {
  9099. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9100. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9101. else
  9102. {
  9103. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9104. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9105. }
  9106. }
  9107. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9108. {
  9109. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9110. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9111. else
  9112. {
  9113. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9114. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9115. }
  9116. }
  9117. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9118. {
  9119. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9120. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9121. else
  9122. {
  9123. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9124. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9125. }
  9126. }
  9127. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9128. {
  9129. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9130. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9131. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9132. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9133. else
  9134. {
  9135. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9136. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9137. }
  9138. }
  9139. if(json_object_object_get(data, "isAuthentication") != NULL)
  9140. {
  9141. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9142. {
  9143. case 0:
  9144. case 1:
  9145. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9146. break;
  9147. default:
  9148. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9149. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9150. break;
  9151. }
  9152. }
  9153. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9154. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9155. }
  9156. else
  9157. {
  9158. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9159. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9160. }
  9161. json_object_put(data);
  9162. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9163. json_object_put(response);
  9164. }
  9165. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9166. {
  9167. json_object *data;
  9168. data = json_tokener_parse(tempdata);
  9169. if(!is_error(data))
  9170. {
  9171. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9172. if(json_object_object_get(data, "stationName") != NULL)
  9173. {
  9174. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9175. }
  9176. else
  9177. {
  9178. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9179. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9180. }
  9181. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9182. {
  9183. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9184. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9185. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9186. }
  9187. }
  9188. else
  9189. {
  9190. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9191. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9192. }
  9193. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9194. json_object_put(response);
  9195. }
  9196. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9197. {
  9198. json_object *data;
  9199. data = json_tokener_parse(tempdata);
  9200. if(!is_error(data))
  9201. {
  9202. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9203. if(json_object_object_get(data, "weatherId") != NULL)
  9204. {
  9205. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9206. }
  9207. else
  9208. {
  9209. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9210. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9211. }
  9212. if(json_object_object_get(data, "Temperature") != NULL)
  9213. {
  9214. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9215. }
  9216. else
  9217. {
  9218. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9219. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9220. }
  9221. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9222. {
  9223. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9224. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9225. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9226. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9227. }
  9228. }
  9229. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9230. {
  9231. json_object *data;
  9232. data = json_tokener_parse(tempdata);
  9233. if(!is_error(data))
  9234. {
  9235. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9236. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9237. {
  9238. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9239. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9240. }
  9241. else
  9242. {
  9243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9244. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9245. }
  9246. }
  9247. else
  9248. {
  9249. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9250. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9251. }
  9252. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9253. json_object_put(response);
  9254. }
  9255. else
  9256. {
  9257. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9258. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9259. }
  9260. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9261. json_object_put(response);
  9262. }
  9263. else
  9264. {
  9265. // Can not find valid message id
  9266. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9267. }
  9268. }
  9269. else
  9270. {
  9271. // Payload is null
  9272. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9273. }
  9274. LWS_Send(message);
  9275. return result;
  9276. }
  9277. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9278. {
  9279. mtrace();
  9280. int result = FAIL;
  9281. int connectorIdInt, durationInt;
  9282. char chargingRateUnitStr[4]={0};
  9283. char comfirmstr[20];
  9284. int confirmPeriods = 0;
  9285. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9286. json_object *GetCompositeSchedule;
  9287. GetCompositeSchedule = json_tokener_parse(payload);
  9288. if(!is_error(GetCompositeSchedule))
  9289. {
  9290. // Required data
  9291. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9292. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9293. else
  9294. connectorIdInt = -1;
  9295. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9296. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9297. else
  9298. durationInt = 86400;
  9299. // Optional data
  9300. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9301. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9302. }
  9303. json_object_put(GetCompositeSchedule);
  9304. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9305. if((connectorIdInt == 0) ||
  9306. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9307. {
  9308. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9309. struct StructChargingProfile tmpProfile[1];
  9310. if(strstr(chargingRateUnitStr, "W") != NULL)
  9311. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9312. else
  9313. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9314. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9315. {
  9316. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9317. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9318. }
  9319. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9320. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9321. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9322. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9323. {
  9324. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9325. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9326. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9327. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9328. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9329. {
  9330. confirmPeriods = idx;
  9331. break;
  9332. }
  9333. }
  9334. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9335. {
  9336. confirmPeriods += 1;
  9337. }
  9338. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9339. }
  9340. else
  9341. {
  9342. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9343. }
  9344. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9345. return result;
  9346. }
  9347. int handleGetConfigurationRequest(char *uuid, char *payload)
  9348. {
  9349. mtrace();
  9350. int result = FAIL;
  9351. int MaxKeySupported = 0;
  9352. int n_keys = 0;
  9353. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9354. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9355. json_object *GetConfiguration;
  9356. GetConfiguration = json_tokener_parse(payload);
  9357. if(!is_error(GetConfiguration))
  9358. {
  9359. // Optional data
  9360. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9361. {
  9362. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9363. {
  9364. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9365. n_keys = idx + 1;
  9366. }
  9367. }
  9368. }
  9369. json_object_put(GetConfiguration);
  9370. UnknownKeynum = 0;
  9371. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9372. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9373. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9374. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9375. if(n_keys != 0)
  9376. {
  9377. for(int i=0;i<n_keys;i++)
  9378. {
  9379. getKeyValue(requestKey[i]);
  9380. }
  9381. }
  9382. else
  9383. {
  9384. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9385. getKeyValue("");
  9386. }
  9387. processUnkownKey();
  9388. sendGetConfigurationConfirmation(uuid);
  9389. return result;
  9390. }
  9391. static char fnamePlusPath[100]={0};
  9392. static char fnamePWithNoPath[60]={0};
  9393. void checkUploadLog(void)
  9394. {
  9395. FILE *fp;
  9396. /* Open the command for reading. */
  9397. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9398. if (fp == NULL) {
  9399. DEBUG_WARN("Failed to run command\n" );
  9400. exit(1);
  9401. }
  9402. int ftppathlen = 0;
  9403. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9404. int i = 0;
  9405. /* Read the output a line at a time - output it. */
  9406. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9407. if(i==0)
  9408. {
  9409. ftppathlen = strlen(fnamePlusPath);
  9410. DEBUG_INFO("%s\n", fnamePlusPath);
  9411. fnamePlusPath[ftppathlen]='\0';
  9412. break;
  9413. }
  9414. i= i+1;
  9415. }
  9416. /* close */
  9417. pclose(fp);
  9418. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9419. {
  9420. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9421. {
  9422. fnamePlusPath[k]='\0';
  9423. }
  9424. }
  9425. i=1;
  9426. //char fname[60]={0};
  9427. while(i < ftppathlen)
  9428. {
  9429. int len=ftppathlen-i;
  9430. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9431. {
  9432. DEBUG_INFO("compare '/' all right\n");
  9433. break;
  9434. }
  9435. i=i+1;
  9436. }
  9437. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9438. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9439. fnamePWithNoPath[i+1] = '\0';
  9440. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9441. {
  9442. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9443. {
  9444. fnamePWithNoPath[j]='\0';
  9445. }
  9446. }
  9447. FILE* fp1 = fopen(fnamePlusPath, "r");
  9448. if (fp1)
  9449. {
  9450. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9451. // file exists
  9452. fclose(fp1);
  9453. }
  9454. else
  9455. {
  9456. // file doesn't exist
  9457. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9458. }
  9459. }
  9460. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9461. {
  9462. mtrace();
  9463. int result = FAIL;
  9464. time_t CurrentTime;
  9465. struct tm *tm;
  9466. pthread_t th_Status;
  9467. CurrentTime = time(NULL);
  9468. tm = localtime(&CurrentTime);
  9469. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9470. 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);
  9471. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9472. if(!interLock.isGetDiagnosticGoing)
  9473. {
  9474. interLock.isGetDiagnosticGoing = 1;
  9475. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9476. sleep(1);
  9477. }
  9478. else
  9479. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9480. return result;
  9481. }
  9482. void* GetDiagnosticsProcess(void* data)
  9483. {
  9484. pthread_detach(pthread_self());
  9485. mtrace();
  9486. int retriesInt=0, retryIntervalInt=0;
  9487. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9488. 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};
  9489. int port=0;
  9490. int isSuccess = FALSE;
  9491. char ftpbuf[200]={0};
  9492. char cmdBuf[2048];
  9493. struct tm *tmNow;
  9494. time_t CurrentTime;
  9495. struct tm tmStart;
  9496. struct tm tmStop;
  9497. CurrentTime = time(NULL);
  9498. tmNow=localtime(&CurrentTime);
  9499. uint16_t targetYear, targetMonth;
  9500. json_object *GetDiagnostics;
  9501. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9502. GetDiagnostics = json_tokener_parse(data);
  9503. if(!is_error(GetDiagnostics))
  9504. {
  9505. // Required data
  9506. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9507. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9508. // Optional data
  9509. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9510. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9511. else
  9512. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9513. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9514. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9515. else
  9516. retryIntervalInt = 30;
  9517. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9518. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9519. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9520. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9521. }
  9522. json_object_put(GetDiagnostics);
  9523. // Pack log to compress file
  9524. 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) &&
  9525. (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))
  9526. {
  9527. // Pack system log
  9528. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9529. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9530. targetYear = tmStart.tm_year;
  9531. targetMonth = tmStart.tm_mon;
  9532. do
  9533. {
  9534. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9535. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9536. if(targetMonth+1>=13)
  9537. {
  9538. targetYear += 1;
  9539. targetMonth = 1;
  9540. }
  9541. else
  9542. {
  9543. targetMonth += 1;
  9544. }
  9545. }while((targetYear < (tmNow->tm_year+1900)) ||
  9546. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9547. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9548. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9549. system(cmdBuf);
  9550. // Pack charging & event log
  9551. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9552. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9553. targetYear = tmStart.tm_year;
  9554. targetMonth = tmStart.tm_mon;
  9555. do
  9556. {
  9557. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9558. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9559. if(targetMonth+1>=13)
  9560. {
  9561. targetYear += 1;
  9562. targetMonth = 1;
  9563. }
  9564. else
  9565. {
  9566. targetMonth += 1;
  9567. }
  9568. }while((targetYear < (tmNow->tm_year+1900)) ||
  9569. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9570. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9571. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9572. system(cmdBuf);
  9573. // Combine log file
  9574. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9575. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9576. }
  9577. else
  9578. {
  9579. system("exec /root/logPackTools 'log' 6");
  9580. }
  9581. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9582. system(cmdBuf);
  9583. checkUploadLog();
  9584. //****************location*******************/
  9585. if(strcmp(locationstr,"")==0)
  9586. {
  9587. DEBUG_INFO("location is <Empty>!\n");
  9588. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9589. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9590. goto end;
  9591. }
  9592. memset(protocol, 0, ARRAY_SIZE(protocol));
  9593. memset(user, 0, ARRAY_SIZE(user) );
  9594. memset(password, 0, ARRAY_SIZE(password));
  9595. memset(host, 0, ARRAY_SIZE(host));
  9596. memset(path, 0, ARRAY_SIZE(path));
  9597. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9598. memset(host1, 0, ARRAY_SIZE(host1));
  9599. memset(path1, 0, ARRAY_SIZE(path1));
  9600. /*location: ftp://user:password@host:port/path*/
  9601. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9602. if((access(fnamePlusPath,F_OK))!=-1)
  9603. {
  9604. DEBUG_INFO("fnamePlusPath exist.\n");
  9605. }
  9606. else
  9607. {
  9608. DEBUG_INFO("fnamePlusPath not exist!\n");
  9609. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9610. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9611. goto end;
  9612. }
  9613. if(strchr(locationstr,'@')==NULL)
  9614. {
  9615. sscanf(locationstr,
  9616. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9617. protocol, host, &port, path);
  9618. strcpy(user,"anonymous");
  9619. strcpy(password,"");
  9620. }
  9621. else
  9622. {
  9623. //DEBUG_INFO("pch=%s\n", pch);
  9624. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9625. protocol, user, password, host, &port, path);
  9626. }
  9627. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9628. {
  9629. DEBUG_INFO("protocol is not ftp/http ! \n");
  9630. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9631. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9632. goto end;
  9633. }
  9634. if(strncmp(locationstr,"http", 4) == 0)
  9635. {
  9636. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9637. sprintf(ftppath,"/%s", path);
  9638. do
  9639. {
  9640. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9641. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9642. sleep(3);
  9643. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9644. if(!isSuccess)
  9645. {
  9646. DEBUG_INFO("Diagnostics fail.\n");
  9647. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9648. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9649. sleep(retryIntervalInt);
  9650. }
  9651. else
  9652. {
  9653. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9654. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9655. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9656. }
  9657. retriesInt--;
  9658. }while((isSuccess == 0)&&(retriesInt >= 0));
  9659. }
  9660. else
  9661. {
  9662. sscanf(host,"%[^/]%s",host1, path1);
  9663. if(strlen(path) > 0)
  9664. sprintf(ftppath,"/%s", path);
  9665. else
  9666. sprintf(ftppath,"/%s", path1);
  9667. int ftppathlen=strlen(ftppath);
  9668. int i=1;
  9669. char filenametemp[50];
  9670. while(i < ftppathlen)
  9671. {
  9672. int len=ftppathlen-i;
  9673. if(ftppath[len]== 47) // '/' ascll code: 47
  9674. {
  9675. DEBUG_INFO("find '/' all right\n");
  9676. break;
  9677. }
  9678. i=i+1;
  9679. }
  9680. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9681. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9682. filenametemp[i+1] = 0;
  9683. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9684. if(port == 0)
  9685. port = 21;
  9686. do
  9687. {
  9688. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9689. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9690. sleep(3);
  9691. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9692. if(!isSuccess)
  9693. {
  9694. DEBUG_INFO("Diagnostics fail.\n");
  9695. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9696. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9697. sleep(retryIntervalInt);
  9698. }
  9699. else
  9700. {
  9701. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9702. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9703. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9704. }
  9705. retriesInt--;
  9706. }while((!isSuccess)&&(retriesInt >= 0));
  9707. }
  9708. end:
  9709. system("rm -f /mnt/*");
  9710. sleep(5);
  9711. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9712. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9713. interLock.isGetDiagnosticGoing = 0;
  9714. pthread_exit(NULL);
  9715. }
  9716. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9717. {
  9718. mtrace();
  9719. int result = FAIL;
  9720. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9721. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9722. {
  9723. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9724. locallistVersion = -1;
  9725. }
  9726. else
  9727. {
  9728. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9729. OCPP_getListVerion();
  9730. }
  9731. //from db.OCPP_getListVerion
  9732. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9733. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9734. sendGetLocalListVersionConfirmation(uuid,"");
  9735. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9736. return result;
  9737. }
  9738. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9739. {
  9740. mtrace();
  9741. int result = FAIL;
  9742. int connectorIdInt=-1;
  9743. int tempIndex = 0;
  9744. int connectorIdIsNULL, chargingProfileIsNULL;
  9745. char comfirmstr[20]={0};
  9746. char cmdBuf[512];
  9747. json_object *RemoteStartTransaction;
  9748. FILE *fp;
  9749. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9750. if(server_pending == TRUE)
  9751. {
  9752. return 0;
  9753. }
  9754. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9755. RemoteStartTransaction = json_tokener_parse(payload);
  9756. if(!is_error(RemoteStartTransaction))
  9757. {
  9758. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9759. {
  9760. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9761. }
  9762. else
  9763. {
  9764. connectorIdIsNULL = TRUE;
  9765. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9766. {
  9767. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9768. {
  9769. connectorIdIsNULL = FALSE;
  9770. connectorIdInt = (gun_index+1);
  9771. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9772. break;
  9773. }
  9774. }
  9775. }
  9776. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9777. {
  9778. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9779. // Required data
  9780. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9781. // Optional data
  9782. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9783. {
  9784. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9785. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9786. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9787. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9788. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9789. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9790. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9791. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9792. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9793. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9794. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9795. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9796. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9797. {
  9798. 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")));
  9799. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9800. 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"));
  9801. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9802. 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"));
  9803. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9804. 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")));
  9805. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9806. {
  9807. 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++)
  9808. {
  9809. 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"));
  9810. 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"));
  9811. 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)
  9812. 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"));
  9813. }
  9814. }
  9815. }
  9816. }
  9817. else
  9818. {
  9819. chargingProfileIsNULL = TRUE;
  9820. }
  9821. }
  9822. }
  9823. else
  9824. {
  9825. connectorIdIsNULL = TRUE;
  9826. }
  9827. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9828. {
  9829. DEBUG_WARN("Connector id is NULL\n.");
  9830. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9831. goto end;
  9832. }
  9833. /*
  9834. enum _SYSTEM_STATUS
  9835. {
  9836. S_BOOTING = 0,
  9837. S_IDLE, = 1
  9838. S_AUTHORIZING, = 2
  9839. S_REASSIGN_CHECK, = 3
  9840. S_REASSIGN, = 4
  9841. S_PRECHARGE, = 5
  9842. S_PREPARING_FOR_EV, = 6
  9843. S_PREPARING_FOR_EVSE, = 7
  9844. S_CHARGING, = 8
  9845. S_TERMINATING, = 9
  9846. S_COMPLETE, = 10
  9847. S_ALARM, = 11
  9848. S_FAULT = 12
  9849. }
  9850. */
  9851. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9852. {
  9853. //check Transaction active
  9854. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9855. {
  9856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9857. {
  9858. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9859. }
  9860. else
  9861. {
  9862. tempIndex = connectorIdInt -1;
  9863. }
  9864. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9865. {
  9866. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9867. {
  9868. 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))
  9869. {
  9870. //Reserved
  9871. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9872. }
  9873. 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))
  9874. {
  9875. //Reserved
  9876. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9877. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9878. goto end;
  9879. }
  9880. else
  9881. {
  9882. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9883. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9884. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9885. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9886. {
  9887. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9888. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9889. goto end;
  9890. }
  9891. }//END FOR ELSE
  9892. }
  9893. }// END FOR CHAdeMO_QUANTITY
  9894. }
  9895. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9896. {
  9897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9898. {
  9899. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9900. }
  9901. else
  9902. {
  9903. tempIndex = connectorIdInt -1;
  9904. }
  9905. for (int index = 0; index < CCS_QUANTITY; index++)
  9906. {
  9907. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9908. {
  9909. 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))
  9910. {
  9911. //Reserved
  9912. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9913. }
  9914. 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))
  9915. {
  9916. //Reserved
  9917. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9919. goto end;
  9920. }
  9921. else
  9922. {
  9923. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9924. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9925. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9926. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9927. {
  9928. DEBUG_WARN("CCS connector not allow start\n.");
  9929. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9930. goto end;
  9931. }
  9932. }// END FOR ELSE
  9933. }
  9934. }// END FOR CCS_QUANTITY
  9935. }
  9936. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9937. {
  9938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9939. {
  9940. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9941. }
  9942. else
  9943. {
  9944. tempIndex = connectorIdInt -1;
  9945. }
  9946. for (int index = 0; index < GB_QUANTITY; index++)
  9947. {
  9948. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9949. {
  9950. 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))
  9951. {
  9952. //Reserved
  9953. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9954. }
  9955. 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))
  9956. {
  9957. //Reserved
  9958. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9960. goto end;
  9961. }
  9962. else
  9963. {
  9964. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9965. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9966. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9967. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9968. {
  9969. DEBUG_WARN("GB connector not allow start\n.");
  9970. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9971. goto end;
  9972. }
  9973. }// END FOR ELSE
  9974. }
  9975. } // END FOR GB_QUANTITY
  9976. }
  9977. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9978. {
  9979. tempIndex = connectorIdInt -1;
  9980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9981. {
  9982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9983. {
  9984. 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))
  9985. {
  9986. //Reserved
  9987. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9988. }
  9989. 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))
  9990. {
  9991. //Reserved
  9992. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9993. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9994. goto end;
  9995. }
  9996. else
  9997. {
  9998. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9999. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10000. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10001. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10002. {
  10003. DEBUG_WARN("GB connector not allow start\n.");
  10004. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10005. goto end;
  10006. }
  10007. }// END FOR ELSE
  10008. }
  10009. } // END FOR GB_QUANTITY
  10010. }
  10011. else
  10012. {
  10013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10014. {
  10015. tempIndex = 2;
  10016. }
  10017. else
  10018. {
  10019. tempIndex = connectorIdInt -1;
  10020. }
  10021. for (int index = 0; index < AC_QUANTITY; index++)
  10022. {
  10023. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10024. {
  10025. 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))
  10026. {
  10027. //Reserved
  10028. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10029. }
  10030. 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))
  10031. {
  10032. //Reserved
  10033. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10034. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10035. goto end;
  10036. }
  10037. else
  10038. {
  10039. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10040. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10041. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10042. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10043. {
  10044. DEBUG_WARN("AC connector not allow start\n.");
  10045. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10046. goto end;
  10047. }
  10048. }//END FOR ELSE
  10049. }
  10050. }// END FOR AC_QUANTITY
  10051. }
  10052. if(chargingProfileIsNULL == FALSE)
  10053. {
  10054. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10055. {
  10056. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10057. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10058. //memset idTag
  10059. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10060. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10061. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10063. // Save profile to file
  10064. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10065. system(cmdBuf);
  10066. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10067. fp = fopen(cmdBuf, "w");
  10068. 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));
  10069. fclose(fp);
  10070. }
  10071. else
  10072. {
  10073. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10075. }
  10076. }
  10077. else
  10078. {
  10079. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10081. //memset idTag
  10082. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10083. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10084. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10086. }
  10087. }
  10088. else
  10089. {
  10090. DEBUG_WARN("Connector id over\n.");
  10091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10092. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10093. }
  10094. end:
  10095. json_object_put(RemoteStartTransaction);
  10096. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10097. {
  10098. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10099. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10100. }
  10101. //OCPP send RemoteStartConfirmation by first.
  10102. sendRemoteStartConfirmation(uuid, comfirmstr);
  10103. return result;
  10104. }
  10105. int handleRemoteStartRequest(char *uuid, char *payload)
  10106. {
  10107. mtrace();
  10108. int result = PASS;
  10109. int connectorIdInt=-1;
  10110. int tempIndex = 0;
  10111. char comfirmstr[20]={0};
  10112. char cmdBuf[512];
  10113. json_object *RemoteStartTransaction;
  10114. FILE *fp;
  10115. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10116. if(server_pending == TRUE)
  10117. {
  10118. result = FAIL;
  10119. }
  10120. RemoteStartTransaction = json_tokener_parse(payload);
  10121. if(!is_error(RemoteStartTransaction))
  10122. {
  10123. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10124. {
  10125. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10126. }
  10127. else
  10128. {
  10129. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10130. {
  10131. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10132. {
  10133. connectorIdInt = (gun_index+1);
  10134. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10135. break;
  10136. }
  10137. }
  10138. }
  10139. if(connectorIdInt == 0)
  10140. {
  10141. DEBUG_WARN("Connector id shall not equal 0.\n");
  10142. result = FAIL;
  10143. }
  10144. else if(connectorIdInt == -1)
  10145. {
  10146. DEBUG_INFO("Connector id does not specific.\n");
  10147. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10148. {
  10149. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10150. // Required data
  10151. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10152. // Optional data
  10153. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10154. {
  10155. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10156. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10157. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10158. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10159. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10160. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10161. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10162. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10163. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10164. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10165. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10166. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10168. {
  10169. 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")));
  10170. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10171. 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"));
  10172. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10173. 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"));
  10174. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10175. 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")));
  10176. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10177. {
  10178. 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++)
  10179. {
  10180. 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"));
  10181. 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"));
  10182. 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)
  10183. 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"));
  10184. }
  10185. }
  10186. }
  10187. }
  10188. else
  10189. {
  10190. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10191. }
  10192. }
  10193. }
  10194. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10195. {
  10196. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10197. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10198. // Required data
  10199. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10200. // Optional data
  10201. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10202. {
  10203. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10204. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10205. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10206. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10207. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10208. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10209. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10210. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10211. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10212. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10213. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10214. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10215. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10216. {
  10217. 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")));
  10218. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10219. 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"));
  10220. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10221. 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"));
  10222. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10223. 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")));
  10224. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10225. {
  10226. 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++)
  10227. {
  10228. 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"));
  10229. 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"));
  10230. 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)
  10231. 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"));
  10232. }
  10233. }
  10234. }
  10235. }
  10236. else
  10237. {
  10238. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10239. }
  10240. }
  10241. else
  10242. {
  10243. DEBUG_WARN("Connector id is over maximun value.\n");
  10244. result = FAIL;
  10245. }
  10246. }
  10247. if(result == PASS)
  10248. {
  10249. if(connectorIdInt > 0)
  10250. {
  10251. //check Transaction active
  10252. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10253. {
  10254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10255. {
  10256. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10257. }
  10258. else
  10259. {
  10260. tempIndex = connectorIdInt -1;
  10261. }
  10262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10263. {
  10264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10265. {
  10266. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10267. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10268. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10269. {
  10270. //Reserved
  10271. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10272. }
  10273. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10275. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10276. {
  10277. //Reserved
  10278. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10279. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10280. goto end;
  10281. }
  10282. else
  10283. {
  10284. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10285. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10286. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10287. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10288. {
  10289. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10290. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10291. goto end;
  10292. }
  10293. }//END FOR ELSE
  10294. }
  10295. }// END FOR CHAdeMO_QUANTITY
  10296. }
  10297. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10298. {
  10299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10300. {
  10301. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10302. }
  10303. else
  10304. {
  10305. tempIndex = connectorIdInt -1;
  10306. }
  10307. for (int index = 0; index < CCS_QUANTITY; index++)
  10308. {
  10309. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10310. {
  10311. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10312. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10313. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10314. {
  10315. //Reserved
  10316. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10317. }
  10318. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10319. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10320. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10321. {
  10322. //Reserved
  10323. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10324. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10325. goto end;
  10326. }
  10327. else
  10328. {
  10329. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10330. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10331. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10332. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10333. {
  10334. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10335. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10336. goto end;
  10337. }
  10338. }// END FOR ELSE
  10339. }
  10340. }// END FOR CCS_QUANTITY
  10341. }
  10342. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10343. {
  10344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10345. {
  10346. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10347. }
  10348. else
  10349. {
  10350. tempIndex = connectorIdInt -1;
  10351. }
  10352. for (int index = 0; index < GB_QUANTITY; index++)
  10353. {
  10354. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10355. {
  10356. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10357. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10358. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10359. {
  10360. //Reserved
  10361. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10362. }
  10363. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10364. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10365. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10366. {
  10367. //Reserved
  10368. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10369. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10370. goto end;
  10371. }
  10372. else
  10373. {
  10374. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10375. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10376. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10377. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10378. {
  10379. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10380. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10381. goto end;
  10382. }
  10383. }// END FOR ELSE
  10384. }
  10385. } // END FOR GB_QUANTITY
  10386. }
  10387. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10388. {
  10389. tempIndex = connectorIdInt -1;
  10390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10391. {
  10392. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10393. {
  10394. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10395. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10396. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10397. {
  10398. //Reserved
  10399. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10400. }
  10401. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10402. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10403. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10404. {
  10405. //Reserved
  10406. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10407. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10408. goto end;
  10409. }
  10410. else
  10411. {
  10412. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10413. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10414. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10415. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10416. {
  10417. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10418. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10419. goto end;
  10420. }
  10421. }// END FOR ELSE
  10422. }
  10423. } // END FOR GB_QUANTITY
  10424. }
  10425. else
  10426. {
  10427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10428. {
  10429. tempIndex = 2;
  10430. }
  10431. else
  10432. {
  10433. tempIndex = connectorIdInt -1;
  10434. }
  10435. for (int index = 0; index < AC_QUANTITY; index++)
  10436. {
  10437. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10438. {
  10439. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10440. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10441. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10442. {
  10443. //Reserved
  10444. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10445. }
  10446. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10447. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10448. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10449. {
  10450. //Reserved
  10451. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10452. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10453. goto end;
  10454. }
  10455. else
  10456. {
  10457. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10458. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10459. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10460. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10461. {
  10462. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10463. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10464. goto end;
  10465. }
  10466. }//END FOR ELSE
  10467. }
  10468. }// END FOR AC_QUANTITY
  10469. }
  10470. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10471. {
  10472. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10473. {
  10474. // Save profile to file
  10475. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10476. system(cmdBuf);
  10477. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10478. fp = fopen(cmdBuf, "w");
  10479. 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));
  10480. fclose(fp);
  10481. }
  10482. else
  10483. {
  10484. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10485. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10486. goto end;
  10487. }
  10488. }
  10489. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10490. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10491. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10492. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10493. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10494. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10495. }
  10496. else
  10497. {
  10498. uint8_t isHasIdleConnector = FALSE;
  10499. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10500. {
  10501. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10502. {
  10503. isHasIdleConnector = TRUE;
  10504. break;
  10505. }
  10506. }
  10507. if(isHasIdleConnector == TRUE)
  10508. {
  10509. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10510. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10511. {
  10512. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10513. {
  10514. // Save profile to file
  10515. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10516. system(cmdBuf);
  10517. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10518. fp = fopen(cmdBuf, "w");
  10519. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10520. fclose(fp);
  10521. refreshStartTimer(&clientTime.RemoteStartWait);
  10522. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10524. }
  10525. else
  10526. {
  10527. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10529. }
  10530. }
  10531. else
  10532. {
  10533. refreshStartTimer(&clientTime.RemoteStartWait);
  10534. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10536. }
  10537. }
  10538. else
  10539. {
  10540. DEBUG_INFO("There is not any connector is idle.\n");
  10541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10542. }
  10543. }
  10544. }
  10545. else
  10546. {
  10547. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10548. }
  10549. end:
  10550. json_object_put(RemoteStartTransaction);
  10551. sendRemoteStartConfirmation(uuid, comfirmstr);
  10552. return result;
  10553. }
  10554. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10555. {
  10556. mtrace();
  10557. int result = FAIL;
  10558. int match = FALSE;
  10559. int GunNO = 0;
  10560. int tempIndex = 0;
  10561. int transactionIdInt=0;
  10562. int transactionIdIsNULL= TRUE;
  10563. char comfirmstr[20];
  10564. json_object *RemoteStopTransaction;
  10565. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10566. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10567. if(server_pending == TRUE)
  10568. {
  10569. return 0;
  10570. }
  10571. RemoteStopTransaction = json_tokener_parse(payload);
  10572. if(!is_error(RemoteStopTransaction))
  10573. {
  10574. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10575. {
  10576. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10577. transactionIdIsNULL = FALSE;
  10578. }
  10579. }
  10580. json_object_put(RemoteStopTransaction);
  10581. if(transactionIdIsNULL == FALSE)
  10582. {
  10583. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10584. {
  10585. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10586. {
  10587. //check Transaction active
  10588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10589. {
  10590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10591. {
  10592. tempIndex = ((gun_index==2) ? 1: 0);
  10593. }
  10594. else
  10595. {
  10596. tempIndex = gun_index;
  10597. }
  10598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10599. {
  10600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10601. {
  10602. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10603. {
  10604. match = TRUE;
  10605. GunNO = gun_index;
  10606. }
  10607. }
  10608. }// END FOR CHAdeMO_QUANTITY
  10609. }
  10610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10611. {
  10612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10613. {
  10614. tempIndex = ((gun_index==2) ? 1: 0);
  10615. }
  10616. else
  10617. {
  10618. tempIndex = gun_index;
  10619. }
  10620. for (int index = 0; index < CCS_QUANTITY; index++)
  10621. {
  10622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10623. {
  10624. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10625. {
  10626. match = TRUE;
  10627. GunNO = gun_index;
  10628. }
  10629. }
  10630. }// END FOR CCS_QUANTITY
  10631. }
  10632. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10633. {
  10634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10635. {
  10636. tempIndex = ((gun_index==2) ? 1: 0);
  10637. }
  10638. else
  10639. {
  10640. tempIndex = gun_index;
  10641. }
  10642. for (int index = 0; index < GB_QUANTITY; index++)
  10643. {
  10644. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10645. {
  10646. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10647. {
  10648. match = TRUE;
  10649. GunNO = gun_index;
  10650. }
  10651. }
  10652. }// END FOR GB_QUANTITY
  10653. }
  10654. else if(gunType[gun_index] == GUN_TYPE_DO)
  10655. {
  10656. tempIndex = gun_index;
  10657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10658. {
  10659. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10660. {
  10661. 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
  10662. {
  10663. match = TRUE;
  10664. GunNO = gun_index;
  10665. }
  10666. }
  10667. }// END FOR GB_QUANTITY
  10668. }
  10669. else
  10670. {
  10671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10672. {
  10673. tempIndex = 2;
  10674. }
  10675. else
  10676. {
  10677. tempIndex = gun_index;
  10678. }
  10679. for (int index = 0; index < AC_QUANTITY; index++)
  10680. {
  10681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10682. {
  10683. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10684. {
  10685. match = TRUE;
  10686. GunNO = gun_index;
  10687. }
  10688. }
  10689. }// END FOR CHAdeMO_QUANTITY
  10690. } // END FOR AC ELSE
  10691. }// CHECK IF ResponseTransactionId == transactionIdInt
  10692. }//END FOR
  10693. if( match == TRUE)
  10694. {
  10695. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10697. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10698. }
  10699. else
  10700. {
  10701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10702. }
  10703. }
  10704. else
  10705. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10706. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10707. return result;
  10708. }
  10709. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10710. {
  10711. mtrace();
  10712. int result = FAIL;
  10713. int connectorIdInt=0, reservationIdInt=0;
  10714. int tempIndex = 0;
  10715. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10716. char comfirmstr[20]={0};
  10717. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10718. int c = 0;
  10719. char *loc;
  10720. //char *ptr;
  10721. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10722. strcpy(sstrtemp, stringtrimspace(payload));
  10723. //***(1)connectorId ****/
  10724. c=0;
  10725. loc = strstr(sstrtemp, "connectorId");
  10726. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10727. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10728. {
  10729. sstr[c] = loc[strlen("connectorId")+2+c];
  10730. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10731. c++;
  10732. }
  10733. sstr[c] = '\0';
  10734. connectorIdInt = atoi(sstr);
  10735. //***(2)expiryDate ****/
  10736. loc = strstr(sstrtemp, "expiryDate");
  10737. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10738. c = 0;
  10739. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10740. {
  10741. sstr[c] = loc[3+strlen("expiryDate")+c];
  10742. c++;
  10743. }
  10744. sstr[c] = '\0';
  10745. strcpy(expiryDatestr, sstr);
  10746. //***(3)idTag ****/
  10747. loc = strstr(sstrtemp, "idTag");
  10748. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10749. c = 0;
  10750. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10751. {
  10752. sstr[c] = loc[3+strlen("idTag")+c];
  10753. c++;
  10754. }
  10755. sstr[c] = '\0';
  10756. strcpy(idTagstr, sstr);
  10757. //***(4)parentIdTag ****/
  10758. loc = strstr(sstrtemp, "parentIdTag");
  10759. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10760. c = 0;
  10761. if(loc == NULL)
  10762. {
  10763. strcpy(parentIdTagstr, "");
  10764. }
  10765. else
  10766. {
  10767. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10768. {
  10769. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10770. c++;
  10771. }
  10772. sstr[c] = '\0';
  10773. strcpy(parentIdTagstr, sstr);
  10774. }
  10775. //***(5)reservationId ****/
  10776. c=0;
  10777. loc = strstr(sstrtemp, "reservationId");
  10778. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10779. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10780. {
  10781. sstr[c] = loc[strlen("reservationId")+2+c];
  10782. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10783. c++;
  10784. }
  10785. sstr[c] = '\0';
  10786. reservationIdInt = atoi(sstr);
  10787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10788. /*
  10789. enum SYSTEM_STATUS
  10790. {
  10791. SYS_MODE_BOOTING = 0,
  10792. SYS_MODE_IDLE = 1,
  10793. SYS_MODE_AUTHORIZING = 2,
  10794. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10795. SYS_MODE_REASSIGN = 4,
  10796. SYS_MODE_PREPARING = 5,
  10797. SYS_MODE_PREPARE_FOR_EV = 6,
  10798. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10799. SYS_MODE_CHARGING = 8,
  10800. SYS_MODE_TERMINATING = 9,
  10801. SYS_MODE_COMPLETE = 10,
  10802. SYS_MODE_ALARM = 11,
  10803. SYS_MODE_FAULT = 12,
  10804. SYS_MODE_RESERVATION = 13,
  10805. SYS_MODE_BOOKING = 14,
  10806. SYS_MODE_MAINTAIN = 15,
  10807. SYS_MODE_DEBUG = 16,
  10808. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10809. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10810. SYS_MODE_UPDATE = 19
  10811. };
  10812. */
  10813. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10814. {
  10815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10816. goto end;
  10817. }
  10818. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10819. {
  10820. //check Transaction active
  10821. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10822. {
  10823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10824. {
  10825. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10826. }
  10827. else
  10828. {
  10829. tempIndex = connectorIdInt -1;
  10830. }
  10831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10832. {
  10833. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10834. {
  10835. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10836. {
  10837. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10838. {
  10839. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10840. {
  10841. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10843. }
  10844. 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'))
  10845. {
  10846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10847. }
  10848. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10849. {
  10850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10851. }
  10852. else
  10853. {
  10854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10855. }
  10856. }
  10857. 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
  10858. {
  10859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10860. }
  10861. }
  10862. else
  10863. {
  10864. //replace reservation
  10865. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10867. }
  10868. }
  10869. } // END FOR CHAdeMO_QUANTITY
  10870. }
  10871. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10872. {
  10873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10874. {
  10875. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10876. }
  10877. else
  10878. {
  10879. tempIndex = connectorIdInt -1;
  10880. }
  10881. for (int index = 0; index < CCS_QUANTITY; index++)
  10882. {
  10883. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10884. {
  10885. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10886. {
  10887. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10888. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10889. {
  10890. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10891. {
  10892. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10894. }
  10895. 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'))
  10896. {
  10897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10898. }
  10899. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10900. {
  10901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10902. }
  10903. else
  10904. {
  10905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10906. }
  10907. }
  10908. 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
  10909. {
  10910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10911. }
  10912. }
  10913. else
  10914. {
  10915. //replace reservation
  10916. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10918. }
  10919. }
  10920. } // END FOR CCS_QUANTITY
  10921. }
  10922. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10923. {
  10924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10925. {
  10926. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10927. }
  10928. else
  10929. {
  10930. tempIndex = connectorIdInt -1;
  10931. }
  10932. for (int index = 0; index < GB_QUANTITY; index++)
  10933. {
  10934. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10935. {
  10936. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10937. {
  10938. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10939. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10940. {
  10941. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10942. {
  10943. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10945. }
  10946. 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'))
  10947. {
  10948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10949. }
  10950. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10951. {
  10952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10953. }
  10954. else
  10955. {
  10956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10957. }
  10958. }
  10959. 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
  10960. {
  10961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10962. }
  10963. }
  10964. else
  10965. {
  10966. //replace reservation
  10967. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10969. }
  10970. }
  10971. }// END FOR GB_QUANTITY
  10972. }
  10973. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10974. {
  10975. tempIndex = connectorIdInt -1;
  10976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10977. {
  10978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10979. {
  10980. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10981. {
  10982. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10983. 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
  10984. {
  10985. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10986. {
  10987. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10989. }
  10990. 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'))
  10991. {
  10992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10993. }
  10994. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10995. {
  10996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10997. }
  10998. else
  10999. {
  11000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11001. }
  11002. }
  11003. 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
  11004. {
  11005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11006. }
  11007. }
  11008. else
  11009. {
  11010. //replace reservation
  11011. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11013. }
  11014. }
  11015. }// END FOR GB_QUANTITY
  11016. }
  11017. else
  11018. {
  11019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11020. {
  11021. tempIndex = 2;
  11022. }
  11023. else
  11024. {
  11025. tempIndex = (connectorIdInt -1);
  11026. }
  11027. for (int index = 0; index < AC_QUANTITY; index++)
  11028. {
  11029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11030. {
  11031. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11032. {
  11033. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11034. {
  11035. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11036. {
  11037. 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))
  11038. {
  11039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11040. }
  11041. else
  11042. {
  11043. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11045. }
  11046. }
  11047. 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'))
  11048. {
  11049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11050. }
  11051. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11052. {
  11053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11054. }
  11055. else
  11056. {
  11057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11058. }
  11059. }
  11060. 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
  11061. {
  11062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11063. }
  11064. }
  11065. else
  11066. {
  11067. //replace reservation
  11068. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11070. }
  11071. }
  11072. } // END FOR AC_QUANTITY
  11073. }
  11074. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11075. }
  11076. else if(connectorIdInt == 0)
  11077. {
  11078. //check Transaction active
  11079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11080. {
  11081. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11082. {
  11083. 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'))
  11084. {
  11085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11086. goto end;
  11087. }
  11088. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11089. {
  11090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11091. goto end;
  11092. }
  11093. 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
  11094. {
  11095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11096. goto end;
  11097. }
  11098. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11099. {
  11100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11101. goto end;
  11102. }
  11103. }
  11104. }// END FOR CHAdeMO_QUANTITY
  11105. for (int index = 0; index < CCS_QUANTITY; index++)
  11106. {
  11107. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11108. {
  11109. 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'))
  11110. {
  11111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11112. goto end;
  11113. }
  11114. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11115. {
  11116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11117. goto end;
  11118. }
  11119. 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
  11120. {
  11121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11122. goto end;
  11123. }
  11124. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11125. {
  11126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11127. goto end;
  11128. }
  11129. }
  11130. } // END FOR CCS_QUANTITY
  11131. for (int index = 0; index < GB_QUANTITY; index++)
  11132. {
  11133. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11134. {
  11135. 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'))
  11136. {
  11137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11138. goto end;
  11139. }
  11140. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11141. {
  11142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11143. goto end;
  11144. }
  11145. 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
  11146. {
  11147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11148. goto end;
  11149. }
  11150. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11151. {
  11152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11153. goto end;
  11154. }
  11155. }
  11156. } // END FOR GB_QUANTITY
  11157. for (int index = 0; index < AC_QUANTITY; index++)
  11158. {
  11159. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11160. {
  11161. 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'))
  11162. {
  11163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11164. goto end;
  11165. }
  11166. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11167. {
  11168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11169. goto end;
  11170. }
  11171. 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
  11172. {
  11173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11174. goto end;
  11175. }
  11176. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11177. {
  11178. 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))
  11179. {
  11180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11181. goto end;
  11182. }
  11183. }
  11184. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11185. {
  11186. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11187. goto end;
  11188. }
  11189. }
  11190. }// END FOR AC_QUANTITY
  11191. //The connectorId is 0
  11192. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11194. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11195. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11196. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11197. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11198. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11199. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11200. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11201. result = TRUE;
  11202. return result;
  11203. }
  11204. else
  11205. {
  11206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11207. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11208. }
  11209. if(strcmp(comfirmstr,"Accepted") == 0)
  11210. {
  11211. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11212. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11213. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11214. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11215. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11216. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11217. result = TRUE;
  11218. return result;
  11219. }
  11220. end:
  11221. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11222. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11223. return result;
  11224. }
  11225. int handleResetRequest(char *uuid, char *payload)
  11226. {
  11227. mtrace();
  11228. int result = FAIL;
  11229. char sstr[10]={0},sstrtemp[30]={ 0 };
  11230. char typestr[10]={0};
  11231. char comfirmstr[20]={0};
  11232. int c = 0;
  11233. char *loc;
  11234. DEBUG_INFO("handleResetRequest...\n");
  11235. strcpy(sstrtemp, stringtrimspace(payload));
  11236. loc = strstr(sstrtemp, "type");
  11237. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11238. c = 0;
  11239. while (loc[3+strlen("type")+c] != '\"')
  11240. {
  11241. sstr[c] = loc[3+strlen("type")+c];
  11242. c++;
  11243. }
  11244. sstr[c] = '\0';
  11245. strcpy(typestr,sstr);
  11246. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11247. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11248. {
  11249. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11250. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11251. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11252. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11253. }
  11254. else
  11255. {
  11256. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11257. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11258. result = PASS;
  11259. }
  11260. sendResetConfirmation(uuid, comfirmstr);
  11261. return result;
  11262. }
  11263. int handleSendLocalListRequest(char *uuid, char *payload)
  11264. {
  11265. mtrace();
  11266. int result = FAIL;
  11267. char comfirmstr[20];
  11268. int checkState_Faulted = FALSE;
  11269. json_object *SendLocalList;
  11270. DEBUG_INFO("handleSendLocalListRequest...\n");
  11271. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11272. {
  11273. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11274. goto end;
  11275. }
  11276. //check Charge Point state
  11277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11278. {
  11279. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11280. {
  11281. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11282. }
  11283. }
  11284. for (int index = 0; index < CCS_QUANTITY; index++)
  11285. {
  11286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11287. {
  11288. checkState_Faulted = TRUE; //OCPP Status
  11289. }
  11290. }
  11291. for (int index = 0; index < GB_QUANTITY; index++)
  11292. {
  11293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11294. {
  11295. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11296. }
  11297. }
  11298. //check Charge Point state
  11299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11300. {
  11301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11302. {
  11303. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11304. }
  11305. }
  11306. //check Charge Point state
  11307. for (int index = 0; index < AC_QUANTITY; index++)
  11308. {
  11309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11310. {
  11311. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11312. }
  11313. }
  11314. if(checkState_Faulted == TRUE)
  11315. {
  11316. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11317. goto end;
  11318. }
  11319. // Parsing payload
  11320. SendLocalList = json_tokener_parse(payload);
  11321. if(!is_error(SendLocalList))
  11322. {
  11323. // Required data
  11324. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11325. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11326. // Optional data
  11327. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11328. {
  11329. //Check UpdateType
  11330. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11331. {
  11332. //Local list full update
  11333. DEBUG_INFO("Local list full update.\n");
  11334. OCPP_getListVerion();
  11335. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11336. {
  11337. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11338. goto end;
  11339. }
  11340. OCPP_cleanLocalList();
  11341. }
  11342. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11343. {
  11344. //Local list different update
  11345. DEBUG_INFO("Local list different update.\n");
  11346. OCPP_getListVerion();
  11347. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11348. {
  11349. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11350. goto end;
  11351. }
  11352. }
  11353. else
  11354. {
  11355. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11356. goto end;
  11357. }
  11358. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11359. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11360. {
  11361. 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")));
  11362. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11363. {
  11364. 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")));
  11365. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11366. 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")));
  11367. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11368. 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")));
  11369. }
  11370. // Add to db
  11371. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11372. {
  11373. //Local list full update
  11374. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11375. idx,
  11376. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11377. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11378. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11379. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11380. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11381. // update list
  11382. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11383. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11384. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11385. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11386. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11387. }
  11388. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11389. {
  11390. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11391. idx,
  11392. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11393. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11394. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11395. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11396. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11397. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11398. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11399. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11400. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11401. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11402. }
  11403. }
  11404. }
  11405. else
  11406. {
  11407. //Check UpdateType
  11408. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11409. {
  11410. //Local list full update
  11411. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11412. OCPP_cleanLocalList();
  11413. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11414. goto end;
  11415. }
  11416. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11417. {
  11418. //Local list different update
  11419. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11420. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11421. goto end;
  11422. }
  11423. }
  11424. result = PASS;
  11425. }
  11426. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11427. end:
  11428. json_object_put(SendLocalList);
  11429. sendSendLocalListConfirmation(uuid, comfirmstr);
  11430. return result;
  11431. }
  11432. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11433. {
  11434. mtrace();
  11435. int result = FAIL;
  11436. struct StructSetChargingProfile SetProfileReq = {0};
  11437. int tempchargingProfileIdInt;
  11438. int chargingSchedulePeriodCount = 0;
  11439. char comfirmstr[20]={0};
  11440. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11441. char rmFileCmd[128]={0};
  11442. int profileQuantity = 0;
  11443. json_object *SetChargingProfile;
  11444. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11445. SetChargingProfile = json_tokener_parse(payload);
  11446. if(!is_error(SetChargingProfile))
  11447. {
  11448. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11449. {
  11450. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11451. }
  11452. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11453. {
  11454. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11455. {
  11456. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11457. }
  11458. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11459. {
  11460. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11461. }
  11462. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11463. {
  11464. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11465. }
  11466. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11467. {
  11468. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11469. }
  11470. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11471. {
  11472. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11473. }
  11474. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11475. {
  11476. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11477. }
  11478. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11479. {
  11480. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11481. }
  11482. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11483. {
  11484. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11485. }
  11486. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11487. {
  11488. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11489. {
  11490. 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")));
  11491. }
  11492. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11493. {
  11494. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11495. }
  11496. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11497. {
  11498. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11499. }
  11500. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11501. {
  11502. 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")));
  11503. }
  11504. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11505. {
  11506. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11507. if(chargingSchedulePeriodCount <= 10)
  11508. {
  11509. 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++)
  11510. {
  11511. 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)
  11512. {
  11513. 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"));
  11514. }
  11515. 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)
  11516. {
  11517. 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"));
  11518. }
  11519. 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)
  11520. {
  11521. 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"));
  11522. }
  11523. }
  11524. }
  11525. }
  11526. }
  11527. }
  11528. }
  11529. // Profile periods quantity check
  11530. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11531. {
  11532. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11533. goto end;
  11534. }
  11535. // Check invalid limit
  11536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11537. {
  11538. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11539. {
  11540. 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)))) ||
  11541. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11542. {
  11543. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11544. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11545. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11546. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11547. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11548. goto end;
  11549. }
  11550. }
  11551. }
  11552. else
  11553. {
  11554. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11555. {
  11556. 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))
  11557. {
  11558. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11559. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11560. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11561. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11562. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11563. goto end;
  11564. }
  11565. }
  11566. }
  11567. // Profile purpose info check
  11568. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11569. {
  11570. FILE *fp;
  11571. char dataLine[4096]={0};
  11572. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11573. if(SetProfileReq.ConnectorId != 0)
  11574. {
  11575. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11576. goto end;
  11577. }
  11578. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11579. if (!fp)
  11580. {
  11581. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11582. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11583. }
  11584. else
  11585. {
  11586. while(fscanf(fp, "%s", dataLine) != EOF)
  11587. {
  11588. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11589. {
  11590. profileQuantity += 1;
  11591. }
  11592. }
  11593. }
  11594. fclose(fp);
  11595. }
  11596. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11597. {
  11598. FILE *fp;
  11599. char dataLine[4096]={0};
  11600. char filename[128]={0};
  11601. int tmpProfileQuantity;
  11602. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11603. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11604. {
  11605. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11606. goto end;
  11607. }
  11608. if(SetProfileReq.ConnectorId == 0)
  11609. {
  11610. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11611. {
  11612. tmpProfileQuantity = 0;
  11613. memset(filename, 0, ARRAY_SIZE(filename));
  11614. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11615. fp = fopen(filename, "r");
  11616. if (!fp)
  11617. {
  11618. DEBUG_INFO("%s does not create.\n", filename);
  11619. fp = fopen(filename, "w+");
  11620. }
  11621. else
  11622. {
  11623. while(fscanf(fp, "%s", dataLine) != EOF)
  11624. {
  11625. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11626. {
  11627. tmpProfileQuantity += 1;
  11628. }
  11629. }
  11630. }
  11631. fclose(fp);
  11632. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11633. }
  11634. }
  11635. else
  11636. {
  11637. memset(filename, 0, ARRAY_SIZE(filename));
  11638. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11639. fp = fopen(filename, "r");
  11640. if (!fp)
  11641. {
  11642. DEBUG_INFO("%s does not create.\n", filename);
  11643. fp = fopen(filename, "w+");
  11644. }
  11645. else
  11646. {
  11647. while(fscanf(fp, "%s", dataLine) != EOF)
  11648. {
  11649. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11650. {
  11651. profileQuantity += 1;
  11652. }
  11653. }
  11654. }
  11655. fclose(fp);
  11656. }
  11657. }
  11658. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11659. {
  11660. int isMatchTransactiodId= FALSE;
  11661. FILE *fp;
  11662. char dataLine[4096]={0};
  11663. char filename[128]={0};
  11664. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11665. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11666. if(SetProfileReq.ConnectorId == 0)
  11667. {
  11668. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11669. goto end;
  11670. }
  11671. int tempIndex = 0;
  11672. //check Transaction active
  11673. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11674. {
  11675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11676. {
  11677. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11678. }
  11679. else
  11680. {
  11681. tempIndex = SetProfileReq.ConnectorId -1;
  11682. }
  11683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11684. {
  11685. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11686. {
  11687. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11688. {
  11689. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11690. {
  11691. isMatchTransactiodId = TRUE;
  11692. break;
  11693. }
  11694. }
  11695. }
  11696. }
  11697. }
  11698. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11699. {
  11700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11701. {
  11702. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11703. }
  11704. else
  11705. {
  11706. tempIndex = SetProfileReq.ConnectorId -1;
  11707. }
  11708. for (int index = 0; index < CCS_QUANTITY; index++)
  11709. {
  11710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11711. {
  11712. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11713. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11714. {
  11715. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11716. {
  11717. isMatchTransactiodId = TRUE;
  11718. break;
  11719. }
  11720. }
  11721. }
  11722. }
  11723. }
  11724. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11725. {
  11726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11727. {
  11728. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11729. }
  11730. else
  11731. {
  11732. tempIndex = SetProfileReq.ConnectorId -1;
  11733. }
  11734. for (int index = 0; index < GB_QUANTITY; index++)
  11735. {
  11736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11737. {
  11738. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11739. {
  11740. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11741. {
  11742. isMatchTransactiodId = TRUE;
  11743. break;
  11744. }
  11745. }
  11746. }
  11747. }
  11748. }
  11749. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11750. {
  11751. tempIndex = SetProfileReq.ConnectorId -1;
  11752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11753. {
  11754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11755. {
  11756. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11757. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11758. {
  11759. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11760. {
  11761. isMatchTransactiodId = TRUE;
  11762. break;
  11763. }
  11764. }
  11765. }
  11766. }
  11767. }
  11768. else
  11769. {
  11770. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11771. {
  11772. tempIndex = 2;
  11773. }
  11774. else
  11775. {
  11776. tempIndex = (SetProfileReq.ConnectorId -1);
  11777. }
  11778. for (int index = 0; index < AC_QUANTITY; index++)
  11779. {
  11780. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11781. {
  11782. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11783. {
  11784. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11785. {
  11786. isMatchTransactiodId = TRUE;
  11787. break;
  11788. }
  11789. }
  11790. }
  11791. }
  11792. }
  11793. //check Transaction active
  11794. if(isMatchTransactiodId == FALSE)
  11795. {
  11796. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11797. goto end;
  11798. }
  11799. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11800. {
  11801. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11802. goto end;
  11803. }
  11804. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11805. fp = fopen(filename, "r");
  11806. if (!fp)
  11807. {
  11808. DEBUG_INFO("%s does not create.\n", filename);
  11809. fp = fopen(filename, "w+");
  11810. }
  11811. else
  11812. {
  11813. //Check Charging Profile Count
  11814. while(fscanf(fp, "%s", dataLine) != EOF)
  11815. {
  11816. //DEBUG_INFO("word=%s\n",word);
  11817. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11818. {
  11819. profileQuantity += 1;
  11820. }
  11821. }
  11822. }
  11823. fclose(fp);
  11824. }
  11825. // Check ChargeProfileMaxStackLevel
  11826. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11827. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11828. {
  11829. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11830. goto end;
  11831. }
  11832. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11833. {
  11834. FILE *fp;
  11835. char dataLine[4096]={0};
  11836. char fnametemp[128]={0};
  11837. int tmpProfileQuantity;
  11838. //Check ChargePointMaxProfile.json exit
  11839. profileQuantity = 0;
  11840. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11841. {
  11842. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11843. //Check Charging Profile Count
  11844. tmpProfileQuantity = 0;
  11845. while(fscanf(fp, "%s", dataLine) != EOF)
  11846. {
  11847. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11848. {
  11849. profileQuantity += 1;
  11850. tmpProfileQuantity += 1;
  11851. }
  11852. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11853. }
  11854. fclose(fp);
  11855. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11856. }
  11857. //Check TxDefaultProfile_%d.json
  11858. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11859. {
  11860. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11861. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11862. if((access(fnametemp,F_OK))!=-1)
  11863. {
  11864. fp = fopen(fnametemp, "r");
  11865. //Check Charging Profile Count
  11866. tmpProfileQuantity = 0;
  11867. while(fscanf(fp, "%s", dataLine) != EOF)
  11868. {
  11869. //DEBUG_INFO("word=%s\n",word);
  11870. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11871. {
  11872. profileQuantity += 1;
  11873. tmpProfileQuantity += 1;
  11874. }
  11875. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11876. }
  11877. fclose(fp);
  11878. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11879. }
  11880. }
  11881. //Check TxProfile_%d.json
  11882. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11883. {
  11884. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11885. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11886. if((access(fnametemp,F_OK))!=-1)
  11887. {
  11888. fp = fopen(fnametemp, "r");
  11889. //Check Charging Profile Count
  11890. tmpProfileQuantity = 0;
  11891. while(fscanf(fp, "%s", dataLine) != EOF)
  11892. {
  11893. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11894. {
  11895. profileQuantity += 1;
  11896. tmpProfileQuantity += 1;
  11897. }
  11898. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11899. }
  11900. fclose(fp);
  11901. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11902. }
  11903. }
  11904. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11905. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11906. {
  11907. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11908. goto end;
  11909. }
  11910. }
  11911. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11912. //**********************************Write to File********************************************************/
  11913. {
  11914. FILE *infile;
  11915. FILE *outfile;
  11916. char dataLine[4096]={0};
  11917. char filename[128]={0};
  11918. int chkChar=0;
  11919. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11920. {
  11921. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11922. {
  11923. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11924. }
  11925. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11926. {
  11927. if(SetProfileReq.ConnectorId==0)
  11928. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11929. else
  11930. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11931. }
  11932. else
  11933. {
  11934. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11935. }
  11936. infile = fopen (filename, "r");
  11937. outfile = fopen (tempfile, "w");
  11938. chkChar = fgetc(infile);
  11939. rewind(infile);
  11940. if(chkChar == EOF)
  11941. {
  11942. // Profile is empty
  11943. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11944. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11945. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11946. fclose(infile);
  11947. fclose(outfile);
  11948. sprintf(rmFileCmd,"rm -f %s",filename);
  11949. system(rmFileCmd);
  11950. rename(tempfile, filename);
  11951. }
  11952. else
  11953. {
  11954. // Profile is not empty
  11955. int ChargingProfileAdded = FALSE;
  11956. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11957. {
  11958. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11959. json_object *tmpChargingProfile;
  11960. tmpChargingProfile = json_tokener_parse(dataLine);
  11961. if(!is_error(SetChargingProfile))
  11962. {
  11963. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11964. {
  11965. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11966. {
  11967. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11968. }
  11969. }
  11970. }
  11971. json_object_put(tmpChargingProfile);
  11972. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11973. {
  11974. if(ChargingProfileAdded == FALSE)
  11975. {
  11976. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11977. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11978. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11979. ChargingProfileAdded = TRUE;
  11980. }
  11981. }
  11982. else
  11983. {
  11984. fprintf(outfile,"%s\n",dataLine);
  11985. if(ChargingProfileAdded == FALSE)
  11986. {
  11987. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11988. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11989. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11990. ChargingProfileAdded = TRUE;
  11991. }
  11992. }
  11993. } // end of while loop
  11994. fclose(infile);
  11995. fclose(outfile);
  11996. sprintf(rmFileCmd,"rm -f %s",filename);
  11997. system(rmFileCmd);
  11998. rename(tempfile, filename);
  11999. }
  12000. }
  12001. sleep(1);
  12002. result = TRUE;
  12003. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12004. }
  12005. end:
  12006. json_object_put(SetChargingProfile);
  12007. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12008. {
  12009. if(SetProfileReq.ConnectorId == 0)
  12010. {
  12011. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12012. {
  12013. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12014. }
  12015. }
  12016. else
  12017. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12018. }
  12019. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12020. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12021. return result;
  12022. }
  12023. int handleTriggerMessageRequest(char *uuid, char *payload)
  12024. {
  12025. mtrace();
  12026. int result = FAIL;
  12027. int connectorIdIsNULL = FALSE;
  12028. int connectorIdInt =0;
  12029. char sstr[40]={0},sstrtemp[100]={ 0 };
  12030. char requestedMessagestr[40]={0};
  12031. char comfirmstr[20]={0};
  12032. int c = 0;
  12033. char *loc;
  12034. DEBUG_INFO("handleTriggerMessageRequest\n");
  12035. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12036. strcpy(sstrtemp, stringtrimspace(payload));
  12037. c = 0;
  12038. loc = strstr(sstrtemp, "requestedMessage");
  12039. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12040. {
  12041. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12042. c++;
  12043. }
  12044. sstr[c] = '\0';
  12045. strcpy(requestedMessagestr, sstr);
  12046. c = 0;
  12047. loc = strstr(sstrtemp, "connectorId");
  12048. if(loc == NULL)
  12049. {
  12050. connectorIdIsNULL = TRUE;
  12051. }
  12052. else
  12053. {
  12054. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12055. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12056. {
  12057. sstr[c] = loc[strlen("connectorId")+2+c];
  12058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12059. c++;
  12060. }
  12061. sstr[c] = '\0';
  12062. connectorIdInt = atoi(sstr);
  12063. }
  12064. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12065. {
  12066. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12067. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12068. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12069. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12070. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12071. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12072. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12073. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12074. {
  12075. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12076. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12077. return TRUE;
  12078. }
  12079. else
  12080. {
  12081. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12082. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12083. }
  12084. }
  12085. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12086. {
  12087. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12088. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12089. return TRUE;
  12090. }
  12091. //==========================
  12092. // Trigger message
  12093. //==========================
  12094. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12095. {
  12096. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12097. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12098. {
  12099. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12100. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12101. }
  12102. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12103. }
  12104. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12105. {
  12106. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12107. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12108. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12109. }
  12110. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12111. {
  12112. //sendBootNotificationRequest();
  12113. server_sign = FALSE;
  12114. }
  12115. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12116. {
  12117. refreshStartTimer(&clientTime.Heartbeat);
  12118. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12119. }
  12120. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12121. {
  12122. if(connectorIdIsNULL == FALSE)
  12123. {
  12124. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12125. {
  12126. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12127. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12128. }
  12129. }
  12130. else
  12131. {
  12132. for(int idx=0;idx< gunTotalNumber;idx++)
  12133. {
  12134. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12135. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12136. }
  12137. }
  12138. }
  12139. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12140. {
  12141. if(connectorIdIsNULL == FALSE)
  12142. {
  12143. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12144. {
  12145. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12146. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12147. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12148. }
  12149. }
  12150. else
  12151. {
  12152. for(int idx=0;idx< gunTotalNumber;idx++)
  12153. {
  12154. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12155. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12156. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12157. }
  12158. }
  12159. }
  12160. return result;
  12161. }
  12162. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12163. {
  12164. mtrace();
  12165. int result = FAIL;
  12166. int connectorIdInt =0;
  12167. char comfirmstr[20]={0};
  12168. int tempIndex = 0;
  12169. json_object *UnlockConnector;
  12170. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12171. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12172. UnlockConnector = json_tokener_parse(payload);
  12173. if(!is_error(UnlockConnector))
  12174. {
  12175. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12176. {
  12177. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12178. }
  12179. }
  12180. json_object_put(UnlockConnector);
  12181. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12182. if(gunTotalNumber == 0)
  12183. {
  12184. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12185. goto end;
  12186. }
  12187. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12188. {
  12189. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12190. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12191. goto end;
  12192. }
  12193. else
  12194. {
  12195. //check Transaction active
  12196. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12197. {
  12198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12199. {
  12200. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12201. }
  12202. else
  12203. {
  12204. tempIndex = connectorIdInt -1;
  12205. }
  12206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12207. {
  12208. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12209. {
  12210. //stop Transaction
  12211. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12212. }
  12213. }
  12214. }
  12215. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12216. {
  12217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12218. {
  12219. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12220. }
  12221. else
  12222. {
  12223. tempIndex = connectorIdInt -1;
  12224. }
  12225. for (int index = 0; index < CCS_QUANTITY; index++)
  12226. {
  12227. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12228. {
  12229. //stop Transaction
  12230. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12231. }
  12232. }
  12233. }
  12234. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12235. {
  12236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12237. {
  12238. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12239. }
  12240. else
  12241. {
  12242. tempIndex = connectorIdInt -1;
  12243. }
  12244. for (int index = 0; index < GB_QUANTITY; index++)
  12245. {
  12246. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12247. {
  12248. //stop Transaction
  12249. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12250. }
  12251. }
  12252. }
  12253. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12254. {
  12255. tempIndex = connectorIdInt -1;
  12256. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12257. {
  12258. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12259. {
  12260. //stop Transaction
  12261. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12262. }
  12263. }
  12264. }
  12265. else
  12266. {
  12267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12268. {
  12269. tempIndex = 2;
  12270. }
  12271. else
  12272. {
  12273. tempIndex = connectorIdInt-1;
  12274. }
  12275. for (int index = 0; index < AC_QUANTITY; index++)
  12276. {
  12277. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12278. {
  12279. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12280. }
  12281. }
  12282. }
  12283. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12284. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12285. result = TRUE;
  12286. return result;
  12287. }
  12288. end:
  12289. //json_object_put(obj); --- remove temporally
  12290. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12291. return result;
  12292. }
  12293. static char UpdateFirmwarepayloadData[300]={0};
  12294. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12295. {
  12296. mtrace();
  12297. int result = FAIL;
  12298. pthread_t t;
  12299. sendUpdateFirmwareConfirmation(uuid);
  12300. memset(UpdateFirmwarepayloadData, 0, 300);
  12301. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12302. if(!interLock.isUpdateFirmwareGoing)
  12303. {
  12304. interLock.isUpdateFirmwareGoing = 1;
  12305. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12306. sleep(1);
  12307. }
  12308. else
  12309. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12310. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12311. return result;
  12312. }
  12313. void *UpdateFirmwareProcess(void *data)
  12314. {
  12315. pthread_detach(pthread_self());
  12316. mtrace();
  12317. int retriesInt =0, retryIntervalInt=0;
  12318. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12319. int port=0;
  12320. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12321. int isSuccess = 0;
  12322. char ftpbuf[512];
  12323. char temp[100];
  12324. char * pch;
  12325. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12326. json_object *UpdateFirmware;
  12327. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12328. if(!is_error(UpdateFirmware))
  12329. {
  12330. // Required data
  12331. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12332. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12333. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12334. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12335. // Optional data
  12336. if(json_object_object_get(UpdateFirmware, "retries"))
  12337. {
  12338. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12339. }
  12340. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12341. {
  12342. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12343. }
  12344. }
  12345. json_object_put(UpdateFirmware);
  12346. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12347. memset(path, 0, ARRAY_SIZE(path));
  12348. // Wait retrieveData
  12349. if(strlen(retrieveDatestr) > 10)
  12350. {
  12351. do
  12352. {
  12353. sleep(1);
  12354. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12355. }
  12356. // Ready to download
  12357. system("rm -f /mnt/*");
  12358. if(strncmp(locationstr,"http", 4) == 0)
  12359. {
  12360. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12361. sprintf(ftppath,"/%s", path);
  12362. DEBUG_INFO("locationstr: %s\n", locationstr);
  12363. DEBUG_INFO("protocol: %s\n",protocol);
  12364. DEBUG_INFO("host: %s\n",host);
  12365. DEBUG_INFO("path: %s\n",path);
  12366. DEBUG_INFO("ftppath: %s\n",ftppath);
  12367. int ftppathlen=strlen(ftppath);
  12368. int i=1;
  12369. char filenametemp[50];
  12370. while(i < ftppathlen)
  12371. {
  12372. int len=ftppathlen-i;
  12373. if(ftppath[len]== 47) // '/' ascll code: 47
  12374. {
  12375. DEBUG_INFO("compare '/' all right\n");
  12376. break;
  12377. }
  12378. i=i+1;
  12379. }
  12380. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12381. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12382. filenametemp[i+1] = 0;
  12383. do
  12384. {
  12385. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12386. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12387. sleep(1);
  12388. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12389. if(!isSuccess)
  12390. {
  12391. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12392. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12393. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12394. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12395. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12396. }
  12397. else
  12398. {
  12399. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12400. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12401. }
  12402. retriesInt--;
  12403. }while((isSuccess == 0)&&(retriesInt >= 0));
  12404. }
  12405. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12406. {
  12407. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12408. memset(temp, 0, ARRAY_SIZE(temp));
  12409. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12410. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12411. int ftppathlen=strlen(ftpbuf);
  12412. int i=1;
  12413. char filenametemp[50];
  12414. while(i < ftppathlen)
  12415. {
  12416. int len=ftppathlen-i;
  12417. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12418. {
  12419. DEBUG_INFO(" compare '/' all right\n");
  12420. break;
  12421. }
  12422. i=i+1;
  12423. }
  12424. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12425. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12426. filenametemp[i+1] = 0;
  12427. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12428. pch=strchr(temp,'@');
  12429. if(pch==NULL)
  12430. {
  12431. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12432. protocol, host, &port, path);
  12433. strcpy(user,"anonymous");
  12434. strcpy(password,"");
  12435. }
  12436. else
  12437. {
  12438. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12439. protocol, user, password, host, &port, path);
  12440. }
  12441. sscanf(host,"%[^/]%s",host1, path1);
  12442. sprintf(ftppath,"%s", path1);
  12443. //DEBUG_INFO("protocol =%s\n",protocol);
  12444. //DEBUG_INFO("user =%s\n",user);
  12445. //DEBUG_INFO("password =%s\n",password);
  12446. //DEBUG_INFO("host1 =%s\n",host1);
  12447. //DEBUG_INFO("port =%d\n",port);
  12448. //DEBUG_INFO("path1 =%s\n",path1);
  12449. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12450. //ftpFile(host, user, password, port, ftppath, fname);
  12451. //download firmware pthred
  12452. if(port == 0)
  12453. {
  12454. port = 21;
  12455. }
  12456. do
  12457. {
  12458. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12459. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12460. sleep(1);
  12461. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12462. if(!isSuccess)
  12463. {
  12464. //BulldogUtil.sleepMs(interval*1000);
  12465. DEBUG_INFO("Update firmware request and download file fail.\n");
  12466. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12467. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12468. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12469. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12470. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12471. }
  12472. else
  12473. {
  12474. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12475. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12476. }
  12477. retriesInt--;
  12478. }while((!isSuccess)&&(retriesInt >= 0));
  12479. }
  12480. else
  12481. {
  12482. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12483. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12484. sleep(1);
  12485. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12486. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12487. }
  12488. // OCPPPH only, must announce CSU upgrade firmware
  12489. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12490. interLock.isUpdateFirmwareGoing = 0;
  12491. pthread_exit(NULL);
  12492. }
  12493. int handleCertificateSignedRequest(char *uuid, char *payload)
  12494. {
  12495. mtrace();
  12496. int result = PASS;
  12497. json_object *CertificateSigned;
  12498. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12499. CertificateSigned = json_tokener_parse(payload);
  12500. if(!is_error(CertificateSigned))
  12501. {
  12502. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12503. }
  12504. json_object_put(CertificateSigned);
  12505. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12506. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12507. fclose(fp);
  12508. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12509. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12510. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12511. sendCertificateSignedConfirmation(uuid);
  12512. return result;
  12513. }
  12514. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12515. {
  12516. mtrace();
  12517. int result = PASS;
  12518. json_object *DeleteCertificate;
  12519. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12520. DeleteCertificate = json_tokener_parse(payload);
  12521. if(!is_error(DeleteCertificate))
  12522. {
  12523. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12524. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12525. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12526. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12527. }
  12528. json_object_put(DeleteCertificate);
  12529. /*
  12530. * TODO: Delete certificateSigned process
  12531. */
  12532. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12533. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12534. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12535. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12536. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12537. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12538. sendDeleteCertificateConfirmation(uuid);
  12539. return result;
  12540. }
  12541. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12542. {
  12543. mtrace();
  12544. int result = PASS;
  12545. json_object *ExtendedTriggerMessage;
  12546. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12547. ExtendedTriggerMessage = json_tokener_parse(payload);
  12548. if(!is_error(ExtendedTriggerMessage))
  12549. {
  12550. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12551. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12552. {
  12553. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12554. }
  12555. else
  12556. {
  12557. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12558. }
  12559. }
  12560. json_object_put(ExtendedTriggerMessage);
  12561. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12562. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12563. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12564. {
  12565. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12566. }
  12567. else
  12568. {
  12569. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12570. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12571. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12572. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12573. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12574. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12575. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12576. {
  12577. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12578. }
  12579. else
  12580. {
  12581. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12582. }
  12583. }
  12584. sendExtendedTriggerMessageConfirmation(uuid);
  12585. //==========================
  12586. // Trigger message
  12587. //==========================
  12588. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12589. {
  12590. //sendBootNotificationRequest();
  12591. server_sign = FALSE;
  12592. }
  12593. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12594. {
  12595. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12596. }
  12597. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12598. {
  12599. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12600. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12601. {
  12602. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12603. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12604. }
  12605. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12606. }
  12607. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12608. {
  12609. refreshStartTimer(&clientTime.Heartbeat);
  12610. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12611. }
  12612. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12613. {
  12614. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12615. {
  12616. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12617. }
  12618. else
  12619. {
  12620. for(int idx=0;idx< gunTotalNumber;idx++)
  12621. {
  12622. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12623. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12624. }
  12625. }
  12626. }
  12627. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12628. {
  12629. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12630. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12631. {
  12632. 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\" &");
  12633. }
  12634. }
  12635. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12636. {
  12637. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12638. {
  12639. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12640. }
  12641. else
  12642. {
  12643. for(int idx=0;idx< gunTotalNumber;idx++)
  12644. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12645. }
  12646. }
  12647. return result;
  12648. }
  12649. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12650. {
  12651. mtrace();
  12652. int result = PASS;
  12653. json_object *GetInstalledCertificateIds;
  12654. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12655. GetInstalledCertificateIds = json_tokener_parse(payload);
  12656. if(!is_error(GetInstalledCertificateIds))
  12657. {
  12658. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12659. }
  12660. json_object_put(GetInstalledCertificateIds);
  12661. /*
  12662. * TODO: Return installed certificate process
  12663. */
  12664. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12665. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12666. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12667. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12668. sendGetInstalledCertificateIdsConfirmation(uuid);
  12669. return result;
  12670. }
  12671. int handleGetLogRequest(char *uuid, char *payload)
  12672. {
  12673. mtrace();
  12674. int result = PASS;
  12675. json_object *GetLog;
  12676. DEBUG_INFO("handleGetLogRequest...\n");
  12677. GetLog = json_tokener_parse(payload);
  12678. if(!is_error(GetLog))
  12679. {
  12680. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12681. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12682. if(json_object_object_get(GetLog, "retries") != NULL)
  12683. {
  12684. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12685. }
  12686. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12687. {
  12688. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12689. }
  12690. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12691. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12692. {
  12693. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12694. }
  12695. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12696. {
  12697. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12698. }
  12699. }
  12700. json_object_put(GetLog);
  12701. /*
  12702. * TODO: Upload log process
  12703. */
  12704. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12705. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12706. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12707. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12708. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12709. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12710. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12711. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12712. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12713. sendGetLogConfirmation(uuid);
  12714. return result;
  12715. }
  12716. int handleInstallCertificateRequest(char *uuid, char *payload)
  12717. {
  12718. mtrace();
  12719. int result = PASS;
  12720. json_object *InstallCertificate;
  12721. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12722. InstallCertificate = json_tokener_parse(payload);
  12723. if(!is_error(InstallCertificate))
  12724. {
  12725. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12726. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12727. /*
  12728. * TODO: Install certificate process
  12729. */
  12730. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12731. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12732. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12733. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12734. sendInstallCertificateConfirmation(uuid);
  12735. }
  12736. json_object_put(InstallCertificate);
  12737. return result;
  12738. }
  12739. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12740. {
  12741. mtrace();
  12742. int result = PASS;
  12743. json_object *SignedUpdateFirmware;
  12744. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12745. SignedUpdateFirmware = json_tokener_parse(payload);
  12746. if(!is_error(SignedUpdateFirmware))
  12747. {
  12748. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12749. {
  12750. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12751. }
  12752. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12753. {
  12754. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12755. }
  12756. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12757. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12758. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12759. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12760. {
  12761. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12762. }
  12763. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12764. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12765. }
  12766. json_object_put(SignedUpdateFirmware);
  12767. /*
  12768. * TODO: Upgrade firmware process
  12769. */
  12770. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12771. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12772. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12773. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12774. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12775. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12776. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12777. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12778. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12779. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12780. sendInstallCertificateConfirmation(uuid);
  12781. return result;
  12782. }
  12783. int handleUnknownRequest(char *uuid, char *payload)
  12784. {
  12785. mtrace();
  12786. int result = PASS;
  12787. DEBUG_INFO("handleUnknownRequest...\n");
  12788. sendUnknownConfirmation(uuid);
  12789. result = PASS;
  12790. return result;
  12791. }
  12792. //==========================================
  12793. // Handle server response routine
  12794. //==========================================
  12795. void handleAuthorizeResponse(char *payload, int gun_index)
  12796. {
  12797. mtrace();
  12798. char expiryDatestr[30]={0};
  12799. char parentIdTagstr[20]={0};
  12800. char statusstr[20]={0};
  12801. int expiryDateISNULL=FALSE;
  12802. int parentIdTagISNULL=FALSE;
  12803. DEBUG_INFO("handleAuthorizeResponse...\n");
  12804. json_object *Authorize;
  12805. Authorize = json_tokener_parse(payload);
  12806. if(!is_error(Authorize))
  12807. {
  12808. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12809. {
  12810. // Required data
  12811. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12812. // Optional data
  12813. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12814. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12815. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12816. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12817. }
  12818. }
  12819. json_object_put(Authorize);
  12820. if(expiryDateISNULL == FALSE)
  12821. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12822. if(parentIdTagISNULL == FALSE)
  12823. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12824. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12825. //Update idTag information to authorization cache if supproted
  12826. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12827. {
  12828. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12829. }
  12830. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12831. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12832. authorizeRetryTimes = 0;
  12833. }
  12834. void handleBootNotificationResponse(char *payload, int gun_index)
  12835. {
  12836. mtrace();
  12837. char statusStr[12]={0};
  12838. char currentTimeStr[30]={0};
  12839. int intervalInt = 0;
  12840. DEBUG_INFO("handleBootNotificationResponse...\n");
  12841. json_object *BootNotification;
  12842. BootNotification = json_tokener_parse(payload);
  12843. if(!is_error(BootNotification))
  12844. {
  12845. // Required data
  12846. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12847. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12848. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12849. }
  12850. json_object_put(BootNotification);
  12851. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12852. BootNotificationInterval = intervalInt;
  12853. HeartBeatWaitTime = intervalInt;
  12854. //write back to ShmOCPP16DataPH->BootNotification
  12855. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12856. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12857. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12858. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12859. {
  12860. if((intervalInt == 0) || (intervalInt >= 10))
  12861. {
  12862. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12863. HeartBeatWaitTime = intervalInt;
  12864. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12865. }
  12866. server_sign = TRUE;
  12867. server_pending =FALSE;
  12868. }
  12869. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12870. {
  12871. server_pending = TRUE;
  12872. }
  12873. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12874. srand(time(NULL));
  12875. refreshStartTimer(&clientTime.Heartbeat);
  12876. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12877. SetOcppConnStatus(TRUE);
  12878. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12879. }
  12880. void handleDataTransferResponse(char *payload, int gun_index)
  12881. {
  12882. json_object *DataTransfer = json_tokener_parse(payload);
  12883. if(!is_error(DataTransfer))
  12884. {
  12885. // Required data
  12886. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12887. // Optional data
  12888. if(json_object_object_get(DataTransfer, "data") != NULL)
  12889. {
  12890. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12891. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12892. if(!is_error(Data))
  12893. {
  12894. if(json_object_object_get(Data, "msgId") != NULL)
  12895. {
  12896. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12897. {
  12898. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  12899. }
  12900. }
  12901. }
  12902. json_object_put(Data);
  12903. }
  12904. }
  12905. json_object_put(DataTransfer);
  12906. }
  12907. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12908. {
  12909. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12910. //struct json_object *obj;
  12911. // obj = json_tokener_parse(payload);
  12912. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12913. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12914. //No fields are defined.
  12915. }
  12916. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12917. {
  12918. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12919. //struct json_object *obj;
  12920. // obj = json_tokener_parse(payload);
  12921. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12922. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12923. //No fields are defined.
  12924. }
  12925. void handleHeartbeatResponse(char *payload, int gun_index)
  12926. {
  12927. mtrace();
  12928. DEBUG_INFO("handleHeartbeatResponse...\n");
  12929. json_object *Heartbeat;
  12930. Heartbeat = json_tokener_parse(payload);
  12931. if(!is_error(Heartbeat))
  12932. {
  12933. // Required data
  12934. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12935. }
  12936. json_object_put(Heartbeat);
  12937. if(FirstHeartBeat == 0)
  12938. {
  12939. FirstHeartBeat = 1;
  12940. DEBUG_INFO("FirstHeartBeat \n");
  12941. }
  12942. HeartBeatWithNOResponse = 0;
  12943. refreshStartTimer(&clientTime.Heartbeat);
  12944. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12945. }
  12946. void handleMeterValuesResponse(char *payload, int gun_index)
  12947. {
  12948. mtrace();
  12949. DEBUG_INFO("handleMeterValuesResponse...\n");
  12950. isQueueSendable = 1;
  12951. }
  12952. void handleStartTransactionResponse(char *payload, int gun_index)
  12953. {
  12954. mtrace();
  12955. //int transactionIdInt = 0;
  12956. FILE *outfile;
  12957. char data[100]={0};
  12958. DEBUG_INFO("handleStartTransactionResponse...\n");
  12959. json_object *StartTransaction;
  12960. StartTransaction = json_tokener_parse(payload);
  12961. if(!is_error(StartTransaction))
  12962. {
  12963. // Required data
  12964. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12965. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12966. // Optional data
  12967. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12968. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12969. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12970. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12971. }
  12972. json_object_put(StartTransaction);
  12973. isQueueSendable = 1;
  12974. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12975. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12976. //-----------Start : write to the Queue TransactionId file -----------------//
  12977. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12978. {}
  12979. else
  12980. {
  12981. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12982. if(log == NULL)
  12983. {
  12984. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12985. return ;
  12986. }
  12987. else
  12988. {
  12989. fclose(log);
  12990. }
  12991. }
  12992. // open file for writing
  12993. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12994. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12995. {
  12996. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12997. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12998. fputs(data, outfile);
  12999. fclose (outfile);
  13000. }
  13001. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13002. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13003. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13004. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13005. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13006. }
  13007. void handleStatusNotificationResponse(char *payload, int gun_index)
  13008. {
  13009. mtrace();
  13010. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13011. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13012. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13013. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13014. }
  13015. void handleStopTransactionnResponse(char *payload, int gun_index)
  13016. {
  13017. mtrace();
  13018. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13019. json_object *StopTransaction;
  13020. StopTransaction = json_tokener_parse(payload);
  13021. if(!is_error(StopTransaction))
  13022. {
  13023. // Optional data
  13024. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13025. {
  13026. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13027. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13028. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13029. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13030. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13031. }
  13032. }
  13033. json_object_put(StopTransaction);
  13034. isQueueSendable = 1;
  13035. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13036. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13037. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13038. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13039. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13040. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13041. }
  13042. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13043. {
  13044. mtrace();
  13045. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13046. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13047. }
  13048. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13049. {
  13050. mtrace();
  13051. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13052. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13053. }
  13054. void handleSignCertificateResponse(char *payload, int gun_index)
  13055. {
  13056. mtrace();
  13057. DEBUG_INFO("handleSignCertificateResponse...\n");
  13058. json_object *SignCertificate;
  13059. SignCertificate = json_tokener_parse(payload);
  13060. if(!is_error(SignCertificate))
  13061. {
  13062. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13063. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13064. }
  13065. json_object_put(SignCertificate);
  13066. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13067. }
  13068. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13069. {
  13070. mtrace();
  13071. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13072. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13073. }
  13074. //==========================================
  13075. // Handle Error routine
  13076. //==========================================
  13077. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13078. {
  13079. mtrace();
  13080. #ifdef SystemLogMessage
  13081. DEBUG_INFO("errorCode: %s\n", errorCode);
  13082. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13083. DEBUG_INFO("errorDetails: %s\n", payload);
  13084. #endif
  13085. }
  13086. //===============================================
  13087. // Common routine
  13088. //===============================================
  13089. int initialConfigurationTable(void)
  13090. {
  13091. //clock_t start_t, end_t, total_t;
  13092. FILE *fp;
  13093. FILE *outfile;
  13094. char str[512]={0};
  13095. char sstr[256]={0};
  13096. int c = 0;
  13097. char *loc;
  13098. int confVersion = 13;
  13099. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13100. //start_t = clock();
  13101. //printf("Starting of the program, start_t = %ld\n", start_t);
  13102. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13103. // Check configuration file size is correct
  13104. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13105. {
  13106. struct stat st;
  13107. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13108. if(st.st_size < 3100)
  13109. {
  13110. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13111. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13112. }
  13113. }
  13114. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13115. {
  13116. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13117. if(outfile == NULL)
  13118. {
  13119. DEBUG_INFO("Error opening file\n");
  13120. return FALSE;
  13121. }
  13122. /*Core Profile*/
  13123. //AllowOfflineTxForUnknownId
  13124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13128. //AuthorizationCacheEnabled
  13129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13133. //AuthorizeRemoteTxRequests
  13134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13138. //BlinkRepeat
  13139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13143. //ClockAlignedDataInterval
  13144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13148. //ConnectionTimeOut
  13149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13153. //GetConfigurationMaxKeys
  13154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13158. // HeartbeatInterval
  13159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13163. // LightIntensity
  13164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13168. // LocalAuthorizeOffline
  13169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13173. // LocalPreAuthorize
  13174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13178. // MaxEnergyOnInvalidId
  13179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13183. // MeterValuesAlignedData
  13184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13187. 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" );
  13188. else
  13189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13191. // MeterValuesAlignedDataMaxLength
  13192. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13196. else
  13197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13199. // MeterValuesSampledData
  13200. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13203. 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" );
  13204. else
  13205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13207. // MeterValuesSampledDataMaxLength
  13208. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13210. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13212. else
  13213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13215. // MeterValueSampleInterval
  13216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13220. // MinimumStatusDuration
  13221. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13224. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13226. // NumberOfConnectors
  13227. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13230. {
  13231. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13232. }
  13233. else
  13234. {
  13235. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13236. }
  13237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13238. // ResetRetries
  13239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13243. // ConnectorPhaseRotation
  13244. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13248. // ConnectorPhaseRotationMaxLength
  13249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13253. // StopTransactionOnEVSideDisconnect
  13254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13258. // StopTransactionOnInvalidId
  13259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13263. // StopTxnAlignedData
  13264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13268. // StopTxnAlignedDataMaxLength
  13269. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13273. // StopTxnSampledData
  13274. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13278. else
  13279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13281. // StopTxnSampledDataMaxLength
  13282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13285. {
  13286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13287. }
  13288. else
  13289. {
  13290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13291. }
  13292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13293. // SupportedFeatureProfiles
  13294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13298. // SupportedFeatureProfilesMaxLength
  13299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13303. // TransactionMessageAttempts
  13304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13307. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13309. // TransactionMessageRetryInterval
  13310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13313. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13315. // UnlockConnectorOnEVSideDisconnect
  13316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13320. // WebSocketPingInterval
  13321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13325. // QueueOffLineMeterValues
  13326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13330. // AuthorizationKey
  13331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13335. // SecurityProfile
  13336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13338. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13340. // DefaultPrice
  13341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13345. // CustomDisplayCostAndPrice
  13346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13350. // CustomIdleFeeAfterStop
  13351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13355. // SystemUptimeSec
  13356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13360. // FreeVend
  13361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13365. // FreeVendIdtag
  13366. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13370. // OcppServer
  13371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13373. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13375. // MaintainServer
  13376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13378. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13380. // StatusNotificationPeriodically
  13381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13385. // StatusNotificationInterval
  13386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13390. // Configuration Version
  13391. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13395. //* Local Auth List Management Profile*/
  13396. #if 0
  13397. //For OCTT Test Case
  13398. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13401. #endif
  13402. #if 1
  13403. //LocalAuthListEnabled
  13404. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13408. #endif
  13409. //LocalAuthListMaxLength
  13410. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13414. //SendLocalListMaxLength
  13415. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13419. //ReserveConnectorZeroSupported
  13420. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13424. //* Smart Charging Profile */
  13425. //ChargeProfileMaxStackLevel
  13426. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13430. // ChargingScheduleAllowedChargingRateUnit
  13431. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13435. // ChargingScheduleMaxPeriods
  13436. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13440. // ConnectorSwitch3to1PhaseSupported
  13441. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13445. // MaxChargingProfilesInstalled
  13446. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13450. fclose(outfile);
  13451. }
  13452. else
  13453. {
  13454. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13455. char keystr[60]={0};
  13456. char readonlystr[10]={0};
  13457. char valuestr[256]={0};
  13458. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13459. if(fp == NULL) {
  13460. DEBUG_INFO("Error opening file");
  13461. return FALSE;
  13462. }
  13463. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13464. {
  13465. //DEBUG_INFO("Get Configuration \n");
  13466. if(strlen(str) > 0)
  13467. {
  13468. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13469. //*************************key*********************************/
  13470. if(strstr(str, "key") != NULL)
  13471. {
  13472. loc = strstr(str, "key");
  13473. c = 0;
  13474. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13475. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13476. {
  13477. sstr[c] = loc[strlen("key")+3+c];
  13478. c++;
  13479. }
  13480. sstr[c] = '\0';
  13481. strcpy(keystr,sstr);
  13482. }
  13483. //*************************readonly*********************************/
  13484. if(strstr(str, "readonly") != NULL)
  13485. {
  13486. loc = strstr(str, "readonly");
  13487. c = 0;
  13488. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13489. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13490. {
  13491. sstr[c] = loc[strlen("readonly")+2+c];
  13492. c++;
  13493. }
  13494. sstr[c] = '\0';
  13495. strcpy(readonlystr,sstr);
  13496. }
  13497. //*************************value*********************************/
  13498. if(strstr(str, "value") != NULL)
  13499. {
  13500. loc = strstr(str, "value");
  13501. c = 0;
  13502. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13503. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13504. {
  13505. sstr[c] = loc[strlen("value")+3+c];
  13506. c++;
  13507. }
  13508. sstr[c] = '\0';
  13509. strcpy(valuestr,sstr);
  13510. }
  13511. // DEBUG_INFO("keystr=%s\n",keystr);
  13512. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13513. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13514. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13515. {
  13516. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13517. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13518. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13519. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13520. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13521. }
  13522. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13523. {
  13524. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13527. }
  13528. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13529. {
  13530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13532. }
  13533. if(strcmp(keystr, "BlinkRepeat") == 0)
  13534. {
  13535. //Charger.BlinkRepeat = Integer.parseInt(value);
  13536. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13538. }
  13539. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13540. {
  13541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13543. }
  13544. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13545. {
  13546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13548. }
  13549. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13550. {
  13551. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13553. }
  13554. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13555. {
  13556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13558. HeartBeatWaitTime = atoi(valuestr);
  13559. }
  13560. if(strcmp(keystr, "LightIntensity") == 0)
  13561. {
  13562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13564. }
  13565. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13566. {
  13567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13569. }
  13570. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13571. {
  13572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13573. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13574. }
  13575. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13576. {
  13577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13579. }
  13580. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13581. {
  13582. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13583. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13584. }
  13585. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13586. {
  13587. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13589. }
  13590. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13591. {
  13592. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13594. }
  13595. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13596. {
  13597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13599. }
  13600. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13601. {
  13602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13604. }
  13605. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13606. {
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13609. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13610. }
  13611. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13612. {
  13613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13614. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13615. }
  13616. if(strcmp(keystr, "ResetRetries") == 0)
  13617. {
  13618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13620. }
  13621. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13622. {
  13623. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13625. }
  13626. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13627. {
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13630. }
  13631. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13632. {
  13633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13635. }
  13636. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13637. {
  13638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13640. }
  13641. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13642. {
  13643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13645. }
  13646. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13647. {
  13648. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13649. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13650. }
  13651. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13652. {
  13653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13655. }
  13656. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13657. {
  13658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13660. }
  13661. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13662. {
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13665. }
  13666. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13667. {
  13668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13670. }
  13671. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13672. {
  13673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13675. TransactionMessageAttemptsValue = atoi(valuestr);
  13676. }
  13677. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13678. {
  13679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13681. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13682. }
  13683. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13684. {
  13685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13686. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13687. }
  13688. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13689. {
  13690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13692. }
  13693. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13694. {
  13695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13697. }
  13698. if(strcmp(keystr, "AuthorizationKey") == 0)
  13699. {
  13700. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13701. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13703. }
  13704. if(strcmp(keystr, "SecurityProfile") == 0)
  13705. {
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13707. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13709. }
  13710. if(strcmp(keystr, "DefaultPrice") == 0)
  13711. {
  13712. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13714. }
  13715. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13716. {
  13717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13719. }
  13720. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13721. {
  13722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13724. }
  13725. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13726. {
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13729. }
  13730. if(strcmp(keystr, "FreeVend") == 0)
  13731. {
  13732. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13734. }
  13735. if(strcmp(keystr, "FreeVendIdtag") == 0)
  13736. {
  13737. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13738. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  13739. }
  13740. if(strcmp(keystr, "OcppServer") == 0)
  13741. {
  13742. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13743. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13744. }
  13745. if(strcmp(keystr, "MaintainServer") == 0)
  13746. {
  13747. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13748. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13749. }
  13750. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13751. {
  13752. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13754. }
  13755. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13756. {
  13757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13758. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13759. }
  13760. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13761. {
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13764. }
  13765. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13766. {
  13767. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13768. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13769. }
  13770. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13771. {
  13772. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13774. }
  13775. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13776. {
  13777. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13778. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13779. }
  13780. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13781. {
  13782. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13784. }
  13785. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13786. {
  13787. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13789. }
  13790. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13791. {
  13792. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13794. }
  13795. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13796. {
  13797. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13798. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13799. }
  13800. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13801. {
  13802. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13804. }
  13805. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13806. {
  13807. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13809. }
  13810. }
  13811. }
  13812. fclose(fp);
  13813. }
  13814. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13815. {
  13816. return PASS;
  13817. }
  13818. else
  13819. {
  13820. return FAIL;
  13821. }
  13822. }
  13823. void StoreConfigurationTable(void)
  13824. {
  13825. FILE *outfile;
  13826. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13827. if(outfile == NULL)
  13828. {
  13829. DEBUG_INFO("Error opening file");
  13830. return ;
  13831. }
  13832. /*Core Profile*/
  13833. //AllowOfflineTxForUnknownId
  13834. /*
  13835. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13836. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13839. */
  13840. //DEBUG_INFO("data=%s\n",data);
  13841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13842. //AuthorizationCacheEnabled
  13843. /*
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13847. */
  13848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13849. //AuthorizeRemoteTxRequests
  13850. /*
  13851. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13854. */
  13855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13856. //BlinkRepeat
  13857. /*
  13858. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13861. */
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13863. //ClockAlignedDataInterval
  13864. /*
  13865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13868. */
  13869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13870. //ConnectionTimeOut
  13871. /*
  13872. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13875. */
  13876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13877. //GetConfigurationMaxKeys
  13878. /*
  13879. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13882. */
  13883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13884. // HeartbeatInterval
  13885. /*
  13886. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13889. */
  13890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13891. // LightIntensity
  13892. /*
  13893. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13896. */
  13897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13898. // LocalAuthorizeOffline
  13899. /*
  13900. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13903. */
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13905. // LocalPreAuthorize
  13906. /*
  13907. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13910. */
  13911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13912. // MaxEnergyOnInvalidId
  13913. /*
  13914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13917. */
  13918. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13920. // MeterValuesAlignedData
  13921. /*
  13922. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13925. */
  13926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13927. // MeterValuesAlignedDataMaxLength
  13928. /*
  13929. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13932. */
  13933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13934. // MeterValuesSampledData
  13935. /*
  13936. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13939. */
  13940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13941. // MeterValuesSampledDataMaxLength
  13942. /*
  13943. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13946. */
  13947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13948. // MeterValueSampleInterval
  13949. /*
  13950. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13953. */
  13954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13955. // MinimumStatusDuration
  13956. /*
  13957. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13960. */
  13961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13962. // NumberOfConnectors
  13963. /*
  13964. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13967. {
  13968. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13969. }
  13970. else
  13971. {
  13972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13973. }
  13974. */
  13975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13976. // ResetRetries
  13977. /*
  13978. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13981. */
  13982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13983. // ConnectorPhaseRotation
  13984. /*
  13985. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13988. */
  13989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13990. // ConnectorPhaseRotationMaxLength
  13991. /*
  13992. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13995. */
  13996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13997. // StopTransactionOnEVSideDisconnect
  13998. /*
  13999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14002. */
  14003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14004. // StopTransactionOnInvalidId
  14005. /*
  14006. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14009. */
  14010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14011. // StopTxnAlignedData
  14012. /*
  14013. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14016. */
  14017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14018. // StopTxnAlignedDataMaxLength
  14019. /*
  14020. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14023. */
  14024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14025. // StopTxnSampledData
  14026. /*
  14027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14030. */
  14031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14032. // StopTxnSampledDataMaxLength
  14033. /*
  14034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14037. */
  14038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14039. // SupportedFeatureProfiles
  14040. /*
  14041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14044. */
  14045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14046. // SupportedFeatureProfilesMaxLength
  14047. /*
  14048. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14051. */
  14052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14053. // TransactionMessageAttempts
  14054. /*
  14055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14058. */
  14059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14060. // TransactionMessageRetryInterval
  14061. /*
  14062. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14065. */
  14066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14067. // UnlockConnectorOnEVSideDisconnect
  14068. /*
  14069. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14072. */
  14073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14074. // WebSocketPingInterval
  14075. /*
  14076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14079. */
  14080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14081. // QueueOffLineMeterValues
  14082. /*
  14083. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14086. */
  14087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14088. // AuthorizationKey
  14089. /*
  14090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14093. */
  14094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14095. // SecurityProfile
  14096. /*
  14097. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14100. */
  14101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14102. // DefaultPrice
  14103. /*
  14104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14107. */
  14108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14109. // CustomDisplayCostAndPrice
  14110. /*
  14111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14114. */
  14115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14116. // CustomIdleFeeAfterStop
  14117. /*
  14118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14121. */
  14122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14123. // SystemUptimeSec
  14124. /*
  14125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14128. */
  14129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14130. // FreeVend
  14131. /*
  14132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14135. */
  14136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14137. // FreeVendIdtag
  14138. /*
  14139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14142. */
  14143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14144. // OcppServer
  14145. /*
  14146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14149. */
  14150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14151. // MaintainServer
  14152. /*
  14153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14156. */
  14157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14158. // StatusNotificationPeriodically
  14159. /*
  14160. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14163. */
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14165. // StatusNotificationInterval
  14166. /*
  14167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14170. */
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14172. // ConfigurationVersion
  14173. /*
  14174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14177. */
  14178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14179. //* Local Auth List Management Profile*/
  14180. //LocalAuthListEnabled
  14181. /*
  14182. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14185. */
  14186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14187. //LocalAuthListMaxLength
  14188. /*
  14189. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14192. */
  14193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14194. //SendLocalListMaxLength
  14195. /*
  14196. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14199. */
  14200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14201. //ReserveConnectorZeroSupported
  14202. /*
  14203. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14206. */
  14207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14208. //* Smart Charging Profile */
  14209. //ChargeProfileMaxStackLevel
  14210. /*
  14211. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14214. */
  14215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14216. // ChargingScheduleAllowedChargingRateUnit
  14217. /*
  14218. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14221. */
  14222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14223. // ChargingScheduleMaxPeriods
  14224. /*
  14225. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14228. */
  14229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14230. // ConnectorSwitch3to1PhaseSupported
  14231. /*
  14232. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14235. */
  14236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14237. // MaxChargingProfilesInstalled
  14238. /*
  14239. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14242. */
  14243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14244. fclose(outfile);
  14245. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14246. }
  14247. void getKeyValue(char *keyReq)
  14248. {
  14249. int isEmpty = FALSE;
  14250. int isKnowKey = FALSE;
  14251. DEBUG_INFO("keyReq = %s\n", keyReq);
  14252. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14253. isEmpty = TRUE;
  14254. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14255. {
  14256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14258. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14259. {
  14260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14261. }
  14262. else
  14263. {
  14264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14265. }
  14266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14267. isKnowKey = TRUE;
  14268. }
  14269. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14270. {
  14271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14273. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14274. {
  14275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14276. }
  14277. else
  14278. {
  14279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14280. }
  14281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14282. isKnowKey = TRUE;
  14283. }
  14284. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14285. {
  14286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14288. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14289. {
  14290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14291. }
  14292. else
  14293. {
  14294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14295. }
  14296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14297. isKnowKey = TRUE;
  14298. }
  14299. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14300. {
  14301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14304. {
  14305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14306. }
  14307. else
  14308. {
  14309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14310. }
  14311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14312. isKnowKey = TRUE;
  14313. }
  14314. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14315. {
  14316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14319. {
  14320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14321. }
  14322. else
  14323. {
  14324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14325. }
  14326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14327. isKnowKey = TRUE;
  14328. }
  14329. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14330. {
  14331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14333. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14334. {
  14335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14336. }
  14337. else
  14338. {
  14339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14340. }
  14341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14342. isKnowKey = TRUE;
  14343. }
  14344. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14345. {
  14346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14348. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14349. {
  14350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14351. }
  14352. else
  14353. {
  14354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14355. }
  14356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14357. isKnowKey = TRUE;
  14358. }
  14359. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14360. {
  14361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14363. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14364. {
  14365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14366. }
  14367. else
  14368. {
  14369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14370. }
  14371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14372. isKnowKey = TRUE;
  14373. }
  14374. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14375. {
  14376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14378. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14379. {
  14380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14381. }
  14382. else
  14383. {
  14384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14385. }
  14386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14387. isKnowKey = TRUE;
  14388. }
  14389. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14390. {
  14391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14394. {
  14395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14396. }
  14397. else
  14398. {
  14399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14400. }
  14401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14402. isKnowKey = TRUE;
  14403. }
  14404. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14405. {
  14406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14408. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14409. {
  14410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14411. }
  14412. else
  14413. {
  14414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14415. }
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14417. isKnowKey = TRUE;
  14418. }
  14419. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14420. {
  14421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14423. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14424. {
  14425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14426. }
  14427. else
  14428. {
  14429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14430. }
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14432. isKnowKey = TRUE;
  14433. }
  14434. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14435. {
  14436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14438. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14439. {
  14440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14441. }
  14442. else
  14443. {
  14444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14445. }
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14447. isKnowKey = TRUE;
  14448. }
  14449. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14450. {
  14451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14453. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14454. {
  14455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14456. }
  14457. else
  14458. {
  14459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14460. }
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14462. isKnowKey = TRUE;
  14463. }
  14464. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14465. {
  14466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14468. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14469. {
  14470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14471. }
  14472. else
  14473. {
  14474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14475. }
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14477. isKnowKey = TRUE;
  14478. }
  14479. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14480. {
  14481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14484. {
  14485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14486. }
  14487. else
  14488. {
  14489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14490. }
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14492. isKnowKey = TRUE;
  14493. }
  14494. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14495. {
  14496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14498. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14499. {
  14500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14501. }
  14502. else
  14503. {
  14504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14505. }
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14507. isKnowKey = TRUE;
  14508. }
  14509. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14510. {
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14513. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14514. {
  14515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14516. }
  14517. else
  14518. {
  14519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14520. }
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14522. isKnowKey = TRUE;
  14523. }
  14524. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14525. {
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14528. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14529. {
  14530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14531. }
  14532. else
  14533. {
  14534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14535. }
  14536. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14538. isKnowKey = TRUE;
  14539. }
  14540. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14541. {
  14542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14544. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14545. {
  14546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14547. }
  14548. else
  14549. {
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14551. }
  14552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14553. isKnowKey = TRUE;
  14554. }
  14555. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14556. {
  14557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14559. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14560. {
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14562. }
  14563. else
  14564. {
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14566. }
  14567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14568. isKnowKey = TRUE;
  14569. }
  14570. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14571. {
  14572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14574. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14575. {
  14576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14577. }
  14578. else
  14579. {
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14581. }
  14582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14583. isKnowKey = TRUE;
  14584. }
  14585. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14586. {
  14587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14589. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14590. {
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14592. }
  14593. else
  14594. {
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14596. }
  14597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14598. isKnowKey = TRUE;
  14599. }
  14600. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14601. {
  14602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14605. {
  14606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14607. }
  14608. else
  14609. {
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14611. }
  14612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14613. isKnowKey = TRUE;
  14614. }
  14615. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14616. {
  14617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14619. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14620. {
  14621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14622. }
  14623. else
  14624. {
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14626. }
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14628. isKnowKey = TRUE;
  14629. }
  14630. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14631. {
  14632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14634. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14635. {
  14636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14637. }
  14638. else
  14639. {
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14641. }
  14642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14643. isKnowKey = TRUE;
  14644. }
  14645. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14646. {
  14647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14649. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14650. {
  14651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14652. }
  14653. else
  14654. {
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14656. }
  14657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14658. isKnowKey = TRUE;
  14659. }
  14660. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14661. {
  14662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14664. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14665. {
  14666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14667. }
  14668. else
  14669. {
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14671. }
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14673. isKnowKey = TRUE;
  14674. }
  14675. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14676. {
  14677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14680. {
  14681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14682. }
  14683. else
  14684. {
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14686. }
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14688. isKnowKey = TRUE;
  14689. }
  14690. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14691. {
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14694. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14695. {
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14697. }
  14698. else
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14701. }
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14703. isKnowKey = TRUE;
  14704. }
  14705. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14706. {
  14707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14709. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14710. {
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14712. }
  14713. else
  14714. {
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14716. }
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14718. isKnowKey = TRUE;
  14719. }
  14720. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14721. {
  14722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14724. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14725. {
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14727. }
  14728. else
  14729. {
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14731. }
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14733. isKnowKey = TRUE;
  14734. }
  14735. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14736. {
  14737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14739. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14740. {
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14742. }
  14743. else
  14744. {
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14746. }
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14748. isKnowKey = TRUE;
  14749. }
  14750. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14751. {
  14752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14754. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14755. {
  14756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14757. }
  14758. else
  14759. {
  14760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14761. }
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14763. isKnowKey = TRUE;
  14764. }
  14765. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14766. {
  14767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14769. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14770. {
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14772. }
  14773. else
  14774. {
  14775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14776. }
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14778. isKnowKey = TRUE;
  14779. }
  14780. /*
  14781. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14782. {
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14785. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14786. {
  14787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14788. }
  14789. else
  14790. {
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14792. }
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14794. isKnowKey = TRUE;
  14795. }*/
  14796. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14797. {
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14800. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14801. {
  14802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14803. }
  14804. else
  14805. {
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14807. }
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14809. isKnowKey = TRUE;
  14810. }
  14811. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14812. {
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14815. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14816. {
  14817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14818. }
  14819. else
  14820. {
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14822. }
  14823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14824. isKnowKey = TRUE;
  14825. }
  14826. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14827. {
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14830. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14831. {
  14832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14833. }
  14834. else
  14835. {
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14837. }
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14839. isKnowKey = TRUE;
  14840. }
  14841. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14842. {
  14843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14845. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14846. {
  14847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14848. }
  14849. else
  14850. {
  14851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14852. }
  14853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14854. isKnowKey = TRUE;
  14855. }
  14856. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14857. {
  14858. struct sysinfo s_info;
  14859. int error = sysinfo(&s_info);
  14860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14862. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14863. {
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14865. }
  14866. else
  14867. {
  14868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14869. }
  14870. if(error != 0)
  14871. {
  14872. DEBUG_WARN("System uptime get error: %d\n", error);
  14873. }
  14874. else
  14875. {
  14876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14877. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14878. }
  14879. isKnowKey = TRUE;
  14880. }
  14881. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14882. {
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14885. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14886. {
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14888. }
  14889. else
  14890. {
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14892. }
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14894. isKnowKey = TRUE;
  14895. }
  14896. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  14897. {
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  14899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  14900. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  14903. }
  14904. else
  14905. {
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  14907. }
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14909. isKnowKey = TRUE;
  14910. }
  14911. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14912. {
  14913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14915. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14916. {
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14918. }
  14919. else
  14920. {
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14922. }
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14924. isKnowKey = TRUE;
  14925. }
  14926. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14927. {
  14928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14930. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14931. {
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14933. }
  14934. else
  14935. {
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14937. }
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14939. isKnowKey = TRUE;
  14940. }
  14941. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14942. {
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  14945. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  14946. {
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  14948. }
  14949. else
  14950. {
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  14952. }
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  14954. isKnowKey = TRUE;
  14955. }
  14956. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  14957. {
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  14959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  14960. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  14961. {
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  14963. }
  14964. else
  14965. {
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  14967. }
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  14969. isKnowKey = TRUE;
  14970. }
  14971. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14972. {
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14975. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14978. }
  14979. else
  14980. {
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14982. }
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14984. isKnowKey = TRUE;
  14985. }
  14986. #if 1
  14987. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14988. {
  14989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14991. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14992. {
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14994. }
  14995. else
  14996. {
  14997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14998. }
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15000. isKnowKey = TRUE;
  15001. }
  15002. #endif
  15003. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15004. {
  15005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15007. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15008. {
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15010. }
  15011. else
  15012. {
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15014. }
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15016. isKnowKey = TRUE;
  15017. }
  15018. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15019. {
  15020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15022. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15023. {
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15025. }
  15026. else
  15027. {
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15029. }
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15031. isKnowKey = TRUE;
  15032. }
  15033. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15034. {
  15035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15037. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15038. {
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15040. }
  15041. else
  15042. {
  15043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15044. }
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15046. isKnowKey = TRUE;
  15047. }
  15048. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15049. {
  15050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15052. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15053. {
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15055. }
  15056. else
  15057. {
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15059. }
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15061. isKnowKey = TRUE;
  15062. }
  15063. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15064. {
  15065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15067. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15068. {
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15070. }
  15071. else
  15072. {
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15074. }
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15076. isKnowKey = TRUE;
  15077. }
  15078. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15079. {
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15082. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15083. {
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15085. }
  15086. else
  15087. {
  15088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15089. }
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15091. isKnowKey = TRUE;
  15092. }
  15093. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15094. {
  15095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15097. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15098. {
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15100. }
  15101. else
  15102. {
  15103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15104. }
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15106. isKnowKey = TRUE;
  15107. }
  15108. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15109. {
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15112. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15113. {
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15115. }
  15116. else
  15117. {
  15118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15119. }
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15121. isKnowKey = TRUE;
  15122. }
  15123. //=========================================================
  15124. if(!isEmpty && !isKnowKey)
  15125. {
  15126. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15127. strcpy(unknownkey[UnknownKeynum], keyReq);
  15128. UnknownKeynum = UnknownKeynum + 1;
  15129. }
  15130. }
  15131. void processUnkownKey(void)
  15132. {
  15133. DEBUG_INFO("processUnkownKey...\n");
  15134. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15135. for(int index=0; index < UnknownKeynum; index++)
  15136. {
  15137. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15138. {
  15139. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15140. }
  15141. }
  15142. }
  15143. int setKeyValue(char *key, char *value)
  15144. {
  15145. int isSuccess = NotSupported;
  15146. int check_ascii=0;
  15147. char str[501]={0};
  15148. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15149. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15150. {
  15151. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15152. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15153. {
  15154. strcpy(str, (const char*)value);
  15155. for(int i = 0; str[i]; i++){
  15156. str[i] = tolower(str[i]);
  15157. }
  15158. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15159. isSuccess = ConfigurationStatus_Accepted;
  15160. }
  15161. else
  15162. {
  15163. isSuccess = ConfigurationStatus_Rejected;
  15164. }
  15165. }
  15166. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15167. {
  15168. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15169. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15170. {
  15171. strcpy(str, (const char*)value);
  15172. for(int i = 0; str[i]; i++){
  15173. str[i] = tolower(str[i]);
  15174. }
  15175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15176. isSuccess = ConfigurationStatus_Accepted;
  15177. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15178. }
  15179. else
  15180. {
  15181. isSuccess = ConfigurationStatus_Rejected;
  15182. }
  15183. }
  15184. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15185. {
  15186. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15187. {
  15188. strcpy(str, (const char*)value);
  15189. for(int i = 0; str[i]; i++)
  15190. {
  15191. str[i] = tolower(str[i]);
  15192. }
  15193. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15194. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15195. isSuccess = ConfigurationStatus_Accepted;
  15196. }
  15197. else
  15198. {
  15199. isSuccess = ConfigurationStatus_Rejected;
  15200. }
  15201. }
  15202. if(strcmp(key, "BlinkRepeat") == 0)
  15203. {
  15204. //Charger.BlinkRepeat = Integer.parseInt(value);
  15205. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15206. {
  15207. check_ascii = value[0];
  15208. if( (check_ascii < 48) || (check_ascii > 57) )
  15209. {
  15210. isSuccess = ConfigurationStatus_Rejected;
  15211. }
  15212. else
  15213. {
  15214. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15215. isSuccess = ConfigurationStatus_Accepted;
  15216. }
  15217. }
  15218. else
  15219. {
  15220. isSuccess = ConfigurationStatus_Rejected;
  15221. }
  15222. }
  15223. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15224. {
  15225. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15226. {
  15227. check_ascii = value[0];
  15228. if( (check_ascii < 48) || (check_ascii > 57) )
  15229. {
  15230. isSuccess = ConfigurationStatus_Rejected;
  15231. }
  15232. else
  15233. {
  15234. if((atoi(value) == 0) || (atoi(value) >= 5))
  15235. {
  15236. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15237. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15238. isSuccess = ConfigurationStatus_Accepted;
  15239. }
  15240. else
  15241. isSuccess = ConfigurationStatus_Rejected;
  15242. }
  15243. }
  15244. else
  15245. {
  15246. isSuccess = ConfigurationStatus_Rejected;
  15247. }
  15248. }
  15249. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15250. {
  15251. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15252. {
  15253. check_ascii = value[0];
  15254. if( (check_ascii < 48) || (check_ascii > 57) )
  15255. {
  15256. isSuccess = ConfigurationStatus_Rejected;
  15257. }
  15258. else
  15259. {
  15260. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15262. isSuccess = ConfigurationStatus_Accepted;
  15263. }
  15264. }
  15265. else
  15266. {
  15267. isSuccess = ConfigurationStatus_Rejected;
  15268. }
  15269. }
  15270. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15271. {
  15272. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15273. {
  15274. check_ascii = value[0];
  15275. if( (check_ascii < 48) || (check_ascii > 57) )
  15276. {
  15277. isSuccess = ConfigurationStatus_Rejected;
  15278. }
  15279. else
  15280. {
  15281. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15283. isSuccess = ConfigurationStatus_Accepted;
  15284. }
  15285. }
  15286. else
  15287. {
  15288. isSuccess = ConfigurationStatus_Rejected;
  15289. }
  15290. }
  15291. if(strcmp(key, "HeartbeatInterval") == 0)
  15292. {
  15293. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15294. {
  15295. check_ascii = value[0];
  15296. if( (check_ascii < 48) || (check_ascii > 57) )
  15297. {
  15298. isSuccess = ConfigurationStatus_Rejected;
  15299. }
  15300. else
  15301. {
  15302. if((atoi(value) == 0) || (atoi(value) >= 10))
  15303. {
  15304. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15306. HeartBeatWaitTime = atoi(value);
  15307. isSuccess = ConfigurationStatus_Accepted;
  15308. }
  15309. else
  15310. {
  15311. isSuccess = ConfigurationStatus_Rejected;
  15312. }
  15313. }
  15314. }
  15315. else
  15316. {
  15317. isSuccess = ConfigurationStatus_Rejected;
  15318. }
  15319. }
  15320. if(strcmp(key, "LightIntensity") == 0)
  15321. {
  15322. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15323. {
  15324. check_ascii = value[0];
  15325. if( (check_ascii < 48) || (check_ascii > 57) )
  15326. {
  15327. isSuccess = ConfigurationStatus_Rejected;
  15328. }
  15329. else
  15330. {
  15331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15332. isSuccess = ConfigurationStatus_Accepted;
  15333. }
  15334. }
  15335. else
  15336. {
  15337. isSuccess = ConfigurationStatus_Rejected;
  15338. }
  15339. }
  15340. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15341. {
  15342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15343. {
  15344. strcpy(str, (const char*)value);
  15345. for(int i = 0; str[i]; i++)
  15346. {
  15347. str[i] = tolower(str[i]);
  15348. }
  15349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15350. isSuccess = ConfigurationStatus_Accepted;
  15351. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15352. }
  15353. else
  15354. {
  15355. isSuccess = ConfigurationStatus_Rejected;
  15356. }
  15357. }
  15358. if(strcmp(key, "LocalPreAuthorize") == 0)
  15359. {
  15360. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15361. {
  15362. strcpy(str, (const char*)value);
  15363. for(int i = 0; str[i]; i++)
  15364. {
  15365. str[i] = tolower(str[i]);
  15366. }
  15367. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15368. isSuccess = ConfigurationStatus_Accepted;
  15369. }
  15370. else
  15371. {
  15372. isSuccess = ConfigurationStatus_Rejected;
  15373. }
  15374. }
  15375. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15376. {
  15377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15378. {
  15379. check_ascii = value[0];
  15380. if( (check_ascii < 48) || (check_ascii > 57) )
  15381. {
  15382. isSuccess = ConfigurationStatus_Rejected;
  15383. }
  15384. else
  15385. {
  15386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15387. isSuccess = ConfigurationStatus_Accepted;
  15388. }
  15389. }
  15390. else
  15391. {
  15392. isSuccess = ConfigurationStatus_Rejected;
  15393. }
  15394. }
  15395. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15396. {
  15397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15398. {
  15399. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15400. isSuccess = ConfigurationStatus_Accepted;
  15401. }
  15402. else
  15403. {
  15404. isSuccess = ConfigurationStatus_Rejected;
  15405. }
  15406. }
  15407. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15408. {
  15409. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15410. {
  15411. check_ascii = value[0];
  15412. if( (check_ascii < 48) || (check_ascii > 57) )
  15413. {
  15414. isSuccess = ConfigurationStatus_Rejected;
  15415. }
  15416. else
  15417. {
  15418. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15419. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15420. isSuccess = ConfigurationStatus_Accepted;
  15421. }
  15422. }
  15423. else
  15424. {
  15425. isSuccess = ConfigurationStatus_Rejected;
  15426. }
  15427. }
  15428. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15429. {
  15430. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15431. {
  15432. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15433. isSuccess = ConfigurationStatus_Accepted;
  15434. }
  15435. else
  15436. {
  15437. isSuccess = ConfigurationStatus_Rejected;
  15438. }
  15439. }
  15440. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15441. {
  15442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].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.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15452. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15453. isSuccess = ConfigurationStatus_Accepted;
  15454. }
  15455. }
  15456. else
  15457. {
  15458. isSuccess = ConfigurationStatus_Rejected;
  15459. }
  15460. }
  15461. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15462. {
  15463. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].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) >= 3))
  15473. {
  15474. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15475. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15476. isSuccess = ConfigurationStatus_Accepted;
  15477. }
  15478. else
  15479. {
  15480. isSuccess = ConfigurationStatus_Rejected;
  15481. }
  15482. }
  15483. }
  15484. else
  15485. {
  15486. isSuccess = ConfigurationStatus_Rejected;
  15487. }
  15488. }
  15489. if(strcmp(key, "MinimumStatusDuration") == 0)
  15490. {
  15491. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15492. {
  15493. check_ascii = value[0];
  15494. if( (check_ascii < 48) || (check_ascii > 57) )
  15495. {
  15496. isSuccess = ConfigurationStatus_Rejected;
  15497. }
  15498. else
  15499. {
  15500. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15501. {
  15502. isSuccess = ConfigurationStatus_Rejected;
  15503. }
  15504. else
  15505. {
  15506. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15507. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15508. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15509. isSuccess = ConfigurationStatus_Accepted;
  15510. }
  15511. }
  15512. }
  15513. else
  15514. {
  15515. isSuccess = ConfigurationStatus_Rejected;
  15516. }
  15517. }
  15518. if(strcmp(key, "NumberOfConnectors") == 0)
  15519. {
  15520. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15521. {
  15522. check_ascii = value[0];
  15523. if( (check_ascii < 48) || (check_ascii > 57) )
  15524. {
  15525. isSuccess = ConfigurationStatus_Rejected;
  15526. }
  15527. else
  15528. {
  15529. //Charger.ResetRetries = Integer.parseInt(value);
  15530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15531. isSuccess = ConfigurationStatus_Accepted;
  15532. }
  15533. }
  15534. else
  15535. {
  15536. isSuccess = ConfigurationStatus_Rejected;
  15537. }
  15538. }
  15539. if(strcmp(key, "ResetRetries") == 0)
  15540. {
  15541. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15542. {
  15543. check_ascii = value[0];
  15544. if( (check_ascii < 48) || (check_ascii > 57) )
  15545. {
  15546. isSuccess = ConfigurationStatus_Rejected;
  15547. }
  15548. else
  15549. {
  15550. //Charger.ResetRetries = Integer.parseInt(value);
  15551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15552. isSuccess = ConfigurationStatus_Accepted;
  15553. }
  15554. }
  15555. else
  15556. {
  15557. isSuccess = ConfigurationStatus_Rejected;
  15558. }
  15559. }
  15560. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15561. {
  15562. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15563. {
  15564. strcpy(str, (const char*)value);
  15565. for(int i = 0; str[i]; i++)
  15566. {
  15567. str[i] = tolower(str[i]);
  15568. }
  15569. if(strcmp(str, "notapplicable")== 0)
  15570. {
  15571. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15572. isSuccess = ConfigurationStatus_Accepted;
  15573. }
  15574. else if(strcmp(str, "unknown")== 0)
  15575. {
  15576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15577. isSuccess = ConfigurationStatus_Accepted;
  15578. }
  15579. else if(strcmp(str, "rst")== 0)
  15580. {
  15581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15582. isSuccess = ConfigurationStatus_Accepted;
  15583. }
  15584. else if(strcmp(str, "rts")== 0)
  15585. {
  15586. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15587. isSuccess = ConfigurationStatus_Accepted;
  15588. }
  15589. else if(strcmp(str, "srt")== 0)
  15590. {
  15591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15592. isSuccess = ConfigurationStatus_Accepted;
  15593. }
  15594. else if(strcmp(str, "str")== 0)
  15595. {
  15596. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15597. isSuccess = ConfigurationStatus_Accepted;
  15598. }
  15599. else if(strcmp(str, "trs")== 0)
  15600. {
  15601. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15602. isSuccess = ConfigurationStatus_Accepted;
  15603. }
  15604. else if(strcmp(str, "tsr")== 0)
  15605. {
  15606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15607. isSuccess = ConfigurationStatus_Accepted;
  15608. }
  15609. else
  15610. {
  15611. isSuccess = ConfigurationStatus_Rejected;
  15612. }
  15613. }
  15614. else
  15615. {
  15616. isSuccess = ConfigurationStatus_Rejected;
  15617. }
  15618. }
  15619. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15620. {
  15621. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15622. {
  15623. check_ascii = value[0];
  15624. if( (check_ascii < 48) || (check_ascii > 57) )
  15625. {
  15626. isSuccess = ConfigurationStatus_Rejected;
  15627. }
  15628. else
  15629. {
  15630. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15631. isSuccess = ConfigurationStatus_Accepted;
  15632. }
  15633. }
  15634. else
  15635. {
  15636. isSuccess = ConfigurationStatus_Rejected;
  15637. }
  15638. }
  15639. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15640. {
  15641. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15642. {
  15643. strcpy(str, (const char*)value);
  15644. for(int i = 0; str[i]; i++)
  15645. {
  15646. str[i] = tolower(str[i]);
  15647. }
  15648. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15649. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15650. isSuccess = ConfigurationStatus_Accepted;
  15651. }
  15652. else
  15653. {
  15654. isSuccess = ConfigurationStatus_Rejected;
  15655. }
  15656. }
  15657. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15658. {
  15659. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15660. {
  15661. strcpy(str, (const char*)value);
  15662. for(int i = 0; str[i]; i++)
  15663. {
  15664. str[i] = tolower(str[i]);
  15665. }
  15666. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15667. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15668. isSuccess = ConfigurationStatus_Accepted;
  15669. }
  15670. else
  15671. {
  15672. isSuccess = ConfigurationStatus_Rejected;
  15673. }
  15674. }
  15675. if(strcmp(key, "StopTxnAlignedData") == 0)
  15676. {
  15677. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15678. {
  15679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15680. isSuccess = ConfigurationStatus_Accepted;
  15681. }
  15682. else
  15683. {
  15684. isSuccess = ConfigurationStatus_Rejected;
  15685. }
  15686. }
  15687. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15688. {
  15689. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15690. {
  15691. check_ascii = value[0];
  15692. if( (check_ascii < 48) || (check_ascii > 57) )
  15693. {
  15694. isSuccess = ConfigurationStatus_Rejected;
  15695. }
  15696. else
  15697. {
  15698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15699. isSuccess = ConfigurationStatus_Accepted;
  15700. }
  15701. }
  15702. else
  15703. {
  15704. isSuccess = ConfigurationStatus_Rejected;
  15705. }
  15706. }
  15707. if(strcmp(key, "StopTxnSampledData") == 0)
  15708. {
  15709. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15710. {
  15711. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15712. isSuccess = ConfigurationStatus_Accepted;
  15713. }
  15714. else
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. }
  15719. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15720. {
  15721. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15722. {
  15723. check_ascii = value[0];
  15724. if( (check_ascii < 48) || (check_ascii > 57) )
  15725. {
  15726. isSuccess = ConfigurationStatus_Rejected;
  15727. }
  15728. else
  15729. {
  15730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15731. isSuccess = ConfigurationStatus_Accepted;
  15732. }
  15733. }
  15734. else
  15735. {
  15736. isSuccess = ConfigurationStatus_Rejected;
  15737. }
  15738. }
  15739. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15740. {
  15741. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15742. {
  15743. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15744. isSuccess = ConfigurationStatus_Accepted;
  15745. }
  15746. else
  15747. {
  15748. isSuccess = ConfigurationStatus_Rejected;
  15749. }
  15750. }
  15751. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15752. {
  15753. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15754. {
  15755. check_ascii = value[0];
  15756. if( (check_ascii < 48) || (check_ascii > 57) )
  15757. {
  15758. isSuccess = ConfigurationStatus_Rejected;
  15759. }
  15760. else
  15761. {
  15762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15763. isSuccess = ConfigurationStatus_Accepted;
  15764. }
  15765. }
  15766. else
  15767. {
  15768. isSuccess = ConfigurationStatus_Rejected;
  15769. }
  15770. }
  15771. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15772. {
  15773. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15774. {
  15775. check_ascii = value[0];
  15776. if( (check_ascii < 48) || (check_ascii > 57) )
  15777. {
  15778. isSuccess = ConfigurationStatus_Rejected;
  15779. }
  15780. else
  15781. {
  15782. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15784. TransactionMessageAttemptsValue = atoi(value);
  15785. isSuccess = ConfigurationStatus_Accepted;
  15786. }
  15787. }
  15788. else
  15789. {
  15790. isSuccess = ConfigurationStatus_Rejected;
  15791. }
  15792. }
  15793. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15794. {
  15795. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15796. {
  15797. check_ascii = value[0];
  15798. if( (check_ascii < 48) || (check_ascii > 57) )
  15799. {
  15800. isSuccess = ConfigurationStatus_Rejected;
  15801. }
  15802. else
  15803. {
  15804. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15806. TransactionMessageRetryIntervalValue = atoi(value);
  15807. isSuccess = ConfigurationStatus_Accepted;
  15808. }
  15809. }
  15810. else
  15811. {
  15812. isSuccess = ConfigurationStatus_Rejected;
  15813. }
  15814. }
  15815. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15816. {
  15817. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15818. {
  15819. strcpy(str, (const char*)value);
  15820. for(int i = 0; str[i]; i++)
  15821. {
  15822. str[i] = tolower(str[i]);
  15823. }
  15824. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15825. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15826. isSuccess = ConfigurationStatus_Accepted;
  15827. }
  15828. else
  15829. {
  15830. isSuccess = ConfigurationStatus_Rejected;
  15831. }
  15832. }
  15833. if(strcmp(key, "WebSocketPingInterval") == 0)
  15834. {
  15835. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15836. {
  15837. check_ascii = value[0];
  15838. if( (check_ascii < 48) || (check_ascii > 57) )
  15839. {
  15840. isSuccess = ConfigurationStatus_Rejected;
  15841. }
  15842. else
  15843. {
  15844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15845. isSuccess = ConfigurationStatus_Accepted;
  15846. if((atoi(value) == 0) || (atoi(value) >= 10))
  15847. {
  15848. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15849. isSuccess = ConfigurationStatus_Accepted;
  15850. }
  15851. else
  15852. isSuccess = ConfigurationStatus_Rejected;
  15853. }
  15854. }
  15855. else
  15856. {
  15857. isSuccess = ConfigurationStatus_Rejected;
  15858. }
  15859. }
  15860. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15861. {
  15862. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15863. {
  15864. strcpy(str, (const char*)value);
  15865. for(int i = 0; str[i]; i++)
  15866. {
  15867. str[i] = tolower(str[i]);
  15868. }
  15869. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15870. isSuccess = ConfigurationStatus_Accepted;
  15871. }
  15872. else
  15873. {
  15874. isSuccess = ConfigurationStatus_Rejected;
  15875. }
  15876. }
  15877. if(strcmp(key, "AuthorizationKey") == 0)
  15878. {
  15879. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15880. {
  15881. strcpy(str, (const char*)value);
  15882. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15883. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15884. isSuccess = ConfigurationStatus_Accepted;
  15885. }
  15886. else
  15887. {
  15888. isSuccess = ConfigurationStatus_Rejected;
  15889. }
  15890. }
  15891. if(strcmp(key, "SecurityProfile") == 0)
  15892. {
  15893. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15894. {
  15895. check_ascii = value[0];
  15896. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15897. {
  15898. isSuccess = ConfigurationStatus_Rejected;
  15899. }
  15900. else if(check_ascii == 0x33)
  15901. {
  15902. isSuccess = NotSupported;
  15903. }
  15904. else
  15905. {
  15906. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15907. {
  15908. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15909. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15910. isSuccess = ConfigurationStatus_Accepted;
  15911. }
  15912. else
  15913. isSuccess = ConfigurationStatus_Rejected;
  15914. }
  15915. }
  15916. else
  15917. {
  15918. isSuccess = ConfigurationStatus_Rejected;
  15919. }
  15920. }
  15921. if(strcmp(key, "DefaultPrice") == 0)
  15922. {
  15923. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15924. {
  15925. strcpy(str, (const char*)value);
  15926. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15927. isSuccess = ConfigurationStatus_Accepted;
  15928. }
  15929. else
  15930. {
  15931. isSuccess = ConfigurationStatus_Rejected;
  15932. }
  15933. }
  15934. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15935. {
  15936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15937. {
  15938. strcpy(str, (const char*)value);
  15939. for(int i = 0; str[i]; i++)
  15940. {
  15941. str[i] = tolower(str[i]);
  15942. }
  15943. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15944. isSuccess = ConfigurationStatus_Accepted;
  15945. }
  15946. else
  15947. {
  15948. isSuccess = ConfigurationStatus_Rejected;
  15949. }
  15950. }
  15951. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15952. {
  15953. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15954. {
  15955. strcpy(str, (const char*)value);
  15956. for(int i = 0; str[i]; i++)
  15957. {
  15958. str[i] = tolower(str[i]);
  15959. }
  15960. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15961. isSuccess = ConfigurationStatus_Accepted;
  15962. }
  15963. else
  15964. {
  15965. isSuccess = ConfigurationStatus_Rejected;
  15966. }
  15967. }
  15968. if(strcmp(key, "SystemUptimeSec") == 0)
  15969. {
  15970. isSuccess = NotSupported;
  15971. }
  15972. if(strcmp(key, "FreeVend") == 0)
  15973. {
  15974. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15975. {
  15976. strcpy(str, (const char*)value);
  15977. for(int i = 0; str[i]; i++)
  15978. {
  15979. str[i] = tolower(str[i]);
  15980. }
  15981. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15982. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15983. isSuccess = ConfigurationStatus_Accepted;
  15984. }
  15985. else
  15986. {
  15987. isSuccess = ConfigurationStatus_Rejected;
  15988. }
  15989. }
  15990. if(strcmp(key, "FreeVendIdtag") == 0)
  15991. {
  15992. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15993. {
  15994. strcpy(str, (const char*)value);
  15995. if(strlen(str) <= 20)
  15996. {
  15997. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  15998. isSuccess = ConfigurationStatus_Accepted;
  15999. }
  16000. else
  16001. {
  16002. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. }
  16006. else
  16007. {
  16008. isSuccess = ConfigurationStatus_Rejected;
  16009. }
  16010. }
  16011. if(strcmp(key, "OcppServer") == 0)
  16012. {
  16013. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16014. {
  16015. strcpy(str, (const char*)value);
  16016. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16017. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16018. isSuccess = ConfigurationStatus_Accepted;
  16019. }
  16020. else
  16021. {
  16022. isSuccess = ConfigurationStatus_Rejected;
  16023. }
  16024. }
  16025. if(strcmp(key, "MaintainServer") == 0)
  16026. {
  16027. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16028. {
  16029. strcpy(str, (const char*)value);
  16030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16031. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16032. isSuccess = ConfigurationStatus_Accepted;
  16033. }
  16034. else
  16035. {
  16036. isSuccess = ConfigurationStatus_Rejected;
  16037. }
  16038. }
  16039. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16040. {
  16041. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16042. {
  16043. strcpy(str, (const char*)value);
  16044. for(int i = 0; str[i]; i++)
  16045. {
  16046. str[i] = tolower(str[i]);
  16047. }
  16048. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16049. isSuccess = ConfigurationStatus_Accepted;
  16050. }
  16051. else
  16052. {
  16053. isSuccess = ConfigurationStatus_Rejected;
  16054. }
  16055. }
  16056. if(strcmp(key, "StatusNotificationInterval") == 0)
  16057. {
  16058. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16059. {
  16060. check_ascii = value[0];
  16061. if( (check_ascii < 48) || (check_ascii > 57) )
  16062. {
  16063. isSuccess = ConfigurationStatus_Rejected;
  16064. }
  16065. else
  16066. {
  16067. if((atoi(value) == 0) || (atoi(value) >= 10))
  16068. {
  16069. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16070. isSuccess = ConfigurationStatus_Accepted;
  16071. }
  16072. else
  16073. isSuccess = ConfigurationStatus_Rejected;
  16074. }
  16075. }
  16076. else
  16077. {
  16078. isSuccess = ConfigurationStatus_Rejected;
  16079. }
  16080. }
  16081. #if 0
  16082. //For OCPP Test Case
  16083. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16084. {
  16085. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16086. {
  16087. strcpy(str, (const char*)value);
  16088. for(int i = 0; str[i]; i++)
  16089. {
  16090. str[i] = tolower(str[i]);
  16091. }
  16092. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16093. isSuccess = ConfigurationStatus_Accepted;
  16094. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16095. }
  16096. else
  16097. {
  16098. isSuccess = ConfigurationStatus_Rejected;
  16099. }
  16100. }
  16101. #endif
  16102. #if 1
  16103. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16104. {
  16105. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16106. {
  16107. strcpy(str, (const char*)value);
  16108. for(int i = 0; str[i]; i++)
  16109. {
  16110. str[i] = tolower(str[i]);
  16111. }
  16112. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16113. isSuccess = ConfigurationStatus_Accepted;
  16114. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16115. }
  16116. else
  16117. {
  16118. isSuccess = ConfigurationStatus_Rejected;
  16119. }
  16120. }
  16121. #endif
  16122. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16123. {
  16124. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16125. {
  16126. check_ascii = value[0];
  16127. if( (check_ascii < 48) || (check_ascii > 57) )
  16128. {
  16129. isSuccess = ConfigurationStatus_Rejected;
  16130. }
  16131. else
  16132. {
  16133. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16134. isSuccess = ConfigurationStatus_Accepted;
  16135. }
  16136. }
  16137. else
  16138. {
  16139. isSuccess = ConfigurationStatus_Rejected;
  16140. }
  16141. }
  16142. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16143. {
  16144. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16145. {
  16146. check_ascii = value[0];
  16147. if( (check_ascii < 48) || (check_ascii > 57) )
  16148. {
  16149. isSuccess = ConfigurationStatus_Rejected;
  16150. }
  16151. else
  16152. {
  16153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16154. isSuccess = ConfigurationStatus_Accepted;
  16155. }
  16156. }
  16157. else
  16158. {
  16159. isSuccess = ConfigurationStatus_Rejected;
  16160. }
  16161. }
  16162. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16163. {
  16164. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16165. {
  16166. strcpy(str, (const char*)value);
  16167. for(int i = 0; str[i]; i++)
  16168. {
  16169. str[i] = tolower(str[i]);
  16170. }
  16171. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16172. isSuccess = ConfigurationStatus_Accepted;
  16173. }
  16174. else
  16175. {
  16176. isSuccess = ConfigurationStatus_Rejected;
  16177. }
  16178. }
  16179. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16180. {
  16181. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16182. {
  16183. check_ascii = value[0];
  16184. if( (check_ascii < 48) || (check_ascii > 57) )
  16185. {
  16186. isSuccess = ConfigurationStatus_Rejected;
  16187. }
  16188. else
  16189. {
  16190. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16191. isSuccess = ConfigurationStatus_Accepted;
  16192. }
  16193. }
  16194. else
  16195. {
  16196. isSuccess = ConfigurationStatus_Rejected;
  16197. }
  16198. }
  16199. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16200. {
  16201. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16202. {
  16203. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16204. isSuccess = ConfigurationStatus_Accepted;
  16205. }
  16206. else
  16207. {
  16208. isSuccess = ConfigurationStatus_Rejected;
  16209. }
  16210. }
  16211. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16212. {
  16213. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16214. {
  16215. check_ascii = value[0];
  16216. if( (check_ascii < 48) || (check_ascii > 57) )
  16217. {
  16218. isSuccess = ConfigurationStatus_Rejected;
  16219. }
  16220. else
  16221. {
  16222. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16223. isSuccess = ConfigurationStatus_Accepted;
  16224. }
  16225. }
  16226. else
  16227. {
  16228. isSuccess = ConfigurationStatus_Rejected;
  16229. }
  16230. }
  16231. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16232. {
  16233. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16234. {
  16235. strcpy(str, (const char*)value);
  16236. for(int i = 0; str[i]; i++)
  16237. {
  16238. str[i] = tolower(str[i]);
  16239. }
  16240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16241. isSuccess = ConfigurationStatus_Accepted;
  16242. }
  16243. else
  16244. {
  16245. isSuccess = ConfigurationStatus_Rejected;
  16246. }
  16247. }
  16248. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16249. {
  16250. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16251. {
  16252. check_ascii = value[0];
  16253. if( (check_ascii < 48) || (check_ascii > 57) )
  16254. {
  16255. isSuccess = ConfigurationStatus_Rejected;
  16256. }
  16257. else
  16258. {
  16259. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16260. isSuccess = ConfigurationStatus_Accepted;
  16261. }
  16262. }
  16263. else
  16264. {
  16265. isSuccess = ConfigurationStatus_Rejected;
  16266. }
  16267. }
  16268. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16269. return isSuccess;
  16270. }
  16271. int TransactionMessageAttemptsGet(void)
  16272. {
  16273. return TransactionMessageAttemptsValue;
  16274. }
  16275. int FirstHeartBeatResponse(void)
  16276. {
  16277. return FirstHeartBeat;
  16278. }
  16279. int TransactionMessageRetryIntervalGet(void)
  16280. {
  16281. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16282. }
  16283. int ReadHttpStatus(int sock)
  16284. {
  16285. //char c;
  16286. char buff[1024]="",*ptr=buff+1;
  16287. int bytes_received, status;
  16288. DEBUG_INFO("Begin Response ..\n");
  16289. while((bytes_received = recv(sock, ptr, 1, 0))){
  16290. if(bytes_received==-1){
  16291. perror("ReadHttpStatus");
  16292. exit(1);
  16293. }
  16294. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16295. ptr++;
  16296. }
  16297. *ptr=0;
  16298. ptr=buff+1;
  16299. sscanf(ptr,"%*s %d ", &status);
  16300. DEBUG_INFO("%s\n",ptr);
  16301. DEBUG_INFO("status=%d\n",status);
  16302. DEBUG_INFO("End Response ..\n");
  16303. return (bytes_received>0)?status:0;
  16304. }
  16305. //the only filed that it parsed is 'Content-Length'
  16306. int ParseHeader(int sock)
  16307. {
  16308. //char c;
  16309. char buff[1024]="",*ptr=buff+4;
  16310. int bytes_received;
  16311. DEBUG_INFO("Begin HEADER ..\n");
  16312. while((bytes_received = recv(sock, ptr, 1, 0))){
  16313. if(bytes_received==-1){
  16314. perror("Parse Header");
  16315. exit(1);
  16316. }
  16317. if(
  16318. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16319. (ptr[-1]=='\r') && (*ptr=='\n' )
  16320. ) break;
  16321. ptr++;
  16322. }
  16323. *ptr=0;
  16324. ptr=buff+4;
  16325. //printf("%s",ptr);
  16326. if(bytes_received){
  16327. ptr=strstr(ptr,"Content-Length:");
  16328. if(ptr){
  16329. sscanf(ptr,"%*s %d",&bytes_received);
  16330. }else
  16331. bytes_received=-1; //unknown size
  16332. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16333. }
  16334. DEBUG_INFO("End HEADER ..\n");
  16335. return bytes_received ;
  16336. }
  16337. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16338. {
  16339. int result = TRUE;
  16340. char rmFileCmd[100]={0};
  16341. char FilePath[100]={0};
  16342. char ftpbuf[200];
  16343. int systemresult;
  16344. sprintf(FilePath,"/mnt/%s",filename);
  16345. system("ping 8.8.8.8 &");
  16346. if((access(FilePath,F_OK))!=-1)
  16347. {
  16348. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16349. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16350. system(rmFileCmd);
  16351. }
  16352. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16353. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16354. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16355. systemresult = system(ftpbuf);
  16356. if(systemresult != 0)
  16357. {
  16358. DEBUG_INFO("http DownLoad error!\n");
  16359. result = FALSE;
  16360. }
  16361. system("pkill ping");
  16362. return result;
  16363. }
  16364. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16365. {
  16366. int result = TRUE;
  16367. char rmFileCmd[100]={0};
  16368. char FilePath[100]={0};
  16369. char ftpbuf[200];
  16370. int systemresult;
  16371. sprintf(FilePath,"/mnt/%s",filename);
  16372. system("ping 8.8.8.8 &");
  16373. if((access(FilePath,F_OK))!=-1)
  16374. {
  16375. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16376. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16377. system(rmFileCmd);
  16378. }
  16379. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16380. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16381. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16382. systemresult = system(ftpbuf);
  16383. if(systemresult != 0)
  16384. {
  16385. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16386. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16387. systemresult = system(ftpbuf);
  16388. if(systemresult != 0)
  16389. {
  16390. DEBUG_WARN("wget error!\n");
  16391. result = FALSE;
  16392. }
  16393. }
  16394. system("pkill ping");
  16395. return result;
  16396. }
  16397. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16398. {
  16399. char rmFileCmd[100]={0};
  16400. char FilePath[100]={0};
  16401. char buf[512];
  16402. int systemresult = 0;
  16403. //DEBUG_INFO("filename=%s\n",filename);
  16404. //DEBUG_INFO("url=%s\n",url);
  16405. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16406. if((access(FilePath,F_OK))!=-1)
  16407. {
  16408. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16409. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16410. system(rmFileCmd);
  16411. }
  16412. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16413. if(fp == NULL)
  16414. {
  16415. DEBUG_INFO("log is NULL\n");
  16416. return FALSE;
  16417. }
  16418. else
  16419. {
  16420. fprintf(fp, "%s\n", url);
  16421. fprintf(fp, "%s\n", filename);
  16422. fclose(fp);
  16423. }
  16424. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16425. if(phpFP == NULL)
  16426. {
  16427. DEBUG_INFO("PHP upload fail.\n");
  16428. return FALSE;
  16429. }
  16430. else
  16431. {
  16432. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16433. {
  16434. if(strstr(buf, "result") != NULL)
  16435. {
  16436. sscanf(buf, "result: %d", &systemresult);
  16437. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16438. }
  16439. }
  16440. pclose(phpFP);
  16441. }
  16442. if(systemresult != 1)
  16443. {
  16444. DEBUG_INFO("HTTP upload error!\n");
  16445. return FALSE;
  16446. }
  16447. return TRUE;
  16448. }
  16449. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16450. {
  16451. int result = FALSE;
  16452. char ftpbuf[200];
  16453. int systemresult;
  16454. /*
  16455. // Domaind name transfer to IP address
  16456. struct hostent* server;
  16457. char *IPbuffer;
  16458. server = gethostbyname(location);
  16459. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16460. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16461. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16462. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16463. systemresult = system(ftpbuf);
  16464. if(systemresult != 0)
  16465. {
  16466. DEBUG_INFO("ftpput error!\n");
  16467. }
  16468. else
  16469. {
  16470. result = TRUE;
  16471. DEBUG_INFO("ftpput OK!\n");
  16472. }
  16473. return result;
  16474. }
  16475. int GetOcppServerURL()
  16476. {
  16477. int result = FALSE;
  16478. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16479. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16480. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16481. struct yuarel url;
  16482. char urlStr[512];
  16483. // OCPPPH only
  16484. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16485. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16486. {
  16487. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16488. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16489. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16490. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16491. if(yuarel_parse(&url, urlStr) != -1)
  16492. {
  16493. sprintf(OcppProtocol, "%s", url.scheme);
  16494. sprintf(OcppHost, "%s", url.host);
  16495. if(url.path == NULL)
  16496. OcppTempPath[0] = '\0';
  16497. else
  16498. sprintf(OcppTempPath, "%s", url.path);
  16499. if(url.port == 0)
  16500. {
  16501. if(strcmp(OcppProtocol, "wss") == 0)
  16502. OcppPort = 443;
  16503. else
  16504. OcppPort = 80;
  16505. }
  16506. else
  16507. OcppPort = url.port;
  16508. result = TRUE;
  16509. }
  16510. }
  16511. else
  16512. {
  16513. strcpy(OcppHost,"");
  16514. }
  16515. return result;
  16516. }
  16517. int GetOcppPath()
  16518. {
  16519. int result = FALSE;
  16520. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16521. {
  16522. if(OcppTempPath == NULL)
  16523. {
  16524. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16525. }
  16526. else
  16527. {
  16528. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16529. }
  16530. result = TRUE;
  16531. goto End;
  16532. }
  16533. else
  16534. {
  16535. strcpy(OcppPath,"");
  16536. }
  16537. End:
  16538. return result;
  16539. }
  16540. int GetOcppPort()
  16541. {
  16542. return OcppPort;
  16543. }
  16544. int GetOcppConnStatus(void)
  16545. {
  16546. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16547. }
  16548. void SetOcppConnStatus(uint8_t status)
  16549. {
  16550. ShmOCPP16DataPH->OcppConnStatus = status;
  16551. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16552. }
  16553. int GetHeartBeatWithNOResponse(void)
  16554. {
  16555. return HeartBeatWithNOResponse;
  16556. }
  16557. void SetHeartBeatWithNOResponse(void)
  16558. {
  16559. HeartBeatWithNOResponse = 0;
  16560. }
  16561. void GetStartTransactionIdTag(int gun_index)
  16562. {
  16563. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16564. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16565. }
  16566. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16567. {
  16568. char ch;
  16569. FILE *fptr1;
  16570. int temptransactionId;
  16571. char str[100]={0};
  16572. temptransactionId = 0;
  16573. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16574. {
  16575. DEBUG_INFO("IdTag is empty.\n");
  16576. return temptransactionId;
  16577. }
  16578. /*------ Read the file ----------------*/
  16579. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16580. if (!fptr1)
  16581. {
  16582. DEBUG_INFO("QueueTransactionId file open error.\n");
  16583. //printf(" File not found or unable to open the input file!!\n");
  16584. return temptransactionId;
  16585. }
  16586. ch=fgetc(fptr1);
  16587. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16588. rewind(fptr1);
  16589. if(ch!=EOF)
  16590. {
  16591. // printf("%c",ch);
  16592. while (fgets(str, 100, fptr1) != NULL)
  16593. {
  16594. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16595. if(str[0]=='\0')
  16596. {
  16597. break;
  16598. }
  16599. char *revbuf[8] = {0}; // Variable store string split
  16600. int num = 0;// Quantity after string split
  16601. DEBUG_INFO("Transaction queue data= %s\n", str);
  16602. splitstring(str,",",revbuf,&num); // String split
  16603. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16604. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16605. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16606. DEBUG_INFO("------------------------------\n");
  16607. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16608. {
  16609. if(isStopTransaction)
  16610. {
  16611. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16612. {
  16613. temptransactionId = atoi(revbuf[2]);
  16614. //break;
  16615. }
  16616. }
  16617. else
  16618. {
  16619. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16620. {
  16621. temptransactionId = atoi(revbuf[2]);
  16622. //break;
  16623. }
  16624. }
  16625. }
  16626. }
  16627. }
  16628. else
  16629. DEBUG_INFO("EOF\n");
  16630. fclose(fptr1);
  16631. /*------- End of reading ---------------*/
  16632. return temptransactionId;
  16633. }
  16634. void SetTransactionIdZero(int transactionId)
  16635. {
  16636. char ch;
  16637. FILE *fptr1, *fptr2;
  16638. int temptransactionId = 0;
  16639. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16640. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16641. if (!fptr1)
  16642. {
  16643. //printf(" File not found or unable to open the input file!!\n");
  16644. return ;
  16645. }
  16646. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16647. if (!fptr2)
  16648. {
  16649. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16650. fclose(fptr1);
  16651. return ;
  16652. }
  16653. ch=fgetc(fptr1);
  16654. rewind(fptr1);
  16655. if(ch!=EOF)
  16656. {
  16657. // copy all contents to the temporary file except the specific line
  16658. while (fgets(str, 100, fptr1) != NULL)
  16659. {
  16660. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16661. if(str[0]=='\0')
  16662. {
  16663. break;
  16664. }
  16665. char *revbuf[8] = {0};
  16666. int num = 0;
  16667. strcpy(strtemp, str);
  16668. splitstring(str,",",revbuf,&num);
  16669. if(revbuf[2][0] != '\0')
  16670. {
  16671. temptransactionId = atoi(revbuf[2]);
  16672. if(transactionId != temptransactionId)
  16673. {
  16674. fprintf(fptr2, "%s\n", strtemp);
  16675. }
  16676. }
  16677. }
  16678. }
  16679. fclose(fptr1);
  16680. fclose(fptr2);
  16681. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16682. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16683. /*------ Read the file ----------------*/
  16684. }
  16685. int InternetDisconnect(void)
  16686. {
  16687. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16688. }
  16689. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16690. void storeTempStopTransaction(int gun_index)
  16691. {
  16692. char guid[37]={0};
  16693. int tempIndex = 0;
  16694. char TempStopTransaction[256];
  16695. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16696. DEBUG_INFO("storeTempStopTransaction...\n");
  16697. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16698. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16699. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16700. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16701. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16702. {
  16703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16704. {
  16705. tempIndex = ((gun_index==2) ? 1: 0);
  16706. }
  16707. else
  16708. {
  16709. tempIndex = gun_index;
  16710. }
  16711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16712. {
  16713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16714. {
  16715. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16716. }
  16717. }// END OF CHAdeMO_QUANTITY
  16718. }
  16719. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16720. {
  16721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16722. {
  16723. tempIndex = ((gun_index==2) ? 1: 0);
  16724. }
  16725. else
  16726. {
  16727. tempIndex = gun_index;
  16728. }
  16729. for (int index = 0; index < CCS_QUANTITY; index++)
  16730. {
  16731. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16732. {
  16733. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16734. }
  16735. }// END OF CCS_QUANTITY
  16736. }
  16737. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16738. {
  16739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16740. {
  16741. tempIndex = ((gun_index==2) ? 1: 0);
  16742. }
  16743. else
  16744. {
  16745. tempIndex = gun_index;
  16746. }
  16747. for (int index = 0; index < GB_QUANTITY; index++)
  16748. {
  16749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16750. {
  16751. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16752. }
  16753. }// END OF GB_QUANTITY
  16754. }
  16755. else if(gunType[gun_index] == GUN_TYPE_DO)
  16756. {
  16757. tempIndex = gun_index;
  16758. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16759. {
  16760. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16761. {
  16762. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16763. }
  16764. }
  16765. }
  16766. else
  16767. {
  16768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16769. {
  16770. tempIndex = 2;
  16771. }
  16772. else
  16773. {
  16774. tempIndex = gun_index;
  16775. }
  16776. for (int index = 0; index < AC_QUANTITY; index++)
  16777. {
  16778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16779. {
  16780. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16781. }
  16782. }// END OF AC_QUANTITY
  16783. }
  16784. //Stop Transaction Time
  16785. struct timeval tmnow;
  16786. struct tm *tm;
  16787. char buf[28];//, usec_buf[6];
  16788. gettimeofday(&tmnow, NULL);
  16789. time_t t;
  16790. t = time(NULL);
  16791. /*UTC time and date*/
  16792. tm = gmtime(&t);
  16793. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16794. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16795. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16797. random_uuid(guid);
  16798. /***********************************transactionData******************************************************/
  16799. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16801. //=================================
  16802. //1. Transaction_Begin
  16803. //=================================
  16804. //============================== Energy.Active.Import.Interval ===========================================
  16805. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16806. {
  16807. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16810. 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*/]);
  16811. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16812. 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))
  16813. {
  16814. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16815. }
  16816. else
  16817. {
  16818. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16819. }
  16820. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16821. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16822. }
  16823. //=================================
  16824. //2. Transaction_End
  16825. //=================================
  16826. //2.1====================================== Current.Import L1 ==============================================
  16827. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16828. {
  16829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16830. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16831. {
  16832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16833. {
  16834. tempIndex = ((gun_index==2) ? 1: 0);
  16835. }
  16836. else
  16837. {
  16838. tempIndex = gun_index;
  16839. }
  16840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16841. {
  16842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16843. {
  16844. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16845. }
  16846. }// End of for CHAdeMO_QUANTITY
  16847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16848. }
  16849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16850. {
  16851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16852. {
  16853. tempIndex = ((gun_index==2) ? 1: 0);
  16854. }
  16855. else
  16856. {
  16857. tempIndex = gun_index;
  16858. }
  16859. for (int index = 0; index < CCS_QUANTITY; index++)
  16860. {
  16861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16862. {
  16863. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16864. }
  16865. }// End of for CCS_QUANTITY
  16866. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16867. }
  16868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  16879. {
  16880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16881. {
  16882. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16883. }
  16884. }// End of for GB_QUANTITY
  16885. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16886. }
  16887. else if(gunType[gun_index] == GUN_TYPE_DO)
  16888. {
  16889. tempIndex = gun_index;
  16890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16891. {
  16892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16893. {
  16894. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16895. }
  16896. }
  16897. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16898. }
  16899. else
  16900. {
  16901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16902. {
  16903. tempIndex = 2;
  16904. }
  16905. else
  16906. {
  16907. tempIndex = gun_index;
  16908. }
  16909. for (int index = 0; index < AC_QUANTITY; index++)
  16910. {
  16911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16912. {
  16913. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16914. }
  16915. }// End of for AC_QUANTITY
  16916. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16917. }
  16918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16921. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16922. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16923. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16924. }
  16925. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16926. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16927. {
  16928. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16929. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16930. {
  16931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16932. {
  16933. tempIndex = ((gun_index==2) ? 1: 0);
  16934. }
  16935. else
  16936. {
  16937. tempIndex = gun_index;
  16938. }
  16939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16940. {
  16941. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16942. {
  16943. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16944. }
  16945. }// END OF CHAdeMO_QUANTITY
  16946. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16947. }
  16948. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16949. {
  16950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16951. {
  16952. tempIndex = ((gun_index==2) ? 1: 0);
  16953. }
  16954. else
  16955. {
  16956. tempIndex = gun_index;
  16957. }
  16958. for (int index = 0; index < CCS_QUANTITY; index++)
  16959. {
  16960. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16961. {
  16962. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16963. }
  16964. }// END OF CCS_QUANTITY
  16965. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16966. }
  16967. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16968. {
  16969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16970. {
  16971. tempIndex = ((gun_index==2) ? 1: 0);
  16972. }
  16973. else
  16974. {
  16975. tempIndex = gun_index;
  16976. }
  16977. for (int index = 0; index < GB_QUANTITY; index++)
  16978. {
  16979. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16980. {
  16981. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16982. }
  16983. }// END OF GB_QUANTITY
  16984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16985. }
  16986. else if(gunType[gun_index] == GUN_TYPE_DO)
  16987. {
  16988. tempIndex = gun_index;
  16989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16990. {
  16991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16992. {
  16993. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16994. }
  16995. }
  16996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16997. }
  16998. else
  16999. {
  17000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17001. {
  17002. tempIndex = 2;
  17003. }
  17004. else
  17005. {
  17006. tempIndex = gun_index;
  17007. }
  17008. for (int index = 0; index < AC_QUANTITY; index++)
  17009. {
  17010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17011. {
  17012. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17013. }
  17014. }// END OF AC_QUANTITY
  17015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17016. }
  17017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17020. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17021. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17023. }
  17024. //2.3====================================== Power.Active.Import =========================================
  17025. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17026. {
  17027. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17028. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17029. {
  17030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17031. {
  17032. tempIndex = ((gun_index==2) ? 1: 0);
  17033. }
  17034. else
  17035. {
  17036. tempIndex = gun_index;
  17037. }
  17038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17039. {
  17040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17041. {
  17042. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17043. }
  17044. } // End for CHAdeMO_QUANTITY
  17045. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17046. }
  17047. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17048. {
  17049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17050. {
  17051. tempIndex = ((gun_index==2) ? 1: 0);
  17052. }
  17053. else
  17054. {
  17055. tempIndex = gun_index;
  17056. }
  17057. for (int index = 0; index < CCS_QUANTITY; index++)
  17058. {
  17059. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17060. {
  17061. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17062. }
  17063. } // END for CCS_QUANTITY
  17064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17065. }
  17066. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17067. {
  17068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17069. {
  17070. tempIndex = ((gun_index==2) ? 1: 0);
  17071. }
  17072. else
  17073. {
  17074. tempIndex = gun_index;
  17075. }
  17076. for (int index = 0; index < GB_QUANTITY; index++)
  17077. {
  17078. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17079. {
  17080. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17081. }
  17082. }// END for GB_QUANTITY
  17083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17084. }
  17085. else if(gunType[gun_index] == GUN_TYPE_DO)
  17086. {
  17087. tempIndex = gun_index;
  17088. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17089. {
  17090. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17091. {
  17092. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17093. }
  17094. }
  17095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17096. }
  17097. else
  17098. {
  17099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17100. {
  17101. tempIndex = 2;
  17102. }
  17103. else
  17104. {
  17105. tempIndex = gun_index;
  17106. }
  17107. for (int index = 0; index < AC_QUANTITY; index++)
  17108. {
  17109. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17110. {
  17111. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17112. }
  17113. } // END for AC_QUANTITY
  17114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17115. }
  17116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17119. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17122. }
  17123. //2.4====================================== Voltage L1 ====================================================
  17124. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17125. {
  17126. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17127. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17128. {
  17129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17130. {
  17131. tempIndex = ((gun_index==2) ? 1: 0);
  17132. }
  17133. else
  17134. {
  17135. tempIndex = gun_index;
  17136. }
  17137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17138. {
  17139. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17140. {
  17141. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17142. }
  17143. } // END OF FOR CHAdeMO_QUANTITY
  17144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17145. }
  17146. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17147. {
  17148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17149. {
  17150. tempIndex = ((gun_index==2) ? 1: 0);
  17151. }
  17152. else
  17153. {
  17154. tempIndex = gun_index;
  17155. }
  17156. for (int index = 0; index < CCS_QUANTITY; index++)
  17157. {
  17158. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17159. {
  17160. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17161. }
  17162. } // END OF FOR CCS_QUANTITY
  17163. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17164. }
  17165. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17166. {
  17167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17168. {
  17169. tempIndex = ((gun_index==2) ? 1: 0);
  17170. }
  17171. else
  17172. {
  17173. tempIndex = gun_index;
  17174. }
  17175. for (int index = 0; index < GB_QUANTITY; index++)
  17176. {
  17177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17178. {
  17179. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17180. }
  17181. } // END OF FOR GB_QUANTITY
  17182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17183. }
  17184. else if(gunType[gun_index] == GUN_TYPE_DO)
  17185. {
  17186. tempIndex = gun_index;
  17187. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17188. {
  17189. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17190. {
  17191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17192. }
  17193. }
  17194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17195. }
  17196. else
  17197. {
  17198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17199. {
  17200. tempIndex = 2;
  17201. }
  17202. else
  17203. {
  17204. tempIndex = gun_index;
  17205. }
  17206. for (int index = 0; index < AC_QUANTITY; index++)
  17207. {
  17208. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17209. {
  17210. 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
  17211. }
  17212. } // END OF FOR AC_QUANTITY
  17213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17214. }
  17215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17218. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17221. }
  17222. //2.5============================================== End SoC =========================================================
  17223. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17224. {
  17225. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17226. 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))
  17227. {
  17228. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17229. {
  17230. tempIndex = ((gun_index==2) ? 1: 0);
  17231. }
  17232. else
  17233. {
  17234. tempIndex = gun_index;
  17235. }
  17236. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17237. {
  17238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17239. {
  17240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17241. {
  17242. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17243. }
  17244. }
  17245. }
  17246. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17247. {
  17248. for (int index = 0; index < CCS_QUANTITY; index++)
  17249. {
  17250. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17251. {
  17252. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17253. }
  17254. }
  17255. }
  17256. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17257. {
  17258. for (int index = 0; index < GB_QUANTITY; index++)
  17259. {
  17260. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17261. {
  17262. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17263. }
  17264. }
  17265. }
  17266. else if(gunType[gun_index] == GUN_TYPE_DO)
  17267. {
  17268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17269. {
  17270. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17271. {
  17272. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17273. }
  17274. }
  17275. }
  17276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17282. } // END FOR DC CASE
  17283. }
  17284. //2.6====================================== Current.Import L2 ==============================================
  17285. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17286. {
  17287. // AC 3 phase L2 current
  17288. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17289. {
  17290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17291. {
  17292. tempIndex = 2;
  17293. }
  17294. else
  17295. {
  17296. tempIndex = gun_index;
  17297. }
  17298. for (int index = 0; index < AC_QUANTITY; index++)
  17299. {
  17300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17301. {
  17302. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17303. }
  17304. }// End of for AC_QUANTITY
  17305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17306. }
  17307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17312. }
  17313. //2.7====================================== Current.Import L3 ==============================================
  17314. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17315. {
  17316. // AC 3 phase L3 current
  17317. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17318. {
  17319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17320. {
  17321. tempIndex = 2;
  17322. }
  17323. else
  17324. {
  17325. tempIndex = gun_index;
  17326. }
  17327. for (int index = 0; index < AC_QUANTITY; index++)
  17328. {
  17329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17330. {
  17331. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17332. }
  17333. }// End of for AC_QUANTITY
  17334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17335. }
  17336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17337. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17338. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17339. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17340. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17341. }
  17342. //2.9====================================== Voltage L2 ====================================================
  17343. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17344. {
  17345. // AC 3 phase L2 volatge
  17346. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17347. {
  17348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17349. {
  17350. tempIndex = 2;
  17351. }
  17352. else
  17353. {
  17354. tempIndex = gun_index;
  17355. }
  17356. for (int index = 0; index < AC_QUANTITY; index++)
  17357. {
  17358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17359. {
  17360. 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
  17361. }
  17362. } // END OF FOR AC_QUANTITY
  17363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17364. }
  17365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17368. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17370. }
  17371. //2.10====================================== Voltage L3 ====================================================
  17372. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17373. {
  17374. // AC 3 phase L3 volatge
  17375. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17376. {
  17377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17378. {
  17379. tempIndex = 2;
  17380. }
  17381. else
  17382. {
  17383. tempIndex = gun_index;
  17384. }
  17385. for (int index = 0; index < AC_QUANTITY; index++)
  17386. {
  17387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17388. {
  17389. 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
  17390. }
  17391. } // END OF FOR AC_QUANTITY
  17392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17393. }
  17394. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17395. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17397. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17398. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17399. }
  17400. //====================== Start SoC ================================
  17401. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17402. {
  17403. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17404. 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))
  17405. {
  17406. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17407. {
  17408. tempIndex = ((gun_index==2) ? 1: 0);
  17409. }
  17410. else
  17411. {
  17412. tempIndex = gun_index;
  17413. }
  17414. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17415. {
  17416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17417. {
  17418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17419. {
  17420. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17421. }
  17422. }
  17423. }
  17424. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17425. {
  17426. for (int index = 0; index < CCS_QUANTITY; index++)
  17427. {
  17428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17429. {
  17430. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17431. }
  17432. }
  17433. }
  17434. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17435. {
  17436. for (int index = 0; index < GB_QUANTITY; index++)
  17437. {
  17438. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17439. {
  17440. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17441. }
  17442. }
  17443. }
  17444. else if(gunType[gun_index] == GUN_TYPE_DO)
  17445. {
  17446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17447. {
  17448. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17449. {
  17450. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17451. }
  17452. }
  17453. }
  17454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17455. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17460. } // END FOR DC CASE
  17461. }
  17462. //======================================== Message create ==============================================
  17463. json_object *StopTransaction = json_object_new_object();
  17464. json_object *transactionDatas = json_object_new_array();
  17465. json_object *sampledValues = json_object_new_array();
  17466. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17467. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17468. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17469. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17470. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17471. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17472. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17473. {
  17474. json_object *transactionData = json_object_new_object();
  17475. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17476. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17477. {
  17478. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17479. {
  17480. json_object *sampledValue = json_object_new_object();
  17481. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17482. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17483. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17484. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17485. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17486. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17487. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17488. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17489. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17490. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17491. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17492. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17493. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17494. json_object_array_add(sampledValues, sampledValue);
  17495. }
  17496. }
  17497. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17498. json_object_array_add(transactionDatas, transactionData);
  17499. }
  17500. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17501. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17502. ,MESSAGE_TYPE_CALL
  17503. ,guid
  17504. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17505. json_object_put(StopTransaction);
  17506. // Check File "TempStopTransaction" Exist
  17507. if((access(TempStopTransaction,F_OK))!=-1)
  17508. {
  17509. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17510. fclose(fopen(TempStopTransaction, "w"));
  17511. }
  17512. else
  17513. {
  17514. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17515. FILE *log = fopen(TempStopTransaction, "w+");
  17516. if(log == NULL)
  17517. {
  17518. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17519. return ;
  17520. }
  17521. else
  17522. {
  17523. fclose(log);
  17524. }
  17525. }
  17526. //Add TempStopTransaction | Update TempStopTransaction
  17527. // open file for writing
  17528. FILE *outfile;
  17529. outfile = fopen (TempStopTransaction, "a");
  17530. //DEBUG_INFO("data = %s\n", queuedata);
  17531. fputs(queuedata, outfile);
  17532. fputs("\n", outfile);
  17533. fclose (outfile);
  17534. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17535. }
  17536. void checkTempStopTransaction(int gun_index)
  17537. {
  17538. FILE *fptr1;
  17539. char ch;
  17540. char str[QUEUE_MESSAGE_LENGTH]={0};
  17541. char guid[37]={0};
  17542. char tempdata[65]={0};
  17543. char connectorStr[2]={0};
  17544. char TempStopTransaction[256];
  17545. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17546. fptr1 = fopen(TempStopTransaction, "r");
  17547. //TempStopTransaction格式: 槍號,StopTransaction封包
  17548. if (!fptr1)
  17549. {
  17550. //printf(" File not found or unable to open the input file!!\n");
  17551. return ;
  17552. }
  17553. ch=fgetc(fptr1);
  17554. //printf(" Now the content of the file %s is : \n",fname);
  17555. rewind(fptr1);
  17556. if(ch!=EOF)
  17557. {
  17558. // copy all contents to the temporary file except the specific line
  17559. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17560. {
  17561. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17562. if(str[0]=='\0')
  17563. {
  17564. break;
  17565. }
  17566. //TempStopTransaction格式: 槍號,StopTransaction封包
  17567. strncpy(connectorStr, str, 1);
  17568. if(atoi(connectorStr) != (gun_index+1))
  17569. {
  17570. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17571. fclose(fptr1);
  17572. return ;
  17573. }
  17574. //random_uuid(guid);
  17575. strncpy(guid, str+6, 36); //copy guid
  17576. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17577. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17578. {
  17579. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17580. }
  17581. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17582. OCPP_insert_transaction_msg(NO, str);
  17583. memset(str,0,ARRAY_SIZE(str));
  17584. }
  17585. }
  17586. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17587. fclose(fptr1);
  17588. remove(TempStopTransaction); // remove the original file
  17589. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17590. }
  17591. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17592. {
  17593. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17594. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17595. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17596. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17597. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17598. }
  17599. int GetWebSocketPingInterval(void)
  17600. {
  17601. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17602. }
  17603. int GetServerSign(void)
  17604. {
  17605. return server_sign;
  17606. }
  17607. uint8_t GetOcppSecurityProfile()
  17608. {
  17609. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17610. }
  17611. void GetOcppChargerBoxId(uint8_t *data)
  17612. {
  17613. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17614. }
  17615. void GetOcppSecurityPassword(uint8_t *data)
  17616. {
  17617. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17618. }
  17619. void SetOcppVersion(uint8_t *version)
  17620. {
  17621. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17622. DEBUG_INFO("ocpp version: %s\n", version);
  17623. if(strstr((char*)version, "ocpp1.6") != NULL)
  17624. {
  17625. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17626. }
  17627. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17628. {
  17629. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17630. system("pkill OcppBackend");
  17631. }
  17632. }
  17633. void SetServerSign(int value)
  17634. {
  17635. server_sign = value;
  17636. }
  17637. int GetBootNotificationInterval(void)
  17638. {
  17639. return BootNotificationInterval;
  17640. }
  17641. int GetInternetConn(void)
  17642. {
  17643. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17644. }
  17645. int GetBackendConnectionTimeout(void)
  17646. {
  17647. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17648. }
  17649. int isConnectorInitMode(int gun_index)
  17650. {
  17651. int tempIndex = 0;
  17652. int result = TRUE;
  17653. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17654. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17655. {
  17656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17657. {
  17658. tempIndex = ((gun_index==2) ? 1: 0);
  17659. }
  17660. else
  17661. {
  17662. tempIndex = gun_index;
  17663. }
  17664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17665. {
  17666. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17667. {
  17668. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17669. } //end of the same index
  17670. }//end of for CHAdeMO_QUANTITY
  17671. }
  17672. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17673. {
  17674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17675. {
  17676. tempIndex = ((gun_index==2) ? 1: 0);
  17677. }
  17678. else
  17679. {
  17680. tempIndex = gun_index;
  17681. }
  17682. for (int index = 0; index < CCS_QUANTITY; index++)
  17683. {
  17684. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17685. {
  17686. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17687. } //end of the same index
  17688. } // end of for CCS_QUANTITY
  17689. }
  17690. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17691. {
  17692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17693. {
  17694. tempIndex = ((gun_index==2) ? 1: 0);
  17695. }
  17696. else
  17697. {
  17698. tempIndex = gun_index;
  17699. }
  17700. for (int index = 0; index < GB_QUANTITY; index++)
  17701. {
  17702. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17703. {
  17704. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17705. } //end of the same index
  17706. } // end of for GB_QUANTITY
  17707. }
  17708. else if(gunType[gun_index] == GUN_TYPE_DO)
  17709. {
  17710. tempIndex = gun_index;
  17711. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17712. {
  17713. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17714. {
  17715. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17716. } //end of the same index
  17717. }
  17718. }
  17719. else
  17720. {
  17721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17722. {
  17723. tempIndex = 2;
  17724. }
  17725. else
  17726. {
  17727. tempIndex = gun_index;
  17728. }
  17729. for (int index = 0; index < AC_QUANTITY; index++)
  17730. {
  17731. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17732. {
  17733. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17734. }//end of the same index
  17735. }//end of for AC_QUANTITY
  17736. }
  17737. return result;
  17738. }
  17739. void refreshProcDogTimer()
  17740. {
  17741. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17742. }
  17743. void InitialSystemValue(void)
  17744. {
  17745. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17746. locallistVersion=0;
  17747. BootNotificationInterval = 0;
  17748. authorizeRetryTimes = 0;
  17749. GunStatusInterval = 10;
  17750. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17751. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17752. //Hear Beat
  17753. HeartBeatWithNOResponse = 0;
  17754. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17755. FirstHeartBeat = 0;
  17756. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17757. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17758. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17759. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17760. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17761. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17762. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17763. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17764. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17765. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17766. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17767. //Status && ConnectorPlugIn Setting
  17768. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17769. {
  17770. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17771. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17772. }
  17773. for (int index = 0; index < CCS_QUANTITY; index++)
  17774. {
  17775. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17776. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17777. }
  17778. for (int index = 0; index < GB_QUANTITY; index++)
  17779. {
  17780. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17781. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17782. }
  17783. for (int index = 0; index < AC_QUANTITY; index++)
  17784. {
  17785. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17786. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17787. }
  17788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17789. {
  17790. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17791. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17792. }
  17793. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17794. {
  17795. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17796. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17797. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17798. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17799. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17800. }
  17801. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17802. refreshStartTimer(&clientTime.Heartbeat);
  17803. sleep(1);
  17804. }
  17805. void LWS_Send(char *str)
  17806. {
  17807. //=====================================================
  17808. // Check InternetConn 0: disconnected, 1: connected
  17809. //====================================================
  17810. if(GetOcppConnStatus() == 0)
  17811. {
  17812. DEBUG_INFO("offline now !!!\n");
  17813. return;
  17814. }
  17815. // Only disable isWebsocketSendable operation initiated by charger
  17816. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17817. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17818. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17819. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17820. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17821. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17822. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17823. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17824. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17825. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17826. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17827. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17828. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17829. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17830. {
  17831. isWebsocketSendable = 0;
  17832. }
  17833. pthread_mutex_lock(&lock_send);
  17834. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17835. sprintf((char *)SendBuffer, "%s", str);
  17836. SendBufLen = strlen(str);
  17837. pthread_mutex_unlock(&lock_send);
  17838. lws_callback_on_writable(wsi_client);
  17839. //lws_service(context, 0);
  17840. //sleep(1);
  17841. }
  17842. void LWS_SendNow(char *str)
  17843. {
  17844. //=====================================================
  17845. // Check InternetConn 0: disconnected, 1: connected
  17846. //====================================================
  17847. if(GetOcppConnStatus() == 0)
  17848. {
  17849. DEBUG_INFO("offline now !!!\n");
  17850. return;
  17851. }
  17852. // Only disable isWebsocketSendable operation initiated by charger
  17853. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17854. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17855. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17856. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17857. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17858. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17859. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17860. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17861. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17862. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17863. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17864. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17865. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17866. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17867. {
  17868. isWebsocketSendable = 0;
  17869. }
  17870. pthread_mutex_lock(&lock_send);
  17871. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17872. sprintf((char *)SendBuffer, "%s", str);
  17873. SendBufLen = strlen(str);
  17874. pthread_mutex_unlock(&lock_send);
  17875. lws_callback_on_writable(wsi_client);
  17876. lws_service(context, 0);
  17877. //sleep(1);
  17878. }