MessageHandler.c 903 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432
  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)
  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, isUploaded) values('%d', '%s', '%d', '%d', '0');", txId, creditNo, deductResult, isDonateInvoice);
  680. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  681. {
  682. result = FAIL;
  683. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  684. }
  685. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. return result;
  692. }
  693. int OCPP_update_deduct_info(int txId, char *creditNo)
  694. {
  695. int result = PASS;
  696. char* errMsg = NULL;
  697. char sqlStr[8192];
  698. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  699. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  700. {
  701. result = FAIL;
  702. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  703. }
  704. return result;
  705. }
  706. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  707. {
  708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s}",
  711. atoi(columnValue[1]),
  712. columnValue[2],
  713. atoi(columnValue[3])==1?"true":"false",
  714. atoi(columnValue[4])==1?"true":"false");
  715. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  716. return 0;
  717. }
  718. void OCPP_query_deduct_info()
  719. {
  720. int rc = 0;
  721. char sql[100];
  722. char zErrMsg[100];
  723. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  724. /* Execute SQL statement */
  725. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  726. if( rc != SQLITE_OK )
  727. {
  728. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  729. }
  730. }
  731. //==========================================
  732. // Check time passed since today
  733. //==========================================
  734. long long DiffTimebWithNow(struct timeb ST)
  735. {
  736. //return milli-second
  737. struct timeb ET;
  738. long long StartTime,StopTime;
  739. ftime(&ET);
  740. StartTime=(long long)ST.time;
  741. StopTime=(long long)ET.time;
  742. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  743. }
  744. int getTimePassSinceToday(uint8_t gun_index)
  745. {
  746. int result = -1;
  747. static time_t lastTime[4];
  748. time_t t;
  749. struct tm *tmStartToday;
  750. struct timeb tbStartToday;
  751. t=time(NULL);
  752. if(difftime(t, lastTime[gun_index])>0)
  753. {
  754. tmStartToday=localtime(&t);
  755. tmStartToday->tm_hour = 0;
  756. tmStartToday->tm_min = 0;
  757. tmStartToday->tm_sec = 0;
  758. tbStartToday.time = mktime(tmStartToday);
  759. tbStartToday.millitm = 0;
  760. result = DiffTimebWithNow(tbStartToday)/1000;
  761. lastTime[gun_index] = t;
  762. }
  763. return result;
  764. }
  765. void getNowDatetime(uint8_t *data)
  766. {
  767. time_t t = time(NULL);
  768. struct tm tm = *localtime(&t);
  769. 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);
  770. }
  771. int syncDateTimeRTC(uint8_t *data)
  772. {
  773. struct ParsingResult
  774. {
  775. int result;
  776. int scanedElement;
  777. int year;
  778. int month;
  779. int mday;
  780. int hour;
  781. int min;
  782. int sec;
  783. int tz_hour;
  784. int tz_min;
  785. float minSec;
  786. }result;
  787. struct tm tmOrg;
  788. struct tm *tmTarget;
  789. struct timeb tbTarget;
  790. char buf[128];
  791. memset(&result, 0x00, sizeof(struct ParsingResult));
  792. result.result = PASS;
  793. if(strstr((char*)data, ".") != NULL)
  794. {
  795. // Original data with mini second
  796. if(strstr((char*)data, "Z") != NULL)
  797. {
  798. // Original data with Z
  799. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  800. &result.year,
  801. &result.month,
  802. &result.mday,
  803. &result.hour,
  804. &result.min,
  805. &result.sec,
  806. &result.minSec);
  807. }
  808. else
  809. {
  810. // Original data without Z
  811. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  812. &result.year,
  813. &result.month,
  814. &result.mday,
  815. &result.hour,
  816. &result.min,
  817. &result.sec,
  818. &result.minSec,
  819. &result.tz_hour,
  820. &result.tz_min);
  821. }
  822. }
  823. else
  824. {
  825. // Original data without mini second
  826. if(strstr((char*)data, "Z") != NULL)
  827. {
  828. // Original data with Z
  829. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  830. &result.year,
  831. &result.month,
  832. &result.mday,
  833. &result.hour,
  834. &result.min,
  835. &result.sec);
  836. }
  837. else
  838. {
  839. // Original data without Z
  840. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  841. &result.year,
  842. &result.month,
  843. &result.mday,
  844. &result.hour,
  845. &result.min,
  846. &result.sec,
  847. &result.tz_hour,
  848. &result.tz_min);
  849. }
  850. }
  851. tmOrg.tm_year = result.year - 1900;
  852. tmOrg.tm_mon = result.month - 1;
  853. tmOrg.tm_mday = result.mday;
  854. tmOrg.tm_hour = result.hour;
  855. tmOrg.tm_min = result.min;
  856. tmOrg.tm_sec = result.sec;
  857. tmOrg.tm_gmtoff = 0;
  858. tbTarget.time = mktime(&tmOrg);
  859. tbTarget.timezone = 0;
  860. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  861. tmTarget = gmtime(&tbTarget.time);
  862. 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);
  863. //DEBUG_INFO(" org date time: %s\n", data);
  864. //DEBUG_INFO("parse date time: %s\n", buf);
  865. system(buf);
  866. system("/sbin/hwclock -w --systohc");
  867. if(result.scanedElement < 6)
  868. result.result = FAIL;
  869. return result.result;
  870. }
  871. //==========================================
  872. // GetCompositeSchedule logic related function
  873. //==========================================
  874. int DiffTimebSec(struct timeb ST, struct timeb ET)
  875. {
  876. //return milli-second
  877. unsigned int StartTime,StopTime;
  878. StartTime=(unsigned int)ST.time;
  879. StopTime=(unsigned int)ET.time;
  880. return (StopTime-StartTime);
  881. }
  882. int DiffTimebWithNowSec(struct timeb ST)
  883. {
  884. //return milli-second
  885. struct timeb ET;
  886. unsigned int StartTime,StopTime;
  887. ftime(&ET);
  888. StartTime=(unsigned int)ST.time;
  889. StopTime=(unsigned int)ET.time;
  890. return (StopTime-StartTime);
  891. }
  892. int getStartStop(uint8_t *start, uint8_t *stop)
  893. {
  894. int result = -1;
  895. struct tm tmStart;
  896. struct timeb tbStart;
  897. struct tm tmStop;
  898. struct timeb tbStop;
  899. 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) &&
  900. (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))
  901. {
  902. //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);
  903. //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);
  904. tmStart.tm_year -= 1900;
  905. tmStart.tm_mon -= 1;
  906. tbStart.time = mktime(&tmStart);
  907. tbStart.millitm = 0;
  908. tmStop.tm_year -= 1900;
  909. tmStop.tm_mon -= 1;
  910. tbStop.time = mktime(&tmStop);
  911. tbStop.millitm = 0;
  912. result = DiffTimebSec(tbStart, tbStop);
  913. //DEBUG_INFO("getStartStop(): %d\n", result);
  914. }
  915. else
  916. {
  917. DEBUG_WARN("Start or stop date parsing error.\r\n");
  918. }
  919. return result;
  920. }
  921. int isOvertNow(uint8_t *start)
  922. {
  923. int result = NO;
  924. struct ParsingResult
  925. {
  926. int result;
  927. int scanedElement;
  928. int year;
  929. int month;
  930. int mday;
  931. int hour;
  932. int min;
  933. int sec;
  934. int tz_hour;
  935. int tz_min;
  936. float minSec;
  937. }parsingResult;
  938. struct tm tmStart;
  939. struct timeb tbStart;
  940. if(strstr((char*)start, ".") != NULL)
  941. {
  942. // Original data with mini second
  943. if(strstr((char*)start, "Z") != NULL)
  944. {
  945. // Original data with Z
  946. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  947. &parsingResult.year,
  948. &parsingResult.month,
  949. &parsingResult.mday,
  950. &parsingResult.hour,
  951. &parsingResult.min,
  952. &parsingResult.sec,
  953. &parsingResult.minSec);
  954. }
  955. else
  956. {
  957. // Original data without Z
  958. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  959. &parsingResult.year,
  960. &parsingResult.month,
  961. &parsingResult.mday,
  962. &parsingResult.hour,
  963. &parsingResult.min,
  964. &parsingResult.sec,
  965. &parsingResult.minSec,
  966. &parsingResult.tz_hour,
  967. &parsingResult.tz_min);
  968. }
  969. }
  970. else
  971. {
  972. // Original data without mini second
  973. if(strstr((char*)start, "Z") != NULL)
  974. {
  975. // Original data with Z
  976. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  977. &parsingResult.year,
  978. &parsingResult.month,
  979. &parsingResult.mday,
  980. &parsingResult.hour,
  981. &parsingResult.min,
  982. &parsingResult.sec);
  983. }
  984. else
  985. {
  986. // Original data without Z
  987. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  988. &parsingResult.year,
  989. &parsingResult.month,
  990. &parsingResult.mday,
  991. &parsingResult.hour,
  992. &parsingResult.min,
  993. &parsingResult.sec,
  994. &parsingResult.tz_hour,
  995. &parsingResult.tz_min);
  996. }
  997. }
  998. if(parsingResult.scanedElement >= 6)
  999. {
  1000. tmStart.tm_year = parsingResult.year - 1900;
  1001. tmStart.tm_mon = parsingResult.month - 1;
  1002. tmStart.tm_mday = parsingResult.mday;
  1003. tmStart.tm_hour = parsingResult.hour;
  1004. tmStart.tm_min = parsingResult.min;
  1005. tmStart.tm_sec = parsingResult.sec;
  1006. tmStart.tm_gmtoff = 0;
  1007. tbStart.time = mktime(&tmStart);
  1008. tbStart.timezone = 0;
  1009. tbStart.millitm = 0;
  1010. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1011. if(DiffTimebWithNowSec(tbStart) <= 0)
  1012. result = NO;
  1013. else
  1014. result = YES;
  1015. }
  1016. else
  1017. {
  1018. DEBUG_WARN("Start date parsing error.\n");
  1019. }
  1020. return result;
  1021. }
  1022. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1023. {
  1024. int result = -1;
  1025. struct tm tmStart;
  1026. struct timeb tbStart;
  1027. struct tm tmStop;
  1028. struct timeb tbStop;
  1029. 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) &&
  1030. (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))
  1031. {
  1032. tmStart.tm_year -= 1900;
  1033. tmStart.tm_mon -= 1;
  1034. tbStart.time = mktime(&tmStart);
  1035. tbStart.millitm = 0;
  1036. tmStop.tm_year -= 1900;
  1037. tmStop.tm_mon -= 1;
  1038. tbStop.time = mktime(&tmStop);
  1039. tbStop.millitm = 0;
  1040. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1041. }
  1042. return result;
  1043. }
  1044. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1045. {
  1046. FILE *fp;
  1047. char profileFileName[128];
  1048. char *line = NULL;
  1049. size_t len = 0;
  1050. time_t CurrentTime;
  1051. struct tm *tmComposite;
  1052. struct StructChargingProfile maxProfile;
  1053. uint8_t limitMax=0;
  1054. int compositePeriodIdx = 0;
  1055. CurrentTime = time(NULL);
  1056. tmComposite=localtime(&CurrentTime);
  1057. 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);
  1058. if(isUnitA)
  1059. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1060. else
  1061. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1062. compositeProfile->ChargingSchedule.Duration = durationReq;
  1063. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1064. {
  1065. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1066. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1067. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1068. }
  1069. compositeProfile->ChargingProfileId = 0;
  1070. compositeProfile->StackLevel = 99 ;
  1071. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1072. maxProfile.ChargingProfileId = -1;
  1073. maxProfile.ChargingSchedule.Duration = -1;
  1074. system("rm -f /tmp/*.json");
  1075. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1076. // Search max profile
  1077. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1078. if((access(profileFileName, F_OK))!=-1)
  1079. {
  1080. fp = fopen(profileFileName, "r");
  1081. while(getline(&line, &len, fp) != -1)
  1082. {
  1083. json_object *obj = NULL;
  1084. obj = json_tokener_parse(line);
  1085. if(is_error(obj))
  1086. {
  1087. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1088. }
  1089. else
  1090. {
  1091. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1092. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1093. )
  1094. {
  1095. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1096. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1097. )
  1098. {
  1099. struct tm tmFrom, tmTo;
  1100. struct timeb tbFrom, tbTo;
  1101. 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) &&
  1102. (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))
  1103. {
  1104. tmFrom.tm_year -= 1900;
  1105. tmFrom.tm_mon -= 1;
  1106. tbFrom.time = mktime(&tmFrom);
  1107. tmTo.tm_year -= 1900;
  1108. tmTo.tm_mon -= 1;
  1109. tbTo.time = mktime(&tmTo);
  1110. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1111. {
  1112. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1113. {
  1114. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1115. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1116. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1117. }
  1118. maxProfile.ChargingProfileId = -1;
  1119. maxProfile.StackLevel = -1;
  1120. if(maxProfile.ChargingProfileId == -1)
  1121. DEBUG_INFO("MaxProfile found.\n");
  1122. else
  1123. DEBUG_INFO("MaxProfile updated.\n");
  1124. // Required item
  1125. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1126. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1127. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1128. if(isUnitA)
  1129. {
  1130. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1131. 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++)
  1132. {
  1133. 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"));
  1134. 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?
  1135. 3:
  1136. 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")));
  1137. 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")));
  1138. }
  1139. }
  1140. else
  1141. {
  1142. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1143. 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++)
  1144. {
  1145. 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"));
  1146. 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?
  1147. 3:
  1148. 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")));
  1149. 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));
  1150. }
  1151. }
  1152. // Optional item
  1153. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1154. {
  1155. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1156. }
  1157. else
  1158. {
  1159. sprintf((char*)maxProfile.ValidFrom, " ");
  1160. }
  1161. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1162. {
  1163. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1164. }
  1165. else
  1166. {
  1167. sprintf((char*)maxProfile.ValidTo, " ");
  1168. }
  1169. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1170. {
  1171. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1172. }
  1173. else
  1174. {
  1175. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1176. }
  1177. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1178. {
  1179. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1180. }
  1181. else
  1182. {
  1183. maxProfile.TransactionId = -1;
  1184. }
  1185. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1186. {
  1187. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1188. }
  1189. else
  1190. {
  1191. maxProfile.ChargingSchedule.Duration = 86400;
  1192. }
  1193. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1194. {
  1195. 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")));
  1196. }
  1197. else
  1198. {
  1199. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1200. }
  1201. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1202. {
  1203. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1204. }
  1205. else
  1206. {
  1207. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1208. }
  1209. }
  1210. }
  1211. }
  1212. else
  1213. {
  1214. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1215. {
  1216. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1217. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1218. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1219. }
  1220. maxProfile.ChargingProfileId = -1;
  1221. maxProfile.StackLevel = -1;
  1222. if(maxProfile.ChargingProfileId == -1)
  1223. DEBUG_INFO("MaxProfile found.\n");
  1224. else
  1225. DEBUG_INFO("MaxProfile updated.\n");
  1226. // Required item
  1227. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1228. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1229. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1230. if(isUnitA)
  1231. {
  1232. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1233. 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++)
  1234. {
  1235. 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"));
  1236. 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?
  1237. 3:
  1238. 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")));
  1239. 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")));
  1240. }
  1241. }
  1242. else
  1243. {
  1244. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1245. 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++)
  1246. {
  1247. 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"));
  1248. 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?
  1249. 3:
  1250. 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")));
  1251. 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));
  1252. }
  1253. }
  1254. // Optional item
  1255. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1256. {
  1257. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1258. }
  1259. else
  1260. {
  1261. sprintf((char*)maxProfile.ValidFrom, " ");
  1262. }
  1263. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1264. {
  1265. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1266. }
  1267. else
  1268. {
  1269. sprintf((char*)maxProfile.ValidTo, " ");
  1270. }
  1271. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1272. {
  1273. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1274. }
  1275. else
  1276. {
  1277. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1278. }
  1279. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1280. {
  1281. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1282. }
  1283. else
  1284. {
  1285. maxProfile.TransactionId = -1;
  1286. }
  1287. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1288. {
  1289. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1290. }
  1291. else
  1292. {
  1293. maxProfile.ChargingSchedule.Duration = 86400;
  1294. }
  1295. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1296. {
  1297. 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")));
  1298. }
  1299. else
  1300. {
  1301. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1302. }
  1303. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1304. {
  1305. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1306. }
  1307. else
  1308. {
  1309. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1310. }
  1311. }
  1312. }
  1313. }
  1314. json_object_put(obj);
  1315. }
  1316. fclose(fp);
  1317. /*
  1318. if(maxProfile.ChargingProfileId !=-1)
  1319. {
  1320. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1321. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1322. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1323. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1324. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1325. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1326. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1327. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1328. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1329. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1330. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1331. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1332. {
  1333. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1334. {
  1335. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1336. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1337. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1338. }
  1339. }
  1340. }
  1341. else
  1342. DEBUG_INFO("MaxProfile not found.\n");
  1343. DEBUG_INFO("------------------------------------\n");*/
  1344. }
  1345. if(maxProfile.ChargingProfileId != -1)
  1346. {
  1347. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1348. {
  1349. if(maxProfile.ChargingSchedule.Duration != -1)
  1350. {
  1351. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1352. 0:
  1353. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1354. }
  1355. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1356. {
  1357. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1358. {
  1359. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1360. 0:
  1361. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1362. if(idxPeriod > 0)
  1363. {
  1364. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1365. {
  1366. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1367. }
  1368. }
  1369. }
  1370. }
  1371. }
  1372. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1373. {
  1374. if(maxProfile.ChargingSchedule.Duration != -1)
  1375. {
  1376. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1377. }
  1378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1379. {
  1380. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1381. {
  1382. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1383. if(idxPeriod > 0)
  1384. {
  1385. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1386. {
  1387. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1388. }
  1389. }
  1390. }
  1391. }
  1392. }
  1393. else
  1394. {
  1395. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1396. {
  1397. if(maxProfile.ChargingSchedule.Duration != -1)
  1398. {
  1399. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1400. 0:
  1401. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1402. }
  1403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1404. {
  1405. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1406. {
  1407. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1408. 0:
  1409. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1410. if(idxPeriod > 0)
  1411. {
  1412. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1413. {
  1414. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if(maxProfile.ChargingSchedule.Duration != -1)
  1423. {
  1424. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1425. 0:
  1426. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1427. }
  1428. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1429. {
  1430. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1431. {
  1432. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1433. 0:
  1434. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1435. if(idxPeriod > 0)
  1436. {
  1437. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1438. {
  1439. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1440. }
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. /*
  1447. DEBUG_INFO("MaxProfile after align.\n");
  1448. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1449. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1450. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1451. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1452. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1453. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1454. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1455. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1456. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1457. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1458. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1462. {
  1463. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1464. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1465. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1466. }
  1467. }
  1468. DEBUG_INFO("------------------------------------\n");*/
  1469. }
  1470. // Find each profile period quantity
  1471. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1472. {
  1473. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1474. limitMax = idx+1;
  1475. }
  1476. if(maxProfile.ChargingProfileId != -1)
  1477. {
  1478. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1479. {
  1480. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1481. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1482. (maxProfile.ChargingSchedule.Duration > 0))
  1483. {
  1484. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1485. {
  1486. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1487. compositePeriodIdx++;
  1488. }
  1489. else
  1490. {
  1491. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1492. }
  1493. }
  1494. }
  1495. }
  1496. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1497. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1498. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1499. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1500. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1501. {
  1502. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1503. {
  1504. compositeProfile->ChargingProfileId = 1;
  1505. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1506. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1507. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1508. }
  1509. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1510. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1511. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1512. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1513. }
  1514. if(line)
  1515. free(line);
  1516. }
  1517. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1518. {
  1519. FILE *fp;
  1520. char profileFileName[128];
  1521. char *line = NULL;
  1522. size_t len = 0;
  1523. time_t CurrentTime;
  1524. struct tm *tmComposite;
  1525. struct StructChargingProfile maxProfile;
  1526. struct StructChargingProfile defaultTxProfile;
  1527. struct StructChargingProfile txProfile;
  1528. struct StructChargingSchedulePeriod tmpPeriod;
  1529. uint8_t limitMax=0;
  1530. uint8_t limitDef=0;
  1531. uint8_t limitTx=0;
  1532. int compositePeriodIdx = 0;
  1533. CurrentTime = time(NULL);
  1534. tmComposite=localtime(&CurrentTime);
  1535. 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);
  1536. if(isUnitA)
  1537. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1538. else
  1539. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1540. compositeProfile->ChargingSchedule.Duration = durationReq;
  1541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1542. {
  1543. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1544. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1545. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1546. }
  1547. compositeProfile->ChargingProfileId = 0;
  1548. compositeProfile->StackLevel = 99 ;
  1549. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1550. maxProfile.ChargingProfileId = -1;
  1551. defaultTxProfile.ChargingProfileId = -1;
  1552. txProfile.ChargingProfileId = -1;
  1553. maxProfile.ChargingSchedule.Duration = -1;
  1554. defaultTxProfile.ChargingSchedule.Duration = -1;
  1555. txProfile.ChargingSchedule.Duration = -1;
  1556. system("rm -f /tmp/*.json");
  1557. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1558. /*
  1559. * Search valid charging profile
  1560. */
  1561. //DEBUG_INFO("====================================\n");
  1562. // Search tx profile
  1563. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1564. if((access(profileFileName, F_OK))!=-1)
  1565. {
  1566. fp = fopen(profileFileName, "r");
  1567. while(getline(&line, &len, fp) != -1)
  1568. {
  1569. json_object *obj = NULL;
  1570. obj = json_tokener_parse(line);
  1571. if(is_error(obj))
  1572. {
  1573. DEBUG_ERROR("Parse txProfile from file error.\n");
  1574. }
  1575. else
  1576. {
  1577. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1578. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1579. )
  1580. {
  1581. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1582. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1583. )
  1584. {
  1585. struct tm tmFrom, tmTo;
  1586. struct timeb tbFrom, tbTo;
  1587. 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) &&
  1588. (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))
  1589. {
  1590. tmFrom.tm_year -= 1900;
  1591. tmFrom.tm_mon -= 1;
  1592. tbFrom.time = mktime(&tmFrom);
  1593. tmTo.tm_year -= 1900;
  1594. tmTo.tm_mon -= 1;
  1595. tbTo.time = mktime(&tmTo);
  1596. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1597. {
  1598. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1599. {
  1600. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1601. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1602. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1603. }
  1604. txProfile.ChargingProfileId = -1;
  1605. txProfile.StackLevel = -1;
  1606. if(txProfile.ChargingProfileId == -1)
  1607. DEBUG_INFO("TxProfile found.\n");
  1608. else
  1609. DEBUG_INFO("TxProfile updated.\n");
  1610. // Required item
  1611. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1612. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1613. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1614. if(isUnitA)
  1615. {
  1616. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1617. 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++)
  1618. {
  1619. 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"));
  1620. 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?
  1621. 3:
  1622. 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")));
  1623. 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")));
  1624. }
  1625. }
  1626. else
  1627. {
  1628. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1629. 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++)
  1630. {
  1631. 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"));
  1632. 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?
  1633. 3:
  1634. 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")));
  1635. 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));
  1636. }
  1637. }
  1638. // Optional item
  1639. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1640. {
  1641. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1642. }
  1643. else
  1644. {
  1645. sprintf((char*)txProfile.ValidFrom, " ");
  1646. }
  1647. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1648. {
  1649. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1650. }
  1651. else
  1652. {
  1653. sprintf((char*)txProfile.ValidTo, " ");
  1654. }
  1655. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1656. {
  1657. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1658. }
  1659. else
  1660. {
  1661. sprintf((char*)txProfile.RecurrencyKind, " ");
  1662. }
  1663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1664. {
  1665. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1666. }
  1667. else
  1668. {
  1669. txProfile.TransactionId = -1;
  1670. }
  1671. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1672. {
  1673. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1674. }
  1675. else
  1676. {
  1677. txProfile.ChargingSchedule.Duration = 86400;
  1678. }
  1679. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1680. {
  1681. 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")));
  1682. }
  1683. else
  1684. {
  1685. 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));
  1686. }
  1687. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1688. {
  1689. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1690. }
  1691. else
  1692. {
  1693. txProfile.ChargingSchedule.MinChargingRate = -1;
  1694. }
  1695. }
  1696. }
  1697. }
  1698. else
  1699. {
  1700. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1701. {
  1702. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1703. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1704. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1705. }
  1706. txProfile.ChargingProfileId = -1;
  1707. txProfile.StackLevel = -1;
  1708. if(txProfile.ChargingProfileId == -1)
  1709. DEBUG_INFO("TxProfile found.\n");
  1710. else
  1711. DEBUG_INFO("TxProfile updated.\n");
  1712. // Required item
  1713. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1714. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1715. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1716. if(isUnitA)
  1717. {
  1718. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1719. 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++)
  1720. {
  1721. 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"));
  1722. 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?
  1723. 3:
  1724. 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")));
  1725. 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")));
  1726. }
  1727. }
  1728. else
  1729. {
  1730. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1731. 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++)
  1732. {
  1733. 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"));
  1734. 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?
  1735. 3:
  1736. 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")));
  1737. 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));
  1738. }
  1739. }
  1740. // Optional item
  1741. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1742. {
  1743. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1744. }
  1745. else
  1746. {
  1747. sprintf((char*)txProfile.ValidFrom, " ");
  1748. }
  1749. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1750. {
  1751. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1752. }
  1753. else
  1754. {
  1755. sprintf((char*)txProfile.ValidTo, " ");
  1756. }
  1757. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1758. {
  1759. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1760. }
  1761. else
  1762. {
  1763. sprintf((char*)txProfile.RecurrencyKind, " ");
  1764. }
  1765. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1766. {
  1767. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1768. }
  1769. else
  1770. {
  1771. txProfile.TransactionId = -1;
  1772. }
  1773. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1774. {
  1775. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1776. }
  1777. else
  1778. {
  1779. txProfile.ChargingSchedule.Duration = 86400;
  1780. }
  1781. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1782. {
  1783. 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")));
  1784. }
  1785. else
  1786. {
  1787. 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));
  1788. }
  1789. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1790. {
  1791. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1792. }
  1793. else
  1794. {
  1795. txProfile.ChargingSchedule.MinChargingRate = -1;
  1796. }
  1797. }
  1798. }
  1799. }
  1800. json_object_put(obj);
  1801. }
  1802. fclose(fp);
  1803. /*
  1804. if(txProfile.ChargingProfileId != -1)
  1805. {
  1806. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1807. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1808. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1809. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1810. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1811. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1812. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1813. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1814. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1815. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1816. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1817. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1818. {
  1819. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1820. {
  1821. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1822. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1823. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1824. }
  1825. }
  1826. }
  1827. else
  1828. DEBUG_INFO("TxProfile not found.\n");*/
  1829. }
  1830. // Search default tx profile
  1831. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1832. if((access(profileFileName, F_OK))==-1)
  1833. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1834. if((access(profileFileName, F_OK))!=-1)
  1835. {
  1836. fp = fopen(profileFileName, "r");
  1837. while(getline(&line, &len, fp) != -1)
  1838. {
  1839. json_object *obj = NULL;
  1840. obj = json_tokener_parse(line);
  1841. if(is_error(obj))
  1842. {
  1843. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1844. }
  1845. else
  1846. {
  1847. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1848. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1849. )
  1850. {
  1851. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1852. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1853. )
  1854. {
  1855. struct tm tmFrom, tmTo;
  1856. struct timeb tbFrom, tbTo;
  1857. 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) &&
  1858. (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))
  1859. {
  1860. tmFrom.tm_year -= 1900;
  1861. tmFrom.tm_mon -= 1;
  1862. tbFrom.time = mktime(&tmFrom);
  1863. tmTo.tm_year -= 1900;
  1864. tmTo.tm_mon -= 1;
  1865. tbTo.time = mktime(&tmTo);
  1866. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1867. {
  1868. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1869. {
  1870. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1871. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1872. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1873. }
  1874. defaultTxProfile.ChargingProfileId = -1;
  1875. defaultTxProfile.StackLevel = -1;
  1876. if(defaultTxProfile.ChargingProfileId == -1)
  1877. DEBUG_INFO("TxDefaultProfile found.\n");
  1878. else
  1879. DEBUG_INFO("TxDefaultProfile updated.\n");
  1880. // Required item
  1881. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1882. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1883. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1884. if(isUnitA)
  1885. {
  1886. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1887. 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++)
  1888. {
  1889. 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"));
  1890. 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?
  1891. 3:
  1892. 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")));
  1893. 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")));
  1894. }
  1895. }
  1896. else
  1897. {
  1898. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1899. 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++)
  1900. {
  1901. 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"));
  1902. 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?
  1903. 3:
  1904. 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")));
  1905. 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));
  1906. }
  1907. }
  1908. // Optional item
  1909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1910. {
  1911. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1912. }
  1913. else
  1914. {
  1915. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1916. }
  1917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1918. {
  1919. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1920. }
  1921. else
  1922. {
  1923. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1924. }
  1925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1926. {
  1927. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1928. }
  1929. else
  1930. {
  1931. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1932. }
  1933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1934. {
  1935. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1936. }
  1937. else
  1938. {
  1939. defaultTxProfile.TransactionId = -1;
  1940. }
  1941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1942. {
  1943. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1944. }
  1945. else
  1946. {
  1947. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1948. }
  1949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1950. {
  1951. 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")));
  1952. }
  1953. else
  1954. {
  1955. 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));
  1956. }
  1957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1958. {
  1959. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1960. }
  1961. else
  1962. {
  1963. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1964. }
  1965. }
  1966. }
  1967. }
  1968. else
  1969. {
  1970. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1971. {
  1972. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1973. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1974. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1975. }
  1976. defaultTxProfile.ChargingProfileId = -1;
  1977. defaultTxProfile.StackLevel = -1;
  1978. if(defaultTxProfile.ChargingProfileId == -1)
  1979. DEBUG_INFO("TxDefaultProfile found.\n");
  1980. else
  1981. DEBUG_INFO("TxDefaultProfile updated.\n");
  1982. // Required item
  1983. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1984. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1985. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1986. if(isUnitA)
  1987. {
  1988. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1989. 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++)
  1990. {
  1991. 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"));
  1992. 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?
  1993. 3:
  1994. 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")));
  1995. 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")));
  1996. }
  1997. }
  1998. else
  1999. {
  2000. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2001. 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++)
  2002. {
  2003. 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"));
  2004. 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?
  2005. 3:
  2006. 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")));
  2007. 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));
  2008. }
  2009. }
  2010. // Optional item
  2011. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2012. {
  2013. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2014. }
  2015. else
  2016. {
  2017. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2018. }
  2019. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2020. {
  2021. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2022. }
  2023. else
  2024. {
  2025. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2026. }
  2027. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2028. {
  2029. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2030. }
  2031. else
  2032. {
  2033. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2034. }
  2035. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2036. {
  2037. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2038. }
  2039. else
  2040. {
  2041. defaultTxProfile.TransactionId = -1;
  2042. }
  2043. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2044. {
  2045. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2046. }
  2047. else
  2048. {
  2049. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2050. }
  2051. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2052. {
  2053. 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")));
  2054. }
  2055. else
  2056. {
  2057. 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));
  2058. }
  2059. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2060. {
  2061. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2062. }
  2063. else
  2064. {
  2065. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2066. }
  2067. }
  2068. }
  2069. }
  2070. json_object_put(obj);
  2071. }
  2072. fclose(fp);
  2073. /*
  2074. if(defaultTxProfile.ChargingProfileId != -1)
  2075. {
  2076. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2077. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2078. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2079. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2080. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2081. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2082. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2083. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2084. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2085. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2086. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2087. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2088. {
  2089. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2090. {
  2091. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2092. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2093. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2094. }
  2095. }
  2096. }
  2097. else
  2098. DEBUG_INFO("TxDefaultProfile not found.\n");
  2099. DEBUG_INFO("------------------------------------\n");*/
  2100. }
  2101. // Search max profile
  2102. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2103. if((access(profileFileName, F_OK))!=-1)
  2104. {
  2105. fp = fopen(profileFileName, "r");
  2106. while(getline(&line, &len, fp) != -1)
  2107. {
  2108. json_object *obj = NULL;
  2109. obj = json_tokener_parse(line);
  2110. if(is_error(obj))
  2111. {
  2112. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2113. }
  2114. else
  2115. {
  2116. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2117. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2118. )
  2119. {
  2120. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2121. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2122. )
  2123. {
  2124. struct tm tmFrom, tmTo;
  2125. struct timeb tbFrom, tbTo;
  2126. 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) &&
  2127. (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))
  2128. {
  2129. tmFrom.tm_year -= 1900;
  2130. tmFrom.tm_mon -= 1;
  2131. tbFrom.time = mktime(&tmFrom);
  2132. tmTo.tm_year -= 1900;
  2133. tmTo.tm_mon -= 1;
  2134. tbTo.time = mktime(&tmTo);
  2135. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2136. {
  2137. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2138. {
  2139. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2140. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2141. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2142. }
  2143. maxProfile.ChargingProfileId = -1;
  2144. maxProfile.StackLevel = -1;
  2145. if(maxProfile.ChargingProfileId == -1)
  2146. DEBUG_INFO("MaxProfile found.\n");
  2147. else
  2148. DEBUG_INFO("MaxProfile updated.\n");
  2149. // Required item
  2150. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2151. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2152. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2153. if(isUnitA)
  2154. {
  2155. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2156. 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++)
  2157. {
  2158. 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"));
  2159. 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?
  2160. 3:
  2161. 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")));
  2162. 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")));
  2163. }
  2164. }
  2165. else
  2166. {
  2167. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2168. 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++)
  2169. {
  2170. 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"));
  2171. 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?
  2172. 3:
  2173. 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")));
  2174. 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));
  2175. }
  2176. }
  2177. // Optional item
  2178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2179. {
  2180. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2181. }
  2182. else
  2183. {
  2184. sprintf((char*)maxProfile.ValidFrom, " ");
  2185. }
  2186. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2187. {
  2188. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)maxProfile.ValidTo, " ");
  2193. }
  2194. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2195. {
  2196. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2197. }
  2198. else
  2199. {
  2200. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2201. }
  2202. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2203. {
  2204. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2205. }
  2206. else
  2207. {
  2208. maxProfile.TransactionId = -1;
  2209. }
  2210. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2211. {
  2212. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2213. }
  2214. else
  2215. {
  2216. maxProfile.ChargingSchedule.Duration = 86400;
  2217. }
  2218. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2219. {
  2220. 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")));
  2221. }
  2222. else
  2223. {
  2224. 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));
  2225. }
  2226. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2227. {
  2228. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2229. }
  2230. else
  2231. {
  2232. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2233. }
  2234. }
  2235. }
  2236. }
  2237. else
  2238. {
  2239. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2240. {
  2241. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2242. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2243. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2244. }
  2245. maxProfile.ChargingProfileId = -1;
  2246. maxProfile.StackLevel = -1;
  2247. if(maxProfile.ChargingProfileId == -1)
  2248. DEBUG_INFO("MaxProfile found.\n");
  2249. else
  2250. DEBUG_INFO("MaxProfile updated.\n");
  2251. // Required item
  2252. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2253. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2254. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2255. if(isUnitA)
  2256. {
  2257. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2258. 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++)
  2259. {
  2260. 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"));
  2261. 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?
  2262. 3:
  2263. 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")));
  2264. 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")));
  2265. }
  2266. }
  2267. else
  2268. {
  2269. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2270. 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++)
  2271. {
  2272. 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"));
  2273. 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?
  2274. 3:
  2275. 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")));
  2276. 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));
  2277. }
  2278. }
  2279. // Optional item
  2280. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2281. {
  2282. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2283. }
  2284. else
  2285. {
  2286. sprintf((char*)maxProfile.ValidFrom, " ");
  2287. }
  2288. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2289. {
  2290. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2291. }
  2292. else
  2293. {
  2294. sprintf((char*)maxProfile.ValidTo, " ");
  2295. }
  2296. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2297. {
  2298. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2299. }
  2300. else
  2301. {
  2302. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2303. }
  2304. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2305. {
  2306. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2307. }
  2308. else
  2309. {
  2310. maxProfile.TransactionId = -1;
  2311. }
  2312. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2313. {
  2314. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2315. }
  2316. else
  2317. {
  2318. maxProfile.ChargingSchedule.Duration = 86400;
  2319. }
  2320. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2321. {
  2322. 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")));
  2323. }
  2324. else
  2325. {
  2326. 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));
  2327. }
  2328. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2329. {
  2330. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2331. }
  2332. else
  2333. {
  2334. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2335. }
  2336. }
  2337. }
  2338. }
  2339. json_object_put(obj);
  2340. }
  2341. fclose(fp);
  2342. /*
  2343. if(maxProfile.ChargingProfileId !=-1)
  2344. {
  2345. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2346. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2347. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2348. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2349. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2350. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2351. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2352. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2353. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2354. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2355. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2356. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2357. {
  2358. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2359. {
  2360. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2361. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2362. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2363. }
  2364. }
  2365. }
  2366. else
  2367. DEBUG_INFO("MaxProfile not found.\n");
  2368. DEBUG_INFO("------------------------------------\n");*/
  2369. }
  2370. /*
  2371. * Align found profile start schedule & periods
  2372. */
  2373. //DEBUG_INFO("====================================\n");
  2374. /*
  2375. // For local test usage, force modify found profile start schedule info
  2376. 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);
  2377. 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);
  2378. 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);
  2379. */
  2380. if(txProfile.ChargingProfileId != -1)
  2381. {
  2382. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2383. {
  2384. if(txProfile.ChargingSchedule.Duration != -1)
  2385. {
  2386. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2387. 0:
  2388. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2389. }
  2390. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2391. {
  2392. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2393. {
  2394. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2395. 0:
  2396. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2397. if(idxPeriod > 0)
  2398. {
  2399. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2400. {
  2401. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2408. {
  2409. if(txProfile.ChargingSchedule.Duration != -1)
  2410. {
  2411. 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?
  2412. 0:
  2413. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2414. }
  2415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2416. {
  2417. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2418. {
  2419. 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?
  2420. 0:
  2421. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2422. if(idxPeriod > 0)
  2423. {
  2424. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2425. {
  2426. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. else
  2433. {
  2434. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2435. {
  2436. if(txProfile.ChargingSchedule.Duration != -1)
  2437. {
  2438. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2439. 0:
  2440. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2441. }
  2442. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2443. {
  2444. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2445. {
  2446. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2447. 0:
  2448. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2449. if(idxPeriod > 0)
  2450. {
  2451. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2452. {
  2453. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2454. }
  2455. }
  2456. }
  2457. }
  2458. }
  2459. else
  2460. {
  2461. if(txProfile.ChargingSchedule.Duration != -1)
  2462. {
  2463. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2464. 0:
  2465. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2466. }
  2467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2468. {
  2469. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2470. {
  2471. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2472. 0:
  2473. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2474. if(idxPeriod > 0)
  2475. {
  2476. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2477. {
  2478. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2479. }
  2480. }
  2481. }
  2482. }
  2483. }
  2484. }
  2485. /*
  2486. DEBUG_INFO("txProfile after align.\n");
  2487. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2488. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2489. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2490. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2491. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2492. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2493. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2494. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2495. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2496. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2497. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2498. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2499. {
  2500. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2501. {
  2502. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2503. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2504. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2505. }
  2506. }*/
  2507. }
  2508. if(defaultTxProfile.ChargingProfileId != -1)
  2509. {
  2510. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2511. {
  2512. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2513. {
  2514. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2515. 0:
  2516. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2517. }
  2518. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2519. {
  2520. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2521. {
  2522. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2523. 0:
  2524. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2525. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2526. {
  2527. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2528. }
  2529. if(idxPeriod > 0)
  2530. {
  2531. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2532. {
  2533. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2534. }
  2535. }
  2536. }
  2537. }
  2538. }
  2539. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2540. {
  2541. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2542. {
  2543. 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?
  2544. 0:
  2545. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2546. }
  2547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2548. {
  2549. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2550. {
  2551. 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?
  2552. 0:
  2553. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2554. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2555. {
  2556. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2557. }
  2558. if(idxPeriod > 0)
  2559. {
  2560. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2561. {
  2562. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2563. }
  2564. }
  2565. }
  2566. }
  2567. }
  2568. else
  2569. {
  2570. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2571. {
  2572. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2573. {
  2574. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2575. 0:
  2576. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2577. }
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2581. {
  2582. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2583. 0:
  2584. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2585. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2586. {
  2587. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2588. }
  2589. if(idxPeriod > 0)
  2590. {
  2591. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2592. {
  2593. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. }
  2599. else
  2600. {
  2601. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2602. {
  2603. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2604. 0:
  2605. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2606. }
  2607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2608. {
  2609. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2610. {
  2611. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2612. 0:
  2613. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2614. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2615. {
  2616. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2617. }
  2618. if(idxPeriod > 0)
  2619. {
  2620. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2621. {
  2622. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2623. }
  2624. }
  2625. }
  2626. }
  2627. }
  2628. }
  2629. /*
  2630. DEBUG_INFO("defaultTxProfile after align.\n");
  2631. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2632. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2633. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2634. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2635. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2637. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2638. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2639. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2640. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2641. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2643. {
  2644. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2645. {
  2646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2649. }
  2650. }
  2651. DEBUG_INFO("------------------------------------\n");*/
  2652. }
  2653. if(maxProfile.ChargingProfileId != -1)
  2654. {
  2655. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2656. {
  2657. if(maxProfile.ChargingSchedule.Duration != -1)
  2658. {
  2659. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2660. 0:
  2661. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2662. }
  2663. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2664. {
  2665. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2666. {
  2667. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2668. 0:
  2669. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2670. if(idxPeriod > 0)
  2671. {
  2672. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2673. {
  2674. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2681. {
  2682. if(maxProfile.ChargingSchedule.Duration != -1)
  2683. {
  2684. 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?
  2685. 0:
  2686. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2687. }
  2688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2689. {
  2690. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2691. {
  2692. 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?
  2693. 0:
  2694. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2695. if(idxPeriod > 0)
  2696. {
  2697. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2698. {
  2699. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2700. }
  2701. }
  2702. }
  2703. }
  2704. }
  2705. else
  2706. {
  2707. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2708. {
  2709. if(maxProfile.ChargingSchedule.Duration != -1)
  2710. {
  2711. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2712. 0:
  2713. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2714. }
  2715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2716. {
  2717. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2718. {
  2719. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2720. 0:
  2721. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2722. if(idxPeriod > 0)
  2723. {
  2724. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2725. {
  2726. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2727. }
  2728. }
  2729. }
  2730. }
  2731. }
  2732. else
  2733. {
  2734. if(maxProfile.ChargingSchedule.Duration != -1)
  2735. {
  2736. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2737. 0:
  2738. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2739. }
  2740. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2741. {
  2742. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2743. {
  2744. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2745. 0:
  2746. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2747. if(idxPeriod > 0)
  2748. {
  2749. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2750. {
  2751. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2752. }
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. /*
  2759. DEBUG_INFO("MaxProfile after align.\n");
  2760. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2761. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2762. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2763. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2764. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2765. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2766. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2767. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2768. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2769. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2770. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2772. {
  2773. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2774. {
  2775. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2776. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2777. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2778. }
  2779. }
  2780. DEBUG_INFO("------------------------------------\n");*/
  2781. }
  2782. /*
  2783. * Merge to conposite schedule
  2784. */
  2785. //DEBUG_INFO("====================================\n");
  2786. // Find each profile period quantity
  2787. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2788. {
  2789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2790. limitMax = idx+1;
  2791. }
  2792. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2793. {
  2794. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2795. limitDef = idx+1;
  2796. }
  2797. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2798. {
  2799. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2800. limitTx = idx+1;
  2801. }
  2802. // TxProfile found, composite schedule based on it
  2803. if(txProfile.ChargingProfileId != -1)
  2804. {
  2805. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2806. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2807. {
  2808. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2809. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2810. (txProfile.ChargingSchedule.Duration > 0))
  2811. {
  2812. if(maxProfile.ChargingProfileId != -1)
  2813. {
  2814. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2815. {
  2816. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2817. {
  2818. if((maxProfile.ChargingSchedule.Duration > 0))
  2819. {
  2820. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2821. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2822. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2823. }
  2824. else
  2825. {
  2826. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2827. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2828. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2829. }
  2830. }
  2831. if(idxMaxPeriod == (limitMax-1))
  2832. {
  2833. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2834. {
  2835. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2836. {
  2837. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2838. compositePeriodIdx++;
  2839. }
  2840. else
  2841. {
  2842. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2843. }
  2844. }
  2845. }
  2846. }
  2847. }
  2848. else
  2849. {
  2850. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2851. {
  2852. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2853. compositePeriodIdx++;
  2854. }
  2855. else
  2856. {
  2857. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2858. }
  2859. }
  2860. }
  2861. if(idxTxPeriod == (limitTx-1))
  2862. {
  2863. if(defaultTxProfile.ChargingProfileId != -1)
  2864. {
  2865. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2866. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2867. {
  2868. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2869. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2870. (defaultTxProfile.ChargingSchedule.Duration>0))
  2871. {
  2872. if(maxProfile.ChargingProfileId != -1)
  2873. {
  2874. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2875. {
  2876. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2877. {
  2878. if((maxProfile.ChargingSchedule.Duration > 0))
  2879. {
  2880. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2881. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2882. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2883. }
  2884. else
  2885. {
  2886. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2887. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2888. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2889. }
  2890. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2891. {
  2892. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2893. {
  2894. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2895. compositePeriodIdx++;
  2896. }
  2897. else
  2898. {
  2899. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2900. }
  2901. }
  2902. // Delete duplicate period
  2903. if(compositePeriodIdx > 1)
  2904. {
  2905. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2906. {
  2907. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2908. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2909. compositePeriodIdx -= 1;
  2910. }
  2911. }
  2912. }
  2913. else
  2914. {
  2915. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2916. {
  2917. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2918. compositePeriodIdx++;
  2919. }
  2920. else
  2921. {
  2922. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2923. }
  2924. break;
  2925. }
  2926. }
  2927. }
  2928. else
  2929. {
  2930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2931. {
  2932. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2933. compositePeriodIdx++;
  2934. }
  2935. else
  2936. {
  2937. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2938. }
  2939. }
  2940. }
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2947. else if(defaultTxProfile.ChargingProfileId != -1)
  2948. {
  2949. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2950. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2951. {
  2952. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2953. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2954. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2955. {
  2956. if(maxProfile.ChargingProfileId != -1)
  2957. {
  2958. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2959. {
  2960. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2961. {
  2962. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2963. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2964. if((maxProfile.ChargingSchedule.Duration > 0))
  2965. {
  2966. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2967. }
  2968. else
  2969. {
  2970. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2971. }
  2972. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2973. {
  2974. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2975. {
  2976. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2977. compositePeriodIdx++;
  2978. }
  2979. else
  2980. {
  2981. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2982. }
  2983. }
  2984. // Delete duplicate period
  2985. if(compositePeriodIdx > 1)
  2986. {
  2987. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2988. {
  2989. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2990. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2991. compositePeriodIdx -= 1;
  2992. }
  2993. }
  2994. }
  2995. else
  2996. {
  2997. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2998. {
  2999. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3000. compositePeriodIdx++;
  3001. }
  3002. else
  3003. {
  3004. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3005. }
  3006. break;
  3007. }
  3008. }
  3009. }
  3010. else
  3011. {
  3012. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3013. {
  3014. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3015. compositePeriodIdx++;
  3016. }
  3017. else
  3018. {
  3019. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3020. }
  3021. }
  3022. }
  3023. }
  3024. }
  3025. // Fill other period by MaxProfile
  3026. if(maxProfile.ChargingProfileId != -1)
  3027. {
  3028. if(compositePeriodIdx==0)
  3029. {
  3030. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3031. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3032. {
  3033. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3034. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3035. (maxProfile.ChargingSchedule.Duration > 0))
  3036. {
  3037. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3038. {
  3039. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3040. compositePeriodIdx++;
  3041. }
  3042. else
  3043. {
  3044. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3045. }
  3046. }
  3047. }
  3048. }
  3049. else
  3050. {
  3051. int lastCompositePeriodIdx = compositePeriodIdx;
  3052. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3053. {
  3054. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3055. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3056. (maxProfile.ChargingSchedule.Duration > 0))
  3057. {
  3058. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3059. {
  3060. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3061. {
  3062. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3063. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3064. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3065. }
  3066. else
  3067. {
  3068. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3069. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3070. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3071. }
  3072. }
  3073. if(tmpPeriod.Limit != -1)
  3074. {
  3075. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3076. {
  3077. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3078. {
  3079. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3080. compositePeriodIdx++;
  3081. }
  3082. else
  3083. {
  3084. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3085. }
  3086. }
  3087. // Delete duplicate period
  3088. if(compositePeriodIdx > 1)
  3089. {
  3090. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3091. {
  3092. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3093. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3094. compositePeriodIdx -= 1;
  3095. }
  3096. }
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. compositeProfile->ChargingSchedule.Duration = durationReq;
  3103. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3104. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3105. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3106. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3107. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3108. {
  3109. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3110. {
  3111. compositeProfile->ChargingProfileId = 1;
  3112. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3113. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3114. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3115. }
  3116. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3117. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3118. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3119. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3120. }
  3121. if(line)
  3122. free(line);
  3123. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3124. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3125. }
  3126. //==========================================
  3127. // Init all share memory
  3128. //==========================================
  3129. int InitShareMemory()
  3130. {
  3131. int result = PASS;
  3132. int MeterSMId;
  3133. //creat ShmSysConfigAndInfo
  3134. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3135. {
  3136. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3137. result = FAIL;
  3138. }
  3139. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3140. {
  3141. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3142. result = FAIL;
  3143. }
  3144. else
  3145. {}
  3146. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3147. {
  3148. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3149. result = FAIL;
  3150. }
  3151. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3152. {
  3153. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3154. result = FAIL;
  3155. }
  3156. else
  3157. {}
  3158. //creat ShmPsuData
  3159. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3160. {
  3161. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3162. result = FAIL;
  3163. }
  3164. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3165. {
  3166. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3167. result = FAIL;
  3168. }
  3169. else
  3170. {}
  3171. //link ShmOCPP16Data
  3172. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3173. {
  3174. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3175. result = FAIL;
  3176. }
  3177. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3178. {
  3179. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3180. result = FAIL;
  3181. }
  3182. else
  3183. {}
  3184. //creat ShmOCPP16DataPH
  3185. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3186. {
  3187. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3188. result = FAIL;
  3189. }
  3190. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3191. {
  3192. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3193. result = FAIL;
  3194. }
  3195. else
  3196. {}
  3197. /****************************** For Initial Settings************************************************/
  3198. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3199. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3200. // allocate Configuration memory address
  3201. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3202. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3203. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3204. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3205. //offline MeterValue Interval
  3206. TempMeterValueInterval = 0;
  3207. return result;
  3208. }
  3209. int ProcessShareMemory()
  3210. {
  3211. int result = PASS;
  3212. if(InitShareMemory() == FAIL)
  3213. {
  3214. DEBUG_ERROR("InitShareMemory NG\n");
  3215. if(ShmStatusCodeData!=NULL)
  3216. {
  3217. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3218. }
  3219. result = FAIL;
  3220. }
  3221. // Model name parsing
  3222. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3223. {
  3224. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3225. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3226. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3227. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3228. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3229. ) // 'D' means DC
  3230. {
  3231. // DO series
  3232. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3233. {
  3234. SystemInitial += 1;
  3235. gunTotalNumber += 1;
  3236. gunType[gun_index] = GUN_TYPE_DO;
  3237. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3238. {
  3239. case Gun_Type_Chademo:
  3240. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3241. break;
  3242. case Gun_Type_CCS_2:
  3243. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3244. break;
  3245. case Gun_Type_GB:
  3246. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3247. break;
  3248. case Gun_Type_AC:
  3249. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3250. break;
  3251. default:
  3252. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3253. break;
  3254. }
  3255. }
  3256. }
  3257. else
  3258. {
  3259. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3260. {
  3261. SystemInitial += 1;
  3262. gunTotalNumber += 1;
  3263. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3264. {
  3265. case Gun_Type_Chademo:
  3266. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3267. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3268. break;
  3269. case Gun_Type_CCS_2:
  3270. gunType[gun_index] = GUN_TYPE_CCS;
  3271. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3272. break;
  3273. case Gun_Type_GB:
  3274. gunType[gun_index] = GUN_TYPE_GBT;
  3275. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3276. break;
  3277. case Gun_Type_AC:
  3278. gunType[gun_index] = GUN_TYPE_AC;
  3279. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3280. break;
  3281. default:
  3282. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3283. break;
  3284. }
  3285. }
  3286. }
  3287. }
  3288. else
  3289. {
  3290. DEBUG_ERROR("Model name parsing fail.\n");
  3291. result = FAIL;
  3292. }
  3293. if(result != PASS)sleep(5);
  3294. return result;
  3295. }
  3296. void checkRemoteStart(uint8_t connectorIdInt)
  3297. {
  3298. uint8_t tempIndex;
  3299. int result = PASS;
  3300. char cmdBuf[512];
  3301. //check Transaction active
  3302. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3303. {
  3304. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3305. {
  3306. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3307. }
  3308. else
  3309. {
  3310. tempIndex = connectorIdInt -1;
  3311. }
  3312. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3313. {
  3314. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3315. {
  3316. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3317. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3318. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3319. {
  3320. //Reserved
  3321. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3322. }
  3323. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3324. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3325. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3326. {
  3327. //Reserved
  3328. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3329. result = FAIL;
  3330. goto end;
  3331. }
  3332. else
  3333. {
  3334. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3335. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3336. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3337. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3338. {
  3339. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3340. result = FAIL;
  3341. goto end;
  3342. }
  3343. }//END FOR ELSE
  3344. }
  3345. }// END FOR CHAdeMO_QUANTITY
  3346. }
  3347. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3348. {
  3349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3350. {
  3351. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3352. }
  3353. else
  3354. {
  3355. tempIndex = connectorIdInt -1;
  3356. }
  3357. for (int index = 0; index < CCS_QUANTITY; index++)
  3358. {
  3359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3360. {
  3361. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3362. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3363. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3364. {
  3365. //Reserved
  3366. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3367. }
  3368. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3369. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3370. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3371. {
  3372. //Reserved
  3373. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3374. result = FAIL;
  3375. goto end;
  3376. }
  3377. else
  3378. {
  3379. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3380. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3381. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3382. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3383. {
  3384. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3385. result = FAIL;
  3386. goto end;
  3387. }
  3388. }// END FOR ELSE
  3389. }
  3390. }// END FOR CCS_QUANTITY
  3391. }
  3392. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3393. {
  3394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3395. {
  3396. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3397. }
  3398. else
  3399. {
  3400. tempIndex = connectorIdInt -1;
  3401. }
  3402. for (int index = 0; index < GB_QUANTITY; index++)
  3403. {
  3404. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3405. {
  3406. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3407. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3408. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3409. {
  3410. //Reserved
  3411. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3412. }
  3413. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3414. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3415. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3416. {
  3417. //Reserved
  3418. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3419. result = FAIL;
  3420. goto end;
  3421. }
  3422. else
  3423. {
  3424. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3425. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3426. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3427. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3428. {
  3429. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3430. result = FAIL;
  3431. goto end;
  3432. }
  3433. }// END FOR ELSE
  3434. }
  3435. } // END FOR GB_QUANTITY
  3436. }
  3437. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3438. {
  3439. tempIndex = connectorIdInt -1;
  3440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3441. {
  3442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3443. {
  3444. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3445. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3446. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3447. {
  3448. //Reserved
  3449. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3450. }
  3451. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3452. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3453. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3454. {
  3455. //Reserved
  3456. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3457. result = FAIL;
  3458. goto end;
  3459. }
  3460. else
  3461. {
  3462. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3463. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3464. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3465. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3466. {
  3467. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3468. result = FAIL;
  3469. goto end;
  3470. }
  3471. }// END FOR ELSE
  3472. }
  3473. } // END FOR GB_QUANTITY
  3474. }
  3475. else
  3476. {
  3477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3478. {
  3479. tempIndex = 2;
  3480. }
  3481. else
  3482. {
  3483. tempIndex = connectorIdInt -1;
  3484. }
  3485. for (int index = 0; index < AC_QUANTITY; index++)
  3486. {
  3487. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3488. {
  3489. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3490. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3491. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3492. {
  3493. //Reserved
  3494. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3495. }
  3496. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3497. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3498. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3499. {
  3500. //Reserved
  3501. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3502. result = FAIL;
  3503. goto end;
  3504. }
  3505. else
  3506. {
  3507. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3508. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3509. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3510. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3511. {
  3512. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3513. result = FAIL;
  3514. goto end;
  3515. }
  3516. }//END FOR ELSE
  3517. }
  3518. }// END FOR AC_QUANTITY
  3519. }
  3520. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3521. {
  3522. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3523. {
  3524. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3525. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3526. {
  3527. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3528. system(cmdBuf);
  3529. }
  3530. }
  3531. else
  3532. {
  3533. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3534. result = FAIL;
  3535. }
  3536. }
  3537. end:
  3538. if(result == PASS)
  3539. {
  3540. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3541. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3542. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3543. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3545. }
  3546. }
  3547. void CheckSystemValue(void)
  3548. {
  3549. char filenmae[100]={0};
  3550. char str[100]={0};
  3551. int tempIndex = 0;
  3552. //===============================
  3553. // send Heartbeat
  3554. //===============================
  3555. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3556. {
  3557. //parameter for test
  3558. sendHeartbeatRequest(0);
  3559. //==============================================
  3560. // Reset Waiting Time
  3561. //==============================================
  3562. HeartBeatWithNOResponse += 2;
  3563. }
  3564. //===============================
  3565. // Credit deduct report
  3566. //===============================
  3567. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3568. {
  3569. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo, ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice);
  3570. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3571. }
  3572. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3573. {
  3574. OCPP_query_deduct_info();
  3575. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3576. }
  3577. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3578. {
  3579. // ClockAlign MeterValue
  3580. 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))
  3581. {
  3582. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3583. {
  3584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3585. {
  3586. tempIndex = ((gun_index==2) ? 1: 0);
  3587. }
  3588. else
  3589. {
  3590. tempIndex = gun_index;
  3591. }
  3592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3593. {
  3594. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3595. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3596. {
  3597. reqClockAlignMeter[gun_index] = 1;
  3598. }
  3599. }// End for CHAdeMO
  3600. }
  3601. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3602. {
  3603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3604. {
  3605. tempIndex = ((gun_index==2) ? 1: 0);
  3606. }
  3607. else
  3608. {
  3609. tempIndex = gun_index;
  3610. }
  3611. for (int index = 0; index < CCS_QUANTITY; index++)
  3612. {
  3613. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3614. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3615. {
  3616. reqClockAlignMeter[gun_index] = 1;
  3617. }
  3618. } // End for CCS
  3619. }
  3620. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3621. {
  3622. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3623. {
  3624. tempIndex = ((gun_index==2) ? 1: 0);
  3625. }
  3626. else
  3627. {
  3628. tempIndex = gun_index;
  3629. }
  3630. for (int index = 0; index < GB_QUANTITY; index++)
  3631. {
  3632. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3633. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3634. {
  3635. reqClockAlignMeter[gun_index] = 1;
  3636. }
  3637. }// End for GB
  3638. }
  3639. else if(gunType[gun_index] == GUN_TYPE_DO)
  3640. {
  3641. tempIndex = gun_index;
  3642. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3643. {
  3644. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3645. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3646. {
  3647. reqClockAlignMeter[gun_index] = 1;
  3648. }
  3649. }
  3650. }
  3651. else
  3652. {
  3653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3654. {
  3655. tempIndex = 2;
  3656. }
  3657. else
  3658. {
  3659. tempIndex = gun_index;
  3660. }
  3661. for (int index = 0; index < AC_QUANTITY; index++)
  3662. {
  3663. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3664. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3665. {
  3666. reqClockAlignMeter[gun_index] = 1;
  3667. }
  3668. }//End for AC
  3669. }
  3670. }
  3671. }
  3672. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3673. {
  3674. //==========================================
  3675. // Check remote start without connector id
  3676. //==========================================
  3677. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3678. {
  3679. int connectorIdInt = -1;
  3680. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3681. {
  3682. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3683. {
  3684. connectorIdInt = (gun_index+1);
  3685. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3686. checkRemoteStart(connectorIdInt);
  3687. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3688. break;
  3689. }
  3690. }
  3691. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3692. {
  3693. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3694. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3695. }
  3696. }
  3697. //==========================================
  3698. // csu trigger DataTransferReq
  3699. //==========================================
  3700. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3701. {
  3702. sendDataTransferRequest(gun_index);
  3703. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3704. }
  3705. //===============================
  3706. // CSU Trigger Authorize Request
  3707. //===============================
  3708. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3709. {
  3710. sendAuthorizeRequest(0);
  3711. authorizeRetryTimes = authorizeRetryTimes + 1;
  3712. if(authorizeRetryTimes < 3)
  3713. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3714. }
  3715. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3716. {
  3717. authorizeRetryTimes = 0;
  3718. SetOcppConnStatus(FALSE);
  3719. server_sign = FALSE;
  3720. }
  3721. 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))
  3722. {
  3723. sendAuthorizeRequest(0);
  3724. }
  3725. //==============================================
  3726. // Charger start transaction
  3727. //==============================================
  3728. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3729. {
  3730. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3731. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3732. sendStartTransactionRequest(gun_index);
  3733. refreshStartTimer(&clientTime.StartTransaction);
  3734. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3735. //storeTempStopTransaction(gun_index);
  3736. }
  3737. //==============================================
  3738. // Charger stop transaction
  3739. //==============================================
  3740. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3741. {
  3742. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3743. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3744. sendStopTransactionRequest(gun_index);
  3745. refreshStartTimer(&clientTime.StopTransaction);
  3746. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3747. }
  3748. //==============================================
  3749. // Charger status report
  3750. //==============================================
  3751. //--- Check Mode Change ---//
  3752. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3753. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3756. {
  3757. tempIndex = ((gun_index==2) ? 1: 0);
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3766. {
  3767. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3768. {
  3769. // Sent unplug message for California pricing logic
  3770. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3771. {
  3772. uint8_t ts[20];
  3773. getNowDatetime(ts);
  3774. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3775. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3776. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3777. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3778. }
  3779. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3780. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3781. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3782. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3783. {
  3784. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3785. if((access(filenmae,F_OK))!=-1)
  3786. {
  3787. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3788. sprintf(str,"rm -f %s",filenmae);
  3789. system(str);
  3790. }
  3791. }
  3792. }
  3793. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3794. #if 1 // for TempStopTransaction
  3795. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3796. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3797. {
  3798. checkTempStopTransaction(gun_index);
  3799. }
  3800. #endif
  3801. }
  3802. }
  3803. }
  3804. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3805. {
  3806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3807. {
  3808. tempIndex = ((gun_index==2) ? 1: 0);
  3809. }
  3810. else
  3811. {
  3812. tempIndex = gun_index;
  3813. }
  3814. for (int index = 0; index < CCS_QUANTITY; index++)
  3815. {
  3816. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3817. {
  3818. 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]*/ )
  3819. {
  3820. // Sent unplug message for California pricing logic
  3821. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3822. {
  3823. uint8_t ts[20];
  3824. getNowDatetime(ts);
  3825. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3826. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3827. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3828. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3829. }
  3830. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3831. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3832. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3833. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3834. {
  3835. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3836. if((access(filenmae,F_OK))!=-1)
  3837. {
  3838. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3839. sprintf(str,"rm -f %s",filenmae);
  3840. system(str);
  3841. }
  3842. }
  3843. }
  3844. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3845. #if 1 // for TempStopTransaction
  3846. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3847. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3848. {
  3849. checkTempStopTransaction(gun_index);
  3850. }
  3851. #endif
  3852. }
  3853. }
  3854. }
  3855. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3856. {
  3857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3858. {
  3859. tempIndex = ((gun_index==2) ? 1: 0);
  3860. }
  3861. else
  3862. {
  3863. tempIndex = gun_index;
  3864. }
  3865. for (int index = 0; index < GB_QUANTITY; index++)
  3866. {
  3867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3868. {
  3869. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3870. {
  3871. // Sent unplug message for California pricing logic
  3872. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3873. {
  3874. uint8_t ts[20];
  3875. getNowDatetime(ts);
  3876. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3877. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3878. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3879. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3880. }
  3881. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3882. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3883. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3884. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3885. {
  3886. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3887. if((access(filenmae,F_OK))!=-1)
  3888. {
  3889. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3890. sprintf(str,"rm -f %s",filenmae);
  3891. system(str);
  3892. }
  3893. }
  3894. }
  3895. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3896. #if 1 // for TempStopTransaction
  3897. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3898. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3899. {
  3900. checkTempStopTransaction(gun_index);
  3901. }
  3902. #endif
  3903. }
  3904. }
  3905. }
  3906. else if(gunType[gun_index] == GUN_TYPE_DO)
  3907. {
  3908. tempIndex = gun_index;
  3909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3910. {
  3911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3912. {
  3913. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3914. {
  3915. // Sent unplug message for California pricing logic
  3916. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3917. {
  3918. uint8_t ts[20];
  3919. getNowDatetime(ts);
  3920. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3921. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3922. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3923. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3924. }
  3925. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3926. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3927. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3928. 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
  3929. {
  3930. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3931. if((access(filenmae,F_OK))!=-1)
  3932. {
  3933. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3934. sprintf(str,"rm -f %s",filenmae);
  3935. system(str);
  3936. }
  3937. }
  3938. }
  3939. 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);
  3940. #if 1 // for TempStopTransaction
  3941. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3942. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3943. {
  3944. checkTempStopTransaction(gun_index);
  3945. }
  3946. #endif
  3947. }
  3948. }
  3949. }
  3950. else
  3951. {
  3952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3953. {
  3954. tempIndex = 2;
  3955. }
  3956. else
  3957. {
  3958. tempIndex = gun_index;
  3959. }
  3960. for (int index = 0; index < AC_QUANTITY; index++)
  3961. {
  3962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3963. {
  3964. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3965. {
  3966. // Sent unplug message for California pricing logic
  3967. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3968. {
  3969. uint8_t ts[20];
  3970. getNowDatetime(ts);
  3971. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3972. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3973. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3974. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3975. }
  3976. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3977. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3978. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3979. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3980. {
  3981. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3982. if((access(filenmae,F_OK))!=-1)
  3983. {
  3984. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3985. sprintf(str,"rm -f %s",filenmae);
  3986. system(str);
  3987. }
  3988. }
  3989. }
  3990. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3991. #if 1 // for TempStopTransaction
  3992. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3993. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3994. {
  3995. checkTempStopTransaction(gun_index);
  3996. }
  3997. #endif
  3998. }
  3999. }// END
  4000. }
  4001. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4002. (
  4003. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4004. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4005. )
  4006. )
  4007. {
  4008. if(SystemInitial > 0)
  4009. SystemInitial -= 1;
  4010. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4011. sendStatusNotificationRequest(gun_index);
  4012. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4013. }
  4014. //==============================================
  4015. // CSU Trigger Smart Charging Profilw
  4016. //==============================================
  4017. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4018. {
  4019. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4020. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4021. }
  4022. //==============================================
  4023. // Meter report
  4024. //==============================================
  4025. // Trigger MeterValue
  4026. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4027. {
  4028. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4029. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4030. }
  4031. // Clock-aligned Meter value
  4032. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4033. {
  4034. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4035. reqClockAlignMeter[gun_index] = 0;
  4036. }
  4037. // Sample period MeterValue
  4038. 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))))
  4039. {
  4040. //check Transaction active
  4041. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4042. {
  4043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4044. {
  4045. tempIndex = ((gun_index==2) ? 1: 0);
  4046. }
  4047. else
  4048. {
  4049. tempIndex = gun_index;
  4050. }
  4051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4052. {
  4053. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4054. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4055. {
  4056. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4057. {
  4058. reqSampleMeter[gun_index] = 1;
  4059. }
  4060. }
  4061. }// End for CHAdeMO
  4062. }
  4063. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4064. {
  4065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4066. {
  4067. tempIndex = ((gun_index==2) ? 1: 0);
  4068. }
  4069. else
  4070. {
  4071. tempIndex = gun_index;
  4072. }
  4073. for (int index = 0; index < CCS_QUANTITY; index++)
  4074. {
  4075. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4076. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4077. {
  4078. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4079. {
  4080. reqSampleMeter[gun_index] = 1;
  4081. }
  4082. }
  4083. } // End for CCS
  4084. }
  4085. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4086. {
  4087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4088. {
  4089. tempIndex = ((gun_index==2) ? 1: 0);
  4090. }
  4091. else
  4092. {
  4093. tempIndex = gun_index;
  4094. }
  4095. for (int index = 0; index < GB_QUANTITY; index++)
  4096. {
  4097. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4098. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4099. {
  4100. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4101. {
  4102. reqSampleMeter[gun_index] = 1;
  4103. }
  4104. }
  4105. }// End for GB
  4106. }
  4107. else if(gunType[gun_index] == GUN_TYPE_DO)
  4108. {
  4109. tempIndex = gun_index;
  4110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4111. {
  4112. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4113. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4114. {
  4115. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4116. {
  4117. reqSampleMeter[gun_index] = 1;
  4118. }
  4119. }
  4120. }
  4121. }
  4122. else
  4123. {
  4124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4125. {
  4126. tempIndex = 2;
  4127. }
  4128. else
  4129. {
  4130. tempIndex = gun_index;
  4131. }
  4132. for (int index = 0; index < AC_QUANTITY; index++)
  4133. {
  4134. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4135. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4136. {
  4137. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4138. {
  4139. reqSampleMeter[gun_index] = 1;
  4140. }
  4141. }
  4142. }//End for AC
  4143. }
  4144. if(reqSampleMeter[gun_index] == 1)
  4145. {
  4146. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4147. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4148. //storeTempStopTransaction(gun_index);
  4149. reqSampleMeter[gun_index] = 0;
  4150. }
  4151. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4152. }
  4153. //==============================================
  4154. // Check Connector reserved
  4155. //==============================================
  4156. //===============================
  4157. // Check if Reserve is expired
  4158. //===============================
  4159. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4160. {
  4161. double diff_t;
  4162. struct tm tp;
  4163. // current time
  4164. time_t t = time(NULL);
  4165. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4166. tp.tm_isdst = -1;
  4167. time_t utc = mktime(&tp);
  4168. diff_t = difftime(utc, t);
  4169. if(diff_t <= 0)
  4170. {
  4171. DEBUG_INFO("reserve expired.\n");
  4172. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4173. }
  4174. }//END OF Check if Reserve is expired
  4175. //==========================================
  4176. // csu trigger FirmwareStatusNotificationReq
  4177. //==========================================
  4178. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4179. {
  4180. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4181. }
  4182. //==========================================
  4183. // csu trigger DiagnosticsStatusNotificationReq
  4184. //==========================================
  4185. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4186. {
  4187. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4188. }
  4189. //==========================================
  4190. // csu trigger CancelReservationConf
  4191. //==========================================
  4192. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4193. {
  4194. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4195. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4196. }
  4197. //==========================================
  4198. // csu trigger ChangeAvailabilityConf
  4199. //==========================================
  4200. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4201. {
  4202. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4203. }
  4204. //==========================================
  4205. // csu trigger UnlockConnectorConf
  4206. //==========================================
  4207. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4208. {
  4209. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4210. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4211. }
  4212. //==========================================
  4213. // csu trigger ReserveNowConf
  4214. //==========================================
  4215. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4216. {
  4217. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4218. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4219. }
  4220. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4221. {
  4222. sendSignCertificateRequest();
  4223. }
  4224. }
  4225. }
  4226. //==========================================
  4227. // send request routine
  4228. //==========================================
  4229. int sendAuthorizeRequest(int gun_index)
  4230. {
  4231. mtrace();
  4232. int result = FAIL;
  4233. char message[100]={0};
  4234. char guid[37];
  4235. char tempdata[65]={0};
  4236. DEBUG_INFO("sendAuthorizeRequest...\n");
  4237. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4238. //Local Authorize
  4239. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4240. {
  4241. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4242. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4243. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4244. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4245. result = PASS;
  4246. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4247. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4248. authorizeRetryTimes = 0;
  4249. return result;
  4250. }
  4251. 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))||
  4252. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4253. {
  4254. // Query from cache
  4255. DEBUG_INFO("Authorize from cache.\n");
  4256. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4257. // Query from list
  4258. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4259. {
  4260. DEBUG_INFO("Authorize from list.\n");
  4261. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4262. }
  4263. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4264. {
  4265. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4266. {
  4267. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4268. }
  4269. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4270. {
  4271. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4272. }
  4273. if(!GetOcppConnStatus())
  4274. {
  4275. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4276. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4277. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4278. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4279. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4280. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4281. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4282. authorizeRetryTimes = 0;
  4283. return result;
  4284. }
  4285. }
  4286. else
  4287. {
  4288. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4289. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4290. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4291. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4292. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4293. else
  4294. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4295. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4296. result = PASS;
  4297. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4298. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4299. authorizeRetryTimes = 0;
  4300. return result;
  4301. }
  4302. }
  4303. //initialize struct Authorize
  4304. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4305. //get data from shared memory
  4306. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4307. random_uuid(guid);
  4308. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4309. LWS_Send(message);
  4310. sprintf(tempdata, "Authorize,%d", gun_index);
  4311. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4312. {
  4313. result = PASS;
  4314. DEBUG_INFO("Authorize mapItem pass\n");
  4315. }
  4316. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4317. return result;
  4318. }
  4319. int sendBootNotificationRequest(void)
  4320. {
  4321. mtrace();
  4322. int result = FAIL;
  4323. char message[500]={0}, payload[700]={0};
  4324. char guid[37]={0};
  4325. char tempdata[65]={0};
  4326. // Fill BootNotification fields
  4327. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4328. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4329. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4330. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4331. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4332. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4333. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4334. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4335. ShmOCPP16DataPH->ChargeBoxId
  4336. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4337. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4338. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4339. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4340. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4341. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4342. random_uuid(guid);
  4343. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4344. LWS_Send(message);
  4345. sprintf(tempdata, "BootNotification,0");
  4346. 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*/)
  4347. {
  4348. result = PASS;
  4349. }
  4350. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4351. strcpy(queuedata,message);
  4352. return result;
  4353. }
  4354. int sendDataTransferRequest(int gun_index)
  4355. {
  4356. mtrace();
  4357. char message[1000]={0};
  4358. char guid[37]={0};
  4359. char tempdata[65]={0};
  4360. int result = FAIL;
  4361. random_uuid(guid);
  4362. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4363. MESSAGE_TYPE_CALL,
  4364. guid,
  4365. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4366. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4367. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4368. LWS_Send(message);
  4369. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4370. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4371. {
  4372. result = PASS;
  4373. DEBUG_INFO("DataTransfer mapItem pass\n");
  4374. }
  4375. return result;
  4376. }
  4377. int sendDiagnosticsStatusNotificationRequest(char *status)
  4378. {
  4379. mtrace();
  4380. int result = FAIL;
  4381. char message[110]={0};
  4382. char guid[37]={0};
  4383. char tempdata[65]={0};
  4384. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4385. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4386. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4387. random_uuid(guid);
  4388. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4389. LWS_SendNow(message);
  4390. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4391. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4392. {
  4393. result = PASS;
  4394. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4395. }
  4396. //#ifdef SystemLogMessage
  4397. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4398. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4399. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4400. //#endif
  4401. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4402. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4403. //record status
  4404. if(strcmp(status,"Idle")==0)
  4405. {
  4406. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4407. }
  4408. else if(strcmp(status,"Uploaded")==0)
  4409. {
  4410. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4411. }
  4412. else if(strcmp(status,"UploadFailed")==0)
  4413. {
  4414. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4415. }
  4416. else if(strcmp(status,"Uploading")==0)
  4417. {
  4418. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4419. }
  4420. return result;
  4421. }
  4422. int sendFirmwareStatusNotificationRequest(char *status)
  4423. {
  4424. mtrace();
  4425. int result = FAIL;
  4426. char message[110]={0};
  4427. char guid[37]={0};
  4428. char tempdata[65]={0};
  4429. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4430. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4431. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4432. random_uuid(guid);
  4433. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4434. LWS_SendNow(message);
  4435. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4436. 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*/)
  4437. {
  4438. result = PASS;
  4439. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4440. }
  4441. //#ifdef SystemLogMessage
  4442. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4443. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4444. //#endif
  4445. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4446. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4447. //record status
  4448. if(strcmp(status,"Downloaded")==0)
  4449. {
  4450. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4451. }
  4452. else if(strcmp(status,"DownloadFailed")==0)
  4453. {
  4454. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4455. }
  4456. else if(strcmp(status,"Downloading")==0)
  4457. {
  4458. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4459. }
  4460. else if(strcmp(status,"Idle")==0)
  4461. {
  4462. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4463. }
  4464. else if(strcmp(status,"InstallationFailed")==0)
  4465. {
  4466. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4467. }
  4468. else if(strcmp(status,"Installing")==0)
  4469. {
  4470. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4471. }
  4472. else if(strcmp(status,"Installed")==0)
  4473. {
  4474. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4475. }
  4476. return result;
  4477. }
  4478. int sendHeartbeatRequest(int gun_index)
  4479. {
  4480. mtrace();
  4481. int result = FAIL;
  4482. char message[80]={0};
  4483. char guid[37]={0};
  4484. char tempdata[65]={0};
  4485. random_uuid(guid);
  4486. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4487. , MESSAGE_TYPE_CALL
  4488. , guid );
  4489. LWS_Send(message);
  4490. sprintf(tempdata, "Heartbeat,%d", 0);
  4491. 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*/)
  4492. {
  4493. result = PASS;
  4494. }
  4495. return result;
  4496. }
  4497. int sendStartTransactionRequest(int gun_index)
  4498. {
  4499. mtrace();
  4500. int result = FAIL;
  4501. char message[250]={0};
  4502. char guid[37]={0};
  4503. struct timeval tmnow;
  4504. struct tm *tm;
  4505. char buf[28];//, usec_buf[6];
  4506. char tempdata[65]={0};
  4507. int tempIndex = 0;
  4508. DEBUG_INFO("sendStartTransactionRequest...\n");
  4509. gettimeofday(&tmnow, NULL);
  4510. time_t t;
  4511. t = time(NULL);
  4512. /*UTC time and date*/
  4513. tm = gmtime(&t);
  4514. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4515. #if 0 // remove temporally
  4516. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4517. strcat(buf,".");
  4518. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4519. strcat(buf,usec_buf);
  4520. #endif
  4521. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4522. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4523. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4524. // clear StartTransaction Response
  4525. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4526. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4527. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4528. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4529. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4530. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4531. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4532. {
  4533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4534. {
  4535. tempIndex = ((gun_index==2) ? 1: 0);
  4536. }
  4537. else
  4538. {
  4539. tempIndex = gun_index;
  4540. }
  4541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4542. {
  4543. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4544. {
  4545. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4546. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4547. }
  4548. }
  4549. }
  4550. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4551. {
  4552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4553. {
  4554. tempIndex = ((gun_index==2) ? 1: 0);
  4555. }
  4556. else
  4557. {
  4558. tempIndex = gun_index;
  4559. }
  4560. for (int index = 0; index < CCS_QUANTITY; index++)
  4561. {
  4562. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4563. {
  4564. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4565. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4566. }
  4567. }
  4568. }
  4569. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4570. {
  4571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4572. {
  4573. tempIndex = ((gun_index==2) ? 1: 0);
  4574. }
  4575. else
  4576. {
  4577. tempIndex = gun_index;
  4578. }
  4579. for (int index = 0; index < GB_QUANTITY; index++)
  4580. {
  4581. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4582. {
  4583. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4584. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4585. }
  4586. }
  4587. }
  4588. else if(gunType[gun_index] == GUN_TYPE_DO)
  4589. {
  4590. tempIndex = gun_index;
  4591. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4592. {
  4593. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4594. {
  4595. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4596. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4597. }
  4598. }
  4599. }
  4600. else
  4601. {
  4602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4603. {
  4604. tempIndex = 2;
  4605. }
  4606. else
  4607. {
  4608. tempIndex = gun_index;
  4609. }
  4610. for (int index = 0; index < AC_QUANTITY; index++)
  4611. {
  4612. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4613. {
  4614. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4615. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4616. }
  4617. }
  4618. }
  4619. random_uuid(guid);
  4620. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4621. {
  4622. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4623. , gun_index +1
  4624. , MESSAGE_TYPE_CALL
  4625. , guid
  4626. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4627. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4628. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4629. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4630. }
  4631. else
  4632. {
  4633. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4634. , gun_index +1
  4635. , MESSAGE_TYPE_CALL
  4636. , guid
  4637. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4638. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4639. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4640. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4641. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4642. }
  4643. #if 1
  4644. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4645. 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*/)
  4646. {
  4647. result = PASS;
  4648. }
  4649. #endif
  4650. strcpy(queuedata, message);
  4651. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4652. OCPP_insert_transaction_msg(YES, queuedata);
  4653. return result;
  4654. }
  4655. int sendStatusNotificationRequest(int gun_index)
  4656. {
  4657. mtrace();
  4658. int result = FAIL;
  4659. char message[600]={0};
  4660. char guid[37];
  4661. int currentStatus = 0;
  4662. struct timeval tmnow;
  4663. struct tm *tm;
  4664. char buf[28];//, usec_buf[6];
  4665. char tempdata[65]={0};
  4666. int tempIndex = 0;
  4667. uint8_t isStateChanged = TRUE;
  4668. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4669. gettimeofday(&tmnow, NULL);
  4670. time_t t;
  4671. t = time(NULL);
  4672. /*UTC time and date*/
  4673. tm = gmtime(&t);
  4674. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4675. #if 0 // remove temporally
  4676. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4677. strcat(buf,".");
  4678. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4679. strcat(buf,usec_buf);
  4680. #endif
  4681. //printf("%s",buf);
  4682. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4683. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4684. // it's option
  4685. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4686. /*
  4687. enum _SYSTEM_STATUS
  4688. {
  4689. S_BOOTING = 0,
  4690. S_IDLE, = 1
  4691. S_AUTHORIZING, =2
  4692. S_REASSIGN_CHECK, =3
  4693. S_REASSIGN, =4
  4694. S_PRECHARGE, =5
  4695. S_PREPARING_FOR_EV, =6
  4696. S_PREPARING_FOR_EVSE, =7
  4697. S_CHARGING, =8
  4698. S_TERMINATING, =9
  4699. S_COMPLETE, =10
  4700. S_ALARM, =11
  4701. S_FAULT =12
  4702. }
  4703. */
  4704. //check Transaction active
  4705. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4706. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4707. {
  4708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4709. {
  4710. tempIndex = ((gun_index==2) ? 1: 0);
  4711. }
  4712. else
  4713. {
  4714. tempIndex = gun_index;
  4715. }
  4716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4717. {
  4718. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4719. {
  4720. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4721. {
  4722. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4723. {
  4724. currentStatus = Preparing; //OCPP Status: Preparing
  4725. }
  4726. else
  4727. {
  4728. currentStatus = Available; //OCPP Status: Available
  4729. }
  4730. }
  4731. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4732. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4733. ) //S_PRECHARGE
  4734. {
  4735. currentStatus = Preparing; //OCPP Status: Preparing
  4736. }
  4737. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4738. {
  4739. currentStatus = Charging; //OCPP Status: Charging
  4740. }
  4741. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4742. {
  4743. currentStatus = Finishing; //OCPP Status: Finishing
  4744. }
  4745. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4746. {
  4747. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4748. }
  4749. 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
  4750. {
  4751. currentStatus = Unavailable; //OCPP Status: Unavailable
  4752. }
  4753. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4754. {
  4755. currentStatus = Faulted; //OCPP Status: Faulted
  4756. }
  4757. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4758. {
  4759. currentStatus = Reserved; //OCPP Status: Reserved
  4760. }
  4761. } //end of the same index
  4762. }//end of for CHAdeMO_QUANTITY
  4763. }
  4764. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4765. {
  4766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4767. {
  4768. tempIndex = ((gun_index==2) ? 1: 0);
  4769. }
  4770. else
  4771. {
  4772. tempIndex = gun_index;
  4773. }
  4774. for (int index = 0; index < CCS_QUANTITY; index++)
  4775. {
  4776. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4777. {
  4778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4779. {
  4780. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4781. {
  4782. currentStatus = Preparing; //OCPP Status: Preparing
  4783. }
  4784. else
  4785. {
  4786. currentStatus = Available; //OCPP Status: Available
  4787. }
  4788. }
  4789. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4790. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4791. ) //S_PRECHARGE
  4792. {
  4793. currentStatus = Preparing; //OCPP Status: Preparing
  4794. }
  4795. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4796. {
  4797. currentStatus = Charging; //OCPP Status: Charging
  4798. }
  4799. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4800. {
  4801. currentStatus = Finishing; //OCPP Status: Finishing
  4802. }
  4803. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4804. {
  4805. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4806. }
  4807. 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
  4808. {
  4809. currentStatus = Unavailable; //OCPP Status : Unavailable
  4810. }
  4811. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4812. {
  4813. currentStatus = Faulted; //OCPP Status: Faulted
  4814. }
  4815. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4816. {
  4817. currentStatus = Reserved; //OCPP Status: Reserved
  4818. }
  4819. } //end of the same index
  4820. } // end of for CCS_QUANTITY
  4821. }
  4822. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4823. {
  4824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4825. {
  4826. tempIndex = ((gun_index==2) ? 1: 0);
  4827. }
  4828. else
  4829. {
  4830. tempIndex = gun_index;
  4831. }
  4832. for (int index = 0; index < GB_QUANTITY; index++)
  4833. {
  4834. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4835. {
  4836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4837. {
  4838. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4839. {
  4840. currentStatus = Preparing; //OCPP Status: Preparing
  4841. }
  4842. else
  4843. {
  4844. currentStatus = Available; //OCPP Status: Available
  4845. }
  4846. }
  4847. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4848. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4849. ) //S_PRECHARGE
  4850. {
  4851. currentStatus = Preparing; //OCPP Status: Preparing
  4852. }
  4853. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4854. {
  4855. currentStatus = Charging; //OCPP Status: Charging
  4856. }
  4857. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4858. {
  4859. currentStatus = Finishing; //OCPP Status: Finishing
  4860. }
  4861. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4862. {
  4863. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4864. }
  4865. 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
  4866. {
  4867. currentStatus = Unavailable; //OCPP Status: Unavailable
  4868. }
  4869. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4870. {
  4871. currentStatus = Faulted; //OCPP Status: Faulted
  4872. }
  4873. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4874. {
  4875. currentStatus = Reserved; //OCPP Status: Reserved
  4876. }
  4877. } //end of the same index
  4878. } // end of for GB_QUANTITY
  4879. }
  4880. else if(gunType[gun_index] == GUN_TYPE_DO)
  4881. {
  4882. tempIndex = gun_index;
  4883. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4886. {
  4887. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4888. {
  4889. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4890. {
  4891. currentStatus = Preparing; //OCPP Status: Preparing
  4892. }
  4893. else
  4894. {
  4895. currentStatus = Available; //OCPP Status: Available
  4896. }
  4897. }
  4898. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4899. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4900. ) //S_PRECHARGE
  4901. {
  4902. currentStatus = Preparing; //OCPP Status: Preparing
  4903. }
  4904. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4905. {
  4906. currentStatus = Charging; //OCPP Status: Charging
  4907. }
  4908. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4909. {
  4910. currentStatus = Finishing; //OCPP Status: Finishing
  4911. }
  4912. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4913. {
  4914. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4915. }
  4916. 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
  4917. {
  4918. currentStatus = Unavailable; //OCPP Status: Unavailable
  4919. }
  4920. 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
  4921. {
  4922. currentStatus = Faulted; //OCPP Status: Faulted
  4923. }
  4924. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4925. {
  4926. currentStatus = Reserved; //OCPP Status: Reserved
  4927. }
  4928. } //end of the same index
  4929. }
  4930. }
  4931. else
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4934. {
  4935. tempIndex = 2;
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < AC_QUANTITY; index++)
  4942. {
  4943. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4944. {
  4945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4946. {
  4947. 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))
  4948. {
  4949. currentStatus = Preparing; //OCPP Status: Preparing
  4950. }
  4951. else
  4952. {
  4953. currentStatus = Available; //OCPP Status: Available
  4954. }
  4955. }
  4956. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4957. {
  4958. currentStatus = Preparing; //OCPP Status: Preparing
  4959. }
  4960. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4961. {
  4962. currentStatus = Charging; //OCPP Status: Charging
  4963. }
  4964. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4965. {
  4966. currentStatus = Finishing; //OCPP Status: Finishing
  4967. }
  4968. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4969. {
  4970. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4971. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4972. else
  4973. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4974. }
  4975. 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
  4976. {
  4977. currentStatus = Unavailable; //OCPP Status: Unavailable
  4978. }
  4979. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4980. {
  4981. currentStatus = Faulted; //OCPP Status: Faulted
  4982. }
  4983. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4984. {
  4985. currentStatus = Reserved; //OCPP Status: Reserved
  4986. }
  4987. }//end of the same index
  4988. }//end of for AC_QUANTITY
  4989. }
  4990. //it's option
  4991. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4992. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  4993. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  4994. {
  4995. isStateChanged = FALSE;
  4996. }
  4997. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4998. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4999. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5000. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5001. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5002. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5003. random_uuid(guid);
  5004. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5005. , MESSAGE_TYPE_CALL
  5006. , guid
  5007. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5008. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5009. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5010. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5011. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5012. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5013. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5014. if((server_sign == TRUE) && isStateChanged)
  5015. {
  5016. LWS_Send(message);
  5017. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5018. 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*/)
  5019. {
  5020. //DEBUG_ERROR("statusNotification mapitem pass");
  5021. result = PASS;
  5022. }
  5023. }
  5024. else
  5025. {
  5026. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5027. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5028. result = PASS;
  5029. }
  5030. return result;
  5031. }
  5032. int sendStopTransactionRequest(int gun_index)
  5033. {
  5034. mtrace();
  5035. int result = FAIL;
  5036. //char message[1500]={0};
  5037. char guid[37]={0};
  5038. char tempdata[65]={0};
  5039. int tempIndex = 0;
  5040. char TempStopTransaction[256];
  5041. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5042. //int idx_sample=0;
  5043. DEBUG_INFO("sendStopTransactionRequest \n");
  5044. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5045. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5046. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5047. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5049. {
  5050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5051. {
  5052. tempIndex = ((gun_index==2) ? 1: 0);
  5053. }
  5054. else
  5055. {
  5056. tempIndex = gun_index;
  5057. }
  5058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5059. {
  5060. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5061. {
  5062. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5063. }
  5064. }// END OF CHAdeMO_QUANTITY
  5065. }
  5066. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5067. {
  5068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5069. {
  5070. tempIndex = ((gun_index==2) ? 1: 0);
  5071. }
  5072. else
  5073. {
  5074. tempIndex = gun_index;
  5075. }
  5076. for (int index = 0; index < CCS_QUANTITY; index++)
  5077. {
  5078. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5079. {
  5080. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5081. }
  5082. }// END OF CCS_QUANTITY
  5083. }
  5084. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5085. {
  5086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5087. {
  5088. tempIndex = ((gun_index==2) ? 1: 0);
  5089. }
  5090. else
  5091. {
  5092. tempIndex = gun_index;
  5093. }
  5094. for (int index = 0; index < GB_QUANTITY; index++)
  5095. {
  5096. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5097. {
  5098. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5099. }
  5100. }// END OF GB_QUANTITY
  5101. }
  5102. else if(gunType[gun_index] == GUN_TYPE_DO)
  5103. {
  5104. tempIndex = gun_index;
  5105. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5108. {
  5109. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5110. }
  5111. }// END OF GB_QUANTITY
  5112. }
  5113. else
  5114. {
  5115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5116. {
  5117. tempIndex = 2;
  5118. }
  5119. else
  5120. {
  5121. tempIndex = gun_index;
  5122. }
  5123. for (int index = 0; index < AC_QUANTITY; index++)
  5124. {
  5125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5126. {
  5127. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5128. }
  5129. }// END OF AC_QUANTITY
  5130. }
  5131. //====================================== Stop Transaction Time =====================================================
  5132. struct timeval tmnow;
  5133. struct tm *tm;
  5134. char buf[28];//, usec_buf[6];
  5135. gettimeofday(&tmnow, NULL);
  5136. time_t t;
  5137. t = time(NULL);
  5138. /*UTC time and date*/
  5139. tm = gmtime(&t);
  5140. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5142. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5143. random_uuid(guid);
  5144. /***********************************transactionData******************************************************/
  5145. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5147. //=================================
  5148. // Transaction_Begin
  5149. //=================================
  5150. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5151. {
  5152. //============================================ Energy.Active.Import.Interval ================================
  5153. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5156. 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*/]);
  5157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5158. 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))
  5159. {
  5160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5161. }
  5162. else
  5163. {
  5164. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5165. }
  5166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5168. }
  5169. //=================================
  5170. // Transaction_End
  5171. //=================================
  5172. // ================================= Current.Import L1 ===============================================
  5173. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5174. {
  5175. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5176. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5177. {
  5178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5179. {
  5180. tempIndex = ((gun_index==2) ? 1: 0);
  5181. }
  5182. else
  5183. {
  5184. tempIndex = gun_index;
  5185. }
  5186. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5189. {
  5190. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5191. }
  5192. }// End of for CHAdeMO_QUANTITY
  5193. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5194. }
  5195. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5196. {
  5197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5198. {
  5199. tempIndex = ((gun_index==2) ? 1: 0);
  5200. }
  5201. else
  5202. {
  5203. tempIndex = gun_index;
  5204. }
  5205. for (int index = 0; index < CCS_QUANTITY; index++)
  5206. {
  5207. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5208. {
  5209. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5210. }
  5211. }// End of for CCS_QUANTITY
  5212. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5213. }
  5214. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5215. {
  5216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5217. {
  5218. tempIndex = ((gun_index==2) ? 1: 0);
  5219. }
  5220. else
  5221. {
  5222. tempIndex = gun_index;
  5223. }
  5224. for (int index = 0; index < GB_QUANTITY; index++)
  5225. {
  5226. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5227. {
  5228. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5229. }
  5230. }// End of for GB_QUANTITY
  5231. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5232. }
  5233. else if(gunType[gun_index] == GUN_TYPE_DO)
  5234. {
  5235. tempIndex = gun_index;
  5236. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5237. {
  5238. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5239. {
  5240. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5241. }
  5242. }
  5243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5244. }
  5245. else
  5246. {
  5247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5248. {
  5249. tempIndex = 2;
  5250. }
  5251. else
  5252. {
  5253. tempIndex = gun_index;
  5254. }
  5255. for (int index = 0; index < AC_QUANTITY; index++)
  5256. {
  5257. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5258. {
  5259. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5260. }
  5261. }// End of for AC_QUANTITY
  5262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5263. }
  5264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5269. }
  5270. // ================================= Energy.Active.Import.Interval ==============================================
  5271. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5272. {
  5273. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5274. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5275. {
  5276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5277. {
  5278. tempIndex = ((gun_index==2) ? 1: 0);
  5279. }
  5280. else
  5281. {
  5282. tempIndex = gun_index;
  5283. }
  5284. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5285. {
  5286. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5287. {
  5288. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5289. }
  5290. }// END OF CHAdeMO_QUANTITY
  5291. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5292. }
  5293. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5294. {
  5295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5296. {
  5297. tempIndex = ((gun_index==2) ? 1: 0);
  5298. }
  5299. else
  5300. {
  5301. tempIndex = gun_index;
  5302. }
  5303. for (int index = 0; index < CCS_QUANTITY; index++)
  5304. {
  5305. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5306. {
  5307. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5308. }
  5309. }// END OF CCS_QUANTITY
  5310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5311. }
  5312. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5313. {
  5314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5315. {
  5316. tempIndex = ((gun_index==2) ? 1: 0);
  5317. }
  5318. else
  5319. {
  5320. tempIndex = gun_index;
  5321. }
  5322. for (int index = 0; index < GB_QUANTITY; index++)
  5323. {
  5324. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5325. {
  5326. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5327. }
  5328. }// END OF GB_QUANTITY
  5329. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5330. }
  5331. else if(gunType[gun_index] == GUN_TYPE_DO)
  5332. {
  5333. tempIndex = gun_index;
  5334. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5335. {
  5336. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5337. {
  5338. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5339. }
  5340. }
  5341. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5342. }
  5343. else
  5344. {
  5345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5346. {
  5347. tempIndex = 2;
  5348. }
  5349. else
  5350. {
  5351. tempIndex = gun_index;
  5352. }
  5353. for (int index = 0; index < AC_QUANTITY; index++)
  5354. {
  5355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5356. {
  5357. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5358. }
  5359. }// END OF AC_QUANTITY
  5360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5361. }
  5362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5367. }
  5368. //=================================== Power.Active.Import ==================================================
  5369. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5370. {
  5371. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5372. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5373. {
  5374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5375. {
  5376. tempIndex = ((gun_index==2) ? 1: 0);
  5377. }
  5378. else
  5379. {
  5380. tempIndex = gun_index;
  5381. }
  5382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5383. {
  5384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5385. {
  5386. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5387. }
  5388. } // End for CHAdeMO_QUANTITY
  5389. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5390. }
  5391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5392. {
  5393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5394. {
  5395. tempIndex = ((gun_index==2) ? 1: 0);
  5396. }
  5397. else
  5398. {
  5399. tempIndex = gun_index;
  5400. }
  5401. for (int index = 0; index < CCS_QUANTITY; index++)
  5402. {
  5403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5404. {
  5405. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5406. }
  5407. } // END for CCS_QUANTITY
  5408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5409. }
  5410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5411. {
  5412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5413. {
  5414. tempIndex = ((gun_index==2) ? 1: 0);
  5415. }
  5416. else
  5417. {
  5418. tempIndex = gun_index;
  5419. }
  5420. for (int index = 0; index < GB_QUANTITY; index++)
  5421. {
  5422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5423. {
  5424. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5425. }
  5426. }// END for GB_QUANTITY
  5427. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5428. }
  5429. else if(gunType[gun_index] == GUN_TYPE_DO)
  5430. {
  5431. tempIndex = gun_index;
  5432. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5433. {
  5434. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5435. {
  5436. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5437. }
  5438. }
  5439. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5440. }
  5441. else
  5442. {
  5443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5444. {
  5445. tempIndex = 2;
  5446. }
  5447. else
  5448. {
  5449. tempIndex = gun_index;
  5450. }
  5451. for (int index = 0; index < AC_QUANTITY; index++)
  5452. {
  5453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5454. {
  5455. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5456. }
  5457. } // END for AC_QUANTITY
  5458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5459. }
  5460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5461. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5465. }
  5466. //============================ Voltage L1 ====================================
  5467. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5468. {
  5469. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5470. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5471. {
  5472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5473. {
  5474. tempIndex = ((gun_index==2) ? 1: 0);
  5475. }
  5476. else
  5477. {
  5478. tempIndex = gun_index;
  5479. }
  5480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5481. {
  5482. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5483. {
  5484. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5485. }
  5486. } // END OF FOR CHAdeMO_QUANTITY
  5487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5488. }
  5489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5490. {
  5491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5492. {
  5493. tempIndex = ((gun_index==2) ? 1: 0);
  5494. }
  5495. else
  5496. {
  5497. tempIndex = gun_index;
  5498. }
  5499. for (int index = 0; index < CCS_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5502. {
  5503. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5504. }
  5505. } // END OF FOR CCS_QUANTITY
  5506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5507. }
  5508. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5509. {
  5510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5511. {
  5512. tempIndex = ((gun_index==2) ? 1: 0);
  5513. }
  5514. else
  5515. {
  5516. tempIndex = gun_index;
  5517. }
  5518. for (int index = 0; index < GB_QUANTITY; index++)
  5519. {
  5520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5521. {
  5522. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5523. }
  5524. } // END OF FOR GB_QUANTITY
  5525. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5526. }
  5527. else if(gunType[gun_index] == GUN_TYPE_DO)
  5528. {
  5529. tempIndex = gun_index;
  5530. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5531. {
  5532. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5533. {
  5534. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5535. }
  5536. }
  5537. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5538. }
  5539. else
  5540. {
  5541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5542. {
  5543. tempIndex = 2;
  5544. }
  5545. else
  5546. {
  5547. tempIndex = gun_index;
  5548. }
  5549. for (int index = 0; index < AC_QUANTITY; index++)
  5550. {
  5551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5552. {
  5553. 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
  5554. }
  5555. } // END OF FOR AC_QUANTITY
  5556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5557. }
  5558. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5562. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5563. }
  5564. //====================== End SoC ================================
  5565. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5566. {
  5567. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5568. 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))
  5569. {
  5570. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5571. {
  5572. tempIndex = ((gun_index==2) ? 1: 0);
  5573. }
  5574. else
  5575. {
  5576. tempIndex = gun_index;
  5577. }
  5578. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5579. {
  5580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5581. {
  5582. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5583. {
  5584. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5585. }
  5586. }
  5587. }
  5588. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5589. {
  5590. for (int index = 0; index < CCS_QUANTITY; index++)
  5591. {
  5592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5593. {
  5594. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5595. }
  5596. }
  5597. }
  5598. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5599. {
  5600. for (int index = 0; index < GB_QUANTITY; index++)
  5601. {
  5602. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5603. {
  5604. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5605. }
  5606. }
  5607. }
  5608. else if(gunType[gun_index] == GUN_TYPE_DO)
  5609. {
  5610. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5611. {
  5612. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5613. {
  5614. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5615. }
  5616. }
  5617. }
  5618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5624. } // END FOR DC CASE
  5625. }
  5626. // ================================= Current.Import L2 ===============================================
  5627. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5628. {
  5629. // AC 3 phse L2 current
  5630. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5631. {
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5633. {
  5634. tempIndex = 2;
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. for (int index = 0; index < AC_QUANTITY; index++)
  5641. {
  5642. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5643. {
  5644. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5645. }
  5646. }// End of for AC_QUANTITY
  5647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5648. }
  5649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5654. }
  5655. // ================================= Current.Import L3 ===============================================
  5656. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5657. {
  5658. // AC 3 phse L3 current
  5659. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5662. {
  5663. tempIndex = 2;
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < AC_QUANTITY; index++)
  5670. {
  5671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5672. {
  5673. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5674. }
  5675. }// End of for AC_QUANTITY
  5676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5677. }
  5678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5683. }
  5684. //============================ Voltage L2 ====================================
  5685. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5686. {
  5687. // AC 3 phse L2 voltage
  5688. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5689. {
  5690. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5691. {
  5692. tempIndex = 2;
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. for (int index = 0; index < AC_QUANTITY; index++)
  5699. {
  5700. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5701. {
  5702. 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
  5703. }
  5704. } // END OF FOR AC_QUANTITY
  5705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5706. }
  5707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5711. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5712. }
  5713. //============================ Voltage L3 ====================================
  5714. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5715. {
  5716. // AC 3 phse L3 voltage
  5717. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5718. {
  5719. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5720. {
  5721. tempIndex = 2;
  5722. }
  5723. else
  5724. {
  5725. tempIndex = gun_index;
  5726. }
  5727. for (int index = 0; index < AC_QUANTITY; index++)
  5728. {
  5729. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5730. {
  5731. 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
  5732. }
  5733. } // END OF FOR AC_QUANTITY
  5734. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5735. }
  5736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5741. }
  5742. //====================== Start SoC ================================
  5743. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5744. {
  5745. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5746. 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))
  5747. {
  5748. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5749. {
  5750. tempIndex = ((gun_index==2) ? 1: 0);
  5751. }
  5752. else
  5753. {
  5754. tempIndex = gun_index;
  5755. }
  5756. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5757. {
  5758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5759. {
  5760. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5761. {
  5762. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5763. }
  5764. }
  5765. }
  5766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5767. {
  5768. for (int index = 0; index < CCS_QUANTITY; index++)
  5769. {
  5770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5771. {
  5772. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5773. }
  5774. }
  5775. }
  5776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5777. {
  5778. for (int index = 0; index < GB_QUANTITY; index++)
  5779. {
  5780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5781. {
  5782. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5783. }
  5784. }
  5785. }
  5786. else if(gunType[gun_index] == GUN_TYPE_DO)
  5787. {
  5788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5789. {
  5790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5791. {
  5792. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5793. }
  5794. }
  5795. }
  5796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5802. } // END FOR DC CASE
  5803. }
  5804. //================================================ Message create ====================================================
  5805. json_object *StopTransaction = json_object_new_object();
  5806. json_object *transactionDatas = json_object_new_array();
  5807. json_object *sampledValues = json_object_new_array();
  5808. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5809. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5810. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5811. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5812. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5813. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5814. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5815. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5816. {
  5817. json_object *transactionData = json_object_new_object();
  5818. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5819. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5820. {
  5821. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5822. {
  5823. json_object *sampledValue = json_object_new_object();
  5824. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5825. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5826. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5827. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5828. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5829. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5830. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5831. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5832. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5833. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5834. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5835. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5836. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5837. json_object_array_add(sampledValues, sampledValue);
  5838. }
  5839. }
  5840. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5841. json_object_array_add(transactionDatas, transactionData);
  5842. }
  5843. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5844. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5845. ,MESSAGE_TYPE_CALL
  5846. ,guid
  5847. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5848. json_object_put(StopTransaction);
  5849. #if 1 // for TempStopTransaction
  5850. //Delete TempStopTransaction
  5851. if((access(TempStopTransaction,F_OK))!=-1)
  5852. {
  5853. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5854. }
  5855. #endif
  5856. #if 1
  5857. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5858. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5859. {
  5860. result = PASS;
  5861. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5862. }
  5863. #endif
  5864. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5865. OCPP_insert_transaction_msg(NO, queuedata);
  5866. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5867. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5868. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5869. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5870. {
  5871. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5872. }
  5873. //for test
  5874. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5875. return result;
  5876. }
  5877. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5878. {
  5879. mtrace();
  5880. int result = FAIL;
  5881. char guid[37]={0};
  5882. char tempdata[65]={0};
  5883. int tempIndex = 0;
  5884. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5885. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5886. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5887. //set value
  5888. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5889. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5890. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5891. -1);
  5892. random_uuid(guid);
  5893. //UTC Date time
  5894. struct timeval tmnow;
  5895. struct tm *tm;
  5896. char buf[28];//, usec_buf[6];
  5897. gettimeofday(&tmnow, NULL);
  5898. time_t t;
  5899. t = time(NULL);
  5900. /*UTC time and date*/
  5901. tm = gmtime(&t);
  5902. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5903. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5904. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5905. //********************************(1)Current.Import L1************************************************/
  5906. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5907. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5908. (dataType == ReadingContext_Trigger))
  5909. {
  5910. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5911. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5912. {
  5913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5914. {
  5915. tempIndex = ((gun_index==2) ? 1: 0);
  5916. }
  5917. else
  5918. {
  5919. tempIndex = gun_index;
  5920. }
  5921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5924. {
  5925. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5926. }
  5927. }
  5928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5929. }
  5930. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5931. {
  5932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5933. {
  5934. tempIndex = ((gun_index==2) ? 1: 0);
  5935. }
  5936. else
  5937. {
  5938. tempIndex = gun_index;
  5939. }
  5940. for (int index = 0; index < CCS_QUANTITY; index++)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5943. {
  5944. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5945. }
  5946. }
  5947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5948. }
  5949. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5952. {
  5953. tempIndex = ((gun_index==2) ? 1: 0);
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < GB_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5962. {
  5963. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5964. }
  5965. }
  5966. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5967. }
  5968. else if(gunType[gun_index] == GUN_TYPE_DO)
  5969. {
  5970. tempIndex = gun_index;
  5971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5972. {
  5973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5974. {
  5975. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5976. }
  5977. }
  5978. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5979. }
  5980. else
  5981. {
  5982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5983. {
  5984. tempIndex = 2;
  5985. }
  5986. else
  5987. {
  5988. tempIndex = gun_index;
  5989. }
  5990. for (int index = 0; index < AC_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5995. }
  5996. }
  5997. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5998. }
  5999. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6000. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6001. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6002. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6003. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6004. }
  6005. //********************************(2)Energy.Active.Import.Register ************************************************/
  6006. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6007. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6008. (dataType == ReadingContext_Trigger))
  6009. {
  6010. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6011. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6012. {
  6013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6014. {
  6015. tempIndex = ((gun_index==2) ? 1: 0);
  6016. }
  6017. else
  6018. {
  6019. tempIndex = gun_index;
  6020. }
  6021. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6022. {
  6023. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6024. {
  6025. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6026. }
  6027. }
  6028. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6029. }
  6030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6031. {
  6032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6033. {
  6034. tempIndex = ((gun_index==2) ? 1: 0);
  6035. }
  6036. else
  6037. {
  6038. tempIndex = gun_index;
  6039. }
  6040. for (int index = 0; index < CCS_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6045. }
  6046. }
  6047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6048. }
  6049. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6050. {
  6051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6052. {
  6053. tempIndex = ((gun_index==2) ? 1: 0);
  6054. }
  6055. else
  6056. {
  6057. tempIndex = gun_index;
  6058. }
  6059. for (int index = 0; index < GB_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6064. }
  6065. }
  6066. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6067. }
  6068. else if(gunType[gun_index] == GUN_TYPE_DO)
  6069. {
  6070. tempIndex = gun_index;
  6071. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6072. {
  6073. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6074. {
  6075. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6076. }
  6077. }
  6078. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6079. }
  6080. else
  6081. {
  6082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6083. {
  6084. tempIndex = 2;
  6085. }
  6086. else
  6087. {
  6088. tempIndex = gun_index;
  6089. }
  6090. for (int index = 0; index < AC_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6095. }
  6096. }
  6097. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6098. }
  6099. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6100. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6101. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6102. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6103. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6104. }
  6105. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6106. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6107. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6108. (dataType == ReadingContext_Trigger))
  6109. {
  6110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6111. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6112. {
  6113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6114. {
  6115. tempIndex = ((gun_index==2) ? 1: 0);
  6116. }
  6117. else
  6118. {
  6119. tempIndex = gun_index;
  6120. }
  6121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6124. {
  6125. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6126. }
  6127. } // END OF FOR CHAdeMO_QUANTITY
  6128. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6129. }
  6130. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6131. {
  6132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6133. {
  6134. tempIndex = ((gun_index==2) ? 1: 0);
  6135. }
  6136. else
  6137. {
  6138. tempIndex = gun_index;
  6139. }
  6140. for (int index = 0; index < CCS_QUANTITY; index++)
  6141. {
  6142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6143. {
  6144. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6145. }
  6146. } // END OF CCS_QUANTITY
  6147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6148. }
  6149. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < GB_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6162. {
  6163. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6164. }
  6165. } // END OF GB_QUANTITY
  6166. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6167. }
  6168. else if(gunType[gun_index] == GUN_TYPE_DO)
  6169. {
  6170. tempIndex = gun_index;
  6171. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6172. {
  6173. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6174. {
  6175. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6176. }
  6177. }
  6178. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6179. }
  6180. else
  6181. {
  6182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6183. {
  6184. tempIndex = 2;
  6185. }
  6186. else
  6187. {
  6188. tempIndex = gun_index;
  6189. }
  6190. for (int index = 0; index < AC_QUANTITY; index++)
  6191. {
  6192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6193. {
  6194. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6195. }
  6196. }
  6197. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6198. }
  6199. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6200. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6201. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6202. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6203. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6204. }
  6205. //********************************(4)Power.Active.Import************************************************/
  6206. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6207. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6208. (dataType == ReadingContext_Trigger))
  6209. {
  6210. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6211. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6212. {
  6213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6214. {
  6215. tempIndex = ((gun_index==2) ? 1: 0);
  6216. }
  6217. else
  6218. {
  6219. tempIndex = gun_index;
  6220. }
  6221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6222. {
  6223. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6224. {
  6225. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6226. }
  6227. } // END OF FOR
  6228. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6229. }
  6230. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6231. {
  6232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6233. {
  6234. tempIndex = ((gun_index==2) ? 1: 0);
  6235. }
  6236. else
  6237. {
  6238. tempIndex = gun_index;
  6239. }
  6240. for (int index = 0; index < CCS_QUANTITY; index++)
  6241. {
  6242. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6243. {
  6244. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6245. }
  6246. }
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6248. }
  6249. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6250. {
  6251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6252. {
  6253. tempIndex = ((gun_index==2) ? 1: 0);
  6254. }
  6255. else
  6256. {
  6257. tempIndex = gun_index;
  6258. }
  6259. for (int index = 0; index < GB_QUANTITY; index++)
  6260. {
  6261. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6262. {
  6263. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6264. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6265. }
  6266. }
  6267. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6268. }
  6269. else if(gunType[gun_index] == GUN_TYPE_DO)
  6270. {
  6271. tempIndex = gun_index;
  6272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6273. {
  6274. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6275. {
  6276. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6277. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6278. }
  6279. }
  6280. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6281. }
  6282. else
  6283. {
  6284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6285. {
  6286. tempIndex = 2;
  6287. }
  6288. else
  6289. {
  6290. tempIndex = gun_index;
  6291. }
  6292. for (int index = 0; index < AC_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6295. {
  6296. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6300. }
  6301. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6302. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6303. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6304. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6305. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6306. }
  6307. //***********************************************(5)VOLTAGE L1******************************************************/
  6308. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6309. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6310. (dataType == ReadingContext_Trigger))
  6311. {
  6312. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6314. {
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6316. {
  6317. tempIndex = ((gun_index==2) ? 1: 0);
  6318. }
  6319. else
  6320. {
  6321. tempIndex = gun_index;
  6322. }
  6323. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6324. {
  6325. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6326. {
  6327. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6328. }
  6329. }
  6330. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6331. }
  6332. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6333. {
  6334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6335. {
  6336. tempIndex = ((gun_index==2) ? 1: 0);
  6337. }
  6338. else
  6339. {
  6340. tempIndex = gun_index;
  6341. }
  6342. for (int index = 0; index < CCS_QUANTITY; index++)
  6343. {
  6344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6345. {
  6346. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6347. }
  6348. }
  6349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6350. }
  6351. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6352. {
  6353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6354. {
  6355. tempIndex = ((gun_index==2) ? 1: 0);
  6356. }
  6357. else
  6358. {
  6359. tempIndex = gun_index;
  6360. }
  6361. for (int index = 0; index < GB_QUANTITY; index++)
  6362. {
  6363. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6364. {
  6365. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6366. }
  6367. }
  6368. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6369. }
  6370. else if(gunType[gun_index] == GUN_TYPE_DO)
  6371. {
  6372. tempIndex = gun_index;
  6373. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6374. {
  6375. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6376. {
  6377. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6378. }
  6379. }
  6380. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6381. }
  6382. else
  6383. {
  6384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6385. {
  6386. tempIndex = 2;
  6387. }
  6388. else
  6389. {
  6390. tempIndex = gun_index;
  6391. }
  6392. for (int index = 0; index < AC_QUANTITY; index++)
  6393. {
  6394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6395. {
  6396. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6397. }
  6398. }
  6399. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6400. }
  6401. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6402. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6403. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6404. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6405. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6406. }
  6407. //***********************************************(6)SOC******************************************************/
  6408. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6409. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6410. (dataType == ReadingContext_Trigger))
  6411. {
  6412. 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))
  6413. {
  6414. //idx_sample=5;
  6415. //sampledValue = NULL;
  6416. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6417. {
  6418. tempIndex = ((gun_index==2) ? 1: 0);
  6419. }
  6420. else
  6421. {
  6422. tempIndex = gun_index;
  6423. }
  6424. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6425. {
  6426. //tempIndex = ((gun_index==2) ? 1: 0);
  6427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6428. {
  6429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6430. {
  6431. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6432. }
  6433. }
  6434. }
  6435. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6436. {
  6437. //tempIndex = ((gun_index==2) ? 1: 0);
  6438. for (int index = 0; index < CCS_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6441. {
  6442. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6443. }
  6444. }
  6445. }
  6446. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6447. {
  6448. //tempIndex = ((gun_index==2) ? 1: 0);
  6449. for (int index = 0; index < GB_QUANTITY; index++)
  6450. {
  6451. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6452. {
  6453. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6454. }
  6455. }
  6456. }
  6457. else if(gunType[gun_index] == GUN_TYPE_DO)
  6458. {
  6459. //tempIndex = ((gun_index==2) ? 1: 0);
  6460. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6461. {
  6462. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6463. {
  6464. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6465. }
  6466. }
  6467. }
  6468. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6469. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6470. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6471. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6472. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6473. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6474. }
  6475. }
  6476. //********************************(7)Current.Import L2************************************************/
  6477. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6478. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6479. (dataType == ReadingContext_Trigger))
  6480. {
  6481. // Only for AC 3 phase
  6482. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6483. {
  6484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6485. {
  6486. tempIndex = 2;
  6487. }
  6488. else
  6489. {
  6490. tempIndex = gun_index;
  6491. }
  6492. for (int index = 0; index < AC_QUANTITY; index++)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6495. {
  6496. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6497. }
  6498. }
  6499. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6500. }
  6501. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6502. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6503. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6504. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6506. }
  6507. //********************************(8)Current.Import L3************************************************/
  6508. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6509. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6510. (dataType == ReadingContext_Trigger))
  6511. {
  6512. // Only for AC 3 phase
  6513. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6514. {
  6515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6516. {
  6517. tempIndex = 2;
  6518. }
  6519. else
  6520. {
  6521. tempIndex = gun_index;
  6522. }
  6523. for (int index = 0; index < AC_QUANTITY; index++)
  6524. {
  6525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6526. {
  6527. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6528. }
  6529. }
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6537. }
  6538. //***********************************************(9)VOLTAGE L2******************************************************/
  6539. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6540. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6541. (dataType == ReadingContext_Trigger))
  6542. {
  6543. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6544. {
  6545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6546. {
  6547. tempIndex = 2;
  6548. }
  6549. else
  6550. {
  6551. tempIndex = gun_index;
  6552. }
  6553. for (int index = 0; index < AC_QUANTITY; index++)
  6554. {
  6555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6556. {
  6557. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6558. }
  6559. }
  6560. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6561. }
  6562. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6563. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6564. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6565. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6566. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6567. }
  6568. //***********************************************(10)VOLTAGE L3******************************************************/
  6569. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6570. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6571. (dataType == ReadingContext_Trigger))
  6572. {
  6573. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6574. {
  6575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6576. {
  6577. tempIndex = 2;
  6578. }
  6579. else
  6580. {
  6581. tempIndex = gun_index;
  6582. }
  6583. for (int index = 0; index < AC_QUANTITY; index++)
  6584. {
  6585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6586. {
  6587. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6588. }
  6589. }
  6590. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6591. }
  6592. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6593. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6594. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6596. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6597. }
  6598. //***********************************************(11)Current.Offered******************************************************/
  6599. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6600. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6601. (dataType == ReadingContext_Trigger))
  6602. {
  6603. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6604. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6605. {
  6606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6607. {
  6608. tempIndex = ((gun_index==2) ? 1: 0);
  6609. }
  6610. else
  6611. {
  6612. tempIndex = gun_index;
  6613. }
  6614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6615. {
  6616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6617. {
  6618. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6619. }
  6620. } // END OF FOR CHAdeMO_QUANTITY
  6621. }
  6622. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6623. {
  6624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6625. {
  6626. tempIndex = ((gun_index==2) ? 1: 0);
  6627. }
  6628. else
  6629. {
  6630. tempIndex = gun_index;
  6631. }
  6632. for (int index = 0; index < CCS_QUANTITY; index++)
  6633. {
  6634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6635. {
  6636. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6637. }
  6638. } // END OF CCS_QUANTITY
  6639. }
  6640. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6641. {
  6642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6643. {
  6644. tempIndex = ((gun_index==2) ? 1: 0);
  6645. }
  6646. else
  6647. {
  6648. tempIndex = gun_index;
  6649. }
  6650. for (int index = 0; index < GB_QUANTITY; index++)
  6651. {
  6652. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6653. {
  6654. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6655. }
  6656. } // END OF GB_QUANTITY
  6657. }
  6658. else if(gunType[gun_index] == GUN_TYPE_DO)
  6659. {
  6660. tempIndex = gun_index;
  6661. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6662. {
  6663. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6664. {
  6665. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6666. }
  6667. }
  6668. }
  6669. else
  6670. {
  6671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6672. {
  6673. tempIndex = 2;
  6674. }
  6675. else
  6676. {
  6677. tempIndex = gun_index;
  6678. }
  6679. for (int index = 0; index < AC_QUANTITY; index++)
  6680. {
  6681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6682. {
  6683. uint16_t currentOffer;
  6684. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6685. {
  6686. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6687. }
  6688. else
  6689. {
  6690. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6691. }
  6692. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6693. }
  6694. }
  6695. }
  6696. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6697. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6698. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6699. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6701. }
  6702. //***********************************************(12)Power.Offered******************************************************/
  6703. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6704. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6705. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6706. {
  6707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6709. {
  6710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6711. {
  6712. tempIndex = ((gun_index==2) ? 1: 0);
  6713. }
  6714. else
  6715. {
  6716. tempIndex = gun_index;
  6717. }
  6718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6719. {
  6720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6721. {
  6722. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6723. }
  6724. } // END OF FOR CHAdeMO_QUANTITY
  6725. }
  6726. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6727. {
  6728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6729. {
  6730. tempIndex = ((gun_index==2) ? 1: 0);
  6731. }
  6732. else
  6733. {
  6734. tempIndex = gun_index;
  6735. }
  6736. for (int index = 0; index < CCS_QUANTITY; index++)
  6737. {
  6738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6739. {
  6740. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6741. }
  6742. } // END OF CCS_QUANTITY
  6743. }
  6744. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6745. {
  6746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6747. {
  6748. tempIndex = ((gun_index==2) ? 1: 0);
  6749. }
  6750. else
  6751. {
  6752. tempIndex = gun_index;
  6753. }
  6754. for (int index = 0; index < GB_QUANTITY; index++)
  6755. {
  6756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6757. {
  6758. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6759. }
  6760. } // END OF GB_QUANTITY
  6761. }
  6762. else if(gunType[gun_index] == GUN_TYPE_DO)
  6763. {
  6764. tempIndex = gun_index;
  6765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6766. {
  6767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6768. {
  6769. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6770. }
  6771. }
  6772. }
  6773. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6774. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6775. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6776. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6778. }
  6779. // Message create ====================================================================================================
  6780. if(TRUE)
  6781. {
  6782. json_object *MeterValueReq = json_object_new_object();
  6783. json_object *MeterValues = json_object_new_array();
  6784. json_object *sampledValues = json_object_new_array();
  6785. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6786. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6787. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6788. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6789. {
  6790. json_object *MeterValue = json_object_new_object();
  6791. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6792. {
  6793. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6794. {
  6795. json_object *sampledValue = json_object_new_object();
  6796. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6797. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6798. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6799. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6800. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6801. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6802. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6803. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6804. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6805. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6806. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6807. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6808. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6809. json_object_array_add(sampledValues, sampledValue);
  6810. }
  6811. }
  6812. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6813. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6814. json_object_array_add(MeterValues, MeterValue);
  6815. }
  6816. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6817. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6818. ,gun_index + 1
  6819. ,MESSAGE_TYPE_CALL
  6820. ,guid
  6821. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6822. json_object_put(MeterValueReq);
  6823. }
  6824. // Put request guid to hash map
  6825. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6826. 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*/)
  6827. {
  6828. result = PASS;
  6829. //DEBUG_INFO("MeterValues mapitem pass\n");
  6830. }
  6831. if((dataType != ReadingContext_Trigger) &&
  6832. (dataType != ReadingContext_Sample_Clock) &&
  6833. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6834. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6835. else
  6836. {
  6837. if(FirstHeartBeat)
  6838. LWS_Send(queuedata +2);
  6839. }
  6840. return result;
  6841. }
  6842. int sendLogStatusNotificationRequest(char *status)
  6843. {
  6844. mtrace();
  6845. int result = PASS;
  6846. char message[4096]={0};
  6847. char guid[37]={0};
  6848. char tempdata[128]={0};
  6849. json_object *LogStatusNotification = json_object_new_object();
  6850. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6851. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6852. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6853. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6854. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6855. random_uuid(guid);
  6856. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6857. json_object_put(LogStatusNotification);
  6858. LWS_Send(message);
  6859. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6860. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6861. {
  6862. result = PASS;
  6863. }
  6864. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6865. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6866. return result;
  6867. }
  6868. int sendSecurityEventNotificationRequest()
  6869. {
  6870. mtrace();
  6871. int result = PASS;
  6872. char message[4096]={0};
  6873. char guid[37]={0};
  6874. char tempdata[128]={0};
  6875. json_object *SecurityEventNotification = json_object_new_object();
  6876. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6877. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6878. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6879. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6880. random_uuid(guid);
  6881. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6882. json_object_put(SecurityEventNotification);
  6883. LWS_Send(message);
  6884. sprintf(tempdata, "SecurityEventNotification,0");
  6885. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6886. {
  6887. result = PASS;
  6888. }
  6889. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6890. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6891. return result;
  6892. }
  6893. int sendSignCertificateRequest()
  6894. {
  6895. mtrace();
  6896. int result = PASS;
  6897. char message[4096]={0};
  6898. char guid[37]={0};
  6899. char tempdata[128]={0};
  6900. json_object *SignCertificate = json_object_new_object();
  6901. DEBUG_INFO("sendSignCertificateRequest...\n");
  6902. // Read csr file content
  6903. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6904. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6905. char *line = NULL;
  6906. size_t len = 0;
  6907. while(getline(&line, &len, fp) != -1)
  6908. {
  6909. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6910. {
  6911. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6912. }
  6913. }
  6914. fclose(fp);
  6915. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6916. random_uuid(guid);
  6917. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6918. json_object_put(SignCertificate);
  6919. LWS_Send(message);
  6920. sprintf(tempdata, "SignCertificate,0");
  6921. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6922. {
  6923. result = PASS;
  6924. }
  6925. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6926. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6927. return result;
  6928. }
  6929. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6930. {
  6931. mtrace();
  6932. int result = PASS;
  6933. char message[110]={0};
  6934. char guid[37]={0};
  6935. char tempdata[65]={0};
  6936. json_object *FirmwareStatusNotification = json_object_new_object();
  6937. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6938. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6939. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6940. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6941. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6942. random_uuid(guid);
  6943. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6944. json_object_put(FirmwareStatusNotification);
  6945. LWS_Send(message);
  6946. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6947. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6948. {
  6949. result = PASS;
  6950. }
  6951. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6952. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6953. return result;
  6954. }
  6955. //==========================================
  6956. // send confirm routine
  6957. //==========================================
  6958. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6959. {
  6960. mtrace();
  6961. int result = FAIL;
  6962. char message[100]={0};
  6963. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6964. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6965. LWS_Send(message);
  6966. result = TRUE;
  6967. return result;
  6968. }
  6969. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6970. {
  6971. mtrace();
  6972. int result = FAIL;
  6973. char message[100]={0};
  6974. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6975. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6976. LWS_Send(message);
  6977. result = TRUE;
  6978. return result;
  6979. }
  6980. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6981. {
  6982. mtrace();
  6983. int result = FAIL;
  6984. char message[100]={0};
  6985. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6986. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6987. LWS_Send(message);
  6988. result = TRUE;
  6989. return result;
  6990. }
  6991. int sendClearCacheConfirmation(char *uuid,char *payload)
  6992. {
  6993. mtrace();
  6994. int result = FAIL;
  6995. char message[500]={0};
  6996. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6997. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6998. LWS_Send(message);
  6999. return result;
  7000. }
  7001. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7002. {
  7003. mtrace();
  7004. int result = FAIL;
  7005. char message[500]={0};
  7006. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7007. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7008. LWS_Send(message);
  7009. return result;
  7010. }
  7011. int sendDataTransferConfirmation(char *uuid,char *payload)
  7012. {
  7013. mtrace();
  7014. char statusStr[20]={0};
  7015. char dataStr[10]={0};
  7016. char sstr[20]={0};
  7017. int c = 0;
  7018. char *loc;
  7019. int result = FAIL;
  7020. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7021. /**********************status**************************/
  7022. loc = strstr(payload, "status");
  7023. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7024. c = 0;
  7025. while (loc[3+strlen("status")+c] != '\"')
  7026. {
  7027. sstr[c] = loc[3+strlen("status")+c];
  7028. c++;
  7029. }
  7030. sstr[c] = '\0';
  7031. strcpy(statusStr, sstr);
  7032. /**********************data**************************/
  7033. loc = strstr(payload, "data");
  7034. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7035. c = 0;
  7036. while (loc[3+strlen("data")+c] != '\"')
  7037. {
  7038. sstr[c] = loc[3+strlen("data")+c];
  7039. c++;
  7040. }
  7041. sstr[c] = '\0';
  7042. strcpy(dataStr, sstr);
  7043. return result;
  7044. }
  7045. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7046. {
  7047. mtrace();
  7048. int result = FAIL;
  7049. char message[1000]={0};
  7050. int CompositeScheduleIndex = 0;
  7051. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7052. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7053. if(nPeriod == 0)
  7054. {
  7055. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7056. {
  7057. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7058. ,MESSAGE_TYPE_CALLRESULT
  7059. ,uuid
  7060. ,payload
  7061. ,connectorIdInt);
  7062. }
  7063. else
  7064. {
  7065. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7066. ,MESSAGE_TYPE_CALLRESULT
  7067. ,uuid
  7068. ,payload
  7069. ,connectorIdInt
  7070. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7071. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7072. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7073. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7074. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7075. }
  7076. }
  7077. else
  7078. {
  7079. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7080. ,MESSAGE_TYPE_CALLRESULT
  7081. ,uuid
  7082. ,payload
  7083. ,connectorIdInt
  7084. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7085. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7086. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7087. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7088. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7089. {
  7090. if (idx_sample == 0)
  7091. {
  7092. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7093. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7094. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7095. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7096. }
  7097. else
  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. }
  7105. sprintf(message + strlen(message), "]}}]");
  7106. }
  7107. LWS_Send(message);
  7108. result = TRUE;
  7109. return result;
  7110. }
  7111. int sendGetConfigurationConfirmation(char *uuid)
  7112. {
  7113. mtrace();
  7114. int result = FAIL;
  7115. int MaxKeySupported = 0;
  7116. int sentConfigurationNumber= 0;
  7117. int sentunConfigurationNumber= 0;
  7118. char message[1024*10]={0};
  7119. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7120. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7121. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7122. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7123. ,MESSAGE_TYPE_CALLRESULT
  7124. ,uuid );
  7125. //configuration key
  7126. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7127. {
  7128. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7129. {
  7130. if (sentConfigurationNumber == 0)
  7131. {
  7132. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7133. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7134. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7135. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7136. }
  7137. else
  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. sentConfigurationNumber = sentConfigurationNumber + 1;
  7145. }
  7146. }
  7147. sprintf(message + strlen(message), "]");
  7148. if(UnknownKeynum != 0)
  7149. {
  7150. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7151. //unkown key
  7152. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7153. {
  7154. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7155. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7156. if(sentunConfigurationNumber == 0)
  7157. {
  7158. sprintf(message + strlen(message), "\"%s\""
  7159. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7160. }
  7161. else
  7162. {
  7163. sprintf(message + strlen(message), ",\"%s\""
  7164. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7165. }
  7166. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7167. }
  7168. sprintf(message + strlen(message), "]");
  7169. }
  7170. sprintf(message + strlen(message), "}]");
  7171. LWS_Send(message);
  7172. return result;
  7173. }
  7174. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7175. {
  7176. mtrace();
  7177. int result = FAIL;
  7178. char message[400]={0};
  7179. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7180. if(strcmp(payload,"")==0)
  7181. {
  7182. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7183. }
  7184. else
  7185. {
  7186. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7187. }
  7188. LWS_Send(message);
  7189. result = TRUE;
  7190. return result;
  7191. }
  7192. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7193. {
  7194. mtrace();
  7195. int result = FAIL;
  7196. char message[80]={0};
  7197. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7198. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7199. LWS_Send(message);
  7200. result = TRUE;
  7201. return result;
  7202. }
  7203. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7204. {
  7205. mtrace();
  7206. int result = FAIL;
  7207. char message[80]={0};
  7208. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7209. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7210. LWS_Send(message);
  7211. result = TRUE;
  7212. return result;
  7213. }
  7214. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7215. {
  7216. mtrace();
  7217. int result = FAIL;
  7218. char message[80]={0};
  7219. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7220. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7221. LWS_Send(message);
  7222. result = TRUE;
  7223. return result;
  7224. }
  7225. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7226. {
  7227. mtrace();
  7228. int result = FAIL;
  7229. char message[80]={0};
  7230. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7231. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7232. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7233. LWS_Send(message);
  7234. result = TRUE;
  7235. return result;
  7236. }
  7237. int sendResetConfirmation(char *uuid,char *payload)
  7238. {
  7239. mtrace();
  7240. int result = FAIL;
  7241. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7242. char message[80]={0};
  7243. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7244. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7245. LWS_Send(message);
  7246. result = TRUE;
  7247. return result;
  7248. }
  7249. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7250. {
  7251. mtrace();
  7252. int result = FAIL;
  7253. char message[500]={0};
  7254. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7255. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7256. LWS_Send(message);
  7257. result = TRUE;
  7258. return result;
  7259. }
  7260. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7261. {
  7262. mtrace();
  7263. int result = FAIL;
  7264. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7265. char message[80]={0};
  7266. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7267. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7268. LWS_Send(message);
  7269. result = TRUE;
  7270. return result;
  7271. }
  7272. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7273. {
  7274. mtrace();
  7275. int result = FAIL;
  7276. char message[80]={0};
  7277. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7278. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7279. LWS_Send(message);
  7280. result = TRUE;
  7281. return result;
  7282. }
  7283. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7284. {
  7285. mtrace();
  7286. int result = FAIL;
  7287. char message[80]={0};
  7288. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7289. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7290. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7291. LWS_Send(message);
  7292. result = TRUE;
  7293. return result;
  7294. }
  7295. int sendUpdateFirmwareConfirmation(char *uuid)
  7296. {
  7297. mtrace();
  7298. int result = FAIL;
  7299. char message[60]={0};
  7300. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7301. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7302. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7303. LWS_Send(message);
  7304. result = TRUE;
  7305. return result;
  7306. }
  7307. int sendCertificateSignedConfirmation(char *uuid)
  7308. {
  7309. mtrace();
  7310. int result = PASS;
  7311. char message[4096]={0};
  7312. json_object *CertificateSigned = json_object_new_object();
  7313. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7314. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7315. sprintf(message,"[%d,\"%s\",%s]"
  7316. ,MESSAGE_TYPE_CALLRESULT
  7317. ,uuid
  7318. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7319. json_object_put(CertificateSigned);
  7320. LWS_Send(message);
  7321. return result;
  7322. }
  7323. int sendDeleteCertificateConfirmation(char *uuid)
  7324. {
  7325. mtrace();
  7326. int result = PASS;
  7327. char message[4096]={0};
  7328. json_object *DeleteCertificate = json_object_new_object();
  7329. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7330. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7331. sprintf(message,"[%d,\"%s\",%s]"
  7332. ,MESSAGE_TYPE_CALLRESULT
  7333. ,uuid
  7334. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7335. json_object_put(DeleteCertificate);
  7336. LWS_Send(message);
  7337. return result;
  7338. }
  7339. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7340. {
  7341. mtrace();
  7342. int result = PASS;
  7343. char message[4096]={0};
  7344. json_object *ExtendedTriggerMessage = json_object_new_object();
  7345. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7346. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7347. sprintf(message,"[%d,\"%s\",%s]"
  7348. ,MESSAGE_TYPE_CALLRESULT
  7349. ,uuid
  7350. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7351. json_object_put(ExtendedTriggerMessage);
  7352. LWS_Send(message);
  7353. return result;
  7354. }
  7355. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7356. {
  7357. mtrace();
  7358. int result = PASS;
  7359. char message[4096]={0};
  7360. json_object *GetInstalledCertificateIds = json_object_new_object();
  7361. json_object *certificateHashDataDatas = json_object_new_array();
  7362. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7363. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7364. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7365. {
  7366. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7367. {
  7368. json_object *certificateHashData = json_object_new_object();
  7369. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7370. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7371. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7372. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7373. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7374. }
  7375. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7376. }
  7377. else
  7378. {
  7379. json_object_put(certificateHashDataDatas);
  7380. }
  7381. sprintf(message,"[%d,\"%s\",%s]"
  7382. ,MESSAGE_TYPE_CALLRESULT
  7383. ,uuid
  7384. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7385. json_object_put(GetInstalledCertificateIds);
  7386. LWS_Send(message);
  7387. return result;
  7388. }
  7389. int sendGetLogConfirmation(char *uuid)
  7390. {
  7391. mtrace();
  7392. int result = PASS;
  7393. char message[4096]={0};
  7394. json_object *GetLog = json_object_new_object();
  7395. DEBUG_INFO("sendGetLogConfirmation...\n");
  7396. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7397. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7398. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7399. sprintf(message,"[%d,\"%s\",%s]"
  7400. ,MESSAGE_TYPE_CALLRESULT
  7401. ,uuid
  7402. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7403. json_object_put(GetLog);
  7404. LWS_Send(message);
  7405. return result;
  7406. }
  7407. int sendInstallCertificateConfirmation(char *uuid)
  7408. {
  7409. mtrace();
  7410. int result = PASS;
  7411. char message[4096]={0};
  7412. json_object *InstallCertificate = json_object_new_object();
  7413. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7414. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7415. sprintf(message,"[%d,\"%s\",%s]"
  7416. ,MESSAGE_TYPE_CALLRESULT
  7417. ,uuid
  7418. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7419. json_object_put(InstallCertificate);
  7420. LWS_Send(message);
  7421. return result;
  7422. }
  7423. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7424. {
  7425. mtrace();
  7426. int result = PASS;
  7427. char message[4096]={0};
  7428. json_object *SignedUpdateFirmware = json_object_new_object();
  7429. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7430. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7431. sprintf(message,"[%d,\"%s\",%s]"
  7432. ,MESSAGE_TYPE_CALLRESULT
  7433. ,uuid
  7434. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7435. json_object_put(SignedUpdateFirmware);
  7436. LWS_Send(message);
  7437. return result;
  7438. }
  7439. int sendUnknownConfirmation(char *uuid)
  7440. {
  7441. mtrace();
  7442. int result = PASS;
  7443. char message[256]={0};
  7444. DEBUG_INFO("sendUnknownConfirmation...\n");
  7445. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7446. LWS_Send(message);
  7447. return result;
  7448. }
  7449. //==========================================
  7450. // Handle server request routine Start
  7451. //==========================================
  7452. int handleCancelReservationRequest(char *uuid, char *payload)
  7453. {
  7454. mtrace();
  7455. int result = FAIL;
  7456. int gunNO = 0;
  7457. int reservationIdInt = -1;
  7458. char comfirmstr[20];
  7459. DEBUG_INFO("handleCancelReservationRequest...\n");
  7460. json_object *CancelReservation;
  7461. CancelReservation = json_tokener_parse(payload);
  7462. if(!is_error(CancelReservation))
  7463. {
  7464. // Required data
  7465. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7466. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7467. }
  7468. json_object_put(CancelReservation);
  7469. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7470. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7471. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7472. if(reservationIdInt != -1)
  7473. {
  7474. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7475. //check Transaction active
  7476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7477. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7478. {
  7479. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7480. {
  7481. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7482. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7483. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7484. {
  7485. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7486. }
  7487. else
  7488. {
  7489. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7490. }
  7491. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7492. goto end;
  7493. }
  7494. }
  7495. for (int index = 0; index < CCS_QUANTITY; index++)
  7496. {
  7497. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7498. {
  7499. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7500. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7501. if(gunType[2] == GUN_TYPE_CCS)
  7502. {
  7503. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7504. }
  7505. else
  7506. {
  7507. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7508. }
  7509. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7510. goto end;
  7511. }
  7512. }
  7513. for (int index = 0; index < GB_QUANTITY; index++)
  7514. {
  7515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7516. {
  7517. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7518. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7519. if(gunType[2] == GUN_TYPE_GBT)
  7520. {
  7521. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7522. }
  7523. else
  7524. {
  7525. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7526. }
  7527. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7528. goto end;
  7529. }
  7530. }
  7531. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7532. {
  7533. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7534. {
  7535. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7536. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7537. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7538. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7539. goto end;
  7540. }
  7541. }
  7542. for (int index = 0; index < AC_QUANTITY; index++)
  7543. {
  7544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7545. {
  7546. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7547. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7549. {
  7550. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7551. }
  7552. else
  7553. {
  7554. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7555. }
  7556. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7557. goto end;
  7558. }
  7559. }
  7560. }
  7561. //The reservationId does NOT match the reservationId
  7562. sendCancelReservationConfirmation(uuid, comfirmstr);
  7563. end:
  7564. // Fill in ocpp packet uuid
  7565. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7566. return result;
  7567. }
  7568. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7569. {
  7570. mtrace();
  7571. int result = FAIL;
  7572. int gunIndex = -1;
  7573. char typeStr[16]={0};
  7574. char comfirmstr[20];
  7575. int specificId = FALSE;
  7576. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7577. json_object *ChangeAvailability;
  7578. ChangeAvailability = json_tokener_parse(payload);
  7579. if(!is_error(ChangeAvailability))
  7580. {
  7581. // Required data
  7582. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7583. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7584. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7585. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7586. }
  7587. json_object_put(ChangeAvailability);
  7588. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7589. {
  7590. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7591. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7592. }
  7593. else if(gunIndex == 0)
  7594. {
  7595. for(int i=0; i < gunTotalNumber; i++)
  7596. {
  7597. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7598. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7599. }
  7600. }
  7601. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7603. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7604. {
  7605. specificId = TRUE;
  7606. }
  7607. if(specificId == FALSE)
  7608. goto end;
  7609. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7610. {
  7611. //----------------------gunIndex is 0 ------------------------------------------------//
  7612. if(gunIndex == 0)
  7613. {
  7614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7615. {
  7616. for(int i=0; i < gunTotalNumber; i++)
  7617. {
  7618. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7619. {
  7620. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7621. {
  7622. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7623. {
  7624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7625. goto end;
  7626. }
  7627. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7628. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7629. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7632. {
  7633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7634. goto end;
  7635. }
  7636. }
  7637. }//END FOR CHAdeMO_QUANTITY
  7638. for (int index = 0; index < CCS_QUANTITY; index++)
  7639. {
  7640. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7641. {
  7642. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7643. {
  7644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7645. goto end;
  7646. }
  7647. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7648. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7652. {
  7653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7654. goto end;
  7655. }
  7656. }
  7657. }//END FOR CCS_QUANTITY
  7658. for (int index = 0; index < GB_QUANTITY; index++)
  7659. {
  7660. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7661. {
  7662. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7663. {
  7664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7665. goto end;
  7666. }
  7667. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7668. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7669. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7670. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7671. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7672. {
  7673. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7674. goto end;
  7675. }
  7676. }
  7677. }// END FOR GB_QUANTITY
  7678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7679. {
  7680. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7681. {
  7682. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7683. {
  7684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7685. goto end;
  7686. }
  7687. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7688. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7689. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7690. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7691. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7692. {
  7693. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7694. goto end;
  7695. }
  7696. }
  7697. }// END FOR GENERAL_GUN_QUANTITY
  7698. for (int index = 0; index < AC_QUANTITY; index++)
  7699. {
  7700. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7701. {
  7702. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7703. {
  7704. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7705. goto end;
  7706. }
  7707. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7708. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7709. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7710. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7711. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7712. {
  7713. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7714. goto end;
  7715. }
  7716. }
  7717. }//END FOR AC_QUANTITY
  7718. }// END FOR gunTotalNumber
  7719. }
  7720. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7721. {
  7722. for(int i=0; i < gunTotalNumber; i++)
  7723. {
  7724. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7725. {
  7726. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7727. goto end;
  7728. }
  7729. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7730. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7731. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7732. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7733. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7734. {
  7735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7736. goto end;
  7737. }
  7738. }
  7739. }
  7740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7741. goto end;
  7742. }
  7743. //----------------------gunIndex is not 0 ------------------------------------------------//
  7744. //check Transaction active
  7745. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7746. {
  7747. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7748. {
  7749. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7750. {
  7751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7752. goto end;
  7753. }
  7754. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7755. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7756. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7757. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7758. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7759. {
  7760. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7761. goto end;
  7762. }
  7763. else
  7764. {
  7765. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7766. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7767. goto end;
  7768. }
  7769. }
  7770. }//END FOR CHAdeMO_QUANTITY
  7771. for (int index = 0; index < CCS_QUANTITY; index++)
  7772. {
  7773. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7774. {
  7775. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7776. {
  7777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7778. goto end;
  7779. }
  7780. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7781. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7782. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7783. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7784. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7785. {
  7786. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7787. goto end;
  7788. }
  7789. else
  7790. {
  7791. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7792. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7793. goto end;
  7794. }
  7795. }
  7796. }//END FOR CCS_QUANTITY
  7797. for (int index = 0; index < GB_QUANTITY; index++)
  7798. {
  7799. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7800. {
  7801. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7802. {
  7803. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7804. goto end;
  7805. }
  7806. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7807. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7808. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7809. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7810. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7811. {
  7812. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7813. goto end;
  7814. }
  7815. else
  7816. {
  7817. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7818. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7819. goto end;
  7820. }
  7821. }
  7822. }// END FOR GB_QUANTITY
  7823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7824. {
  7825. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7826. {
  7827. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7828. {
  7829. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7830. goto end;
  7831. }
  7832. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7833. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7834. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7837. {
  7838. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7839. goto end;
  7840. }
  7841. else
  7842. {
  7843. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7844. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7845. goto end;
  7846. }
  7847. }
  7848. }// END FOR GENERAL_GUN_QUANTITY
  7849. for (int index = 0; index < AC_QUANTITY; index++)
  7850. {
  7851. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7852. {
  7853. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7854. {
  7855. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7856. goto end;
  7857. }
  7858. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7859. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7860. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7861. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7862. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7863. {
  7864. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7865. goto end;
  7866. }
  7867. else
  7868. {
  7869. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7870. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7871. goto end;
  7872. }
  7873. }
  7874. }//END FOR AC_QUANTITY
  7875. }//END FOR AvailabilityTypeStr[Inoperative]
  7876. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7877. {
  7878. //----------------------gunIndex is 0 ------------------------------------------------//
  7879. if(gunIndex == 0)
  7880. {
  7881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7882. {
  7883. for(int i=0; i < gunTotalNumber; i++)
  7884. {
  7885. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7886. {
  7887. 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
  7888. {
  7889. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7890. goto end;
  7891. }
  7892. }//END FOR CHAdeMO_QUANTITY
  7893. for (int index = 0; index < CCS_QUANTITY; index++)
  7894. {
  7895. 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
  7896. {
  7897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7898. goto end;
  7899. }
  7900. }//END FOR CCS_QUANTITY
  7901. for (int index = 0; index < GB_QUANTITY; index++)
  7902. {
  7903. 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
  7904. {
  7905. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7906. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7907. goto end;
  7908. }
  7909. }// END FOR GB_QUANTITY
  7910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7911. {
  7912. 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
  7913. {
  7914. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7915. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7916. goto end;
  7917. }
  7918. }// END FOR GENERAL_GUN_QUANTITY
  7919. for (int index = 0; index < AC_QUANTITY; index++)
  7920. {
  7921. 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
  7922. {
  7923. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7924. goto end;
  7925. }
  7926. }//END FOR CHAdeMO_QUANTITY
  7927. }// END FOR gunTotalNumber
  7928. }
  7929. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7930. {
  7931. for(int i=0; i < gunTotalNumber; i++)
  7932. {
  7933. for (int index = 0; index < AC_QUANTITY; index++)
  7934. {
  7935. 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
  7936. {
  7937. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7938. goto end;
  7939. }
  7940. }//END FOR CHAdeMO_QUANTITY
  7941. } // END FOR gunTotalNumber
  7942. }
  7943. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7944. goto end;
  7945. }
  7946. //----------------------gunIndex is not 0 ------------------------------------------------//
  7947. //check Transaction active
  7948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7949. {
  7950. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7951. {
  7952. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7953. goto end;
  7954. }
  7955. }//END FOR CHAdeMO_QUANTITY
  7956. for (int index = 0; index < CCS_QUANTITY; index++)
  7957. {
  7958. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7959. {
  7960. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7961. goto end;
  7962. }
  7963. }//END FOR CCS_QUANTITY
  7964. for (int index = 0; index < GB_QUANTITY; index++)
  7965. {
  7966. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7967. {
  7968. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7969. goto end;
  7970. }
  7971. }// END FOR GB_QUANTITY
  7972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7973. {
  7974. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7975. {
  7976. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7977. goto end;
  7978. }
  7979. }// END FOR GENERAL_GUN_QUANTITY
  7980. for (int index = 0; index < AC_QUANTITY; index++)
  7981. {
  7982. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7983. {
  7984. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7985. goto end;
  7986. }
  7987. }//END FOR AC_QUANTITY
  7988. }//END FOR AvailabilityTypeStr[Operative]
  7989. end:
  7990. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7991. {
  7992. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7993. }
  7994. else
  7995. {
  7996. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7997. }
  7998. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7999. {
  8000. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8001. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8002. }
  8003. else if(gunIndex == 0)
  8004. {
  8005. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8006. {
  8007. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8008. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8009. }
  8010. }
  8011. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8012. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8013. return result;
  8014. }
  8015. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8016. {
  8017. mtrace();
  8018. int valueInvalid = NO;
  8019. int result = FAIL;
  8020. char keystr[40]={0};
  8021. char valuestr[501]={0}; //value should be limited in 500 bytes
  8022. char comfirmstr[20]={0};
  8023. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8024. json_object *ChangeConfiguration;
  8025. ChangeConfiguration = json_tokener_parse(payload);
  8026. if(!is_error(ChangeConfiguration))
  8027. {
  8028. // Required data
  8029. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8030. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8031. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8032. {
  8033. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8034. }
  8035. else
  8036. {
  8037. valueInvalid = YES;
  8038. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8039. }
  8040. }
  8041. json_object_put(ChangeConfiguration);
  8042. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8043. {
  8044. DEBUG_ERROR("Payload is null or not accepted.\n");
  8045. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8046. }
  8047. else
  8048. {
  8049. int status = setKeyValue(keystr, valuestr);
  8050. switch(status)
  8051. {
  8052. case ConfigurationStatus_Accepted:
  8053. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8054. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8055. StoreConfigurationTable();
  8056. break;
  8057. case RebootRequired:
  8058. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8059. StoreConfigurationTable();
  8060. break;
  8061. case NotSupported:
  8062. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8063. break;
  8064. case ConfigurationStatus_Rejected:
  8065. default:
  8066. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8067. break;
  8068. }
  8069. }
  8070. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8071. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8072. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8073. {
  8074. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8075. SetOcppConnStatus(FALSE);
  8076. }
  8077. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8078. {
  8079. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8080. }
  8081. return result;
  8082. }
  8083. int handleClearCacheRequest(char *uuid, char *payload)
  8084. {
  8085. mtrace();
  8086. int result = FAIL;
  8087. char comfirmstr[20];
  8088. char rmFileCmd[100]={0};
  8089. struct stat stats;
  8090. DEBUG_INFO("handleClearCacheRequest...\n");
  8091. stat("/Storage/OCPP_PH", &stats);
  8092. // Check for directory existence
  8093. if (S_ISDIR(stats.st_mode) == 1)
  8094. {}
  8095. else
  8096. {
  8097. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8098. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8099. system(rmFileCmd);
  8100. }
  8101. if(OCPP_cleanLocalCache())
  8102. {
  8103. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8104. }
  8105. else
  8106. {
  8107. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8108. }
  8109. sendClearCacheConfirmation(uuid, comfirmstr);
  8110. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8111. return result;
  8112. }
  8113. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8114. {
  8115. mtrace();
  8116. int result = FAIL;
  8117. int resultRename;
  8118. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8119. char chargingProfilePurposeStr[26]={0};
  8120. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8121. char tempchargingProfilePurposeStr[26]={0};
  8122. char str[100]={0};
  8123. char fname[200]={0};
  8124. char comfirmstr[20]={0};
  8125. char word[1600]={0};
  8126. int clearflag = FALSE;
  8127. int chargingProfileIdIsNULL = FALSE;
  8128. int connectorIsNULL = FALSE;
  8129. int chargingProfilePurposeIsNULL = FALSE;
  8130. int stackLevelIsNULL = FALSE;
  8131. //int GotoEnd = FALSE;
  8132. FILE *fptr1, *fptr2;
  8133. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8134. int n_chargingProfile=0;
  8135. int isEmptyFile = FALSE;
  8136. char sLineWord[1600]={0};
  8137. char chargingProfiles[10][100]={0};
  8138. int ChargeProfileCount = 0;
  8139. int ch;
  8140. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8141. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8142. json_object *ClearChargingProfile;
  8143. ClearChargingProfile = json_tokener_parse(payload);
  8144. if(!is_error(ClearChargingProfile))
  8145. {
  8146. // Optional data
  8147. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8148. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8149. else
  8150. chargingProfileIdIsNULL = TRUE;
  8151. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8152. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8153. else
  8154. connectorIsNULL = TRUE;
  8155. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8156. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8157. else
  8158. chargingProfilePurposeIsNULL = TRUE;
  8159. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8160. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8161. else
  8162. stackLevelIsNULL = TRUE;
  8163. }
  8164. json_object_put(ClearChargingProfile);
  8165. if(connectorIsNULL == FALSE)
  8166. {
  8167. switch(connectorIdInt)
  8168. {
  8169. case 0:
  8170. if(chargingProfilePurposeIsNULL == TRUE)
  8171. {
  8172. int l = 0;
  8173. strcpy(fname, ChargePointMaxProfile_JSON);
  8174. if((access(fname,F_OK))!=-1)
  8175. {
  8176. strcpy(chargingProfiles[l], fname);
  8177. l = l + 1;
  8178. }
  8179. strcpy(fname, TxDefaultProfile_0_JSON);
  8180. if((access(fname,F_OK))!=-1)
  8181. {
  8182. strcpy(chargingProfiles[l], fname);
  8183. l = l + 1;
  8184. }
  8185. ChargeProfileCount = l;
  8186. }
  8187. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8188. {
  8189. strcpy(fname, ChargePointMaxProfile_JSON);
  8190. if((access(fname,F_OK))!=-1)
  8191. {
  8192. strcpy(chargingProfiles[0], fname);
  8193. ChargeProfileCount = 1;
  8194. }
  8195. }
  8196. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8197. {
  8198. strcpy(fname, TxDefaultProfile_0_JSON);
  8199. if((access(fname,F_OK))!=-1)
  8200. {
  8201. strcpy(chargingProfiles[0], fname);
  8202. ChargeProfileCount = 1;
  8203. }
  8204. }
  8205. break;
  8206. default:
  8207. if(chargingProfilePurposeIsNULL == TRUE)
  8208. {
  8209. int m = 0;
  8210. memset(fname, 0, ARRAY_SIZE(fname));
  8211. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8212. if((access(fname,F_OK))!=-1)
  8213. {
  8214. strcpy(chargingProfiles[m], fname);
  8215. m = m + 1;
  8216. }
  8217. memset(fname, 0, ARRAY_SIZE(fname));
  8218. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8219. if((access(fname,F_OK))!=-1)
  8220. {
  8221. strcpy(chargingProfiles[m], fname);
  8222. m = m + 1;
  8223. }
  8224. ChargeProfileCount = m;
  8225. }
  8226. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8227. {
  8228. //strcpy(fname, TxDefaultProfile_1_JSON);
  8229. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8230. if((access(fname,F_OK))!=-1)
  8231. {
  8232. strcpy(chargingProfiles[0], fname);
  8233. ChargeProfileCount = 1;
  8234. }
  8235. }
  8236. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8237. {
  8238. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8239. if((access(fname,F_OK))!=-1)
  8240. {
  8241. strcpy(chargingProfiles[0], fname);
  8242. ChargeProfileCount = 1;
  8243. }
  8244. //strcpy(fname, TxProfile_1_JSON);
  8245. }
  8246. //strcpy(fname, ChargePointMaxProfile_JSON );
  8247. break;
  8248. }
  8249. }
  8250. else // Check all Charging Profiles
  8251. {
  8252. int i = 0;
  8253. char fnametemp[200]={0};
  8254. ChargeProfileCount = 0;
  8255. //Check ChargePointMaxProfile.json exit
  8256. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8257. {
  8258. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8259. i = i + 1;
  8260. }
  8261. //Check TxDefaultProfile_0.json exit
  8262. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8263. {
  8264. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8265. i = i + 1;
  8266. }
  8267. //Check TxDefaultProfile_%d.json
  8268. for(int j=1; j <= gunTotalNumber; j++)
  8269. {
  8270. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8271. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8272. if((access(fnametemp,F_OK))!=-1)
  8273. {
  8274. strcpy(chargingProfiles[i], fnametemp);
  8275. i = i + 1;
  8276. }
  8277. }
  8278. //Check TxProfile_%d.json
  8279. for(int j=1; j <= gunTotalNumber; j++)
  8280. {
  8281. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8282. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8283. if((access(fnametemp,F_OK))!=-1)
  8284. {
  8285. strcpy(chargingProfiles[i], fnametemp);
  8286. i = i + 1;
  8287. }
  8288. }
  8289. ChargeProfileCount = i;
  8290. }// End connectorIsNULL is TRUE
  8291. if(ChargeProfileCount == 0)
  8292. {
  8293. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8294. goto end;
  8295. }
  8296. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8297. {
  8298. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8299. goto end;
  8300. }
  8301. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8302. {
  8303. memset(str, 0, ARRAY_SIZE(str));
  8304. // clear temp file
  8305. sprintf(str,"rm -f %s",temp);
  8306. system(str);
  8307. for(int k=0; k < ChargeProfileCount; k++)
  8308. {
  8309. memset(str, 0, ARRAY_SIZE(str));
  8310. //clear file in C
  8311. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8312. system(str);
  8313. }
  8314. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8315. goto end;
  8316. }
  8317. else if(connectorIsNULL == TRUE)
  8318. {
  8319. for(int k=0; k < ChargeProfileCount; k++)
  8320. {
  8321. fptr1 = fopen(chargingProfiles[k], "r");
  8322. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8323. //Check Charging Profile Count
  8324. while(fscanf(fptr1, "%s", word) != EOF)
  8325. {
  8326. //DEBUG_INFO("word=%s\n",word);
  8327. if(strstr(word, "chargingProfileId")!= NULL)
  8328. {
  8329. //DEBUG_INFO("test chargingProfileId \n");
  8330. n_chargingProfile = n_chargingProfile + 1;
  8331. //DEBUG_INFO("chargingProfileId Found\n");
  8332. }
  8333. }
  8334. rewind(fptr1);
  8335. //search Charging Profile Element
  8336. //int i= 0;
  8337. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8338. {
  8339. json_object *tmpProfilee;
  8340. tmpProfilee = json_tokener_parse(sLineWord);
  8341. if(!is_error(tmpProfilee))
  8342. {
  8343. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8344. {
  8345. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8346. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8347. }
  8348. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8349. {
  8350. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8351. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8352. }
  8353. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8354. {
  8355. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8356. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8357. }
  8358. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8359. {
  8360. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8361. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8362. }
  8363. }
  8364. json_object_put(tmpProfilee);
  8365. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8366. {
  8367. //------- not write to fptr2-------//
  8368. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8369. //clearflag = TRUE;
  8370. }
  8371. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8372. {
  8373. //------- not write to fptr2-------//
  8374. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8375. }
  8376. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8377. {
  8378. //------- not write to fptr2-------//
  8379. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8380. }
  8381. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8382. {
  8383. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8384. }
  8385. else
  8386. {
  8387. fprintf(fptr2, sLineWord);//writing data into file
  8388. }
  8389. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8390. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8391. if(clearflag == TRUE)
  8392. {
  8393. fclose(fptr1);
  8394. fclose(fptr2);
  8395. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8396. system(str);
  8397. // clear temp file
  8398. sprintf(str,"rm -f %s",temp);
  8399. system(str);
  8400. }
  8401. else
  8402. {
  8403. fclose(fptr1);
  8404. fclose(fptr2);
  8405. memset(str, 0, ARRAY_SIZE(str));
  8406. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8407. system(str);
  8408. resultRename = rename(temp, chargingProfiles[k]);
  8409. if(resultRename == 0)
  8410. {
  8411. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8412. }
  8413. else
  8414. {
  8415. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8416. }
  8417. if(comfirmstr[0]== 0)
  8418. {
  8419. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8420. }
  8421. //Check chargingProfile is empty file
  8422. /*------ Read the file ----------------*/
  8423. fptr1=fopen(chargingProfiles[k],"r");
  8424. ch=fgetc(fptr1);
  8425. rewind(fptr1);
  8426. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8427. if(ch!=EOF)
  8428. {
  8429. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8430. {
  8431. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8432. if(sLineWord[0]=='\0')
  8433. {
  8434. isEmptyFile = TRUE;
  8435. break;
  8436. }
  8437. else
  8438. {
  8439. isEmptyFile = FALSE;
  8440. break;
  8441. }
  8442. }
  8443. }
  8444. else
  8445. isEmptyFile = TRUE;
  8446. fclose(fptr1);
  8447. if(isEmptyFile == TRUE)
  8448. {
  8449. memset(str, 0, ARRAY_SIZE(str));
  8450. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8451. system(str);
  8452. }
  8453. }
  8454. }// End of while(int k=0; k < ChargePointCount; k++)
  8455. }
  8456. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8457. {
  8458. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8459. for(int k=0; k < ChargeProfileCount; k++)
  8460. {
  8461. fptr1 = fopen(chargingProfiles[k], "r");
  8462. fptr2 = fopen(temp, "w+");
  8463. //Check Charging Profile Count
  8464. while(fscanf(fptr1, "%s", word) != EOF)
  8465. {
  8466. //DEBUG_INFO("word=%s\n",word);
  8467. if(strstr(word, "chargingProfileId")!= NULL)
  8468. {
  8469. n_chargingProfile = n_chargingProfile + 1;
  8470. }
  8471. }
  8472. rewind(fptr1);
  8473. //search Charging Profile Element
  8474. //int i= 0;
  8475. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8476. {
  8477. json_object *tmpProfilee;
  8478. tmpProfilee = json_tokener_parse(sLineWord);
  8479. if(!is_error(tmpProfilee))
  8480. {
  8481. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8482. {
  8483. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8484. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8485. }
  8486. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8487. {
  8488. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8489. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8490. }
  8491. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8492. {
  8493. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8494. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8495. }
  8496. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8497. {
  8498. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8499. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8500. }
  8501. }
  8502. json_object_put(tmpProfilee);
  8503. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8504. {
  8505. //------- not write to fptr2-------//
  8506. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8507. //clearflag = TRUE;
  8508. }
  8509. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8510. {
  8511. //------- not write to fptr2-------//
  8512. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8513. }
  8514. else if(stackLevelIsNULL == TRUE)
  8515. {
  8516. //Clear Whole File
  8517. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8518. clearflag = TRUE;
  8519. break;
  8520. }
  8521. else
  8522. {
  8523. fprintf(fptr2, sLineWord);//writing data into file
  8524. }
  8525. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8526. }
  8527. if(clearflag == TRUE)
  8528. {
  8529. fclose(fptr1);
  8530. fclose(fptr2);
  8531. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8532. system(str);
  8533. // clear temp file
  8534. sprintf(str,"rm -f %s",temp);
  8535. system(str);
  8536. }
  8537. else
  8538. {
  8539. fclose(fptr1);
  8540. fclose(fptr2);
  8541. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8542. system(str);
  8543. resultRename = rename(temp, chargingProfiles[k]);
  8544. if(resultRename == 0)
  8545. {
  8546. DEBUG_INFO("File ChargingProfile renamed successfully");
  8547. }
  8548. else
  8549. {
  8550. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8551. }
  8552. if(comfirmstr[0]== 0)
  8553. {
  8554. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8555. }
  8556. //Check chargingProfile is empty file
  8557. /*------ Read the file ----------------*/
  8558. fptr1=fopen(chargingProfiles[k],"r");
  8559. ch=fgetc(fptr1);
  8560. rewind(fptr1);
  8561. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8562. if(ch!=EOF)
  8563. {
  8564. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8565. {
  8566. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8567. if(sLineWord[0]=='\0')
  8568. {
  8569. isEmptyFile = TRUE;
  8570. break;
  8571. }
  8572. else
  8573. {
  8574. isEmptyFile = FALSE;
  8575. break;
  8576. }
  8577. }
  8578. }
  8579. else
  8580. isEmptyFile = TRUE;
  8581. fclose(fptr1);
  8582. if(isEmptyFile == TRUE)
  8583. {
  8584. memset(str, 0, ARRAY_SIZE(str));
  8585. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8586. system(str);
  8587. }
  8588. /*------- End of reading ---------------*/
  8589. }
  8590. } // while(int k=0; k < ChargeProfileCount; k++)
  8591. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8592. end:
  8593. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8594. {
  8595. if(connectorIdInt == 0)
  8596. {
  8597. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8598. {
  8599. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8600. }
  8601. }
  8602. else
  8603. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8604. }
  8605. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8606. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8607. return result;
  8608. }
  8609. void createFirmwareVersionByDataTransfer(void)
  8610. {
  8611. json_object *FirmwareDataTransfer = json_object_new_object();
  8612. // AC & DC model
  8613. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8614. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8615. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8616. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8617. // DC model
  8618. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8619. {
  8620. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8621. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8622. (gunType[3] != GUN_TYPE_UNKNOWN))
  8623. {
  8624. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8625. }
  8626. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8627. {
  8628. // DS DM DW
  8629. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8630. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8631. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8632. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8633. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8634. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8635. }
  8636. else
  8637. {
  8638. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8639. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  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. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8643. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8644. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8645. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8646. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8647. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8648. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8649. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8650. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8651. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8652. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8653. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8654. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8655. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8656. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8657. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8658. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8659. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8660. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8661. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8662. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8663. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8664. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8665. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8666. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8667. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8668. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8669. }
  8670. }
  8671. // 4G model
  8672. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8673. {
  8674. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8675. }
  8676. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8677. json_object_put(FirmwareDataTransfer);
  8678. }
  8679. int handleDataTransferRequest(char *uuid, char *payload)
  8680. {
  8681. mtrace();
  8682. json_object *response = json_object_new_object();
  8683. int result = FAIL;
  8684. char tempvendorId[255]={0};
  8685. char tempmessageId[50]={0};
  8686. char tempdata[512]={0};
  8687. char message[2048]={0};
  8688. DEBUG_INFO("handleDataTransferRequest...\n");
  8689. if((uuid != NULL) && (payload != NULL))
  8690. {
  8691. json_object *DataTransfer;
  8692. DataTransfer = json_tokener_parse(payload);
  8693. if(!is_error(DataTransfer))
  8694. {
  8695. // Required data
  8696. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8697. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8698. // Optional data
  8699. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8700. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8701. if(json_object_object_get(DataTransfer, "data") != NULL)
  8702. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8703. result = PASS;
  8704. }
  8705. json_object_put(DataTransfer);
  8706. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8707. {
  8708. // Send all moudle firmware version on EVSE
  8709. createFirmwareVersionByDataTransfer();
  8710. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8711. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8712. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8713. json_object_put(response);
  8714. }
  8715. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8716. {
  8717. system("/usr/bin/run_tmate_restart.sh &");
  8718. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  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_ChargingPreference") != NULL)
  8723. {
  8724. json_object *data;
  8725. data = json_tokener_parse(tempdata);
  8726. if(!is_error(data))
  8727. {
  8728. 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))
  8729. {
  8730. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8731. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8732. if(json_object_object_get(data, "SOC") != NULL)
  8733. {
  8734. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8735. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8736. }
  8737. if(json_object_object_get(data, "Energy") != NULL)
  8738. {
  8739. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8740. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8741. }
  8742. if(json_object_object_get(data, "Duration") != NULL)
  8743. {
  8744. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8745. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8746. }
  8747. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8748. }
  8749. else
  8750. {
  8751. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8752. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8753. }
  8754. }
  8755. else
  8756. {
  8757. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8758. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8759. }
  8760. json_object_put(data);
  8761. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8762. json_object_put(response);
  8763. }
  8764. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8765. {
  8766. json_object *data;
  8767. data = json_tokener_parse(tempdata);
  8768. if(!is_error(data))
  8769. {
  8770. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8771. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8772. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8773. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8774. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8775. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8776. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8777. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8778. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8779. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8780. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8781. }
  8782. else
  8783. {
  8784. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8785. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8786. }
  8787. json_object_put(data);
  8788. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8789. json_object_put(response);
  8790. }
  8791. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8792. {
  8793. json_object *data;
  8794. data = json_tokener_parse(tempdata);
  8795. if(!is_error(data))
  8796. {
  8797. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8798. if(json_object_object_get(data, "idToken") != NULL)
  8799. {
  8800. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8801. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8802. }
  8803. if(json_object_object_get(data, "price") != NULL)
  8804. {
  8805. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8806. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8807. }
  8808. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8809. }
  8810. else
  8811. {
  8812. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8813. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8814. }
  8815. json_object_put(data);
  8816. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8817. json_object_put(response);
  8818. }
  8819. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8820. {
  8821. json_object *data;
  8822. data = json_tokener_parse(tempdata);
  8823. if(!is_error(data))
  8824. {
  8825. if(json_object_object_get(data, "txId") != NULL)
  8826. {
  8827. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8828. for(int idx = 0;idx<gunTotalNumber;idx++)
  8829. {
  8830. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8831. {
  8832. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8833. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8834. if(json_object_object_get(data, "description") != NULL)
  8835. {
  8836. // California pricing V1.0
  8837. DEBUG_INFO("California pricing V1.0\n");
  8838. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8839. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8840. }
  8841. else
  8842. {
  8843. // California pricing V1.1
  8844. DEBUG_INFO("California pricing V1.1\n");
  8845. if(json_object_object_get(data, "timestamp") != NULL)
  8846. {
  8847. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8848. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8849. }
  8850. if(json_object_object_get(data, "meterValue") != NULL)
  8851. {
  8852. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8853. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8854. }
  8855. if(json_object_object_get(data, "cost") != NULL)
  8856. {
  8857. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8858. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8859. }
  8860. if(json_object_object_get(data, "state") != NULL)
  8861. {
  8862. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8863. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8864. }
  8865. if(json_object_object_get(data, "chargingPrice") != NULL)
  8866. {
  8867. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8868. {
  8869. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8870. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8871. }
  8872. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8873. {
  8874. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8875. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8876. }
  8877. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8878. {
  8879. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8880. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8881. }
  8882. }
  8883. if(json_object_object_get(data, "idlePrice") != NULL)
  8884. {
  8885. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8886. {
  8887. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8888. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8889. }
  8890. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8891. {
  8892. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8893. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8894. }
  8895. }
  8896. if(json_object_object_get(data, "nextPeriod") != NULL)
  8897. {
  8898. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8899. {
  8900. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8901. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8902. }
  8903. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8904. {
  8905. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8906. {
  8907. 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")));
  8908. 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"));
  8909. }
  8910. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8911. {
  8912. 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")));
  8913. 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"));
  8914. }
  8915. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8916. {
  8917. 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")));
  8918. 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"));
  8919. }
  8920. }
  8921. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8922. {
  8923. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8924. {
  8925. 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")));
  8926. 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"));
  8927. }
  8928. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8929. {
  8930. 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")));
  8931. 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"));
  8932. }
  8933. }
  8934. }
  8935. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8936. {
  8937. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8938. {
  8939. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8940. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8941. }
  8942. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8943. {
  8944. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8945. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8946. }
  8947. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8948. {
  8949. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8950. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8951. }
  8952. }
  8953. }
  8954. }
  8955. }
  8956. }
  8957. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8958. }
  8959. else
  8960. {
  8961. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8962. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8963. }
  8964. json_object_put(data);
  8965. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8966. json_object_put(response);
  8967. }
  8968. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8969. {
  8970. json_object *data;
  8971. data = json_tokener_parse(tempdata);
  8972. if(!is_error(data))
  8973. {
  8974. if(json_object_object_get(data, "txId") != NULL)
  8975. {
  8976. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8977. for(int idx = 0;idx<gunTotalNumber;idx++)
  8978. {
  8979. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8980. {
  8981. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8982. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8983. if(json_object_object_get(data, "description") != NULL)
  8984. {
  8985. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8986. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8987. }
  8988. }
  8989. }
  8990. }
  8991. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8992. }
  8993. else
  8994. {
  8995. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8996. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8997. }
  8998. json_object_put(data);
  8999. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9000. json_object_put(response);
  9001. }
  9002. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9003. {
  9004. json_object *data;
  9005. data = json_tokener_parse(tempdata);
  9006. if(!is_error(data))
  9007. {
  9008. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9009. if(json_object_object_get(data, "Content_Type") != NULL)
  9010. {
  9011. 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))
  9012. {
  9013. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9014. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9015. {
  9016. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9017. }
  9018. }
  9019. else
  9020. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9021. }
  9022. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9023. }
  9024. else
  9025. {
  9026. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9027. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9028. }
  9029. json_object_put(data);
  9030. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9031. json_object_put(response);
  9032. }
  9033. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9034. {
  9035. json_object *data;
  9036. data = json_tokener_parse(tempdata);
  9037. if(!is_error(data))
  9038. {
  9039. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9040. if(json_object_object_get(data, "ConnectorId") != NULL)
  9041. {
  9042. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9043. }
  9044. if(json_object_object_get(data, "Page_Index") != NULL)
  9045. {
  9046. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9047. }
  9048. if(json_object_object_get(data, "Duration") != NULL)
  9049. {
  9050. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9051. }
  9052. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9053. }
  9054. else
  9055. {
  9056. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9057. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9058. }
  9059. json_object_put(data);
  9060. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9061. json_object_put(response);
  9062. }
  9063. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9064. {
  9065. json_object *data;
  9066. data = json_tokener_parse(tempdata);
  9067. if(!is_error(data))
  9068. {
  9069. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9070. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9071. {
  9072. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9073. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9074. else
  9075. {
  9076. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9077. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9078. }
  9079. }
  9080. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9081. {
  9082. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9083. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9084. else
  9085. {
  9086. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9087. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9088. }
  9089. }
  9090. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9091. {
  9092. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9093. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9094. else
  9095. {
  9096. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9097. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9098. }
  9099. }
  9100. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9101. {
  9102. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9103. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9104. else
  9105. {
  9106. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9107. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9108. }
  9109. }
  9110. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9111. {
  9112. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9113. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9114. else
  9115. {
  9116. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9117. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9118. }
  9119. }
  9120. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9121. {
  9122. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9123. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9124. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9125. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9126. else
  9127. {
  9128. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9129. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9130. }
  9131. }
  9132. if(json_object_object_get(data, "isAuthentication") != NULL)
  9133. {
  9134. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9135. {
  9136. case 0:
  9137. case 1:
  9138. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9139. break;
  9140. default:
  9141. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9142. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9143. break;
  9144. }
  9145. }
  9146. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9147. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9148. }
  9149. else
  9150. {
  9151. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9152. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9153. }
  9154. json_object_put(data);
  9155. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9156. json_object_put(response);
  9157. }
  9158. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9159. {
  9160. json_object *data;
  9161. data = json_tokener_parse(tempdata);
  9162. if(!is_error(data))
  9163. {
  9164. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9165. if(json_object_object_get(data, "stationName") != NULL)
  9166. {
  9167. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9168. }
  9169. else
  9170. {
  9171. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9172. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9173. }
  9174. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9175. {
  9176. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9177. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9178. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9179. }
  9180. }
  9181. else
  9182. {
  9183. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9184. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9185. }
  9186. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9187. json_object_put(response);
  9188. }
  9189. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9190. {
  9191. json_object *data;
  9192. data = json_tokener_parse(tempdata);
  9193. if(!is_error(data))
  9194. {
  9195. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9196. if(json_object_object_get(data, "weatherId") != NULL)
  9197. {
  9198. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9199. }
  9200. else
  9201. {
  9202. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9203. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9204. }
  9205. if(json_object_object_get(data, "Temperature") != NULL)
  9206. {
  9207. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9208. }
  9209. else
  9210. {
  9211. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9212. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9213. }
  9214. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9215. {
  9216. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9217. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9218. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9219. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9220. }
  9221. }
  9222. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9223. {
  9224. json_object *data;
  9225. data = json_tokener_parse(tempdata);
  9226. if(!is_error(data))
  9227. {
  9228. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9229. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9230. {
  9231. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9232. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9233. }
  9234. else
  9235. {
  9236. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9237. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9238. }
  9239. }
  9240. else
  9241. {
  9242. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9243. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9244. }
  9245. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9246. json_object_put(response);
  9247. }
  9248. else
  9249. {
  9250. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9251. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9252. }
  9253. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9254. json_object_put(response);
  9255. }
  9256. else
  9257. {
  9258. // Can not find valid message id
  9259. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9260. }
  9261. }
  9262. else
  9263. {
  9264. // Payload is null
  9265. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9266. }
  9267. LWS_Send(message);
  9268. return result;
  9269. }
  9270. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9271. {
  9272. mtrace();
  9273. int result = FAIL;
  9274. int connectorIdInt, durationInt;
  9275. char chargingRateUnitStr[4]={0};
  9276. char comfirmstr[20];
  9277. int confirmPeriods = 0;
  9278. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9279. json_object *GetCompositeSchedule;
  9280. GetCompositeSchedule = json_tokener_parse(payload);
  9281. if(!is_error(GetCompositeSchedule))
  9282. {
  9283. // Required data
  9284. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9285. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9286. else
  9287. connectorIdInt = -1;
  9288. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9289. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9290. else
  9291. durationInt = 86400;
  9292. // Optional data
  9293. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9294. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9295. }
  9296. json_object_put(GetCompositeSchedule);
  9297. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9298. if((connectorIdInt == 0) ||
  9299. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9300. {
  9301. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9302. struct StructChargingProfile tmpProfile[1];
  9303. if(strstr(chargingRateUnitStr, "W") != NULL)
  9304. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9305. else
  9306. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9307. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9308. {
  9309. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9310. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9311. }
  9312. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9313. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9314. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9315. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9316. {
  9317. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9318. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9319. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9320. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9321. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9322. {
  9323. confirmPeriods = idx;
  9324. break;
  9325. }
  9326. }
  9327. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9328. {
  9329. confirmPeriods += 1;
  9330. }
  9331. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9332. }
  9333. else
  9334. {
  9335. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9336. }
  9337. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9338. return result;
  9339. }
  9340. int handleGetConfigurationRequest(char *uuid, char *payload)
  9341. {
  9342. mtrace();
  9343. int result = FAIL;
  9344. int MaxKeySupported = 0;
  9345. int n_keys = 0;
  9346. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9347. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9348. json_object *GetConfiguration;
  9349. GetConfiguration = json_tokener_parse(payload);
  9350. if(!is_error(GetConfiguration))
  9351. {
  9352. // Optional data
  9353. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9354. {
  9355. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9356. {
  9357. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9358. n_keys = idx + 1;
  9359. }
  9360. }
  9361. }
  9362. json_object_put(GetConfiguration);
  9363. UnknownKeynum = 0;
  9364. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9365. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9366. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9367. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9368. if(n_keys != 0)
  9369. {
  9370. for(int i=0;i<n_keys;i++)
  9371. {
  9372. getKeyValue(requestKey[i]);
  9373. }
  9374. }
  9375. else
  9376. {
  9377. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9378. getKeyValue("");
  9379. }
  9380. processUnkownKey();
  9381. sendGetConfigurationConfirmation(uuid);
  9382. return result;
  9383. }
  9384. static char fnamePlusPath[100]={0};
  9385. static char fnamePWithNoPath[60]={0};
  9386. void checkUploadLog(void)
  9387. {
  9388. FILE *fp;
  9389. /* Open the command for reading. */
  9390. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9391. if (fp == NULL) {
  9392. DEBUG_WARN("Failed to run command\n" );
  9393. exit(1);
  9394. }
  9395. int ftppathlen = 0;
  9396. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9397. int i = 0;
  9398. /* Read the output a line at a time - output it. */
  9399. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9400. if(i==0)
  9401. {
  9402. ftppathlen = strlen(fnamePlusPath);
  9403. DEBUG_INFO("%s\n", fnamePlusPath);
  9404. fnamePlusPath[ftppathlen]='\0';
  9405. break;
  9406. }
  9407. i= i+1;
  9408. }
  9409. /* close */
  9410. pclose(fp);
  9411. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9412. {
  9413. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9414. {
  9415. fnamePlusPath[k]='\0';
  9416. }
  9417. }
  9418. i=1;
  9419. //char fname[60]={0};
  9420. while(i < ftppathlen)
  9421. {
  9422. int len=ftppathlen-i;
  9423. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9424. {
  9425. DEBUG_INFO("compare '/' all right\n");
  9426. break;
  9427. }
  9428. i=i+1;
  9429. }
  9430. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9431. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9432. fnamePWithNoPath[i+1] = '\0';
  9433. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9434. {
  9435. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9436. {
  9437. fnamePWithNoPath[j]='\0';
  9438. }
  9439. }
  9440. FILE* fp1 = fopen(fnamePlusPath, "r");
  9441. if (fp1)
  9442. {
  9443. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9444. // file exists
  9445. fclose(fp1);
  9446. }
  9447. else
  9448. {
  9449. // file doesn't exist
  9450. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9451. }
  9452. }
  9453. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9454. {
  9455. mtrace();
  9456. int result = FAIL;
  9457. time_t CurrentTime;
  9458. struct tm *tm;
  9459. pthread_t th_Status;
  9460. CurrentTime = time(NULL);
  9461. tm = localtime(&CurrentTime);
  9462. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9463. 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);
  9464. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9465. if(!interLock.isGetDiagnosticGoing)
  9466. {
  9467. interLock.isGetDiagnosticGoing = 1;
  9468. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9469. sleep(1);
  9470. }
  9471. else
  9472. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9473. return result;
  9474. }
  9475. void* GetDiagnosticsProcess(void* data)
  9476. {
  9477. pthread_detach(pthread_self());
  9478. mtrace();
  9479. int retriesInt=0, retryIntervalInt=0;
  9480. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9481. 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};
  9482. int port=0;
  9483. int isSuccess = FALSE;
  9484. char ftpbuf[200]={0};
  9485. char cmdBuf[2048];
  9486. struct tm *tmNow;
  9487. time_t CurrentTime;
  9488. struct tm tmStart;
  9489. struct tm tmStop;
  9490. CurrentTime = time(NULL);
  9491. tmNow=localtime(&CurrentTime);
  9492. uint16_t targetYear, targetMonth;
  9493. json_object *GetDiagnostics;
  9494. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9495. GetDiagnostics = json_tokener_parse(data);
  9496. if(!is_error(GetDiagnostics))
  9497. {
  9498. // Required data
  9499. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9500. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9501. // Optional data
  9502. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9503. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9504. else
  9505. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9506. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9507. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9508. else
  9509. retryIntervalInt = 30;
  9510. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9511. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9512. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9513. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9514. }
  9515. json_object_put(GetDiagnostics);
  9516. // Pack log to compress file
  9517. 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) &&
  9518. (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))
  9519. {
  9520. // Pack system log
  9521. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9522. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9523. targetYear = tmStart.tm_year;
  9524. targetMonth = tmStart.tm_mon;
  9525. do
  9526. {
  9527. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9528. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9529. if(targetMonth+1>=13)
  9530. {
  9531. targetYear += 1;
  9532. targetMonth = 1;
  9533. }
  9534. else
  9535. {
  9536. targetMonth += 1;
  9537. }
  9538. }while((targetYear < (tmNow->tm_year+1900)) ||
  9539. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9540. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9541. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9542. system(cmdBuf);
  9543. // Pack charging & event log
  9544. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9545. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9546. targetYear = tmStart.tm_year;
  9547. targetMonth = tmStart.tm_mon;
  9548. do
  9549. {
  9550. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9551. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9552. if(targetMonth+1>=13)
  9553. {
  9554. targetYear += 1;
  9555. targetMonth = 1;
  9556. }
  9557. else
  9558. {
  9559. targetMonth += 1;
  9560. }
  9561. }while((targetYear < (tmNow->tm_year+1900)) ||
  9562. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9563. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9564. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9565. system(cmdBuf);
  9566. // Combine log file
  9567. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9568. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9569. }
  9570. else
  9571. {
  9572. system("exec /root/logPackTools 'log' 6");
  9573. }
  9574. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9575. system(cmdBuf);
  9576. checkUploadLog();
  9577. //****************location*******************/
  9578. if(strcmp(locationstr,"")==0)
  9579. {
  9580. DEBUG_INFO("location is <Empty>!\n");
  9581. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9582. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9583. goto end;
  9584. }
  9585. memset(protocol, 0, ARRAY_SIZE(protocol));
  9586. memset(user, 0, ARRAY_SIZE(user) );
  9587. memset(password, 0, ARRAY_SIZE(password));
  9588. memset(host, 0, ARRAY_SIZE(host));
  9589. memset(path, 0, ARRAY_SIZE(path));
  9590. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9591. memset(host1, 0, ARRAY_SIZE(host1));
  9592. memset(path1, 0, ARRAY_SIZE(path1));
  9593. /*location: ftp://user:password@host:port/path*/
  9594. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9595. if((access(fnamePlusPath,F_OK))!=-1)
  9596. {
  9597. DEBUG_INFO("fnamePlusPath exist.\n");
  9598. }
  9599. else
  9600. {
  9601. DEBUG_INFO("fnamePlusPath not exist!\n");
  9602. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9603. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9604. goto end;
  9605. }
  9606. if(strchr(locationstr,'@')==NULL)
  9607. {
  9608. sscanf(locationstr,
  9609. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9610. protocol, host, &port, path);
  9611. strcpy(user,"anonymous");
  9612. strcpy(password,"");
  9613. }
  9614. else
  9615. {
  9616. //DEBUG_INFO("pch=%s\n", pch);
  9617. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9618. protocol, user, password, host, &port, path);
  9619. }
  9620. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9621. {
  9622. DEBUG_INFO("protocol is not ftp/http ! \n");
  9623. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9624. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9625. goto end;
  9626. }
  9627. if(strncmp(locationstr,"http", 4) == 0)
  9628. {
  9629. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9630. sprintf(ftppath,"/%s", path);
  9631. do
  9632. {
  9633. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9634. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9635. sleep(3);
  9636. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9637. if(!isSuccess)
  9638. {
  9639. DEBUG_INFO("Diagnostics fail.\n");
  9640. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9641. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9642. sleep(retryIntervalInt);
  9643. }
  9644. else
  9645. {
  9646. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9647. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9648. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9649. }
  9650. retriesInt--;
  9651. }while((isSuccess == 0)&&(retriesInt >= 0));
  9652. }
  9653. else
  9654. {
  9655. sscanf(host,"%[^/]%s",host1, path1);
  9656. if(strlen(path) > 0)
  9657. sprintf(ftppath,"/%s", path);
  9658. else
  9659. sprintf(ftppath,"/%s", path1);
  9660. int ftppathlen=strlen(ftppath);
  9661. int i=1;
  9662. char filenametemp[50];
  9663. while(i < ftppathlen)
  9664. {
  9665. int len=ftppathlen-i;
  9666. if(ftppath[len]== 47) // '/' ascll code: 47
  9667. {
  9668. DEBUG_INFO("find '/' all right\n");
  9669. break;
  9670. }
  9671. i=i+1;
  9672. }
  9673. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9674. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9675. filenametemp[i+1] = 0;
  9676. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9677. if(port == 0)
  9678. port = 21;
  9679. do
  9680. {
  9681. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9682. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9683. sleep(3);
  9684. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9685. if(!isSuccess)
  9686. {
  9687. DEBUG_INFO("Diagnostics fail.\n");
  9688. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9689. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9690. sleep(retryIntervalInt);
  9691. }
  9692. else
  9693. {
  9694. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9695. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9696. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9697. }
  9698. retriesInt--;
  9699. }while((!isSuccess)&&(retriesInt >= 0));
  9700. }
  9701. end:
  9702. system("rm -f /mnt/*");
  9703. sleep(5);
  9704. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9705. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9706. interLock.isGetDiagnosticGoing = 0;
  9707. pthread_exit(NULL);
  9708. }
  9709. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9710. {
  9711. mtrace();
  9712. int result = FAIL;
  9713. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9714. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9715. {
  9716. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9717. locallistVersion = -1;
  9718. }
  9719. else
  9720. {
  9721. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9722. OCPP_getListVerion();
  9723. }
  9724. //from db.OCPP_getListVerion
  9725. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9726. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9727. sendGetLocalListVersionConfirmation(uuid,"");
  9728. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9729. return result;
  9730. }
  9731. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9732. {
  9733. mtrace();
  9734. int result = FAIL;
  9735. int connectorIdInt=-1;
  9736. int tempIndex = 0;
  9737. int connectorIdIsNULL, chargingProfileIsNULL;
  9738. char comfirmstr[20]={0};
  9739. char cmdBuf[512];
  9740. json_object *RemoteStartTransaction;
  9741. FILE *fp;
  9742. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9743. if(server_pending == TRUE)
  9744. {
  9745. return 0;
  9746. }
  9747. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9748. RemoteStartTransaction = json_tokener_parse(payload);
  9749. if(!is_error(RemoteStartTransaction))
  9750. {
  9751. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9752. {
  9753. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9754. }
  9755. else
  9756. {
  9757. connectorIdIsNULL = TRUE;
  9758. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9759. {
  9760. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9761. {
  9762. connectorIdIsNULL = FALSE;
  9763. connectorIdInt = (gun_index+1);
  9764. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9765. break;
  9766. }
  9767. }
  9768. }
  9769. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9770. {
  9771. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9772. // Required data
  9773. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9774. // Optional data
  9775. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9776. {
  9777. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9778. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9779. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9780. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9781. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9782. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9783. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9784. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9785. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9786. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9787. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9788. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9789. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9790. {
  9791. 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")));
  9792. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9793. 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"));
  9794. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9795. 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"));
  9796. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9797. 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")));
  9798. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9799. {
  9800. 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++)
  9801. {
  9802. 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"));
  9803. 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"));
  9804. 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)
  9805. 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"));
  9806. }
  9807. }
  9808. }
  9809. }
  9810. else
  9811. {
  9812. chargingProfileIsNULL = TRUE;
  9813. }
  9814. }
  9815. }
  9816. else
  9817. {
  9818. connectorIdIsNULL = TRUE;
  9819. }
  9820. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9821. {
  9822. DEBUG_WARN("Connector id is NULL\n.");
  9823. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9824. goto end;
  9825. }
  9826. /*
  9827. enum _SYSTEM_STATUS
  9828. {
  9829. S_BOOTING = 0,
  9830. S_IDLE, = 1
  9831. S_AUTHORIZING, = 2
  9832. S_REASSIGN_CHECK, = 3
  9833. S_REASSIGN, = 4
  9834. S_PRECHARGE, = 5
  9835. S_PREPARING_FOR_EV, = 6
  9836. S_PREPARING_FOR_EVSE, = 7
  9837. S_CHARGING, = 8
  9838. S_TERMINATING, = 9
  9839. S_COMPLETE, = 10
  9840. S_ALARM, = 11
  9841. S_FAULT = 12
  9842. }
  9843. */
  9844. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9845. {
  9846. //check Transaction active
  9847. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9848. {
  9849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9850. {
  9851. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9852. }
  9853. else
  9854. {
  9855. tempIndex = connectorIdInt -1;
  9856. }
  9857. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9858. {
  9859. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9860. {
  9861. 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))
  9862. {
  9863. //Reserved
  9864. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9865. }
  9866. 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))
  9867. {
  9868. //Reserved
  9869. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9870. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9871. goto end;
  9872. }
  9873. else
  9874. {
  9875. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9876. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9877. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9878. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9879. {
  9880. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9881. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9882. goto end;
  9883. }
  9884. }//END FOR ELSE
  9885. }
  9886. }// END FOR CHAdeMO_QUANTITY
  9887. }
  9888. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9889. {
  9890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9891. {
  9892. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9893. }
  9894. else
  9895. {
  9896. tempIndex = connectorIdInt -1;
  9897. }
  9898. for (int index = 0; index < CCS_QUANTITY; index++)
  9899. {
  9900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9901. {
  9902. 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))
  9903. {
  9904. //Reserved
  9905. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9906. }
  9907. 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))
  9908. {
  9909. //Reserved
  9910. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9911. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9912. goto end;
  9913. }
  9914. else
  9915. {
  9916. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9917. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9918. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9919. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9920. {
  9921. DEBUG_WARN("CCS connector not allow start\n.");
  9922. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9923. goto end;
  9924. }
  9925. }// END FOR ELSE
  9926. }
  9927. }// END FOR CCS_QUANTITY
  9928. }
  9929. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9930. {
  9931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9932. {
  9933. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9934. }
  9935. else
  9936. {
  9937. tempIndex = connectorIdInt -1;
  9938. }
  9939. for (int index = 0; index < GB_QUANTITY; index++)
  9940. {
  9941. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9942. {
  9943. 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))
  9944. {
  9945. //Reserved
  9946. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9947. }
  9948. 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))
  9949. {
  9950. //Reserved
  9951. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9953. goto end;
  9954. }
  9955. else
  9956. {
  9957. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9958. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9959. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9960. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9961. {
  9962. DEBUG_WARN("GB connector not allow start\n.");
  9963. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9964. goto end;
  9965. }
  9966. }// END FOR ELSE
  9967. }
  9968. } // END FOR GB_QUANTITY
  9969. }
  9970. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9971. {
  9972. tempIndex = connectorIdInt -1;
  9973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9974. {
  9975. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9976. {
  9977. 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))
  9978. {
  9979. //Reserved
  9980. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9981. }
  9982. 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))
  9983. {
  9984. //Reserved
  9985. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9986. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9987. goto end;
  9988. }
  9989. else
  9990. {
  9991. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9992. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9993. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9994. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9995. {
  9996. DEBUG_WARN("GB connector not allow start\n.");
  9997. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9998. goto end;
  9999. }
  10000. }// END FOR ELSE
  10001. }
  10002. } // END FOR GB_QUANTITY
  10003. }
  10004. else
  10005. {
  10006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10007. {
  10008. tempIndex = 2;
  10009. }
  10010. else
  10011. {
  10012. tempIndex = connectorIdInt -1;
  10013. }
  10014. for (int index = 0; index < AC_QUANTITY; index++)
  10015. {
  10016. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10017. {
  10018. 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))
  10019. {
  10020. //Reserved
  10021. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10022. }
  10023. 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))
  10024. {
  10025. //Reserved
  10026. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10027. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10028. goto end;
  10029. }
  10030. else
  10031. {
  10032. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10033. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10034. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10035. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10036. {
  10037. DEBUG_WARN("AC connector not allow start\n.");
  10038. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10039. goto end;
  10040. }
  10041. }//END FOR ELSE
  10042. }
  10043. }// END FOR AC_QUANTITY
  10044. }
  10045. if(chargingProfileIsNULL == FALSE)
  10046. {
  10047. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10048. {
  10049. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10050. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10051. //memset idTag
  10052. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10053. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10054. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10056. // Save profile to file
  10057. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10058. system(cmdBuf);
  10059. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10060. fp = fopen(cmdBuf, "w");
  10061. 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));
  10062. fclose(fp);
  10063. }
  10064. else
  10065. {
  10066. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10068. }
  10069. }
  10070. else
  10071. {
  10072. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10074. //memset idTag
  10075. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10076. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10077. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10078. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10079. }
  10080. }
  10081. else
  10082. {
  10083. DEBUG_WARN("Connector id over\n.");
  10084. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10085. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10086. }
  10087. end:
  10088. json_object_put(RemoteStartTransaction);
  10089. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10090. {
  10091. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10092. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10093. }
  10094. //OCPP send RemoteStartConfirmation by first.
  10095. sendRemoteStartConfirmation(uuid, comfirmstr);
  10096. return result;
  10097. }
  10098. int handleRemoteStartRequest(char *uuid, char *payload)
  10099. {
  10100. mtrace();
  10101. int result = PASS;
  10102. int connectorIdInt=-1;
  10103. int tempIndex = 0;
  10104. char comfirmstr[20]={0};
  10105. char cmdBuf[512];
  10106. json_object *RemoteStartTransaction;
  10107. FILE *fp;
  10108. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10109. if(server_pending == TRUE)
  10110. {
  10111. result = FAIL;
  10112. }
  10113. RemoteStartTransaction = json_tokener_parse(payload);
  10114. if(!is_error(RemoteStartTransaction))
  10115. {
  10116. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10117. {
  10118. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10119. }
  10120. else
  10121. {
  10122. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10123. {
  10124. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10125. {
  10126. connectorIdInt = (gun_index+1);
  10127. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10128. break;
  10129. }
  10130. }
  10131. }
  10132. if(connectorIdInt == 0)
  10133. {
  10134. DEBUG_WARN("Connector id shall not equal 0.\n");
  10135. result = FAIL;
  10136. }
  10137. else if(connectorIdInt == -1)
  10138. {
  10139. DEBUG_INFO("Connector id does not specific.\n");
  10140. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10141. {
  10142. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10143. // Required data
  10144. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10145. // Optional data
  10146. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10147. {
  10148. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10149. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10150. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10151. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10152. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10153. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10154. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10155. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10156. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10157. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10158. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10159. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10160. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10161. {
  10162. 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")));
  10163. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10164. 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"));
  10165. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10166. 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"));
  10167. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10168. 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")));
  10169. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10170. {
  10171. 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++)
  10172. {
  10173. 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"));
  10174. 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"));
  10175. 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)
  10176. 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"));
  10177. }
  10178. }
  10179. }
  10180. }
  10181. else
  10182. {
  10183. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10184. }
  10185. }
  10186. }
  10187. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10188. {
  10189. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10190. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10191. // Required data
  10192. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10193. // Optional data
  10194. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10195. {
  10196. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10197. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10198. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10199. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10200. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10201. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10202. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10203. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10204. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10205. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10206. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10207. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10208. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10209. {
  10210. 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")));
  10211. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10212. 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"));
  10213. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10214. 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"));
  10215. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10216. 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")));
  10217. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10218. {
  10219. 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++)
  10220. {
  10221. 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"));
  10222. 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"));
  10223. 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)
  10224. 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"));
  10225. }
  10226. }
  10227. }
  10228. }
  10229. else
  10230. {
  10231. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10232. }
  10233. }
  10234. else
  10235. {
  10236. DEBUG_WARN("Connector id is over maximun value.\n");
  10237. result = FAIL;
  10238. }
  10239. }
  10240. if(result == PASS)
  10241. {
  10242. if(connectorIdInt > 0)
  10243. {
  10244. //check Transaction active
  10245. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10246. {
  10247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10248. {
  10249. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10250. }
  10251. else
  10252. {
  10253. tempIndex = connectorIdInt -1;
  10254. }
  10255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10256. {
  10257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10258. {
  10259. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10260. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10261. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10262. {
  10263. //Reserved
  10264. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10265. }
  10266. else 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 does not match.\n");
  10272. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10273. goto end;
  10274. }
  10275. else
  10276. {
  10277. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10278. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10279. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10280. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10281. {
  10282. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10283. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10284. goto end;
  10285. }
  10286. }//END FOR ELSE
  10287. }
  10288. }// END FOR CHAdeMO_QUANTITY
  10289. }
  10290. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10291. {
  10292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10293. {
  10294. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10295. }
  10296. else
  10297. {
  10298. tempIndex = connectorIdInt -1;
  10299. }
  10300. for (int index = 0; index < CCS_QUANTITY; index++)
  10301. {
  10302. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10303. {
  10304. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10305. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10306. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10307. {
  10308. //Reserved
  10309. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10310. }
  10311. else 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 does not match.\n");
  10317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10318. goto end;
  10319. }
  10320. else
  10321. {
  10322. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10323. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10324. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10325. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10326. {
  10327. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10328. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10329. goto end;
  10330. }
  10331. }// END FOR ELSE
  10332. }
  10333. }// END FOR CCS_QUANTITY
  10334. }
  10335. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10336. {
  10337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10338. {
  10339. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10340. }
  10341. else
  10342. {
  10343. tempIndex = connectorIdInt -1;
  10344. }
  10345. for (int index = 0; index < GB_QUANTITY; index++)
  10346. {
  10347. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10348. {
  10349. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10350. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10351. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10352. {
  10353. //Reserved
  10354. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10355. }
  10356. else 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 does not match.\n");
  10362. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10363. goto end;
  10364. }
  10365. else
  10366. {
  10367. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10368. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10369. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10370. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10371. {
  10372. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10373. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10374. goto end;
  10375. }
  10376. }// END FOR ELSE
  10377. }
  10378. } // END FOR GB_QUANTITY
  10379. }
  10380. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10381. {
  10382. tempIndex = connectorIdInt -1;
  10383. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10384. {
  10385. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10386. {
  10387. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10388. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10389. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10390. {
  10391. //Reserved
  10392. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10393. }
  10394. else 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 does not match.\n");
  10400. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10401. goto end;
  10402. }
  10403. else
  10404. {
  10405. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10406. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10407. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10408. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10409. {
  10410. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10411. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10412. goto end;
  10413. }
  10414. }// END FOR ELSE
  10415. }
  10416. } // END FOR GB_QUANTITY
  10417. }
  10418. else
  10419. {
  10420. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10421. {
  10422. tempIndex = 2;
  10423. }
  10424. else
  10425. {
  10426. tempIndex = connectorIdInt -1;
  10427. }
  10428. for (int index = 0; index < AC_QUANTITY; index++)
  10429. {
  10430. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10431. {
  10432. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10433. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10434. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10435. {
  10436. //Reserved
  10437. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10438. }
  10439. else 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 does not match.\n");
  10445. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10446. goto end;
  10447. }
  10448. else
  10449. {
  10450. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10451. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10452. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10453. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10454. {
  10455. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10456. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10457. goto end;
  10458. }
  10459. }//END FOR ELSE
  10460. }
  10461. }// END FOR AC_QUANTITY
  10462. }
  10463. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10464. {
  10465. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10466. {
  10467. // Save profile to file
  10468. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10469. system(cmdBuf);
  10470. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10471. fp = fopen(cmdBuf, "w");
  10472. 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));
  10473. fclose(fp);
  10474. }
  10475. else
  10476. {
  10477. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10478. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10479. goto end;
  10480. }
  10481. }
  10482. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10483. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10484. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10485. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10486. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10488. }
  10489. else
  10490. {
  10491. uint8_t isHasIdleConnector = FALSE;
  10492. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10493. {
  10494. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10495. {
  10496. isHasIdleConnector = TRUE;
  10497. break;
  10498. }
  10499. }
  10500. if(isHasIdleConnector == TRUE)
  10501. {
  10502. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10503. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10504. {
  10505. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10506. {
  10507. // Save profile to file
  10508. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10509. system(cmdBuf);
  10510. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10511. fp = fopen(cmdBuf, "w");
  10512. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10513. fclose(fp);
  10514. refreshStartTimer(&clientTime.RemoteStartWait);
  10515. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10516. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10517. }
  10518. else
  10519. {
  10520. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10521. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10522. }
  10523. }
  10524. else
  10525. {
  10526. refreshStartTimer(&clientTime.RemoteStartWait);
  10527. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10529. }
  10530. }
  10531. else
  10532. {
  10533. DEBUG_INFO("There is not any connector is idle.\n");
  10534. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10535. }
  10536. }
  10537. }
  10538. else
  10539. {
  10540. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10541. }
  10542. end:
  10543. json_object_put(RemoteStartTransaction);
  10544. sendRemoteStartConfirmation(uuid, comfirmstr);
  10545. return result;
  10546. }
  10547. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10548. {
  10549. mtrace();
  10550. int result = FAIL;
  10551. int match = FALSE;
  10552. int GunNO = 0;
  10553. int tempIndex = 0;
  10554. int transactionIdInt=0;
  10555. int transactionIdIsNULL= TRUE;
  10556. char comfirmstr[20];
  10557. json_object *RemoteStopTransaction;
  10558. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10559. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10560. if(server_pending == TRUE)
  10561. {
  10562. return 0;
  10563. }
  10564. RemoteStopTransaction = json_tokener_parse(payload);
  10565. if(!is_error(RemoteStopTransaction))
  10566. {
  10567. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10568. {
  10569. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10570. transactionIdIsNULL = FALSE;
  10571. }
  10572. }
  10573. json_object_put(RemoteStopTransaction);
  10574. if(transactionIdIsNULL == FALSE)
  10575. {
  10576. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10577. {
  10578. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10579. {
  10580. //check Transaction active
  10581. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10582. {
  10583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10584. {
  10585. tempIndex = ((gun_index==2) ? 1: 0);
  10586. }
  10587. else
  10588. {
  10589. tempIndex = gun_index;
  10590. }
  10591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10592. {
  10593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10594. {
  10595. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10596. {
  10597. match = TRUE;
  10598. GunNO = gun_index;
  10599. }
  10600. }
  10601. }// END FOR CHAdeMO_QUANTITY
  10602. }
  10603. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10604. {
  10605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10606. {
  10607. tempIndex = ((gun_index==2) ? 1: 0);
  10608. }
  10609. else
  10610. {
  10611. tempIndex = gun_index;
  10612. }
  10613. for (int index = 0; index < CCS_QUANTITY; index++)
  10614. {
  10615. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10616. {
  10617. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10618. {
  10619. match = TRUE;
  10620. GunNO = gun_index;
  10621. }
  10622. }
  10623. }// END FOR CCS_QUANTITY
  10624. }
  10625. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10626. {
  10627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10628. {
  10629. tempIndex = ((gun_index==2) ? 1: 0);
  10630. }
  10631. else
  10632. {
  10633. tempIndex = gun_index;
  10634. }
  10635. for (int index = 0; index < GB_QUANTITY; index++)
  10636. {
  10637. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10638. {
  10639. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10640. {
  10641. match = TRUE;
  10642. GunNO = gun_index;
  10643. }
  10644. }
  10645. }// END FOR GB_QUANTITY
  10646. }
  10647. else if(gunType[gun_index] == GUN_TYPE_DO)
  10648. {
  10649. tempIndex = gun_index;
  10650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10651. {
  10652. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10653. {
  10654. 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
  10655. {
  10656. match = TRUE;
  10657. GunNO = gun_index;
  10658. }
  10659. }
  10660. }// END FOR GB_QUANTITY
  10661. }
  10662. else
  10663. {
  10664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10665. {
  10666. tempIndex = 2;
  10667. }
  10668. else
  10669. {
  10670. tempIndex = gun_index;
  10671. }
  10672. for (int index = 0; index < AC_QUANTITY; index++)
  10673. {
  10674. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10675. {
  10676. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10677. {
  10678. match = TRUE;
  10679. GunNO = gun_index;
  10680. }
  10681. }
  10682. }// END FOR CHAdeMO_QUANTITY
  10683. } // END FOR AC ELSE
  10684. }// CHECK IF ResponseTransactionId == transactionIdInt
  10685. }//END FOR
  10686. if( match == TRUE)
  10687. {
  10688. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10689. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10690. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10691. }
  10692. else
  10693. {
  10694. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10695. }
  10696. }
  10697. else
  10698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10699. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10700. return result;
  10701. }
  10702. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10703. {
  10704. mtrace();
  10705. int result = FAIL;
  10706. int connectorIdInt=0, reservationIdInt=0;
  10707. int tempIndex = 0;
  10708. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10709. char comfirmstr[20]={0};
  10710. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10711. int c = 0;
  10712. char *loc;
  10713. //char *ptr;
  10714. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10715. strcpy(sstrtemp, stringtrimspace(payload));
  10716. //***(1)connectorId ****/
  10717. c=0;
  10718. loc = strstr(sstrtemp, "connectorId");
  10719. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10720. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10721. {
  10722. sstr[c] = loc[strlen("connectorId")+2+c];
  10723. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10724. c++;
  10725. }
  10726. sstr[c] = '\0';
  10727. connectorIdInt = atoi(sstr);
  10728. //***(2)expiryDate ****/
  10729. loc = strstr(sstrtemp, "expiryDate");
  10730. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10731. c = 0;
  10732. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10733. {
  10734. sstr[c] = loc[3+strlen("expiryDate")+c];
  10735. c++;
  10736. }
  10737. sstr[c] = '\0';
  10738. strcpy(expiryDatestr, sstr);
  10739. //***(3)idTag ****/
  10740. loc = strstr(sstrtemp, "idTag");
  10741. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10742. c = 0;
  10743. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10744. {
  10745. sstr[c] = loc[3+strlen("idTag")+c];
  10746. c++;
  10747. }
  10748. sstr[c] = '\0';
  10749. strcpy(idTagstr, sstr);
  10750. //***(4)parentIdTag ****/
  10751. loc = strstr(sstrtemp, "parentIdTag");
  10752. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10753. c = 0;
  10754. if(loc == NULL)
  10755. {
  10756. strcpy(parentIdTagstr, "");
  10757. }
  10758. else
  10759. {
  10760. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10761. {
  10762. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10763. c++;
  10764. }
  10765. sstr[c] = '\0';
  10766. strcpy(parentIdTagstr, sstr);
  10767. }
  10768. //***(5)reservationId ****/
  10769. c=0;
  10770. loc = strstr(sstrtemp, "reservationId");
  10771. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10772. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10773. {
  10774. sstr[c] = loc[strlen("reservationId")+2+c];
  10775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10776. c++;
  10777. }
  10778. sstr[c] = '\0';
  10779. reservationIdInt = atoi(sstr);
  10780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10781. /*
  10782. enum SYSTEM_STATUS
  10783. {
  10784. SYS_MODE_BOOTING = 0,
  10785. SYS_MODE_IDLE = 1,
  10786. SYS_MODE_AUTHORIZING = 2,
  10787. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10788. SYS_MODE_REASSIGN = 4,
  10789. SYS_MODE_PREPARING = 5,
  10790. SYS_MODE_PREPARE_FOR_EV = 6,
  10791. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10792. SYS_MODE_CHARGING = 8,
  10793. SYS_MODE_TERMINATING = 9,
  10794. SYS_MODE_COMPLETE = 10,
  10795. SYS_MODE_ALARM = 11,
  10796. SYS_MODE_FAULT = 12,
  10797. SYS_MODE_RESERVATION = 13,
  10798. SYS_MODE_BOOKING = 14,
  10799. SYS_MODE_MAINTAIN = 15,
  10800. SYS_MODE_DEBUG = 16,
  10801. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10802. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10803. SYS_MODE_UPDATE = 19
  10804. };
  10805. */
  10806. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10807. {
  10808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10809. goto end;
  10810. }
  10811. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10812. {
  10813. //check Transaction active
  10814. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10815. {
  10816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10817. {
  10818. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10819. }
  10820. else
  10821. {
  10822. tempIndex = connectorIdInt -1;
  10823. }
  10824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10825. {
  10826. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10827. {
  10828. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10829. {
  10830. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10831. {
  10832. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10833. {
  10834. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10836. }
  10837. 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'))
  10838. {
  10839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10840. }
  10841. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10842. {
  10843. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10844. }
  10845. else
  10846. {
  10847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10848. }
  10849. }
  10850. 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
  10851. {
  10852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10853. }
  10854. }
  10855. else
  10856. {
  10857. //replace reservation
  10858. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10860. }
  10861. }
  10862. } // END FOR CHAdeMO_QUANTITY
  10863. }
  10864. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10865. {
  10866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10867. {
  10868. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10869. }
  10870. else
  10871. {
  10872. tempIndex = connectorIdInt -1;
  10873. }
  10874. for (int index = 0; index < CCS_QUANTITY; index++)
  10875. {
  10876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10877. {
  10878. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10879. {
  10880. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10881. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10882. {
  10883. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10884. {
  10885. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10887. }
  10888. 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'))
  10889. {
  10890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10891. }
  10892. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10893. {
  10894. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10895. }
  10896. else
  10897. {
  10898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10899. }
  10900. }
  10901. 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
  10902. {
  10903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10904. }
  10905. }
  10906. else
  10907. {
  10908. //replace reservation
  10909. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10911. }
  10912. }
  10913. } // END FOR CCS_QUANTITY
  10914. }
  10915. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10916. {
  10917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10918. {
  10919. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10920. }
  10921. else
  10922. {
  10923. tempIndex = connectorIdInt -1;
  10924. }
  10925. for (int index = 0; index < GB_QUANTITY; index++)
  10926. {
  10927. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10928. {
  10929. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10930. {
  10931. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10932. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10933. {
  10934. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10935. {
  10936. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10938. }
  10939. 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'))
  10940. {
  10941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10942. }
  10943. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10944. {
  10945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10946. }
  10947. else
  10948. {
  10949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10950. }
  10951. }
  10952. 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
  10953. {
  10954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10955. }
  10956. }
  10957. else
  10958. {
  10959. //replace reservation
  10960. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10962. }
  10963. }
  10964. }// END FOR GB_QUANTITY
  10965. }
  10966. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10967. {
  10968. tempIndex = connectorIdInt -1;
  10969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10970. {
  10971. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10972. {
  10973. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10974. {
  10975. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10976. 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
  10977. {
  10978. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10979. {
  10980. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10982. }
  10983. 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'))
  10984. {
  10985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10986. }
  10987. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10988. {
  10989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10990. }
  10991. else
  10992. {
  10993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10994. }
  10995. }
  10996. 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
  10997. {
  10998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10999. }
  11000. }
  11001. else
  11002. {
  11003. //replace reservation
  11004. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11006. }
  11007. }
  11008. }// END FOR GB_QUANTITY
  11009. }
  11010. else
  11011. {
  11012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11013. {
  11014. tempIndex = 2;
  11015. }
  11016. else
  11017. {
  11018. tempIndex = (connectorIdInt -1);
  11019. }
  11020. for (int index = 0; index < AC_QUANTITY; index++)
  11021. {
  11022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11023. {
  11024. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11025. {
  11026. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11027. {
  11028. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11029. {
  11030. 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))
  11031. {
  11032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11033. }
  11034. else
  11035. {
  11036. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11038. }
  11039. }
  11040. 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'))
  11041. {
  11042. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11043. }
  11044. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11045. {
  11046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11047. }
  11048. else
  11049. {
  11050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11051. }
  11052. }
  11053. 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
  11054. {
  11055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11056. }
  11057. }
  11058. else
  11059. {
  11060. //replace reservation
  11061. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11063. }
  11064. }
  11065. } // END FOR AC_QUANTITY
  11066. }
  11067. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11068. }
  11069. else if(connectorIdInt == 0)
  11070. {
  11071. //check Transaction active
  11072. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11073. {
  11074. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11075. {
  11076. 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'))
  11077. {
  11078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11079. goto end;
  11080. }
  11081. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11082. {
  11083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11084. goto end;
  11085. }
  11086. 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
  11087. {
  11088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11089. goto end;
  11090. }
  11091. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11092. {
  11093. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11094. goto end;
  11095. }
  11096. }
  11097. }// END FOR CHAdeMO_QUANTITY
  11098. for (int index = 0; index < CCS_QUANTITY; index++)
  11099. {
  11100. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11101. {
  11102. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11103. {
  11104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11105. goto end;
  11106. }
  11107. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11108. {
  11109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11110. goto end;
  11111. }
  11112. 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
  11113. {
  11114. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11115. goto end;
  11116. }
  11117. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11118. {
  11119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11120. goto end;
  11121. }
  11122. }
  11123. } // END FOR CCS_QUANTITY
  11124. for (int index = 0; index < GB_QUANTITY; index++)
  11125. {
  11126. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11127. {
  11128. 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'))
  11129. {
  11130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11131. goto end;
  11132. }
  11133. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11134. {
  11135. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11136. goto end;
  11137. }
  11138. 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
  11139. {
  11140. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11141. goto end;
  11142. }
  11143. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11144. {
  11145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11146. goto end;
  11147. }
  11148. }
  11149. } // END FOR GB_QUANTITY
  11150. for (int index = 0; index < AC_QUANTITY; index++)
  11151. {
  11152. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11153. {
  11154. 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'))
  11155. {
  11156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11157. goto end;
  11158. }
  11159. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11160. {
  11161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11162. goto end;
  11163. }
  11164. 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
  11165. {
  11166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11167. goto end;
  11168. }
  11169. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11170. {
  11171. 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))
  11172. {
  11173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11174. goto end;
  11175. }
  11176. }
  11177. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11178. {
  11179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11180. goto end;
  11181. }
  11182. }
  11183. }// END FOR AC_QUANTITY
  11184. //The connectorId is 0
  11185. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11186. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11187. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11188. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11189. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11190. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11191. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11192. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11193. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11194. result = TRUE;
  11195. return result;
  11196. }
  11197. else
  11198. {
  11199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11200. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11201. }
  11202. if(strcmp(comfirmstr,"Accepted") == 0)
  11203. {
  11204. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11205. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11206. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11207. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11208. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11209. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11210. result = TRUE;
  11211. return result;
  11212. }
  11213. end:
  11214. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11215. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11216. return result;
  11217. }
  11218. int handleResetRequest(char *uuid, char *payload)
  11219. {
  11220. mtrace();
  11221. int result = FAIL;
  11222. char sstr[10]={0},sstrtemp[30]={ 0 };
  11223. char typestr[10]={0};
  11224. char comfirmstr[20]={0};
  11225. int c = 0;
  11226. char *loc;
  11227. DEBUG_INFO("handleResetRequest...\n");
  11228. strcpy(sstrtemp, stringtrimspace(payload));
  11229. loc = strstr(sstrtemp, "type");
  11230. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11231. c = 0;
  11232. while (loc[3+strlen("type")+c] != '\"')
  11233. {
  11234. sstr[c] = loc[3+strlen("type")+c];
  11235. c++;
  11236. }
  11237. sstr[c] = '\0';
  11238. strcpy(typestr,sstr);
  11239. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11240. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11241. {
  11242. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11243. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11244. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11245. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11246. }
  11247. else
  11248. {
  11249. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11250. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11251. result = PASS;
  11252. }
  11253. sendResetConfirmation(uuid, comfirmstr);
  11254. return result;
  11255. }
  11256. int handleSendLocalListRequest(char *uuid, char *payload)
  11257. {
  11258. mtrace();
  11259. int result = FAIL;
  11260. char comfirmstr[20];
  11261. int checkState_Faulted = FALSE;
  11262. json_object *SendLocalList;
  11263. DEBUG_INFO("handleSendLocalListRequest...\n");
  11264. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11265. {
  11266. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11267. goto end;
  11268. }
  11269. //check Charge Point state
  11270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11271. {
  11272. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11273. {
  11274. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11275. }
  11276. }
  11277. for (int index = 0; index < CCS_QUANTITY; index++)
  11278. {
  11279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11280. {
  11281. checkState_Faulted = TRUE; //OCPP Status
  11282. }
  11283. }
  11284. for (int index = 0; index < GB_QUANTITY; index++)
  11285. {
  11286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11287. {
  11288. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11289. }
  11290. }
  11291. //check Charge Point state
  11292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11293. {
  11294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11295. {
  11296. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11297. }
  11298. }
  11299. //check Charge Point state
  11300. for (int index = 0; index < AC_QUANTITY; index++)
  11301. {
  11302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11303. {
  11304. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11305. }
  11306. }
  11307. if(checkState_Faulted == TRUE)
  11308. {
  11309. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11310. goto end;
  11311. }
  11312. // Parsing payload
  11313. SendLocalList = json_tokener_parse(payload);
  11314. if(!is_error(SendLocalList))
  11315. {
  11316. // Required data
  11317. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11318. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11319. // Optional data
  11320. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11321. {
  11322. //Check UpdateType
  11323. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11324. {
  11325. //Local list full update
  11326. DEBUG_INFO("Local list full update.\n");
  11327. OCPP_getListVerion();
  11328. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11329. {
  11330. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11331. goto end;
  11332. }
  11333. OCPP_cleanLocalList();
  11334. }
  11335. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11336. {
  11337. //Local list different update
  11338. DEBUG_INFO("Local list different update.\n");
  11339. OCPP_getListVerion();
  11340. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11341. {
  11342. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11343. goto end;
  11344. }
  11345. }
  11346. else
  11347. {
  11348. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11349. goto end;
  11350. }
  11351. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11352. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11353. {
  11354. 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")));
  11355. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11356. {
  11357. 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")));
  11358. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11359. 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")));
  11360. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11361. 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")));
  11362. }
  11363. // Add to db
  11364. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11365. {
  11366. //Local list full update
  11367. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11368. idx,
  11369. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11370. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11371. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11372. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11373. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11374. // update list
  11375. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11376. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11377. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11378. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11379. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11380. }
  11381. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11382. {
  11383. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11384. idx,
  11385. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11386. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11387. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11388. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11389. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11390. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11391. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11392. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11393. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11394. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11395. }
  11396. }
  11397. }
  11398. else
  11399. {
  11400. //Check UpdateType
  11401. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11402. {
  11403. //Local list full update
  11404. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11405. OCPP_cleanLocalList();
  11406. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11407. goto end;
  11408. }
  11409. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11410. {
  11411. //Local list different update
  11412. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11413. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11414. goto end;
  11415. }
  11416. }
  11417. result = PASS;
  11418. }
  11419. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11420. end:
  11421. json_object_put(SendLocalList);
  11422. sendSendLocalListConfirmation(uuid, comfirmstr);
  11423. return result;
  11424. }
  11425. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11426. {
  11427. mtrace();
  11428. int result = FAIL;
  11429. struct StructSetChargingProfile SetProfileReq = {0};
  11430. int tempchargingProfileIdInt;
  11431. int chargingSchedulePeriodCount = 0;
  11432. char comfirmstr[20]={0};
  11433. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11434. char rmFileCmd[128]={0};
  11435. int profileQuantity = 0;
  11436. json_object *SetChargingProfile;
  11437. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11438. SetChargingProfile = json_tokener_parse(payload);
  11439. if(!is_error(SetChargingProfile))
  11440. {
  11441. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11442. {
  11443. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11444. }
  11445. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11446. {
  11447. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11448. {
  11449. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11450. }
  11451. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11452. {
  11453. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11454. }
  11455. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11456. {
  11457. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11458. }
  11459. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11460. {
  11461. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11462. }
  11463. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11464. {
  11465. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11466. }
  11467. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11468. {
  11469. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11470. }
  11471. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11472. {
  11473. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11474. }
  11475. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11476. {
  11477. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11478. }
  11479. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11480. {
  11481. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11482. {
  11483. 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")));
  11484. }
  11485. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11486. {
  11487. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11488. }
  11489. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11490. {
  11491. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11492. }
  11493. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11494. {
  11495. 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")));
  11496. }
  11497. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11498. {
  11499. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11500. if(chargingSchedulePeriodCount <= 10)
  11501. {
  11502. 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++)
  11503. {
  11504. 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)
  11505. {
  11506. 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"));
  11507. }
  11508. 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)
  11509. {
  11510. 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"));
  11511. }
  11512. 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)
  11513. {
  11514. 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"));
  11515. }
  11516. }
  11517. }
  11518. }
  11519. }
  11520. }
  11521. }
  11522. // Profile periods quantity check
  11523. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11524. {
  11525. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11526. goto end;
  11527. }
  11528. // Check invalid limit
  11529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11530. {
  11531. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11532. {
  11533. 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)))) ||
  11534. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11535. {
  11536. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11537. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11538. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11539. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11540. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11541. goto end;
  11542. }
  11543. }
  11544. }
  11545. else
  11546. {
  11547. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11548. {
  11549. 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))
  11550. {
  11551. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11552. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11553. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11554. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11555. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11556. goto end;
  11557. }
  11558. }
  11559. }
  11560. // Profile purpose info check
  11561. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11562. {
  11563. FILE *fp;
  11564. char dataLine[4096]={0};
  11565. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11566. if(SetProfileReq.ConnectorId != 0)
  11567. {
  11568. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11569. goto end;
  11570. }
  11571. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11572. if (!fp)
  11573. {
  11574. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11575. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11576. }
  11577. else
  11578. {
  11579. while(fscanf(fp, "%s", dataLine) != EOF)
  11580. {
  11581. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11582. {
  11583. profileQuantity += 1;
  11584. }
  11585. }
  11586. }
  11587. fclose(fp);
  11588. }
  11589. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11590. {
  11591. FILE *fp;
  11592. char dataLine[4096]={0};
  11593. char filename[128]={0};
  11594. int tmpProfileQuantity;
  11595. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11596. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11597. {
  11598. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11599. goto end;
  11600. }
  11601. if(SetProfileReq.ConnectorId == 0)
  11602. {
  11603. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11604. {
  11605. tmpProfileQuantity = 0;
  11606. memset(filename, 0, ARRAY_SIZE(filename));
  11607. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11608. fp = fopen(filename, "r");
  11609. if (!fp)
  11610. {
  11611. DEBUG_INFO("%s does not create.\n", filename);
  11612. fp = fopen(filename, "w+");
  11613. }
  11614. else
  11615. {
  11616. while(fscanf(fp, "%s", dataLine) != EOF)
  11617. {
  11618. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11619. {
  11620. tmpProfileQuantity += 1;
  11621. }
  11622. }
  11623. }
  11624. fclose(fp);
  11625. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11626. }
  11627. }
  11628. else
  11629. {
  11630. memset(filename, 0, ARRAY_SIZE(filename));
  11631. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11632. fp = fopen(filename, "r");
  11633. if (!fp)
  11634. {
  11635. DEBUG_INFO("%s does not create.\n", filename);
  11636. fp = fopen(filename, "w+");
  11637. }
  11638. else
  11639. {
  11640. while(fscanf(fp, "%s", dataLine) != EOF)
  11641. {
  11642. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11643. {
  11644. profileQuantity += 1;
  11645. }
  11646. }
  11647. }
  11648. fclose(fp);
  11649. }
  11650. }
  11651. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11652. {
  11653. int isMatchTransactiodId= FALSE;
  11654. FILE *fp;
  11655. char dataLine[4096]={0};
  11656. char filename[128]={0};
  11657. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11658. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11659. if(SetProfileReq.ConnectorId == 0)
  11660. {
  11661. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11662. goto end;
  11663. }
  11664. int tempIndex = 0;
  11665. //check Transaction active
  11666. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11667. {
  11668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11669. {
  11670. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11671. }
  11672. else
  11673. {
  11674. tempIndex = SetProfileReq.ConnectorId -1;
  11675. }
  11676. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11677. {
  11678. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11679. {
  11680. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11681. {
  11682. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11683. {
  11684. isMatchTransactiodId = TRUE;
  11685. break;
  11686. }
  11687. }
  11688. }
  11689. }
  11690. }
  11691. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11692. {
  11693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11694. {
  11695. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11696. }
  11697. else
  11698. {
  11699. tempIndex = SetProfileReq.ConnectorId -1;
  11700. }
  11701. for (int index = 0; index < CCS_QUANTITY; index++)
  11702. {
  11703. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11704. {
  11705. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11706. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11707. {
  11708. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11709. {
  11710. isMatchTransactiodId = TRUE;
  11711. break;
  11712. }
  11713. }
  11714. }
  11715. }
  11716. }
  11717. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11718. {
  11719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11720. {
  11721. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11722. }
  11723. else
  11724. {
  11725. tempIndex = SetProfileReq.ConnectorId -1;
  11726. }
  11727. for (int index = 0; index < GB_QUANTITY; index++)
  11728. {
  11729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11730. {
  11731. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11732. {
  11733. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11734. {
  11735. isMatchTransactiodId = TRUE;
  11736. break;
  11737. }
  11738. }
  11739. }
  11740. }
  11741. }
  11742. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11743. {
  11744. tempIndex = SetProfileReq.ConnectorId -1;
  11745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11746. {
  11747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11748. {
  11749. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11750. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11751. {
  11752. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11753. {
  11754. isMatchTransactiodId = TRUE;
  11755. break;
  11756. }
  11757. }
  11758. }
  11759. }
  11760. }
  11761. else
  11762. {
  11763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11764. {
  11765. tempIndex = 2;
  11766. }
  11767. else
  11768. {
  11769. tempIndex = (SetProfileReq.ConnectorId -1);
  11770. }
  11771. for (int index = 0; index < AC_QUANTITY; index++)
  11772. {
  11773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11774. {
  11775. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11776. {
  11777. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11778. {
  11779. isMatchTransactiodId = TRUE;
  11780. break;
  11781. }
  11782. }
  11783. }
  11784. }
  11785. }
  11786. //check Transaction active
  11787. if(isMatchTransactiodId == FALSE)
  11788. {
  11789. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11790. goto end;
  11791. }
  11792. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11793. {
  11794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11795. goto end;
  11796. }
  11797. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11798. fp = fopen(filename, "r");
  11799. if (!fp)
  11800. {
  11801. DEBUG_INFO("%s does not create.\n", filename);
  11802. fp = fopen(filename, "w+");
  11803. }
  11804. else
  11805. {
  11806. //Check Charging Profile Count
  11807. while(fscanf(fp, "%s", dataLine) != EOF)
  11808. {
  11809. //DEBUG_INFO("word=%s\n",word);
  11810. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11811. {
  11812. profileQuantity += 1;
  11813. }
  11814. }
  11815. }
  11816. fclose(fp);
  11817. }
  11818. // Check ChargeProfileMaxStackLevel
  11819. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11820. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11821. {
  11822. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11823. goto end;
  11824. }
  11825. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11826. {
  11827. FILE *fp;
  11828. char dataLine[4096]={0};
  11829. char fnametemp[128]={0};
  11830. int tmpProfileQuantity;
  11831. //Check ChargePointMaxProfile.json exit
  11832. profileQuantity = 0;
  11833. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11834. {
  11835. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11836. //Check Charging Profile Count
  11837. tmpProfileQuantity = 0;
  11838. while(fscanf(fp, "%s", dataLine) != EOF)
  11839. {
  11840. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11841. {
  11842. profileQuantity += 1;
  11843. tmpProfileQuantity += 1;
  11844. }
  11845. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11846. }
  11847. fclose(fp);
  11848. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11849. }
  11850. //Check TxDefaultProfile_%d.json
  11851. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11852. {
  11853. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11854. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11855. if((access(fnametemp,F_OK))!=-1)
  11856. {
  11857. fp = fopen(fnametemp, "r");
  11858. //Check Charging Profile Count
  11859. tmpProfileQuantity = 0;
  11860. while(fscanf(fp, "%s", dataLine) != EOF)
  11861. {
  11862. //DEBUG_INFO("word=%s\n",word);
  11863. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11864. {
  11865. profileQuantity += 1;
  11866. tmpProfileQuantity += 1;
  11867. }
  11868. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11869. }
  11870. fclose(fp);
  11871. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11872. }
  11873. }
  11874. //Check TxProfile_%d.json
  11875. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11876. {
  11877. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11878. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11879. if((access(fnametemp,F_OK))!=-1)
  11880. {
  11881. fp = fopen(fnametemp, "r");
  11882. //Check Charging Profile Count
  11883. tmpProfileQuantity = 0;
  11884. while(fscanf(fp, "%s", dataLine) != EOF)
  11885. {
  11886. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11887. {
  11888. profileQuantity += 1;
  11889. tmpProfileQuantity += 1;
  11890. }
  11891. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11892. }
  11893. fclose(fp);
  11894. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11895. }
  11896. }
  11897. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11898. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11899. {
  11900. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11901. goto end;
  11902. }
  11903. }
  11904. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11905. //**********************************Write to File********************************************************/
  11906. {
  11907. FILE *infile;
  11908. FILE *outfile;
  11909. char dataLine[4096]={0};
  11910. char filename[128]={0};
  11911. int chkChar=0;
  11912. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11913. {
  11914. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11915. {
  11916. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11917. }
  11918. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11919. {
  11920. if(SetProfileReq.ConnectorId==0)
  11921. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11922. else
  11923. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11924. }
  11925. else
  11926. {
  11927. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11928. }
  11929. infile = fopen (filename, "r");
  11930. outfile = fopen (tempfile, "w");
  11931. chkChar = fgetc(infile);
  11932. rewind(infile);
  11933. if(chkChar == EOF)
  11934. {
  11935. // Profile is empty
  11936. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11937. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11938. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11939. fclose(infile);
  11940. fclose(outfile);
  11941. sprintf(rmFileCmd,"rm -f %s",filename);
  11942. system(rmFileCmd);
  11943. rename(tempfile, filename);
  11944. }
  11945. else
  11946. {
  11947. // Profile is not empty
  11948. int ChargingProfileAdded = FALSE;
  11949. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11950. {
  11951. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11952. json_object *tmpChargingProfile;
  11953. tmpChargingProfile = json_tokener_parse(dataLine);
  11954. if(!is_error(SetChargingProfile))
  11955. {
  11956. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11957. {
  11958. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11959. {
  11960. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11961. }
  11962. }
  11963. }
  11964. json_object_put(tmpChargingProfile);
  11965. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11966. {
  11967. if(ChargingProfileAdded == FALSE)
  11968. {
  11969. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11970. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11971. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11972. ChargingProfileAdded = TRUE;
  11973. }
  11974. }
  11975. else
  11976. {
  11977. fprintf(outfile,"%s\n",dataLine);
  11978. if(ChargingProfileAdded == FALSE)
  11979. {
  11980. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11981. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11982. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11983. ChargingProfileAdded = TRUE;
  11984. }
  11985. }
  11986. } // end of while loop
  11987. fclose(infile);
  11988. fclose(outfile);
  11989. sprintf(rmFileCmd,"rm -f %s",filename);
  11990. system(rmFileCmd);
  11991. rename(tempfile, filename);
  11992. }
  11993. }
  11994. sleep(1);
  11995. result = TRUE;
  11996. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11997. }
  11998. end:
  11999. json_object_put(SetChargingProfile);
  12000. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12001. {
  12002. if(SetProfileReq.ConnectorId == 0)
  12003. {
  12004. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12005. {
  12006. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12007. }
  12008. }
  12009. else
  12010. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12011. }
  12012. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12013. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12014. return result;
  12015. }
  12016. int handleTriggerMessageRequest(char *uuid, char *payload)
  12017. {
  12018. mtrace();
  12019. int result = FAIL;
  12020. int connectorIdIsNULL = FALSE;
  12021. int connectorIdInt =0;
  12022. char sstr[40]={0},sstrtemp[100]={ 0 };
  12023. char requestedMessagestr[40]={0};
  12024. char comfirmstr[20]={0};
  12025. int c = 0;
  12026. char *loc;
  12027. DEBUG_INFO("handleTriggerMessageRequest\n");
  12028. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12029. strcpy(sstrtemp, stringtrimspace(payload));
  12030. c = 0;
  12031. loc = strstr(sstrtemp, "requestedMessage");
  12032. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12033. {
  12034. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12035. c++;
  12036. }
  12037. sstr[c] = '\0';
  12038. strcpy(requestedMessagestr, sstr);
  12039. c = 0;
  12040. loc = strstr(sstrtemp, "connectorId");
  12041. if(loc == NULL)
  12042. {
  12043. connectorIdIsNULL = TRUE;
  12044. }
  12045. else
  12046. {
  12047. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12048. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12049. {
  12050. sstr[c] = loc[strlen("connectorId")+2+c];
  12051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12052. c++;
  12053. }
  12054. sstr[c] = '\0';
  12055. connectorIdInt = atoi(sstr);
  12056. }
  12057. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12058. {
  12059. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12060. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12061. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12062. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12063. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12064. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12065. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12066. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12067. {
  12068. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12069. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12070. return TRUE;
  12071. }
  12072. else
  12073. {
  12074. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12075. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12076. }
  12077. }
  12078. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12079. {
  12080. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12081. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12082. return TRUE;
  12083. }
  12084. //==========================
  12085. // Trigger message
  12086. //==========================
  12087. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12088. {
  12089. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12090. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12091. {
  12092. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12093. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12094. }
  12095. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12096. }
  12097. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12098. {
  12099. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12100. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12101. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12102. }
  12103. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12104. {
  12105. //sendBootNotificationRequest();
  12106. server_sign = FALSE;
  12107. }
  12108. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12109. {
  12110. refreshStartTimer(&clientTime.Heartbeat);
  12111. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12112. }
  12113. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12114. {
  12115. if(connectorIdIsNULL == FALSE)
  12116. {
  12117. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12118. {
  12119. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12120. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12121. }
  12122. }
  12123. else
  12124. {
  12125. for(int idx=0;idx< gunTotalNumber;idx++)
  12126. {
  12127. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12128. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12129. }
  12130. }
  12131. }
  12132. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12133. {
  12134. if(connectorIdIsNULL == FALSE)
  12135. {
  12136. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12137. {
  12138. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12139. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12140. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12141. }
  12142. }
  12143. else
  12144. {
  12145. for(int idx=0;idx< gunTotalNumber;idx++)
  12146. {
  12147. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12148. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12149. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12150. }
  12151. }
  12152. }
  12153. return result;
  12154. }
  12155. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12156. {
  12157. mtrace();
  12158. int result = FAIL;
  12159. int connectorIdInt =0;
  12160. char comfirmstr[20]={0};
  12161. int tempIndex = 0;
  12162. json_object *UnlockConnector;
  12163. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12164. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12165. UnlockConnector = json_tokener_parse(payload);
  12166. if(!is_error(UnlockConnector))
  12167. {
  12168. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12169. {
  12170. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12171. }
  12172. }
  12173. json_object_put(UnlockConnector);
  12174. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12175. if(gunTotalNumber == 0)
  12176. {
  12177. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12178. goto end;
  12179. }
  12180. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12181. {
  12182. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12183. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12184. goto end;
  12185. }
  12186. else
  12187. {
  12188. //check Transaction active
  12189. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12190. {
  12191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12192. {
  12193. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12194. }
  12195. else
  12196. {
  12197. tempIndex = connectorIdInt -1;
  12198. }
  12199. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12200. {
  12201. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12202. {
  12203. //stop Transaction
  12204. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12205. }
  12206. }
  12207. }
  12208. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12209. {
  12210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12211. {
  12212. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12213. }
  12214. else
  12215. {
  12216. tempIndex = connectorIdInt -1;
  12217. }
  12218. for (int index = 0; index < CCS_QUANTITY; index++)
  12219. {
  12220. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12221. {
  12222. //stop Transaction
  12223. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12224. }
  12225. }
  12226. }
  12227. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12228. {
  12229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12230. {
  12231. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12232. }
  12233. else
  12234. {
  12235. tempIndex = connectorIdInt -1;
  12236. }
  12237. for (int index = 0; index < GB_QUANTITY; index++)
  12238. {
  12239. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12240. {
  12241. //stop Transaction
  12242. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12243. }
  12244. }
  12245. }
  12246. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12247. {
  12248. tempIndex = connectorIdInt -1;
  12249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12250. {
  12251. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12252. {
  12253. //stop Transaction
  12254. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12255. }
  12256. }
  12257. }
  12258. else
  12259. {
  12260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12261. {
  12262. tempIndex = 2;
  12263. }
  12264. else
  12265. {
  12266. tempIndex = connectorIdInt-1;
  12267. }
  12268. for (int index = 0; index < AC_QUANTITY; index++)
  12269. {
  12270. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12271. {
  12272. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12273. }
  12274. }
  12275. }
  12276. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12277. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12278. result = TRUE;
  12279. return result;
  12280. }
  12281. end:
  12282. //json_object_put(obj); --- remove temporally
  12283. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12284. return result;
  12285. }
  12286. static char UpdateFirmwarepayloadData[300]={0};
  12287. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12288. {
  12289. mtrace();
  12290. int result = FAIL;
  12291. pthread_t t;
  12292. sendUpdateFirmwareConfirmation(uuid);
  12293. memset(UpdateFirmwarepayloadData, 0, 300);
  12294. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12295. if(!interLock.isUpdateFirmwareGoing)
  12296. {
  12297. interLock.isUpdateFirmwareGoing = 1;
  12298. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12299. sleep(1);
  12300. }
  12301. else
  12302. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12303. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12304. return result;
  12305. }
  12306. void *UpdateFirmwareProcess(void *data)
  12307. {
  12308. pthread_detach(pthread_self());
  12309. mtrace();
  12310. int retriesInt =0, retryIntervalInt=0;
  12311. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12312. int port=0;
  12313. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12314. int isSuccess = 0;
  12315. char ftpbuf[512];
  12316. char temp[100];
  12317. char * pch;
  12318. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12319. json_object *UpdateFirmware;
  12320. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12321. if(!is_error(UpdateFirmware))
  12322. {
  12323. // Required data
  12324. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12325. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12326. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12327. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12328. // Optional data
  12329. if(json_object_object_get(UpdateFirmware, "retries"))
  12330. {
  12331. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12332. }
  12333. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12334. {
  12335. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12336. }
  12337. }
  12338. json_object_put(UpdateFirmware);
  12339. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12340. memset(path, 0, ARRAY_SIZE(path));
  12341. // Wait retrieveData
  12342. if(strlen(retrieveDatestr) > 10)
  12343. {
  12344. do
  12345. {
  12346. sleep(1);
  12347. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12348. }
  12349. // Ready to download
  12350. system("rm -f /mnt/*");
  12351. if(strncmp(locationstr,"http", 4) == 0)
  12352. {
  12353. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12354. sprintf(ftppath,"/%s", path);
  12355. DEBUG_INFO("locationstr: %s\n", locationstr);
  12356. DEBUG_INFO("protocol: %s\n",protocol);
  12357. DEBUG_INFO("host: %s\n",host);
  12358. DEBUG_INFO("path: %s\n",path);
  12359. DEBUG_INFO("ftppath: %s\n",ftppath);
  12360. int ftppathlen=strlen(ftppath);
  12361. int i=1;
  12362. char filenametemp[50];
  12363. while(i < ftppathlen)
  12364. {
  12365. int len=ftppathlen-i;
  12366. if(ftppath[len]== 47) // '/' ascll code: 47
  12367. {
  12368. DEBUG_INFO("compare '/' all right\n");
  12369. break;
  12370. }
  12371. i=i+1;
  12372. }
  12373. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12374. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12375. filenametemp[i+1] = 0;
  12376. do
  12377. {
  12378. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12379. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12380. sleep(1);
  12381. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12382. if(!isSuccess)
  12383. {
  12384. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12385. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12386. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12387. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12388. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12389. }
  12390. else
  12391. {
  12392. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12393. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12394. }
  12395. retriesInt--;
  12396. }while((isSuccess == 0)&&(retriesInt >= 0));
  12397. }
  12398. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12399. {
  12400. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12401. memset(temp, 0, ARRAY_SIZE(temp));
  12402. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12403. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12404. int ftppathlen=strlen(ftpbuf);
  12405. int i=1;
  12406. char filenametemp[50];
  12407. while(i < ftppathlen)
  12408. {
  12409. int len=ftppathlen-i;
  12410. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12411. {
  12412. DEBUG_INFO(" compare '/' all right\n");
  12413. break;
  12414. }
  12415. i=i+1;
  12416. }
  12417. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12418. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12419. filenametemp[i+1] = 0;
  12420. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12421. pch=strchr(temp,'@');
  12422. if(pch==NULL)
  12423. {
  12424. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12425. protocol, host, &port, path);
  12426. strcpy(user,"anonymous");
  12427. strcpy(password,"");
  12428. }
  12429. else
  12430. {
  12431. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12432. protocol, user, password, host, &port, path);
  12433. }
  12434. sscanf(host,"%[^/]%s",host1, path1);
  12435. sprintf(ftppath,"%s", path1);
  12436. //DEBUG_INFO("protocol =%s\n",protocol);
  12437. //DEBUG_INFO("user =%s\n",user);
  12438. //DEBUG_INFO("password =%s\n",password);
  12439. //DEBUG_INFO("host1 =%s\n",host1);
  12440. //DEBUG_INFO("port =%d\n",port);
  12441. //DEBUG_INFO("path1 =%s\n",path1);
  12442. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12443. //ftpFile(host, user, password, port, ftppath, fname);
  12444. //download firmware pthred
  12445. if(port == 0)
  12446. {
  12447. port = 21;
  12448. }
  12449. do
  12450. {
  12451. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12452. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12453. sleep(1);
  12454. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12455. if(!isSuccess)
  12456. {
  12457. //BulldogUtil.sleepMs(interval*1000);
  12458. DEBUG_INFO("Update firmware request and download file fail.\n");
  12459. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12460. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12461. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12462. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12463. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12464. }
  12465. else
  12466. {
  12467. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12468. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12469. }
  12470. retriesInt--;
  12471. }while((!isSuccess)&&(retriesInt >= 0));
  12472. }
  12473. else
  12474. {
  12475. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12476. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12477. sleep(1);
  12478. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12479. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12480. }
  12481. // OCPPPH only, must announce CSU upgrade firmware
  12482. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12483. interLock.isUpdateFirmwareGoing = 0;
  12484. pthread_exit(NULL);
  12485. }
  12486. int handleCertificateSignedRequest(char *uuid, char *payload)
  12487. {
  12488. mtrace();
  12489. int result = PASS;
  12490. json_object *CertificateSigned;
  12491. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12492. CertificateSigned = json_tokener_parse(payload);
  12493. if(!is_error(CertificateSigned))
  12494. {
  12495. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12496. }
  12497. json_object_put(CertificateSigned);
  12498. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12499. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12500. fclose(fp);
  12501. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12502. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12503. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12504. sendCertificateSignedConfirmation(uuid);
  12505. return result;
  12506. }
  12507. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12508. {
  12509. mtrace();
  12510. int result = PASS;
  12511. json_object *DeleteCertificate;
  12512. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12513. DeleteCertificate = json_tokener_parse(payload);
  12514. if(!is_error(DeleteCertificate))
  12515. {
  12516. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12517. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12518. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12519. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12520. }
  12521. json_object_put(DeleteCertificate);
  12522. /*
  12523. * TODO: Delete certificateSigned process
  12524. */
  12525. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12526. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12527. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12528. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12529. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12530. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12531. sendDeleteCertificateConfirmation(uuid);
  12532. return result;
  12533. }
  12534. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12535. {
  12536. mtrace();
  12537. int result = PASS;
  12538. json_object *ExtendedTriggerMessage;
  12539. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12540. ExtendedTriggerMessage = json_tokener_parse(payload);
  12541. if(!is_error(ExtendedTriggerMessage))
  12542. {
  12543. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12544. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12545. {
  12546. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12547. }
  12548. else
  12549. {
  12550. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12551. }
  12552. }
  12553. json_object_put(ExtendedTriggerMessage);
  12554. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12555. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12556. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12557. {
  12558. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12559. }
  12560. else
  12561. {
  12562. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12563. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12564. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12565. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12566. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12567. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12568. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12569. {
  12570. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12571. }
  12572. else
  12573. {
  12574. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12575. }
  12576. }
  12577. sendExtendedTriggerMessageConfirmation(uuid);
  12578. //==========================
  12579. // Trigger message
  12580. //==========================
  12581. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12582. {
  12583. //sendBootNotificationRequest();
  12584. server_sign = FALSE;
  12585. }
  12586. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12587. {
  12588. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12589. }
  12590. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12591. {
  12592. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12593. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12594. {
  12595. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12596. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12597. }
  12598. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12599. }
  12600. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12601. {
  12602. refreshStartTimer(&clientTime.Heartbeat);
  12603. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12604. }
  12605. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12606. {
  12607. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12608. {
  12609. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12610. }
  12611. else
  12612. {
  12613. for(int idx=0;idx< gunTotalNumber;idx++)
  12614. {
  12615. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12616. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12617. }
  12618. }
  12619. }
  12620. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12621. {
  12622. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12623. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12624. {
  12625. 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\" &");
  12626. }
  12627. }
  12628. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12629. {
  12630. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12631. {
  12632. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12633. }
  12634. else
  12635. {
  12636. for(int idx=0;idx< gunTotalNumber;idx++)
  12637. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12638. }
  12639. }
  12640. return result;
  12641. }
  12642. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12643. {
  12644. mtrace();
  12645. int result = PASS;
  12646. json_object *GetInstalledCertificateIds;
  12647. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12648. GetInstalledCertificateIds = json_tokener_parse(payload);
  12649. if(!is_error(GetInstalledCertificateIds))
  12650. {
  12651. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12652. }
  12653. json_object_put(GetInstalledCertificateIds);
  12654. /*
  12655. * TODO: Return installed certificate process
  12656. */
  12657. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12658. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12659. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12660. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12661. sendGetInstalledCertificateIdsConfirmation(uuid);
  12662. return result;
  12663. }
  12664. int handleGetLogRequest(char *uuid, char *payload)
  12665. {
  12666. mtrace();
  12667. int result = PASS;
  12668. json_object *GetLog;
  12669. DEBUG_INFO("handleGetLogRequest...\n");
  12670. GetLog = json_tokener_parse(payload);
  12671. if(!is_error(GetLog))
  12672. {
  12673. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12674. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12675. if(json_object_object_get(GetLog, "retries") != NULL)
  12676. {
  12677. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12678. }
  12679. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12680. {
  12681. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12682. }
  12683. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12684. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12685. {
  12686. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12687. }
  12688. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12689. {
  12690. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12691. }
  12692. }
  12693. json_object_put(GetLog);
  12694. /*
  12695. * TODO: Upload log process
  12696. */
  12697. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12698. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12699. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12700. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12701. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12702. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12703. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12704. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12705. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12706. sendGetLogConfirmation(uuid);
  12707. return result;
  12708. }
  12709. int handleInstallCertificateRequest(char *uuid, char *payload)
  12710. {
  12711. mtrace();
  12712. int result = PASS;
  12713. json_object *InstallCertificate;
  12714. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12715. InstallCertificate = json_tokener_parse(payload);
  12716. if(!is_error(InstallCertificate))
  12717. {
  12718. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12719. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12720. /*
  12721. * TODO: Install certificate process
  12722. */
  12723. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12724. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12725. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12726. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12727. sendInstallCertificateConfirmation(uuid);
  12728. }
  12729. json_object_put(InstallCertificate);
  12730. return result;
  12731. }
  12732. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12733. {
  12734. mtrace();
  12735. int result = PASS;
  12736. json_object *SignedUpdateFirmware;
  12737. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12738. SignedUpdateFirmware = json_tokener_parse(payload);
  12739. if(!is_error(SignedUpdateFirmware))
  12740. {
  12741. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12742. {
  12743. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12744. }
  12745. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12746. {
  12747. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12748. }
  12749. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12750. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12751. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12752. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12753. {
  12754. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12755. }
  12756. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12757. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12758. }
  12759. json_object_put(SignedUpdateFirmware);
  12760. /*
  12761. * TODO: Upgrade firmware process
  12762. */
  12763. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12764. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12765. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12766. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12767. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12768. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12769. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12770. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12771. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12772. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12773. sendInstallCertificateConfirmation(uuid);
  12774. return result;
  12775. }
  12776. int handleUnknownRequest(char *uuid, char *payload)
  12777. {
  12778. mtrace();
  12779. int result = PASS;
  12780. DEBUG_INFO("handleUnknownRequest...\n");
  12781. sendUnknownConfirmation(uuid);
  12782. result = PASS;
  12783. return result;
  12784. }
  12785. //==========================================
  12786. // Handle server response routine
  12787. //==========================================
  12788. void handleAuthorizeResponse(char *payload, int gun_index)
  12789. {
  12790. mtrace();
  12791. char expiryDatestr[30]={0};
  12792. char parentIdTagstr[20]={0};
  12793. char statusstr[20]={0};
  12794. int expiryDateISNULL=FALSE;
  12795. int parentIdTagISNULL=FALSE;
  12796. DEBUG_INFO("handleAuthorizeResponse...\n");
  12797. json_object *Authorize;
  12798. Authorize = json_tokener_parse(payload);
  12799. if(!is_error(Authorize))
  12800. {
  12801. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12802. {
  12803. // Required data
  12804. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12805. // Optional data
  12806. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12807. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12808. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12809. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12810. }
  12811. }
  12812. json_object_put(Authorize);
  12813. if(expiryDateISNULL == FALSE)
  12814. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12815. if(parentIdTagISNULL == FALSE)
  12816. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12817. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12818. //Update idTag information to authorization cache if supproted
  12819. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12820. {
  12821. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12822. }
  12823. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12824. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12825. authorizeRetryTimes = 0;
  12826. }
  12827. void handleBootNotificationResponse(char *payload, int gun_index)
  12828. {
  12829. mtrace();
  12830. char statusStr[12]={0};
  12831. char currentTimeStr[30]={0};
  12832. int intervalInt = 0;
  12833. DEBUG_INFO("handleBootNotificationResponse...\n");
  12834. json_object *BootNotification;
  12835. BootNotification = json_tokener_parse(payload);
  12836. if(!is_error(BootNotification))
  12837. {
  12838. // Required data
  12839. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12840. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12841. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12842. }
  12843. json_object_put(BootNotification);
  12844. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12845. BootNotificationInterval = intervalInt;
  12846. HeartBeatWaitTime = intervalInt;
  12847. //write back to ShmOCPP16DataPH->BootNotification
  12848. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12849. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12850. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12851. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12852. {
  12853. if((intervalInt == 0) || (intervalInt >= 10))
  12854. {
  12855. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12856. HeartBeatWaitTime = intervalInt;
  12857. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12858. }
  12859. server_sign = TRUE;
  12860. server_pending =FALSE;
  12861. }
  12862. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12863. {
  12864. server_pending = TRUE;
  12865. }
  12866. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12867. srand(time(NULL));
  12868. refreshStartTimer(&clientTime.Heartbeat);
  12869. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12870. SetOcppConnStatus(TRUE);
  12871. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12872. }
  12873. void handleDataTransferResponse(char *payload, int gun_index)
  12874. {
  12875. json_object *DataTransfer = json_tokener_parse(payload);
  12876. if(!is_error(DataTransfer))
  12877. {
  12878. // Required data
  12879. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12880. // Optional data
  12881. if(json_object_object_get(DataTransfer, "data") != NULL)
  12882. {
  12883. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12884. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12885. if(!is_error(Data))
  12886. {
  12887. if(json_object_object_get(Data, "msgId") != NULL)
  12888. {
  12889. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12890. {
  12891. 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")));
  12892. }
  12893. }
  12894. }
  12895. json_object_put(Data);
  12896. }
  12897. }
  12898. json_object_put(DataTransfer);
  12899. }
  12900. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12901. {
  12902. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12903. //struct json_object *obj;
  12904. // obj = json_tokener_parse(payload);
  12905. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12906. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12907. //No fields are defined.
  12908. }
  12909. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12910. {
  12911. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12912. //struct json_object *obj;
  12913. // obj = json_tokener_parse(payload);
  12914. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12915. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12916. //No fields are defined.
  12917. }
  12918. void handleHeartbeatResponse(char *payload, int gun_index)
  12919. {
  12920. mtrace();
  12921. DEBUG_INFO("handleHeartbeatResponse...\n");
  12922. json_object *Heartbeat;
  12923. Heartbeat = json_tokener_parse(payload);
  12924. if(!is_error(Heartbeat))
  12925. {
  12926. // Required data
  12927. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12928. }
  12929. json_object_put(Heartbeat);
  12930. if(FirstHeartBeat == 0)
  12931. {
  12932. FirstHeartBeat = 1;
  12933. DEBUG_INFO("FirstHeartBeat \n");
  12934. }
  12935. HeartBeatWithNOResponse = 0;
  12936. refreshStartTimer(&clientTime.Heartbeat);
  12937. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12938. }
  12939. void handleMeterValuesResponse(char *payload, int gun_index)
  12940. {
  12941. mtrace();
  12942. DEBUG_INFO("handleMeterValuesResponse...\n");
  12943. isQueueSendable = 1;
  12944. }
  12945. void handleStartTransactionResponse(char *payload, int gun_index)
  12946. {
  12947. mtrace();
  12948. //int transactionIdInt = 0;
  12949. FILE *outfile;
  12950. char data[100]={0};
  12951. DEBUG_INFO("handleStartTransactionResponse...\n");
  12952. json_object *StartTransaction;
  12953. StartTransaction = json_tokener_parse(payload);
  12954. if(!is_error(StartTransaction))
  12955. {
  12956. // Required data
  12957. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12958. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12959. // Optional data
  12960. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12961. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12962. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12963. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12964. }
  12965. json_object_put(StartTransaction);
  12966. isQueueSendable = 1;
  12967. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12968. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12969. //-----------Start : write to the Queue TransactionId file -----------------//
  12970. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12971. {}
  12972. else
  12973. {
  12974. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12975. if(log == NULL)
  12976. {
  12977. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12978. return ;
  12979. }
  12980. else
  12981. {
  12982. fclose(log);
  12983. }
  12984. }
  12985. // open file for writing
  12986. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12987. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12988. {
  12989. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12990. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12991. fputs(data, outfile);
  12992. fclose (outfile);
  12993. }
  12994. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12995. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12996. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12997. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12998. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12999. }
  13000. void handleStatusNotificationResponse(char *payload, int gun_index)
  13001. {
  13002. mtrace();
  13003. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13004. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13005. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13006. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13007. }
  13008. void handleStopTransactionnResponse(char *payload, int gun_index)
  13009. {
  13010. mtrace();
  13011. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13012. json_object *StopTransaction;
  13013. StopTransaction = json_tokener_parse(payload);
  13014. if(!is_error(StopTransaction))
  13015. {
  13016. // Optional data
  13017. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13018. {
  13019. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13020. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13021. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13022. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13024. }
  13025. }
  13026. json_object_put(StopTransaction);
  13027. isQueueSendable = 1;
  13028. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13029. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13030. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13031. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13032. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13033. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13034. }
  13035. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13036. {
  13037. mtrace();
  13038. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13039. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13040. }
  13041. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13042. {
  13043. mtrace();
  13044. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13045. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13046. }
  13047. void handleSignCertificateResponse(char *payload, int gun_index)
  13048. {
  13049. mtrace();
  13050. DEBUG_INFO("handleSignCertificateResponse...\n");
  13051. json_object *SignCertificate;
  13052. SignCertificate = json_tokener_parse(payload);
  13053. if(!is_error(SignCertificate))
  13054. {
  13055. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13056. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13057. }
  13058. json_object_put(SignCertificate);
  13059. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13060. }
  13061. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13062. {
  13063. mtrace();
  13064. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13065. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13066. }
  13067. //==========================================
  13068. // Handle Error routine
  13069. //==========================================
  13070. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13071. {
  13072. mtrace();
  13073. #ifdef SystemLogMessage
  13074. DEBUG_INFO("errorCode: %s\n", errorCode);
  13075. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13076. DEBUG_INFO("errorDetails: %s\n", payload);
  13077. #endif
  13078. }
  13079. //===============================================
  13080. // Common routine
  13081. //===============================================
  13082. int initialConfigurationTable(void)
  13083. {
  13084. //clock_t start_t, end_t, total_t;
  13085. FILE *fp;
  13086. FILE *outfile;
  13087. char str[512]={0};
  13088. char sstr[256]={0};
  13089. int c = 0;
  13090. char *loc;
  13091. int confVersion = 12;
  13092. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13093. //start_t = clock();
  13094. //printf("Starting of the program, start_t = %ld\n", start_t);
  13095. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13096. // Check configuration file size is correct
  13097. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13098. {
  13099. struct stat st;
  13100. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13101. if(st.st_size < 3100)
  13102. {
  13103. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13104. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13105. }
  13106. }
  13107. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13108. {
  13109. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13110. if(outfile == NULL)
  13111. {
  13112. DEBUG_INFO("Error opening file\n");
  13113. return FALSE;
  13114. }
  13115. /*Core Profile*/
  13116. //AllowOfflineTxForUnknownId
  13117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13121. //AuthorizationCacheEnabled
  13122. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13126. //AuthorizeRemoteTxRequests
  13127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13131. //BlinkRepeat
  13132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13136. //ClockAlignedDataInterval
  13137. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13141. //ConnectionTimeOut
  13142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13146. //GetConfigurationMaxKeys
  13147. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13149. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13151. // HeartbeatInterval
  13152. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13156. // LightIntensity
  13157. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13161. // LocalAuthorizeOffline
  13162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13166. // LocalPreAuthorize
  13167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13171. // MaxEnergyOnInvalidId
  13172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13176. // MeterValuesAlignedData
  13177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13180. 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" );
  13181. else
  13182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13184. // MeterValuesAlignedDataMaxLength
  13185. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13189. else
  13190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13192. // MeterValuesSampledData
  13193. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13196. 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" );
  13197. else
  13198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13200. // MeterValuesSampledDataMaxLength
  13201. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13205. else
  13206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13208. // MeterValueSampleInterval
  13209. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13213. // MinimumStatusDuration
  13214. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13217. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13219. // NumberOfConnectors
  13220. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13222. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13223. {
  13224. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13225. }
  13226. else
  13227. {
  13228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13229. }
  13230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13231. // ResetRetries
  13232. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13236. // ConnectorPhaseRotation
  13237. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13238. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13241. // ConnectorPhaseRotationMaxLength
  13242. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13246. // StopTransactionOnEVSideDisconnect
  13247. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13251. // StopTransactionOnInvalidId
  13252. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13253. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13256. // StopTxnAlignedData
  13257. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13258. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13261. // StopTxnAlignedDataMaxLength
  13262. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13266. // StopTxnSampledData
  13267. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13271. else
  13272. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13274. // StopTxnSampledDataMaxLength
  13275. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13277. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13278. {
  13279. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13280. }
  13281. else
  13282. {
  13283. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13284. }
  13285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13286. // SupportedFeatureProfiles
  13287. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13291. // SupportedFeatureProfilesMaxLength
  13292. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13296. // TransactionMessageAttempts
  13297. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13300. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13302. // TransactionMessageRetryInterval
  13303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13306. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13308. // UnlockConnectorOnEVSideDisconnect
  13309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13313. // WebSocketPingInterval
  13314. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13315. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13318. // QueueOffLineMeterValues
  13319. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13323. // AuthorizationKey
  13324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13328. // SecurityProfile
  13329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13333. // DefaultPrice
  13334. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13338. // CustomDisplayCostAndPrice
  13339. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13343. // CustomIdleFeeAfterStop
  13344. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13345. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13348. // SystemUptimeSec
  13349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13353. // FreeVend
  13354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13358. // OcppServer
  13359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13361. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13363. // MaintainServer
  13364. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13365. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13366. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13368. // StatusNotificationPeriodically
  13369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13373. // StatusNotificationInterval
  13374. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13378. // Configuration Version
  13379. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13381. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13383. //* Local Auth List Management Profile*/
  13384. #if 0
  13385. //For OCTT Test Case
  13386. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13389. #endif
  13390. #if 1
  13391. //LocalAuthListEnabled
  13392. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13396. #endif
  13397. //LocalAuthListMaxLength
  13398. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13402. //SendLocalListMaxLength
  13403. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13407. //ReserveConnectorZeroSupported
  13408. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13410. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13412. //* Smart Charging Profile */
  13413. //ChargeProfileMaxStackLevel
  13414. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13415. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13418. // ChargingScheduleAllowedChargingRateUnit
  13419. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13420. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13423. // ChargingScheduleMaxPeriods
  13424. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13428. // ConnectorSwitch3to1PhaseSupported
  13429. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13433. // MaxChargingProfilesInstalled
  13434. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13435. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13438. fclose(outfile);
  13439. }
  13440. else
  13441. {
  13442. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13443. char keystr[60]={0};
  13444. char readonlystr[10]={0};
  13445. char valuestr[256]={0};
  13446. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13447. if(fp == NULL) {
  13448. DEBUG_INFO("Error opening file");
  13449. return FALSE;
  13450. }
  13451. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13452. {
  13453. //DEBUG_INFO("Get Configuration \n");
  13454. if(strlen(str) > 0)
  13455. {
  13456. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13457. //*************************key*********************************/
  13458. if(strstr(str, "key") != NULL)
  13459. {
  13460. loc = strstr(str, "key");
  13461. c = 0;
  13462. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13463. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13464. {
  13465. sstr[c] = loc[strlen("key")+3+c];
  13466. c++;
  13467. }
  13468. sstr[c] = '\0';
  13469. strcpy(keystr,sstr);
  13470. }
  13471. //*************************readonly*********************************/
  13472. if(strstr(str, "readonly") != NULL)
  13473. {
  13474. loc = strstr(str, "readonly");
  13475. c = 0;
  13476. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13477. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13478. {
  13479. sstr[c] = loc[strlen("readonly")+2+c];
  13480. c++;
  13481. }
  13482. sstr[c] = '\0';
  13483. strcpy(readonlystr,sstr);
  13484. }
  13485. //*************************value*********************************/
  13486. if(strstr(str, "value") != NULL)
  13487. {
  13488. loc = strstr(str, "value");
  13489. c = 0;
  13490. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13491. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13492. {
  13493. sstr[c] = loc[strlen("value")+3+c];
  13494. c++;
  13495. }
  13496. sstr[c] = '\0';
  13497. strcpy(valuestr,sstr);
  13498. }
  13499. // DEBUG_INFO("keystr=%s\n",keystr);
  13500. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13501. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13502. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13503. {
  13504. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13505. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13506. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13507. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13508. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13509. }
  13510. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13511. {
  13512. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13513. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13514. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13515. }
  13516. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13517. {
  13518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13520. }
  13521. if(strcmp(keystr, "BlinkRepeat") == 0)
  13522. {
  13523. //Charger.BlinkRepeat = Integer.parseInt(value);
  13524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13526. }
  13527. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13528. {
  13529. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13531. }
  13532. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13533. {
  13534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13536. }
  13537. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13538. {
  13539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13541. }
  13542. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13543. {
  13544. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13546. HeartBeatWaitTime = atoi(valuestr);
  13547. }
  13548. if(strcmp(keystr, "LightIntensity") == 0)
  13549. {
  13550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13552. }
  13553. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13554. {
  13555. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13557. }
  13558. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13559. {
  13560. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13562. }
  13563. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13564. {
  13565. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13566. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13567. }
  13568. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13569. {
  13570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13571. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13572. }
  13573. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13574. {
  13575. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13577. }
  13578. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13579. {
  13580. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13582. }
  13583. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13584. {
  13585. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13586. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13587. }
  13588. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13589. {
  13590. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13592. }
  13593. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13594. {
  13595. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13596. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13597. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13598. }
  13599. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13600. {
  13601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13603. }
  13604. if(strcmp(keystr, "ResetRetries") == 0)
  13605. {
  13606. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13607. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13608. }
  13609. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13610. {
  13611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13612. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13613. }
  13614. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13615. {
  13616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13617. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13618. }
  13619. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13620. {
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13622. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13623. }
  13624. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13625. {
  13626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13627. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13628. }
  13629. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13630. {
  13631. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13633. }
  13634. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13635. {
  13636. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13638. }
  13639. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13640. {
  13641. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13643. }
  13644. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13645. {
  13646. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13648. }
  13649. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13650. {
  13651. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13652. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13653. }
  13654. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13655. {
  13656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13658. }
  13659. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13660. {
  13661. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13662. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13663. TransactionMessageAttemptsValue = atoi(valuestr);
  13664. }
  13665. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13666. {
  13667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13668. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13669. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13670. }
  13671. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13672. {
  13673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13675. }
  13676. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13677. {
  13678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13680. }
  13681. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13682. {
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13685. }
  13686. if(strcmp(keystr, "AuthorizationKey") == 0)
  13687. {
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13689. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13691. }
  13692. if(strcmp(keystr, "SecurityProfile") == 0)
  13693. {
  13694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13695. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13697. }
  13698. if(strcmp(keystr, "DefaultPrice") == 0)
  13699. {
  13700. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13702. }
  13703. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13704. {
  13705. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13707. }
  13708. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13709. {
  13710. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13711. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13712. }
  13713. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13714. {
  13715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13717. }
  13718. if(strcmp(keystr, "FreeVend") == 0)
  13719. {
  13720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13722. }
  13723. if(strcmp(keystr, "OcppServer") == 0)
  13724. {
  13725. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13726. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13727. }
  13728. if(strcmp(keystr, "MaintainServer") == 0)
  13729. {
  13730. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13731. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13732. }
  13733. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13734. {
  13735. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13736. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13737. }
  13738. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13739. {
  13740. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13741. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13742. }
  13743. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13744. {
  13745. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13747. }
  13748. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13749. {
  13750. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13751. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13752. }
  13753. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13754. {
  13755. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13757. }
  13758. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13759. {
  13760. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13762. }
  13763. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13764. {
  13765. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13767. }
  13768. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13769. {
  13770. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13772. }
  13773. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13774. {
  13775. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13777. }
  13778. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13779. {
  13780. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13782. }
  13783. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13784. {
  13785. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13787. }
  13788. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13789. {
  13790. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13791. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13792. }
  13793. }
  13794. }
  13795. fclose(fp);
  13796. }
  13797. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13798. {
  13799. return PASS;
  13800. }
  13801. else
  13802. {
  13803. return FAIL;
  13804. }
  13805. }
  13806. void StoreConfigurationTable(void)
  13807. {
  13808. FILE *outfile;
  13809. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13810. if(outfile == NULL)
  13811. {
  13812. DEBUG_INFO("Error opening file");
  13813. return ;
  13814. }
  13815. /*Core Profile*/
  13816. //AllowOfflineTxForUnknownId
  13817. /*
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13819. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13822. */
  13823. //DEBUG_INFO("data=%s\n",data);
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13825. //AuthorizationCacheEnabled
  13826. /*
  13827. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13828. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13830. */
  13831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13832. //AuthorizeRemoteTxRequests
  13833. /*
  13834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13837. */
  13838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13839. //BlinkRepeat
  13840. /*
  13841. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13842. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13844. */
  13845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13846. //ClockAlignedDataInterval
  13847. /*
  13848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13849. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13851. */
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13853. //ConnectionTimeOut
  13854. /*
  13855. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13858. */
  13859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13860. //GetConfigurationMaxKeys
  13861. /*
  13862. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13863. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13865. */
  13866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13867. // HeartbeatInterval
  13868. /*
  13869. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13872. */
  13873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13874. // LightIntensity
  13875. /*
  13876. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13879. */
  13880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13881. // LocalAuthorizeOffline
  13882. /*
  13883. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13886. */
  13887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13888. // LocalPreAuthorize
  13889. /*
  13890. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13893. */
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13895. // MaxEnergyOnInvalidId
  13896. /*
  13897. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13899. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13900. */
  13901. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13903. // MeterValuesAlignedData
  13904. /*
  13905. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13908. */
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13910. // MeterValuesAlignedDataMaxLength
  13911. /*
  13912. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13915. */
  13916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13917. // MeterValuesSampledData
  13918. /*
  13919. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13922. */
  13923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13924. // MeterValuesSampledDataMaxLength
  13925. /*
  13926. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13929. */
  13930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13931. // MeterValueSampleInterval
  13932. /*
  13933. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13936. */
  13937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13938. // MinimumStatusDuration
  13939. /*
  13940. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13943. */
  13944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13945. // NumberOfConnectors
  13946. /*
  13947. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13948. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13950. {
  13951. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13952. }
  13953. else
  13954. {
  13955. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13956. }
  13957. */
  13958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13959. // ResetRetries
  13960. /*
  13961. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13964. */
  13965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13966. // ConnectorPhaseRotation
  13967. /*
  13968. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13971. */
  13972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13973. // ConnectorPhaseRotationMaxLength
  13974. /*
  13975. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13978. */
  13979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13980. // StopTransactionOnEVSideDisconnect
  13981. /*
  13982. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13985. */
  13986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13987. // StopTransactionOnInvalidId
  13988. /*
  13989. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13992. */
  13993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13994. // StopTxnAlignedData
  13995. /*
  13996. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13999. */
  14000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14001. // StopTxnAlignedDataMaxLength
  14002. /*
  14003. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14006. */
  14007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14008. // StopTxnSampledData
  14009. /*
  14010. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14013. */
  14014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14015. // StopTxnSampledDataMaxLength
  14016. /*
  14017. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14020. */
  14021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14022. // SupportedFeatureProfiles
  14023. /*
  14024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14027. */
  14028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14029. // SupportedFeatureProfilesMaxLength
  14030. /*
  14031. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14032. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14034. */
  14035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14036. // TransactionMessageAttempts
  14037. /*
  14038. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14041. */
  14042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14043. // TransactionMessageRetryInterval
  14044. /*
  14045. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14048. */
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14050. // UnlockConnectorOnEVSideDisconnect
  14051. /*
  14052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14055. */
  14056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14057. // WebSocketPingInterval
  14058. /*
  14059. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14060. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14062. */
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14064. // QueueOffLineMeterValues
  14065. /*
  14066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14069. */
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14071. // AuthorizationKey
  14072. /*
  14073. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14074. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14075. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14076. */
  14077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14078. // SecurityProfile
  14079. /*
  14080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14081. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14083. */
  14084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14085. // DefaultPrice
  14086. /*
  14087. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14090. */
  14091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14092. // CustomDisplayCostAndPrice
  14093. /*
  14094. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14097. */
  14098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14099. // CustomIdleFeeAfterStop
  14100. /*
  14101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14104. */
  14105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14106. // SystemUptimeSec
  14107. /*
  14108. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14111. */
  14112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14113. // FreeVend
  14114. /*
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14118. */
  14119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14120. // OcppServer
  14121. /*
  14122. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14125. */
  14126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14127. // MaintainServer
  14128. /*
  14129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14132. */
  14133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14134. // StatusNotificationPeriodically
  14135. /*
  14136. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14139. */
  14140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14141. // StatusNotificationInterval
  14142. /*
  14143. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14146. */
  14147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14148. // ConfigurationVersion
  14149. /*
  14150. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14153. */
  14154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14155. //* Local Auth List Management Profile*/
  14156. //LocalAuthListEnabled
  14157. /*
  14158. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14161. */
  14162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14163. //LocalAuthListMaxLength
  14164. /*
  14165. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14168. */
  14169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14170. //SendLocalListMaxLength
  14171. /*
  14172. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14175. */
  14176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14177. //ReserveConnectorZeroSupported
  14178. /*
  14179. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14182. */
  14183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14184. //* Smart Charging Profile */
  14185. //ChargeProfileMaxStackLevel
  14186. /*
  14187. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14190. */
  14191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14192. // ChargingScheduleAllowedChargingRateUnit
  14193. /*
  14194. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14197. */
  14198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14199. // ChargingScheduleMaxPeriods
  14200. /*
  14201. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14204. */
  14205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14206. // ConnectorSwitch3to1PhaseSupported
  14207. /*
  14208. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14211. */
  14212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14213. // MaxChargingProfilesInstalled
  14214. /*
  14215. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14218. */
  14219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14220. fclose(outfile);
  14221. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14222. }
  14223. void getKeyValue(char *keyReq)
  14224. {
  14225. int isEmpty = FALSE;
  14226. int isKnowKey = FALSE;
  14227. DEBUG_INFO("keyReq = %s\n", keyReq);
  14228. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14229. isEmpty = TRUE;
  14230. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14231. {
  14232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14234. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14235. {
  14236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14237. }
  14238. else
  14239. {
  14240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14241. }
  14242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14243. isKnowKey = TRUE;
  14244. }
  14245. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14246. {
  14247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14249. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14250. {
  14251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14252. }
  14253. else
  14254. {
  14255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14256. }
  14257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14258. isKnowKey = TRUE;
  14259. }
  14260. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14261. {
  14262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14264. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14265. {
  14266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14267. }
  14268. else
  14269. {
  14270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14271. }
  14272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14273. isKnowKey = TRUE;
  14274. }
  14275. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14276. {
  14277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14279. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14280. {
  14281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14282. }
  14283. else
  14284. {
  14285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14286. }
  14287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14288. isKnowKey = TRUE;
  14289. }
  14290. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14291. {
  14292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14294. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14295. {
  14296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14297. }
  14298. else
  14299. {
  14300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14301. }
  14302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14303. isKnowKey = TRUE;
  14304. }
  14305. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14306. {
  14307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14309. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14310. {
  14311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14312. }
  14313. else
  14314. {
  14315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14316. }
  14317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14318. isKnowKey = TRUE;
  14319. }
  14320. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14321. {
  14322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14324. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14325. {
  14326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14327. }
  14328. else
  14329. {
  14330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14331. }
  14332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14333. isKnowKey = TRUE;
  14334. }
  14335. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14336. {
  14337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14339. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14340. {
  14341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14342. }
  14343. else
  14344. {
  14345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14346. }
  14347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14348. isKnowKey = TRUE;
  14349. }
  14350. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14351. {
  14352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14354. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14355. {
  14356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14357. }
  14358. else
  14359. {
  14360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14361. }
  14362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14363. isKnowKey = TRUE;
  14364. }
  14365. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14366. {
  14367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14369. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14370. {
  14371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14372. }
  14373. else
  14374. {
  14375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14376. }
  14377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14378. isKnowKey = TRUE;
  14379. }
  14380. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14381. {
  14382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14384. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14385. {
  14386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14387. }
  14388. else
  14389. {
  14390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14391. }
  14392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14393. isKnowKey = TRUE;
  14394. }
  14395. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14396. {
  14397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14399. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14400. {
  14401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14402. }
  14403. else
  14404. {
  14405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14406. }
  14407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14408. isKnowKey = TRUE;
  14409. }
  14410. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14411. {
  14412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14414. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14415. {
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14417. }
  14418. else
  14419. {
  14420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14421. }
  14422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14423. isKnowKey = TRUE;
  14424. }
  14425. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14426. {
  14427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14429. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14430. {
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14432. }
  14433. else
  14434. {
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14436. }
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14438. isKnowKey = TRUE;
  14439. }
  14440. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14441. {
  14442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14445. {
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14447. }
  14448. else
  14449. {
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14451. }
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14453. isKnowKey = TRUE;
  14454. }
  14455. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14456. {
  14457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14459. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14460. {
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14462. }
  14463. else
  14464. {
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14466. }
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14468. isKnowKey = TRUE;
  14469. }
  14470. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14471. {
  14472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14475. {
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14477. }
  14478. else
  14479. {
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14481. }
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14483. isKnowKey = TRUE;
  14484. }
  14485. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14486. {
  14487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14490. {
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14492. }
  14493. else
  14494. {
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14496. }
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14498. isKnowKey = TRUE;
  14499. }
  14500. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14501. {
  14502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14505. {
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14507. }
  14508. else
  14509. {
  14510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14511. }
  14512. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14514. isKnowKey = TRUE;
  14515. }
  14516. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14517. {
  14518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14520. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14521. {
  14522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14523. }
  14524. else
  14525. {
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14527. }
  14528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14529. isKnowKey = TRUE;
  14530. }
  14531. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14532. {
  14533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14535. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14536. {
  14537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14538. }
  14539. else
  14540. {
  14541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14542. }
  14543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14544. isKnowKey = TRUE;
  14545. }
  14546. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14547. {
  14548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14550. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14551. {
  14552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14553. }
  14554. else
  14555. {
  14556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14557. }
  14558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14559. isKnowKey = TRUE;
  14560. }
  14561. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14562. {
  14563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14565. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14566. {
  14567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14568. }
  14569. else
  14570. {
  14571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14572. }
  14573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14574. isKnowKey = TRUE;
  14575. }
  14576. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14577. {
  14578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14580. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14581. {
  14582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14583. }
  14584. else
  14585. {
  14586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14587. }
  14588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14589. isKnowKey = TRUE;
  14590. }
  14591. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14592. {
  14593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14595. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14596. {
  14597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14598. }
  14599. else
  14600. {
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14602. }
  14603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14604. isKnowKey = TRUE;
  14605. }
  14606. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14607. {
  14608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14610. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14611. {
  14612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14613. }
  14614. else
  14615. {
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14617. }
  14618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14619. isKnowKey = TRUE;
  14620. }
  14621. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14622. {
  14623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14625. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14626. {
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14628. }
  14629. else
  14630. {
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14632. }
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14634. isKnowKey = TRUE;
  14635. }
  14636. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14637. {
  14638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14640. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14641. {
  14642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14643. }
  14644. else
  14645. {
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14647. }
  14648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14649. isKnowKey = TRUE;
  14650. }
  14651. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14652. {
  14653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14655. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14656. {
  14657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14658. }
  14659. else
  14660. {
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14662. }
  14663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14664. isKnowKey = TRUE;
  14665. }
  14666. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14667. {
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14671. {
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14673. }
  14674. else
  14675. {
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14677. }
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14679. isKnowKey = TRUE;
  14680. }
  14681. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14682. {
  14683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14686. {
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14688. }
  14689. else
  14690. {
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14692. }
  14693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14694. isKnowKey = TRUE;
  14695. }
  14696. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14697. {
  14698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14701. {
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14703. }
  14704. else
  14705. {
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14707. }
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14709. isKnowKey = TRUE;
  14710. }
  14711. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14712. {
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14716. {
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14718. }
  14719. else
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14722. }
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14724. isKnowKey = TRUE;
  14725. }
  14726. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14727. {
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14730. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14731. {
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14733. }
  14734. else
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14737. }
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14739. isKnowKey = TRUE;
  14740. }
  14741. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14742. {
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14746. {
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14748. }
  14749. else
  14750. {
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14752. }
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14754. isKnowKey = TRUE;
  14755. }
  14756. /*
  14757. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14758. {
  14759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14762. {
  14763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14764. }
  14765. else
  14766. {
  14767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14768. }
  14769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14770. isKnowKey = TRUE;
  14771. }*/
  14772. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14773. {
  14774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14776. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14777. {
  14778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14779. }
  14780. else
  14781. {
  14782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14783. }
  14784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14785. isKnowKey = TRUE;
  14786. }
  14787. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14788. {
  14789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14791. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14792. {
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14794. }
  14795. else
  14796. {
  14797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14798. }
  14799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14800. isKnowKey = TRUE;
  14801. }
  14802. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14803. {
  14804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14806. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14807. {
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14809. }
  14810. else
  14811. {
  14812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14813. }
  14814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14815. isKnowKey = TRUE;
  14816. }
  14817. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14818. {
  14819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14821. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14822. {
  14823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14824. }
  14825. else
  14826. {
  14827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14828. }
  14829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14830. isKnowKey = TRUE;
  14831. }
  14832. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14833. {
  14834. struct sysinfo s_info;
  14835. int error = sysinfo(&s_info);
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14838. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14839. {
  14840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14841. }
  14842. else
  14843. {
  14844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14845. }
  14846. if(error != 0)
  14847. {
  14848. DEBUG_WARN("System uptime get error: %d\n", error);
  14849. }
  14850. else
  14851. {
  14852. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14853. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14854. }
  14855. isKnowKey = TRUE;
  14856. }
  14857. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14858. {
  14859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14861. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14862. {
  14863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14864. }
  14865. else
  14866. {
  14867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14868. }
  14869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14870. isKnowKey = TRUE;
  14871. }
  14872. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14873. {
  14874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14876. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14877. {
  14878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14879. }
  14880. else
  14881. {
  14882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14883. }
  14884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14885. isKnowKey = TRUE;
  14886. }
  14887. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14888. {
  14889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14891. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14892. {
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14894. }
  14895. else
  14896. {
  14897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14898. }
  14899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14900. isKnowKey = TRUE;
  14901. }
  14902. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14903. {
  14904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  14906. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  14907. {
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  14909. }
  14910. else
  14911. {
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  14913. }
  14914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  14915. isKnowKey = TRUE;
  14916. }
  14917. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  14918. {
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  14920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  14921. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  14922. {
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  14924. }
  14925. else
  14926. {
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  14928. }
  14929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  14930. isKnowKey = TRUE;
  14931. }
  14932. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14933. {
  14934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14937. {
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14939. }
  14940. else
  14941. {
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14943. }
  14944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14945. isKnowKey = TRUE;
  14946. }
  14947. #if 1
  14948. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14949. {
  14950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14952. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14953. {
  14954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14955. }
  14956. else
  14957. {
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14959. }
  14960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14961. isKnowKey = TRUE;
  14962. }
  14963. #endif
  14964. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14965. {
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14968. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14969. {
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14971. }
  14972. else
  14973. {
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14975. }
  14976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14977. isKnowKey = TRUE;
  14978. }
  14979. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14980. {
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14983. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14984. {
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14986. }
  14987. else
  14988. {
  14989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14990. }
  14991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14992. isKnowKey = TRUE;
  14993. }
  14994. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14995. {
  14996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14998. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14999. {
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15001. }
  15002. else
  15003. {
  15004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15005. }
  15006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15007. isKnowKey = TRUE;
  15008. }
  15009. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15010. {
  15011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15013. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15014. {
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15016. }
  15017. else
  15018. {
  15019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15020. }
  15021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15022. isKnowKey = TRUE;
  15023. }
  15024. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15025. {
  15026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15028. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15029. {
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15031. }
  15032. else
  15033. {
  15034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15035. }
  15036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15037. isKnowKey = TRUE;
  15038. }
  15039. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15040. {
  15041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15043. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15044. {
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15046. }
  15047. else
  15048. {
  15049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15050. }
  15051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15052. isKnowKey = TRUE;
  15053. }
  15054. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15055. {
  15056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15058. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15061. }
  15062. else
  15063. {
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15065. }
  15066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15067. isKnowKey = TRUE;
  15068. }
  15069. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15070. {
  15071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15073. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15076. }
  15077. else
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15080. }
  15081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15082. isKnowKey = TRUE;
  15083. }
  15084. //=========================================================
  15085. if(!isEmpty && !isKnowKey)
  15086. {
  15087. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15088. strcpy(unknownkey[UnknownKeynum], keyReq);
  15089. UnknownKeynum = UnknownKeynum + 1;
  15090. }
  15091. }
  15092. void processUnkownKey(void)
  15093. {
  15094. DEBUG_INFO("processUnkownKey...\n");
  15095. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15096. for(int index=0; index < UnknownKeynum; index++)
  15097. {
  15098. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15099. {
  15100. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15101. }
  15102. }
  15103. }
  15104. int setKeyValue(char *key, char *value)
  15105. {
  15106. int isSuccess = NotSupported;
  15107. int check_ascii=0;
  15108. char str[501]={0};
  15109. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15110. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15111. {
  15112. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15113. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15114. {
  15115. strcpy(str, (const char*)value);
  15116. for(int i = 0; str[i]; i++){
  15117. str[i] = tolower(str[i]);
  15118. }
  15119. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15120. isSuccess = ConfigurationStatus_Accepted;
  15121. }
  15122. else
  15123. {
  15124. isSuccess = ConfigurationStatus_Rejected;
  15125. }
  15126. }
  15127. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15128. {
  15129. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15130. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15131. {
  15132. strcpy(str, (const char*)value);
  15133. for(int i = 0; str[i]; i++){
  15134. str[i] = tolower(str[i]);
  15135. }
  15136. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15137. isSuccess = ConfigurationStatus_Accepted;
  15138. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15139. }
  15140. else
  15141. {
  15142. isSuccess = ConfigurationStatus_Rejected;
  15143. }
  15144. }
  15145. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15146. {
  15147. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15148. {
  15149. strcpy(str, (const char*)value);
  15150. for(int i = 0; str[i]; i++)
  15151. {
  15152. str[i] = tolower(str[i]);
  15153. }
  15154. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15156. isSuccess = ConfigurationStatus_Accepted;
  15157. }
  15158. else
  15159. {
  15160. isSuccess = ConfigurationStatus_Rejected;
  15161. }
  15162. }
  15163. if(strcmp(key, "BlinkRepeat") == 0)
  15164. {
  15165. //Charger.BlinkRepeat = Integer.parseInt(value);
  15166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15167. {
  15168. check_ascii = value[0];
  15169. if( (check_ascii < 48) || (check_ascii > 57) )
  15170. {
  15171. isSuccess = ConfigurationStatus_Rejected;
  15172. }
  15173. else
  15174. {
  15175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15176. isSuccess = ConfigurationStatus_Accepted;
  15177. }
  15178. }
  15179. else
  15180. {
  15181. isSuccess = ConfigurationStatus_Rejected;
  15182. }
  15183. }
  15184. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15185. {
  15186. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15187. {
  15188. check_ascii = value[0];
  15189. if( (check_ascii < 48) || (check_ascii > 57) )
  15190. {
  15191. isSuccess = ConfigurationStatus_Rejected;
  15192. }
  15193. else
  15194. {
  15195. if((atoi(value) == 0) || (atoi(value) >= 5))
  15196. {
  15197. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15199. isSuccess = ConfigurationStatus_Accepted;
  15200. }
  15201. else
  15202. isSuccess = ConfigurationStatus_Rejected;
  15203. }
  15204. }
  15205. else
  15206. {
  15207. isSuccess = ConfigurationStatus_Rejected;
  15208. }
  15209. }
  15210. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15211. {
  15212. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15213. {
  15214. check_ascii = value[0];
  15215. if( (check_ascii < 48) || (check_ascii > 57) )
  15216. {
  15217. isSuccess = ConfigurationStatus_Rejected;
  15218. }
  15219. else
  15220. {
  15221. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15222. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15223. isSuccess = ConfigurationStatus_Accepted;
  15224. }
  15225. }
  15226. else
  15227. {
  15228. isSuccess = ConfigurationStatus_Rejected;
  15229. }
  15230. }
  15231. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15232. {
  15233. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15234. {
  15235. check_ascii = value[0];
  15236. if( (check_ascii < 48) || (check_ascii > 57) )
  15237. {
  15238. isSuccess = ConfigurationStatus_Rejected;
  15239. }
  15240. else
  15241. {
  15242. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15243. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15244. isSuccess = ConfigurationStatus_Accepted;
  15245. }
  15246. }
  15247. else
  15248. {
  15249. isSuccess = ConfigurationStatus_Rejected;
  15250. }
  15251. }
  15252. if(strcmp(key, "HeartbeatInterval") == 0)
  15253. {
  15254. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15255. {
  15256. check_ascii = value[0];
  15257. if( (check_ascii < 48) || (check_ascii > 57) )
  15258. {
  15259. isSuccess = ConfigurationStatus_Rejected;
  15260. }
  15261. else
  15262. {
  15263. if((atoi(value) == 0) || (atoi(value) >= 10))
  15264. {
  15265. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15266. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15267. HeartBeatWaitTime = atoi(value);
  15268. isSuccess = ConfigurationStatus_Accepted;
  15269. }
  15270. else
  15271. {
  15272. isSuccess = ConfigurationStatus_Rejected;
  15273. }
  15274. }
  15275. }
  15276. else
  15277. {
  15278. isSuccess = ConfigurationStatus_Rejected;
  15279. }
  15280. }
  15281. if(strcmp(key, "LightIntensity") == 0)
  15282. {
  15283. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15284. {
  15285. check_ascii = value[0];
  15286. if( (check_ascii < 48) || (check_ascii > 57) )
  15287. {
  15288. isSuccess = ConfigurationStatus_Rejected;
  15289. }
  15290. else
  15291. {
  15292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15293. isSuccess = ConfigurationStatus_Accepted;
  15294. }
  15295. }
  15296. else
  15297. {
  15298. isSuccess = ConfigurationStatus_Rejected;
  15299. }
  15300. }
  15301. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15302. {
  15303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15304. {
  15305. strcpy(str, (const char*)value);
  15306. for(int i = 0; str[i]; i++)
  15307. {
  15308. str[i] = tolower(str[i]);
  15309. }
  15310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15311. isSuccess = ConfigurationStatus_Accepted;
  15312. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15313. }
  15314. else
  15315. {
  15316. isSuccess = ConfigurationStatus_Rejected;
  15317. }
  15318. }
  15319. if(strcmp(key, "LocalPreAuthorize") == 0)
  15320. {
  15321. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15322. {
  15323. strcpy(str, (const char*)value);
  15324. for(int i = 0; str[i]; i++)
  15325. {
  15326. str[i] = tolower(str[i]);
  15327. }
  15328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15329. isSuccess = ConfigurationStatus_Accepted;
  15330. }
  15331. else
  15332. {
  15333. isSuccess = ConfigurationStatus_Rejected;
  15334. }
  15335. }
  15336. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15337. {
  15338. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15339. {
  15340. check_ascii = value[0];
  15341. if( (check_ascii < 48) || (check_ascii > 57) )
  15342. {
  15343. isSuccess = ConfigurationStatus_Rejected;
  15344. }
  15345. else
  15346. {
  15347. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15348. isSuccess = ConfigurationStatus_Accepted;
  15349. }
  15350. }
  15351. else
  15352. {
  15353. isSuccess = ConfigurationStatus_Rejected;
  15354. }
  15355. }
  15356. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15357. {
  15358. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15359. {
  15360. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15361. isSuccess = ConfigurationStatus_Accepted;
  15362. }
  15363. else
  15364. {
  15365. isSuccess = ConfigurationStatus_Rejected;
  15366. }
  15367. }
  15368. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15369. {
  15370. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15371. {
  15372. check_ascii = value[0];
  15373. if( (check_ascii < 48) || (check_ascii > 57) )
  15374. {
  15375. isSuccess = ConfigurationStatus_Rejected;
  15376. }
  15377. else
  15378. {
  15379. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15381. isSuccess = ConfigurationStatus_Accepted;
  15382. }
  15383. }
  15384. else
  15385. {
  15386. isSuccess = ConfigurationStatus_Rejected;
  15387. }
  15388. }
  15389. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15390. {
  15391. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15392. {
  15393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15394. isSuccess = ConfigurationStatus_Accepted;
  15395. }
  15396. else
  15397. {
  15398. isSuccess = ConfigurationStatus_Rejected;
  15399. }
  15400. }
  15401. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15402. {
  15403. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15404. {
  15405. check_ascii = value[0];
  15406. if( (check_ascii < 48) || (check_ascii > 57) )
  15407. {
  15408. isSuccess = ConfigurationStatus_Rejected;
  15409. }
  15410. else
  15411. {
  15412. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15413. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15414. isSuccess = ConfigurationStatus_Accepted;
  15415. }
  15416. }
  15417. else
  15418. {
  15419. isSuccess = ConfigurationStatus_Rejected;
  15420. }
  15421. }
  15422. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15423. {
  15424. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15425. {
  15426. check_ascii = value[0];
  15427. if( (check_ascii < 48) || (check_ascii > 57) )
  15428. {
  15429. isSuccess = ConfigurationStatus_Rejected;
  15430. }
  15431. else
  15432. {
  15433. if((atoi(value) == 0) || (atoi(value) >= 3))
  15434. {
  15435. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15436. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15437. isSuccess = ConfigurationStatus_Accepted;
  15438. }
  15439. else
  15440. {
  15441. isSuccess = ConfigurationStatus_Rejected;
  15442. }
  15443. }
  15444. }
  15445. else
  15446. {
  15447. isSuccess = ConfigurationStatus_Rejected;
  15448. }
  15449. }
  15450. if(strcmp(key, "MinimumStatusDuration") == 0)
  15451. {
  15452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15453. {
  15454. check_ascii = value[0];
  15455. if( (check_ascii < 48) || (check_ascii > 57) )
  15456. {
  15457. isSuccess = ConfigurationStatus_Rejected;
  15458. }
  15459. else
  15460. {
  15461. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15462. {
  15463. isSuccess = ConfigurationStatus_Rejected;
  15464. }
  15465. else
  15466. {
  15467. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15468. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15469. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15470. isSuccess = ConfigurationStatus_Accepted;
  15471. }
  15472. }
  15473. }
  15474. else
  15475. {
  15476. isSuccess = ConfigurationStatus_Rejected;
  15477. }
  15478. }
  15479. if(strcmp(key, "NumberOfConnectors") == 0)
  15480. {
  15481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15482. {
  15483. check_ascii = value[0];
  15484. if( (check_ascii < 48) || (check_ascii > 57) )
  15485. {
  15486. isSuccess = ConfigurationStatus_Rejected;
  15487. }
  15488. else
  15489. {
  15490. //Charger.ResetRetries = Integer.parseInt(value);
  15491. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15492. isSuccess = ConfigurationStatus_Accepted;
  15493. }
  15494. }
  15495. else
  15496. {
  15497. isSuccess = ConfigurationStatus_Rejected;
  15498. }
  15499. }
  15500. if(strcmp(key, "ResetRetries") == 0)
  15501. {
  15502. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15503. {
  15504. check_ascii = value[0];
  15505. if( (check_ascii < 48) || (check_ascii > 57) )
  15506. {
  15507. isSuccess = ConfigurationStatus_Rejected;
  15508. }
  15509. else
  15510. {
  15511. //Charger.ResetRetries = Integer.parseInt(value);
  15512. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15513. isSuccess = ConfigurationStatus_Accepted;
  15514. }
  15515. }
  15516. else
  15517. {
  15518. isSuccess = ConfigurationStatus_Rejected;
  15519. }
  15520. }
  15521. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15522. {
  15523. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15524. {
  15525. strcpy(str, (const char*)value);
  15526. for(int i = 0; str[i]; i++)
  15527. {
  15528. str[i] = tolower(str[i]);
  15529. }
  15530. if(strcmp(str, "notapplicable")== 0)
  15531. {
  15532. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15533. isSuccess = ConfigurationStatus_Accepted;
  15534. }
  15535. else if(strcmp(str, "unknown")== 0)
  15536. {
  15537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15538. isSuccess = ConfigurationStatus_Accepted;
  15539. }
  15540. else if(strcmp(str, "rst")== 0)
  15541. {
  15542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15543. isSuccess = ConfigurationStatus_Accepted;
  15544. }
  15545. else if(strcmp(str, "rts")== 0)
  15546. {
  15547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15548. isSuccess = ConfigurationStatus_Accepted;
  15549. }
  15550. else if(strcmp(str, "srt")== 0)
  15551. {
  15552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15553. isSuccess = ConfigurationStatus_Accepted;
  15554. }
  15555. else if(strcmp(str, "str")== 0)
  15556. {
  15557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15558. isSuccess = ConfigurationStatus_Accepted;
  15559. }
  15560. else if(strcmp(str, "trs")== 0)
  15561. {
  15562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15563. isSuccess = ConfigurationStatus_Accepted;
  15564. }
  15565. else if(strcmp(str, "tsr")== 0)
  15566. {
  15567. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15568. isSuccess = ConfigurationStatus_Accepted;
  15569. }
  15570. else
  15571. {
  15572. isSuccess = ConfigurationStatus_Rejected;
  15573. }
  15574. }
  15575. else
  15576. {
  15577. isSuccess = ConfigurationStatus_Rejected;
  15578. }
  15579. }
  15580. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15581. {
  15582. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15583. {
  15584. check_ascii = value[0];
  15585. if( (check_ascii < 48) || (check_ascii > 57) )
  15586. {
  15587. isSuccess = ConfigurationStatus_Rejected;
  15588. }
  15589. else
  15590. {
  15591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15592. isSuccess = ConfigurationStatus_Accepted;
  15593. }
  15594. }
  15595. else
  15596. {
  15597. isSuccess = ConfigurationStatus_Rejected;
  15598. }
  15599. }
  15600. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15601. {
  15602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15603. {
  15604. strcpy(str, (const char*)value);
  15605. for(int i = 0; str[i]; i++)
  15606. {
  15607. str[i] = tolower(str[i]);
  15608. }
  15609. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15611. isSuccess = ConfigurationStatus_Accepted;
  15612. }
  15613. else
  15614. {
  15615. isSuccess = ConfigurationStatus_Rejected;
  15616. }
  15617. }
  15618. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15619. {
  15620. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15621. {
  15622. strcpy(str, (const char*)value);
  15623. for(int i = 0; str[i]; i++)
  15624. {
  15625. str[i] = tolower(str[i]);
  15626. }
  15627. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15629. isSuccess = ConfigurationStatus_Accepted;
  15630. }
  15631. else
  15632. {
  15633. isSuccess = ConfigurationStatus_Rejected;
  15634. }
  15635. }
  15636. if(strcmp(key, "StopTxnAlignedData") == 0)
  15637. {
  15638. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15639. {
  15640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15641. isSuccess = ConfigurationStatus_Accepted;
  15642. }
  15643. else
  15644. {
  15645. isSuccess = ConfigurationStatus_Rejected;
  15646. }
  15647. }
  15648. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15649. {
  15650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15651. {
  15652. check_ascii = value[0];
  15653. if( (check_ascii < 48) || (check_ascii > 57) )
  15654. {
  15655. isSuccess = ConfigurationStatus_Rejected;
  15656. }
  15657. else
  15658. {
  15659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15660. isSuccess = ConfigurationStatus_Accepted;
  15661. }
  15662. }
  15663. else
  15664. {
  15665. isSuccess = ConfigurationStatus_Rejected;
  15666. }
  15667. }
  15668. if(strcmp(key, "StopTxnSampledData") == 0)
  15669. {
  15670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15671. {
  15672. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15673. isSuccess = ConfigurationStatus_Accepted;
  15674. }
  15675. else
  15676. {
  15677. isSuccess = ConfigurationStatus_Rejected;
  15678. }
  15679. }
  15680. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15681. {
  15682. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15683. {
  15684. check_ascii = value[0];
  15685. if( (check_ascii < 48) || (check_ascii > 57) )
  15686. {
  15687. isSuccess = ConfigurationStatus_Rejected;
  15688. }
  15689. else
  15690. {
  15691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15692. isSuccess = ConfigurationStatus_Accepted;
  15693. }
  15694. }
  15695. else
  15696. {
  15697. isSuccess = ConfigurationStatus_Rejected;
  15698. }
  15699. }
  15700. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15701. {
  15702. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15703. {
  15704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15705. isSuccess = ConfigurationStatus_Accepted;
  15706. }
  15707. else
  15708. {
  15709. isSuccess = ConfigurationStatus_Rejected;
  15710. }
  15711. }
  15712. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15713. {
  15714. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15715. {
  15716. check_ascii = value[0];
  15717. if( (check_ascii < 48) || (check_ascii > 57) )
  15718. {
  15719. isSuccess = ConfigurationStatus_Rejected;
  15720. }
  15721. else
  15722. {
  15723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15724. isSuccess = ConfigurationStatus_Accepted;
  15725. }
  15726. }
  15727. else
  15728. {
  15729. isSuccess = ConfigurationStatus_Rejected;
  15730. }
  15731. }
  15732. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15733. {
  15734. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15735. {
  15736. check_ascii = value[0];
  15737. if( (check_ascii < 48) || (check_ascii > 57) )
  15738. {
  15739. isSuccess = ConfigurationStatus_Rejected;
  15740. }
  15741. else
  15742. {
  15743. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15745. TransactionMessageAttemptsValue = atoi(value);
  15746. isSuccess = ConfigurationStatus_Accepted;
  15747. }
  15748. }
  15749. else
  15750. {
  15751. isSuccess = ConfigurationStatus_Rejected;
  15752. }
  15753. }
  15754. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15755. {
  15756. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15757. {
  15758. check_ascii = value[0];
  15759. if( (check_ascii < 48) || (check_ascii > 57) )
  15760. {
  15761. isSuccess = ConfigurationStatus_Rejected;
  15762. }
  15763. else
  15764. {
  15765. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15767. TransactionMessageRetryIntervalValue = atoi(value);
  15768. isSuccess = ConfigurationStatus_Accepted;
  15769. }
  15770. }
  15771. else
  15772. {
  15773. isSuccess = ConfigurationStatus_Rejected;
  15774. }
  15775. }
  15776. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15777. {
  15778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15779. {
  15780. strcpy(str, (const char*)value);
  15781. for(int i = 0; str[i]; i++)
  15782. {
  15783. str[i] = tolower(str[i]);
  15784. }
  15785. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15787. isSuccess = ConfigurationStatus_Accepted;
  15788. }
  15789. else
  15790. {
  15791. isSuccess = ConfigurationStatus_Rejected;
  15792. }
  15793. }
  15794. if(strcmp(key, "WebSocketPingInterval") == 0)
  15795. {
  15796. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15797. {
  15798. check_ascii = value[0];
  15799. if( (check_ascii < 48) || (check_ascii > 57) )
  15800. {
  15801. isSuccess = ConfigurationStatus_Rejected;
  15802. }
  15803. else
  15804. {
  15805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15806. isSuccess = ConfigurationStatus_Accepted;
  15807. if((atoi(value) == 0) || (atoi(value) >= 10))
  15808. {
  15809. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15810. isSuccess = ConfigurationStatus_Accepted;
  15811. }
  15812. else
  15813. isSuccess = ConfigurationStatus_Rejected;
  15814. }
  15815. }
  15816. else
  15817. {
  15818. isSuccess = ConfigurationStatus_Rejected;
  15819. }
  15820. }
  15821. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15822. {
  15823. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15824. {
  15825. strcpy(str, (const char*)value);
  15826. for(int i = 0; str[i]; i++)
  15827. {
  15828. str[i] = tolower(str[i]);
  15829. }
  15830. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15831. isSuccess = ConfigurationStatus_Accepted;
  15832. }
  15833. else
  15834. {
  15835. isSuccess = ConfigurationStatus_Rejected;
  15836. }
  15837. }
  15838. if(strcmp(key, "AuthorizationKey") == 0)
  15839. {
  15840. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15841. {
  15842. strcpy(str, (const char*)value);
  15843. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15844. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15845. isSuccess = ConfigurationStatus_Accepted;
  15846. }
  15847. else
  15848. {
  15849. isSuccess = ConfigurationStatus_Rejected;
  15850. }
  15851. }
  15852. if(strcmp(key, "SecurityProfile") == 0)
  15853. {
  15854. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15855. {
  15856. check_ascii = value[0];
  15857. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15858. {
  15859. isSuccess = ConfigurationStatus_Rejected;
  15860. }
  15861. else if(check_ascii == 0x33)
  15862. {
  15863. isSuccess = NotSupported;
  15864. }
  15865. else
  15866. {
  15867. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15868. {
  15869. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15870. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15871. isSuccess = ConfigurationStatus_Accepted;
  15872. }
  15873. else
  15874. isSuccess = ConfigurationStatus_Rejected;
  15875. }
  15876. }
  15877. else
  15878. {
  15879. isSuccess = ConfigurationStatus_Rejected;
  15880. }
  15881. }
  15882. if(strcmp(key, "DefaultPrice") == 0)
  15883. {
  15884. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15885. {
  15886. strcpy(str, (const char*)value);
  15887. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15888. isSuccess = ConfigurationStatus_Accepted;
  15889. }
  15890. else
  15891. {
  15892. isSuccess = ConfigurationStatus_Rejected;
  15893. }
  15894. }
  15895. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15896. {
  15897. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15898. {
  15899. strcpy(str, (const char*)value);
  15900. for(int i = 0; str[i]; i++)
  15901. {
  15902. str[i] = tolower(str[i]);
  15903. }
  15904. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15905. isSuccess = ConfigurationStatus_Accepted;
  15906. }
  15907. else
  15908. {
  15909. isSuccess = ConfigurationStatus_Rejected;
  15910. }
  15911. }
  15912. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15913. {
  15914. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15915. {
  15916. strcpy(str, (const char*)value);
  15917. for(int i = 0; str[i]; i++)
  15918. {
  15919. str[i] = tolower(str[i]);
  15920. }
  15921. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15922. isSuccess = ConfigurationStatus_Accepted;
  15923. }
  15924. else
  15925. {
  15926. isSuccess = ConfigurationStatus_Rejected;
  15927. }
  15928. }
  15929. if(strcmp(key, "SystemUptimeSec") == 0)
  15930. {
  15931. isSuccess = NotSupported;
  15932. }
  15933. if(strcmp(key, "FreeVend") == 0)
  15934. {
  15935. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15936. {
  15937. strcpy(str, (const char*)value);
  15938. for(int i = 0; str[i]; i++)
  15939. {
  15940. str[i] = tolower(str[i]);
  15941. }
  15942. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15943. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].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, "OcppServer") == 0)
  15952. {
  15953. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15954. {
  15955. strcpy(str, (const char*)value);
  15956. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  15957. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  15958. isSuccess = ConfigurationStatus_Accepted;
  15959. }
  15960. else
  15961. {
  15962. isSuccess = ConfigurationStatus_Rejected;
  15963. }
  15964. }
  15965. if(strcmp(key, "MaintainServer") == 0)
  15966. {
  15967. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15968. {
  15969. strcpy(str, (const char*)value);
  15970. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  15971. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  15972. isSuccess = ConfigurationStatus_Accepted;
  15973. }
  15974. else
  15975. {
  15976. isSuccess = ConfigurationStatus_Rejected;
  15977. }
  15978. }
  15979. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  15980. {
  15981. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15982. {
  15983. strcpy(str, (const char*)value);
  15984. for(int i = 0; str[i]; i++)
  15985. {
  15986. str[i] = tolower(str[i]);
  15987. }
  15988. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  15989. isSuccess = ConfigurationStatus_Accepted;
  15990. }
  15991. else
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. }
  15996. if(strcmp(key, "StatusNotificationInterval") == 0)
  15997. {
  15998. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15999. {
  16000. check_ascii = value[0];
  16001. if( (check_ascii < 48) || (check_ascii > 57) )
  16002. {
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. else
  16006. {
  16007. if((atoi(value) == 0) || (atoi(value) >= 10))
  16008. {
  16009. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16010. isSuccess = ConfigurationStatus_Accepted;
  16011. }
  16012. else
  16013. isSuccess = ConfigurationStatus_Rejected;
  16014. }
  16015. }
  16016. else
  16017. {
  16018. isSuccess = ConfigurationStatus_Rejected;
  16019. }
  16020. }
  16021. #if 0
  16022. //For OCPP Test Case
  16023. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16024. {
  16025. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16026. {
  16027. strcpy(str, (const char*)value);
  16028. for(int i = 0; str[i]; i++)
  16029. {
  16030. str[i] = tolower(str[i]);
  16031. }
  16032. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16033. isSuccess = ConfigurationStatus_Accepted;
  16034. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16035. }
  16036. else
  16037. {
  16038. isSuccess = ConfigurationStatus_Rejected;
  16039. }
  16040. }
  16041. #endif
  16042. #if 1
  16043. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16044. {
  16045. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16046. {
  16047. strcpy(str, (const char*)value);
  16048. for(int i = 0; str[i]; i++)
  16049. {
  16050. str[i] = tolower(str[i]);
  16051. }
  16052. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16053. isSuccess = ConfigurationStatus_Accepted;
  16054. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16055. }
  16056. else
  16057. {
  16058. isSuccess = ConfigurationStatus_Rejected;
  16059. }
  16060. }
  16061. #endif
  16062. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16063. {
  16064. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16065. {
  16066. check_ascii = value[0];
  16067. if( (check_ascii < 48) || (check_ascii > 57) )
  16068. {
  16069. isSuccess = ConfigurationStatus_Rejected;
  16070. }
  16071. else
  16072. {
  16073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16074. isSuccess = ConfigurationStatus_Accepted;
  16075. }
  16076. }
  16077. else
  16078. {
  16079. isSuccess = ConfigurationStatus_Rejected;
  16080. }
  16081. }
  16082. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16083. {
  16084. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16085. {
  16086. check_ascii = value[0];
  16087. if( (check_ascii < 48) || (check_ascii > 57) )
  16088. {
  16089. isSuccess = ConfigurationStatus_Rejected;
  16090. }
  16091. else
  16092. {
  16093. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16094. isSuccess = ConfigurationStatus_Accepted;
  16095. }
  16096. }
  16097. else
  16098. {
  16099. isSuccess = ConfigurationStatus_Rejected;
  16100. }
  16101. }
  16102. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16103. {
  16104. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16105. {
  16106. strcpy(str, (const char*)value);
  16107. for(int i = 0; str[i]; i++)
  16108. {
  16109. str[i] = tolower(str[i]);
  16110. }
  16111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16112. isSuccess = ConfigurationStatus_Accepted;
  16113. }
  16114. else
  16115. {
  16116. isSuccess = ConfigurationStatus_Rejected;
  16117. }
  16118. }
  16119. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16120. {
  16121. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16122. {
  16123. check_ascii = value[0];
  16124. if( (check_ascii < 48) || (check_ascii > 57) )
  16125. {
  16126. isSuccess = ConfigurationStatus_Rejected;
  16127. }
  16128. else
  16129. {
  16130. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16131. isSuccess = ConfigurationStatus_Accepted;
  16132. }
  16133. }
  16134. else
  16135. {
  16136. isSuccess = ConfigurationStatus_Rejected;
  16137. }
  16138. }
  16139. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16140. {
  16141. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16142. {
  16143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16144. isSuccess = ConfigurationStatus_Accepted;
  16145. }
  16146. else
  16147. {
  16148. isSuccess = ConfigurationStatus_Rejected;
  16149. }
  16150. }
  16151. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16152. {
  16153. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16154. {
  16155. check_ascii = value[0];
  16156. if( (check_ascii < 48) || (check_ascii > 57) )
  16157. {
  16158. isSuccess = ConfigurationStatus_Rejected;
  16159. }
  16160. else
  16161. {
  16162. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16163. isSuccess = ConfigurationStatus_Accepted;
  16164. }
  16165. }
  16166. else
  16167. {
  16168. isSuccess = ConfigurationStatus_Rejected;
  16169. }
  16170. }
  16171. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16172. {
  16173. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16174. {
  16175. strcpy(str, (const char*)value);
  16176. for(int i = 0; str[i]; i++)
  16177. {
  16178. str[i] = tolower(str[i]);
  16179. }
  16180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16181. isSuccess = ConfigurationStatus_Accepted;
  16182. }
  16183. else
  16184. {
  16185. isSuccess = ConfigurationStatus_Rejected;
  16186. }
  16187. }
  16188. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16189. {
  16190. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16191. {
  16192. check_ascii = value[0];
  16193. if( (check_ascii < 48) || (check_ascii > 57) )
  16194. {
  16195. isSuccess = ConfigurationStatus_Rejected;
  16196. }
  16197. else
  16198. {
  16199. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16200. isSuccess = ConfigurationStatus_Accepted;
  16201. }
  16202. }
  16203. else
  16204. {
  16205. isSuccess = ConfigurationStatus_Rejected;
  16206. }
  16207. }
  16208. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16209. return isSuccess;
  16210. }
  16211. int TransactionMessageAttemptsGet(void)
  16212. {
  16213. return TransactionMessageAttemptsValue;
  16214. }
  16215. int FirstHeartBeatResponse(void)
  16216. {
  16217. return FirstHeartBeat;
  16218. }
  16219. int TransactionMessageRetryIntervalGet(void)
  16220. {
  16221. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16222. }
  16223. int ReadHttpStatus(int sock)
  16224. {
  16225. //char c;
  16226. char buff[1024]="",*ptr=buff+1;
  16227. int bytes_received, status;
  16228. DEBUG_INFO("Begin Response ..\n");
  16229. while((bytes_received = recv(sock, ptr, 1, 0))){
  16230. if(bytes_received==-1){
  16231. perror("ReadHttpStatus");
  16232. exit(1);
  16233. }
  16234. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16235. ptr++;
  16236. }
  16237. *ptr=0;
  16238. ptr=buff+1;
  16239. sscanf(ptr,"%*s %d ", &status);
  16240. DEBUG_INFO("%s\n",ptr);
  16241. DEBUG_INFO("status=%d\n",status);
  16242. DEBUG_INFO("End Response ..\n");
  16243. return (bytes_received>0)?status:0;
  16244. }
  16245. //the only filed that it parsed is 'Content-Length'
  16246. int ParseHeader(int sock)
  16247. {
  16248. //char c;
  16249. char buff[1024]="",*ptr=buff+4;
  16250. int bytes_received;
  16251. DEBUG_INFO("Begin HEADER ..\n");
  16252. while((bytes_received = recv(sock, ptr, 1, 0))){
  16253. if(bytes_received==-1){
  16254. perror("Parse Header");
  16255. exit(1);
  16256. }
  16257. if(
  16258. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16259. (ptr[-1]=='\r') && (*ptr=='\n' )
  16260. ) break;
  16261. ptr++;
  16262. }
  16263. *ptr=0;
  16264. ptr=buff+4;
  16265. //printf("%s",ptr);
  16266. if(bytes_received){
  16267. ptr=strstr(ptr,"Content-Length:");
  16268. if(ptr){
  16269. sscanf(ptr,"%*s %d",&bytes_received);
  16270. }else
  16271. bytes_received=-1; //unknown size
  16272. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16273. }
  16274. DEBUG_INFO("End HEADER ..\n");
  16275. return bytes_received ;
  16276. }
  16277. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16278. {
  16279. int result = TRUE;
  16280. char rmFileCmd[100]={0};
  16281. char FilePath[100]={0};
  16282. char ftpbuf[200];
  16283. int systemresult;
  16284. sprintf(FilePath,"/mnt/%s",filename);
  16285. system("ping 8.8.8.8 &");
  16286. if((access(FilePath,F_OK))!=-1)
  16287. {
  16288. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16289. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16290. system(rmFileCmd);
  16291. }
  16292. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16293. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16294. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16295. systemresult = system(ftpbuf);
  16296. if(systemresult != 0)
  16297. {
  16298. DEBUG_INFO("http DownLoad error!\n");
  16299. result = FALSE;
  16300. }
  16301. system("pkill ping");
  16302. return result;
  16303. }
  16304. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16305. {
  16306. int result = TRUE;
  16307. char rmFileCmd[100]={0};
  16308. char FilePath[100]={0};
  16309. char ftpbuf[200];
  16310. int systemresult;
  16311. sprintf(FilePath,"/mnt/%s",filename);
  16312. system("ping 8.8.8.8 &");
  16313. if((access(FilePath,F_OK))!=-1)
  16314. {
  16315. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16316. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16317. system(rmFileCmd);
  16318. }
  16319. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16320. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16321. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16322. systemresult = system(ftpbuf);
  16323. if(systemresult != 0)
  16324. {
  16325. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16326. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16327. systemresult = system(ftpbuf);
  16328. if(systemresult != 0)
  16329. {
  16330. DEBUG_WARN("wget error!\n");
  16331. result = FALSE;
  16332. }
  16333. }
  16334. system("pkill ping");
  16335. return result;
  16336. }
  16337. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16338. {
  16339. char rmFileCmd[100]={0};
  16340. char FilePath[100]={0};
  16341. char buf[512];
  16342. int systemresult = 0;
  16343. //DEBUG_INFO("filename=%s\n",filename);
  16344. //DEBUG_INFO("url=%s\n",url);
  16345. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  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. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16353. if(fp == NULL)
  16354. {
  16355. DEBUG_INFO("log is NULL\n");
  16356. return FALSE;
  16357. }
  16358. else
  16359. {
  16360. fprintf(fp, "%s\n", url);
  16361. fprintf(fp, "%s\n", filename);
  16362. fclose(fp);
  16363. }
  16364. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16365. if(phpFP == NULL)
  16366. {
  16367. DEBUG_INFO("PHP upload fail.\n");
  16368. return FALSE;
  16369. }
  16370. else
  16371. {
  16372. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16373. {
  16374. if(strstr(buf, "result") != NULL)
  16375. {
  16376. sscanf(buf, "result: %d", &systemresult);
  16377. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16378. }
  16379. }
  16380. pclose(phpFP);
  16381. }
  16382. if(systemresult != 1)
  16383. {
  16384. DEBUG_INFO("HTTP upload error!\n");
  16385. return FALSE;
  16386. }
  16387. return TRUE;
  16388. }
  16389. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16390. {
  16391. int result = FALSE;
  16392. char ftpbuf[200];
  16393. int systemresult;
  16394. /*
  16395. // Domaind name transfer to IP address
  16396. struct hostent* server;
  16397. char *IPbuffer;
  16398. server = gethostbyname(location);
  16399. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16400. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16401. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16402. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16403. systemresult = system(ftpbuf);
  16404. if(systemresult != 0)
  16405. {
  16406. DEBUG_INFO("ftpput error!\n");
  16407. }
  16408. else
  16409. {
  16410. result = TRUE;
  16411. DEBUG_INFO("ftpput OK!\n");
  16412. }
  16413. return result;
  16414. }
  16415. int GetOcppServerURL()
  16416. {
  16417. int result = FALSE;
  16418. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16419. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16420. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16421. struct yuarel url;
  16422. char urlStr[512];
  16423. // OCPPPH only
  16424. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16425. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16426. {
  16427. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16428. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16429. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16430. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16431. if(yuarel_parse(&url, urlStr) != -1)
  16432. {
  16433. sprintf(OcppProtocol, "%s", url.scheme);
  16434. sprintf(OcppHost, "%s", url.host);
  16435. if(url.path == NULL)
  16436. OcppTempPath[0] = '\0';
  16437. else
  16438. sprintf(OcppTempPath, "%s", url.path);
  16439. if(url.port == 0)
  16440. {
  16441. if(strcmp(OcppProtocol, "wss") == 0)
  16442. OcppPort = 443;
  16443. else
  16444. OcppPort = 80;
  16445. }
  16446. else
  16447. OcppPort = url.port;
  16448. result = TRUE;
  16449. }
  16450. }
  16451. else
  16452. {
  16453. strcpy(OcppHost,"");
  16454. }
  16455. return result;
  16456. }
  16457. int GetOcppPath()
  16458. {
  16459. int result = FALSE;
  16460. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16461. {
  16462. if(OcppTempPath == NULL)
  16463. {
  16464. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16465. }
  16466. else
  16467. {
  16468. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16469. }
  16470. result = TRUE;
  16471. goto End;
  16472. }
  16473. else
  16474. {
  16475. strcpy(OcppPath,"");
  16476. }
  16477. End:
  16478. return result;
  16479. }
  16480. int GetOcppPort()
  16481. {
  16482. return OcppPort;
  16483. }
  16484. int GetOcppConnStatus(void)
  16485. {
  16486. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16487. }
  16488. void SetOcppConnStatus(uint8_t status)
  16489. {
  16490. ShmOCPP16DataPH->OcppConnStatus = status;
  16491. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16492. }
  16493. int GetHeartBeatWithNOResponse(void)
  16494. {
  16495. return HeartBeatWithNOResponse;
  16496. }
  16497. void SetHeartBeatWithNOResponse(void)
  16498. {
  16499. HeartBeatWithNOResponse = 0;
  16500. }
  16501. void GetStartTransactionIdTag(int gun_index)
  16502. {
  16503. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16504. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16505. }
  16506. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16507. {
  16508. char ch;
  16509. FILE *fptr1;
  16510. int temptransactionId;
  16511. char str[100]={0};
  16512. temptransactionId = 0;
  16513. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16514. {
  16515. DEBUG_INFO("IdTag is empty.\n");
  16516. return temptransactionId;
  16517. }
  16518. /*------ Read the file ----------------*/
  16519. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16520. if (!fptr1)
  16521. {
  16522. DEBUG_INFO("QueueTransactionId file open error.\n");
  16523. //printf(" File not found or unable to open the input file!!\n");
  16524. return temptransactionId;
  16525. }
  16526. ch=fgetc(fptr1);
  16527. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16528. rewind(fptr1);
  16529. if(ch!=EOF)
  16530. {
  16531. // printf("%c",ch);
  16532. while (fgets(str, 100, fptr1) != NULL)
  16533. {
  16534. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16535. if(str[0]=='\0')
  16536. {
  16537. break;
  16538. }
  16539. char *revbuf[8] = {0}; // Variable store string split
  16540. int num = 0;// Quantity after string split
  16541. DEBUG_INFO("Transaction queue data= %s\n", str);
  16542. splitstring(str,",",revbuf,&num); // String split
  16543. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16544. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16545. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16546. DEBUG_INFO("------------------------------\n");
  16547. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16548. {
  16549. if(isStopTransaction)
  16550. {
  16551. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16552. {
  16553. temptransactionId = atoi(revbuf[2]);
  16554. //break;
  16555. }
  16556. }
  16557. else
  16558. {
  16559. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16560. {
  16561. temptransactionId = atoi(revbuf[2]);
  16562. //break;
  16563. }
  16564. }
  16565. }
  16566. }
  16567. }
  16568. else
  16569. DEBUG_INFO("EOF\n");
  16570. fclose(fptr1);
  16571. /*------- End of reading ---------------*/
  16572. return temptransactionId;
  16573. }
  16574. void SetTransactionIdZero(int transactionId)
  16575. {
  16576. char ch;
  16577. FILE *fptr1, *fptr2;
  16578. int temptransactionId = 0;
  16579. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16580. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16581. if (!fptr1)
  16582. {
  16583. //printf(" File not found or unable to open the input file!!\n");
  16584. return ;
  16585. }
  16586. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16587. if (!fptr2)
  16588. {
  16589. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16590. fclose(fptr1);
  16591. return ;
  16592. }
  16593. ch=fgetc(fptr1);
  16594. rewind(fptr1);
  16595. if(ch!=EOF)
  16596. {
  16597. // copy all contents to the temporary file except the specific line
  16598. while (fgets(str, 100, fptr1) != NULL)
  16599. {
  16600. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16601. if(str[0]=='\0')
  16602. {
  16603. break;
  16604. }
  16605. char *revbuf[8] = {0};
  16606. int num = 0;
  16607. strcpy(strtemp, str);
  16608. splitstring(str,",",revbuf,&num);
  16609. if(revbuf[2][0] != '\0')
  16610. {
  16611. temptransactionId = atoi(revbuf[2]);
  16612. if(transactionId != temptransactionId)
  16613. {
  16614. fprintf(fptr2, "%s\n", strtemp);
  16615. }
  16616. }
  16617. }
  16618. }
  16619. fclose(fptr1);
  16620. fclose(fptr2);
  16621. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16622. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16623. /*------ Read the file ----------------*/
  16624. }
  16625. int InternetDisconnect(void)
  16626. {
  16627. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16628. }
  16629. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16630. void storeTempStopTransaction(int gun_index)
  16631. {
  16632. char guid[37]={0};
  16633. int tempIndex = 0;
  16634. char TempStopTransaction[256];
  16635. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16636. DEBUG_INFO("storeTempStopTransaction...\n");
  16637. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16638. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16639. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16640. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16641. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16642. {
  16643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16644. {
  16645. tempIndex = ((gun_index==2) ? 1: 0);
  16646. }
  16647. else
  16648. {
  16649. tempIndex = gun_index;
  16650. }
  16651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16652. {
  16653. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16654. {
  16655. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16656. }
  16657. }// END OF CHAdeMO_QUANTITY
  16658. }
  16659. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16660. {
  16661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16662. {
  16663. tempIndex = ((gun_index==2) ? 1: 0);
  16664. }
  16665. else
  16666. {
  16667. tempIndex = gun_index;
  16668. }
  16669. for (int index = 0; index < CCS_QUANTITY; index++)
  16670. {
  16671. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16672. {
  16673. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16674. }
  16675. }// END OF CCS_QUANTITY
  16676. }
  16677. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16678. {
  16679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16680. {
  16681. tempIndex = ((gun_index==2) ? 1: 0);
  16682. }
  16683. else
  16684. {
  16685. tempIndex = gun_index;
  16686. }
  16687. for (int index = 0; index < GB_QUANTITY; index++)
  16688. {
  16689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16690. {
  16691. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16692. }
  16693. }// END OF GB_QUANTITY
  16694. }
  16695. else if(gunType[gun_index] == GUN_TYPE_DO)
  16696. {
  16697. tempIndex = gun_index;
  16698. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16699. {
  16700. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16701. {
  16702. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16703. }
  16704. }
  16705. }
  16706. else
  16707. {
  16708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16709. {
  16710. tempIndex = 2;
  16711. }
  16712. else
  16713. {
  16714. tempIndex = gun_index;
  16715. }
  16716. for (int index = 0; index < AC_QUANTITY; index++)
  16717. {
  16718. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16719. {
  16720. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16721. }
  16722. }// END OF AC_QUANTITY
  16723. }
  16724. //Stop Transaction Time
  16725. struct timeval tmnow;
  16726. struct tm *tm;
  16727. char buf[28];//, usec_buf[6];
  16728. gettimeofday(&tmnow, NULL);
  16729. time_t t;
  16730. t = time(NULL);
  16731. /*UTC time and date*/
  16732. tm = gmtime(&t);
  16733. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16734. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16735. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16737. random_uuid(guid);
  16738. /***********************************transactionData******************************************************/
  16739. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16741. //=================================
  16742. //1. Transaction_Begin
  16743. //=================================
  16744. //============================== Energy.Active.Import.Interval ===========================================
  16745. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16746. {
  16747. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16750. 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*/]);
  16751. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16752. 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))
  16753. {
  16754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16755. }
  16756. else
  16757. {
  16758. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16759. }
  16760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16761. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16762. }
  16763. //=================================
  16764. //2. Transaction_End
  16765. //=================================
  16766. //2.1====================================== Current.Import L1 ==============================================
  16767. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16768. {
  16769. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16770. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16771. {
  16772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16773. {
  16774. tempIndex = ((gun_index==2) ? 1: 0);
  16775. }
  16776. else
  16777. {
  16778. tempIndex = gun_index;
  16779. }
  16780. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16781. {
  16782. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16783. {
  16784. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16785. }
  16786. }// End of for CHAdeMO_QUANTITY
  16787. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16788. }
  16789. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16790. {
  16791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16792. {
  16793. tempIndex = ((gun_index==2) ? 1: 0);
  16794. }
  16795. else
  16796. {
  16797. tempIndex = gun_index;
  16798. }
  16799. for (int index = 0; index < CCS_QUANTITY; index++)
  16800. {
  16801. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16802. {
  16803. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16804. }
  16805. }// End of for CCS_QUANTITY
  16806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16807. }
  16808. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16809. {
  16810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16811. {
  16812. tempIndex = ((gun_index==2) ? 1: 0);
  16813. }
  16814. else
  16815. {
  16816. tempIndex = gun_index;
  16817. }
  16818. for (int index = 0; index < GB_QUANTITY; index++)
  16819. {
  16820. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16821. {
  16822. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16823. }
  16824. }// End of for GB_QUANTITY
  16825. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16826. }
  16827. else if(gunType[gun_index] == GUN_TYPE_DO)
  16828. {
  16829. tempIndex = gun_index;
  16830. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16831. {
  16832. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16833. {
  16834. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16835. }
  16836. }
  16837. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16838. }
  16839. else
  16840. {
  16841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16842. {
  16843. tempIndex = 2;
  16844. }
  16845. else
  16846. {
  16847. tempIndex = gun_index;
  16848. }
  16849. for (int index = 0; index < AC_QUANTITY; index++)
  16850. {
  16851. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16852. {
  16853. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16854. }
  16855. }// End of for AC_QUANTITY
  16856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16857. }
  16858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16861. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16864. }
  16865. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16866. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16867. {
  16868. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16869. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16870. {
  16871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16872. {
  16873. tempIndex = ((gun_index==2) ? 1: 0);
  16874. }
  16875. else
  16876. {
  16877. tempIndex = gun_index;
  16878. }
  16879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16880. {
  16881. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16882. {
  16883. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16884. }
  16885. }// END OF CHAdeMO_QUANTITY
  16886. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16887. }
  16888. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16889. {
  16890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16891. {
  16892. tempIndex = ((gun_index==2) ? 1: 0);
  16893. }
  16894. else
  16895. {
  16896. tempIndex = gun_index;
  16897. }
  16898. for (int index = 0; index < CCS_QUANTITY; index++)
  16899. {
  16900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16901. {
  16902. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16903. }
  16904. }// END OF CCS_QUANTITY
  16905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16906. }
  16907. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16908. {
  16909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16910. {
  16911. tempIndex = ((gun_index==2) ? 1: 0);
  16912. }
  16913. else
  16914. {
  16915. tempIndex = gun_index;
  16916. }
  16917. for (int index = 0; index < GB_QUANTITY; index++)
  16918. {
  16919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16920. {
  16921. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16922. }
  16923. }// END OF GB_QUANTITY
  16924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16925. }
  16926. else if(gunType[gun_index] == GUN_TYPE_DO)
  16927. {
  16928. tempIndex = gun_index;
  16929. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16930. {
  16931. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16932. {
  16933. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16934. }
  16935. }
  16936. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16937. }
  16938. else
  16939. {
  16940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16941. {
  16942. tempIndex = 2;
  16943. }
  16944. else
  16945. {
  16946. tempIndex = gun_index;
  16947. }
  16948. for (int index = 0; index < AC_QUANTITY; index++)
  16949. {
  16950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16951. {
  16952. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16953. }
  16954. }// END OF AC_QUANTITY
  16955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16956. }
  16957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16960. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16961. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16962. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16963. }
  16964. //2.3====================================== Power.Active.Import =========================================
  16965. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16966. {
  16967. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16968. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16969. {
  16970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16971. {
  16972. tempIndex = ((gun_index==2) ? 1: 0);
  16973. }
  16974. else
  16975. {
  16976. tempIndex = gun_index;
  16977. }
  16978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16979. {
  16980. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16981. {
  16982. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16983. }
  16984. } // End for CHAdeMO_QUANTITY
  16985. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16986. }
  16987. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16988. {
  16989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16990. {
  16991. tempIndex = ((gun_index==2) ? 1: 0);
  16992. }
  16993. else
  16994. {
  16995. tempIndex = gun_index;
  16996. }
  16997. for (int index = 0; index < CCS_QUANTITY; index++)
  16998. {
  16999. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17000. {
  17001. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17002. }
  17003. } // END for CCS_QUANTITY
  17004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17005. }
  17006. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17007. {
  17008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17009. {
  17010. tempIndex = ((gun_index==2) ? 1: 0);
  17011. }
  17012. else
  17013. {
  17014. tempIndex = gun_index;
  17015. }
  17016. for (int index = 0; index < GB_QUANTITY; index++)
  17017. {
  17018. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17019. {
  17020. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17021. }
  17022. }// END for GB_QUANTITY
  17023. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17024. }
  17025. else if(gunType[gun_index] == GUN_TYPE_DO)
  17026. {
  17027. tempIndex = gun_index;
  17028. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17029. {
  17030. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17031. {
  17032. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17033. }
  17034. }
  17035. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17036. }
  17037. else
  17038. {
  17039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17040. {
  17041. tempIndex = 2;
  17042. }
  17043. else
  17044. {
  17045. tempIndex = gun_index;
  17046. }
  17047. for (int index = 0; index < AC_QUANTITY; index++)
  17048. {
  17049. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17050. {
  17051. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17052. }
  17053. } // END for AC_QUANTITY
  17054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17055. }
  17056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17059. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17062. }
  17063. //2.4====================================== Voltage L1 ====================================================
  17064. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17065. {
  17066. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17067. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17068. {
  17069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17070. {
  17071. tempIndex = ((gun_index==2) ? 1: 0);
  17072. }
  17073. else
  17074. {
  17075. tempIndex = gun_index;
  17076. }
  17077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17078. {
  17079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17080. {
  17081. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17082. }
  17083. } // END OF FOR CHAdeMO_QUANTITY
  17084. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17085. }
  17086. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17087. {
  17088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17089. {
  17090. tempIndex = ((gun_index==2) ? 1: 0);
  17091. }
  17092. else
  17093. {
  17094. tempIndex = gun_index;
  17095. }
  17096. for (int index = 0; index < CCS_QUANTITY; index++)
  17097. {
  17098. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17099. {
  17100. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17101. }
  17102. } // END OF FOR CCS_QUANTITY
  17103. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17104. }
  17105. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17106. {
  17107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17108. {
  17109. tempIndex = ((gun_index==2) ? 1: 0);
  17110. }
  17111. else
  17112. {
  17113. tempIndex = gun_index;
  17114. }
  17115. for (int index = 0; index < GB_QUANTITY; index++)
  17116. {
  17117. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17118. {
  17119. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17120. }
  17121. } // END OF FOR GB_QUANTITY
  17122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17123. }
  17124. else if(gunType[gun_index] == GUN_TYPE_DO)
  17125. {
  17126. tempIndex = gun_index;
  17127. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17128. {
  17129. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17130. {
  17131. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17132. }
  17133. }
  17134. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17135. }
  17136. else
  17137. {
  17138. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17139. {
  17140. tempIndex = 2;
  17141. }
  17142. else
  17143. {
  17144. tempIndex = gun_index;
  17145. }
  17146. for (int index = 0; index < AC_QUANTITY; index++)
  17147. {
  17148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17149. {
  17150. 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
  17151. }
  17152. } // END OF FOR AC_QUANTITY
  17153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17154. }
  17155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17158. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17161. }
  17162. //2.5============================================== End SoC =========================================================
  17163. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17164. {
  17165. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17166. 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))
  17167. {
  17168. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17169. {
  17170. tempIndex = ((gun_index==2) ? 1: 0);
  17171. }
  17172. else
  17173. {
  17174. tempIndex = gun_index;
  17175. }
  17176. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17177. {
  17178. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17179. {
  17180. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17181. {
  17182. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17183. }
  17184. }
  17185. }
  17186. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17187. {
  17188. for (int index = 0; index < CCS_QUANTITY; index++)
  17189. {
  17190. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17191. {
  17192. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17193. }
  17194. }
  17195. }
  17196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17197. {
  17198. for (int index = 0; index < GB_QUANTITY; index++)
  17199. {
  17200. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17201. {
  17202. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17203. }
  17204. }
  17205. }
  17206. else if(gunType[gun_index] == GUN_TYPE_DO)
  17207. {
  17208. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17209. {
  17210. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17211. {
  17212. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17213. }
  17214. }
  17215. }
  17216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17221. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17222. } // END FOR DC CASE
  17223. }
  17224. //2.6====================================== Current.Import L2 ==============================================
  17225. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17226. {
  17227. // AC 3 phase L2 current
  17228. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17229. {
  17230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17231. {
  17232. tempIndex = 2;
  17233. }
  17234. else
  17235. {
  17236. tempIndex = gun_index;
  17237. }
  17238. for (int index = 0; index < AC_QUANTITY; index++)
  17239. {
  17240. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17241. {
  17242. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17243. }
  17244. }// End of for AC_QUANTITY
  17245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17246. }
  17247. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17248. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17249. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17250. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17251. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17252. }
  17253. //2.7====================================== Current.Import L3 ==============================================
  17254. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17255. {
  17256. // AC 3 phase L3 current
  17257. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17258. {
  17259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17260. {
  17261. tempIndex = 2;
  17262. }
  17263. else
  17264. {
  17265. tempIndex = gun_index;
  17266. }
  17267. for (int index = 0; index < AC_QUANTITY; index++)
  17268. {
  17269. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17270. {
  17271. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17272. }
  17273. }// End of for AC_QUANTITY
  17274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17275. }
  17276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17281. }
  17282. //2.9====================================== Voltage L2 ====================================================
  17283. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17284. {
  17285. // AC 3 phase L2 volatge
  17286. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17287. {
  17288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17289. {
  17290. tempIndex = 2;
  17291. }
  17292. else
  17293. {
  17294. tempIndex = gun_index;
  17295. }
  17296. for (int index = 0; index < AC_QUANTITY; index++)
  17297. {
  17298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17299. {
  17300. 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
  17301. }
  17302. } // END OF FOR AC_QUANTITY
  17303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17304. }
  17305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17310. }
  17311. //2.10====================================== Voltage L3 ====================================================
  17312. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17313. {
  17314. // AC 3 phase L3 volatge
  17315. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17316. {
  17317. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17318. {
  17319. tempIndex = 2;
  17320. }
  17321. else
  17322. {
  17323. tempIndex = gun_index;
  17324. }
  17325. for (int index = 0; index < AC_QUANTITY; index++)
  17326. {
  17327. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17328. {
  17329. 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
  17330. }
  17331. } // END OF FOR AC_QUANTITY
  17332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17333. }
  17334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17337. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17338. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17339. }
  17340. //====================== Start SoC ================================
  17341. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17342. {
  17343. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17344. 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))
  17345. {
  17346. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17347. {
  17348. tempIndex = ((gun_index==2) ? 1: 0);
  17349. }
  17350. else
  17351. {
  17352. tempIndex = gun_index;
  17353. }
  17354. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17355. {
  17356. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17357. {
  17358. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17359. {
  17360. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17361. }
  17362. }
  17363. }
  17364. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17365. {
  17366. for (int index = 0; index < CCS_QUANTITY; index++)
  17367. {
  17368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17369. {
  17370. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17371. }
  17372. }
  17373. }
  17374. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17375. {
  17376. for (int index = 0; index < GB_QUANTITY; index++)
  17377. {
  17378. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17379. {
  17380. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17381. }
  17382. }
  17383. }
  17384. else if(gunType[gun_index] == GUN_TYPE_DO)
  17385. {
  17386. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17387. {
  17388. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17389. {
  17390. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17391. }
  17392. }
  17393. }
  17394. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17395. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17397. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17398. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17399. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17400. } // END FOR DC CASE
  17401. }
  17402. //======================================== Message create ==============================================
  17403. json_object *StopTransaction = json_object_new_object();
  17404. json_object *transactionDatas = json_object_new_array();
  17405. json_object *sampledValues = json_object_new_array();
  17406. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17407. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17408. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17409. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17410. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17411. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17412. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17413. {
  17414. json_object *transactionData = json_object_new_object();
  17415. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17416. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17417. {
  17418. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17419. {
  17420. json_object *sampledValue = json_object_new_object();
  17421. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17422. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17423. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17424. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17425. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17426. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17427. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17428. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17429. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17430. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17431. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17432. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17433. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17434. json_object_array_add(sampledValues, sampledValue);
  17435. }
  17436. }
  17437. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17438. json_object_array_add(transactionDatas, transactionData);
  17439. }
  17440. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17441. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17442. ,MESSAGE_TYPE_CALL
  17443. ,guid
  17444. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17445. json_object_put(StopTransaction);
  17446. // Check File "TempStopTransaction" Exist
  17447. if((access(TempStopTransaction,F_OK))!=-1)
  17448. {
  17449. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17450. fclose(fopen(TempStopTransaction, "w"));
  17451. }
  17452. else
  17453. {
  17454. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17455. FILE *log = fopen(TempStopTransaction, "w+");
  17456. if(log == NULL)
  17457. {
  17458. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17459. return ;
  17460. }
  17461. else
  17462. {
  17463. fclose(log);
  17464. }
  17465. }
  17466. //Add TempStopTransaction | Update TempStopTransaction
  17467. // open file for writing
  17468. FILE *outfile;
  17469. outfile = fopen (TempStopTransaction, "a");
  17470. //DEBUG_INFO("data = %s\n", queuedata);
  17471. fputs(queuedata, outfile);
  17472. fputs("\n", outfile);
  17473. fclose (outfile);
  17474. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17475. }
  17476. void checkTempStopTransaction(int gun_index)
  17477. {
  17478. FILE *fptr1;
  17479. char ch;
  17480. char str[QUEUE_MESSAGE_LENGTH]={0};
  17481. char guid[37]={0};
  17482. char tempdata[65]={0};
  17483. char connectorStr[2]={0};
  17484. char TempStopTransaction[256];
  17485. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17486. fptr1 = fopen(TempStopTransaction, "r");
  17487. //TempStopTransaction格式: 槍號,StopTransaction封包
  17488. if (!fptr1)
  17489. {
  17490. //printf(" File not found or unable to open the input file!!\n");
  17491. return ;
  17492. }
  17493. ch=fgetc(fptr1);
  17494. //printf(" Now the content of the file %s is : \n",fname);
  17495. rewind(fptr1);
  17496. if(ch!=EOF)
  17497. {
  17498. // copy all contents to the temporary file except the specific line
  17499. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17500. {
  17501. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17502. if(str[0]=='\0')
  17503. {
  17504. break;
  17505. }
  17506. //TempStopTransaction格式: 槍號,StopTransaction封包
  17507. strncpy(connectorStr, str, 1);
  17508. if(atoi(connectorStr) != (gun_index+1))
  17509. {
  17510. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17511. fclose(fptr1);
  17512. return ;
  17513. }
  17514. //random_uuid(guid);
  17515. strncpy(guid, str+6, 36); //copy guid
  17516. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17517. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17518. {
  17519. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17520. }
  17521. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17522. OCPP_insert_transaction_msg(NO, str);
  17523. memset(str,0,ARRAY_SIZE(str));
  17524. }
  17525. }
  17526. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17527. fclose(fptr1);
  17528. remove(TempStopTransaction); // remove the original file
  17529. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17530. }
  17531. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17532. {
  17533. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17534. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17535. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17536. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17537. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17538. }
  17539. int GetWebSocketPingInterval(void)
  17540. {
  17541. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17542. }
  17543. int GetServerSign(void)
  17544. {
  17545. return server_sign;
  17546. }
  17547. uint8_t GetOcppSecurityProfile()
  17548. {
  17549. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17550. }
  17551. void GetOcppChargerBoxId(uint8_t *data)
  17552. {
  17553. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17554. }
  17555. void GetOcppSecurityPassword(uint8_t *data)
  17556. {
  17557. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17558. }
  17559. void SetOcppVersion(uint8_t *version)
  17560. {
  17561. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17562. DEBUG_INFO("ocpp version: %s\n", version);
  17563. if(strstr((char*)version, "ocpp1.6") != NULL)
  17564. {
  17565. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17566. }
  17567. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17568. {
  17569. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17570. system("pkill OcppBackend");
  17571. }
  17572. }
  17573. void SetServerSign(int value)
  17574. {
  17575. server_sign = value;
  17576. }
  17577. int GetBootNotificationInterval(void)
  17578. {
  17579. return BootNotificationInterval;
  17580. }
  17581. int GetInternetConn(void)
  17582. {
  17583. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17584. }
  17585. int GetBackendConnectionTimeout(void)
  17586. {
  17587. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17588. }
  17589. int isConnectorInitMode(int gun_index)
  17590. {
  17591. int tempIndex = 0;
  17592. int result = TRUE;
  17593. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17594. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17595. {
  17596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17597. {
  17598. tempIndex = ((gun_index==2) ? 1: 0);
  17599. }
  17600. else
  17601. {
  17602. tempIndex = gun_index;
  17603. }
  17604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17605. {
  17606. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17607. {
  17608. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17609. } //end of the same index
  17610. }//end of for CHAdeMO_QUANTITY
  17611. }
  17612. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17613. {
  17614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17615. {
  17616. tempIndex = ((gun_index==2) ? 1: 0);
  17617. }
  17618. else
  17619. {
  17620. tempIndex = gun_index;
  17621. }
  17622. for (int index = 0; index < CCS_QUANTITY; index++)
  17623. {
  17624. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17625. {
  17626. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17627. } //end of the same index
  17628. } // end of for CCS_QUANTITY
  17629. }
  17630. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17631. {
  17632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17633. {
  17634. tempIndex = ((gun_index==2) ? 1: 0);
  17635. }
  17636. else
  17637. {
  17638. tempIndex = gun_index;
  17639. }
  17640. for (int index = 0; index < GB_QUANTITY; index++)
  17641. {
  17642. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17643. {
  17644. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17645. } //end of the same index
  17646. } // end of for GB_QUANTITY
  17647. }
  17648. else if(gunType[gun_index] == GUN_TYPE_DO)
  17649. {
  17650. tempIndex = gun_index;
  17651. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17652. {
  17653. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17654. {
  17655. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17656. } //end of the same index
  17657. }
  17658. }
  17659. else
  17660. {
  17661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17662. {
  17663. tempIndex = 2;
  17664. }
  17665. else
  17666. {
  17667. tempIndex = gun_index;
  17668. }
  17669. for (int index = 0; index < AC_QUANTITY; index++)
  17670. {
  17671. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17672. {
  17673. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17674. }//end of the same index
  17675. }//end of for AC_QUANTITY
  17676. }
  17677. return result;
  17678. }
  17679. void refreshProcDogTimer()
  17680. {
  17681. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17682. }
  17683. void InitialSystemValue(void)
  17684. {
  17685. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17686. locallistVersion=0;
  17687. BootNotificationInterval = 0;
  17688. authorizeRetryTimes = 0;
  17689. GunStatusInterval = 10;
  17690. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17691. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17692. //Hear Beat
  17693. HeartBeatWithNOResponse = 0;
  17694. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17695. FirstHeartBeat = 0;
  17696. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17697. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17698. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17699. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17700. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17701. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17702. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17703. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17704. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17705. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17706. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17707. //Status && ConnectorPlugIn Setting
  17708. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17709. {
  17710. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17711. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17712. }
  17713. for (int index = 0; index < CCS_QUANTITY; index++)
  17714. {
  17715. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17716. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17717. }
  17718. for (int index = 0; index < GB_QUANTITY; index++)
  17719. {
  17720. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17721. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17722. }
  17723. for (int index = 0; index < AC_QUANTITY; index++)
  17724. {
  17725. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17726. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17727. }
  17728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17729. {
  17730. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17731. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17732. }
  17733. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17734. {
  17735. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17736. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17737. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17738. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17739. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17740. }
  17741. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17742. refreshStartTimer(&clientTime.Heartbeat);
  17743. sleep(1);
  17744. }
  17745. void LWS_Send(char *str)
  17746. {
  17747. //=====================================================
  17748. // Check InternetConn 0: disconnected, 1: connected
  17749. //====================================================
  17750. if(GetOcppConnStatus() == 0)
  17751. {
  17752. DEBUG_INFO("offline now !!!\n");
  17753. return;
  17754. }
  17755. // Only disable isWebsocketSendable operation initiated by charger
  17756. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17757. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17758. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17759. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17760. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17761. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17762. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17763. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17764. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17765. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17766. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17767. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17768. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17769. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17770. {
  17771. isWebsocketSendable = 0;
  17772. }
  17773. pthread_mutex_lock(&lock_send);
  17774. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17775. sprintf((char *)SendBuffer, "%s", str);
  17776. SendBufLen = strlen(str);
  17777. pthread_mutex_unlock(&lock_send);
  17778. lws_callback_on_writable(wsi_client);
  17779. //lws_service(context, 0);
  17780. //sleep(1);
  17781. }
  17782. void LWS_SendNow(char *str)
  17783. {
  17784. //=====================================================
  17785. // Check InternetConn 0: disconnected, 1: connected
  17786. //====================================================
  17787. if(GetOcppConnStatus() == 0)
  17788. {
  17789. DEBUG_INFO("offline now !!!\n");
  17790. return;
  17791. }
  17792. // Only disable isWebsocketSendable operation initiated by charger
  17793. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17794. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17795. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17796. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17797. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17798. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17799. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17800. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17801. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17802. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17803. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17804. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17805. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17806. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17807. {
  17808. isWebsocketSendable = 0;
  17809. }
  17810. pthread_mutex_lock(&lock_send);
  17811. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17812. sprintf((char *)SendBuffer, "%s", str);
  17813. SendBufLen = strlen(str);
  17814. pthread_mutex_unlock(&lock_send);
  17815. lws_callback_on_writable(wsi_client);
  17816. lws_service(context, 0);
  17817. //sleep(1);
  17818. }